Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update qlook module #139

Merged
merged 31 commits into from
Nov 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
223ccf5
#135 Make include positional argument in select.by
astropenguin Nov 18, 2023
2e642b9
#135 Fix wrong (reversed) selections of src and sky
astropenguin Nov 18, 2023
154be12
#135 Fix assign.scan
astropenguin Nov 18, 2023
ebdc85a
#135 Remove inplace option from convert module
astropenguin Nov 19, 2023
5814edc
#135 Load DEMS with common loader
astropenguin Nov 19, 2023
152def1
#135 Use long_name in DEMS as data_type if it exists
astropenguin Nov 19, 2023
e0bbb64
#135 Update channel weight method
astropenguin Nov 19, 2023
835f918
#135 Add common function for saving result
astropenguin Nov 23, 2023
81feaee
#135 Add common function for robust limit
astropenguin Nov 23, 2023
c79e517
#135 Assign sec(Z) when loading DEMS
astropenguin Nov 23, 2023
9b229cd
#135 Update still command using common functions
astropenguin Nov 23, 2023
a5abd2b
#135 Update pswsc command using common functions
astropenguin Nov 23, 2023
ba21e04
#135 Update raster command using common functions
astropenguin Nov 23, 2023
6877361
#135 Update skydip command using common functions
astropenguin Nov 23, 2023
db53cf2
#135 Update zscan command using common functions
astropenguin Nov 23, 2023
b4d34e1
#135 Reorder commands alphabetically
astropenguin Nov 23, 2023
fdfd685
#135 Pin Poetry version (1.7.1)
astropenguin Nov 23, 2023
3218e4b
#135 Fix common function for robust limit
astropenguin Nov 24, 2023
c68da6e
#135 Fix channel weight method
astropenguin Nov 24, 2023
3b0d944
#135 Ignore warnings related to standard deviation
astropenguin Nov 24, 2023
8cec3f8
#135 Fix figure title of raster command
astropenguin Nov 24, 2023
f8b9d41
#135 Fix assigned long_name in load_dems
astropenguin Nov 25, 2023
35ce579
#135 Fix skydip command
astropenguin Nov 25, 2023
7d919ff
#135 Update docstrings of qlook commands
astropenguin Nov 25, 2023
150fddc
#135 Update default MKID IDs to be excluded
astropenguin Nov 25, 2023
39c2c41
#135 Remove unused constants
astropenguin Nov 25, 2023
12feca0
#135 Fix figure title of raster command
astropenguin Nov 25, 2023
9558e0c
#135 Accept DataArray with units as new_units
astropenguin Nov 25, 2023
c1e9b87
#135 Update docstrings of utils.mad
astropenguin Nov 25, 2023
848b5fd
#135 Update package version (2.8.0 → 2.9.0)
astropenguin Nov 25, 2023
ad9ee4d
#135 Update release date
astropenguin Nov 25, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "decode",
"image":"python:3.11",
"onCreateCommand": "pip install poetry==1.6.1",
"onCreateCommand": "pip install poetry==1.7.1",
"postCreateCommand": "poetry install",
"containerEnv": {
"POETRY_VIRTUALENVS_CREATE": "false"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pypi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ jobs:
- uses: actions/setup-python@v4
with:
python-version: "3.11"
- run: pip install poetry && poetry publish --build
- run: pip install poetry==1.7.1 && poetry publish --build
2 changes: 1 addition & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
- run: pip install poetry && poetry install
- run: pip install poetry==1.7.1 && poetry install
- run: black --check decode docs tests
- run: pyright decode docs tests
- run: pytest -v tests
Expand Down
4 changes: 2 additions & 2 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ message: "If you use this software, please cite it as below."

title: "de:code"
abstract: "DESHIMA code for data analysis"
version: 2.8.0
date-released: 2023-11-12
version: 2.9.0
date-released: 2023-11-25
license: "MIT"
doi: "10.5281/zenodo.3384216"
url: "https://github.com/deshima-dev/decode"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ DESHIMA code for data analysis
## Installation

```shell
pip install decode==2.8.0
pip install decode==2.9.0
```
2 changes: 1 addition & 1 deletion decode/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"select",
"utils",
]
__version__ = "2.8.0"
__version__ = "2.9.0"


# submodules
Expand Down
18 changes: 9 additions & 9 deletions decode/assign.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def scan(
dems: xr.DataArray,
/,
*,
by: Literal["state"] = "state",
by: Literal["beam", "scan", "state"] = "state",
dt: Optional[np.timedelta64] = None,
inplace: bool = False,
) -> xr.DataArray:
Expand All @@ -33,16 +33,16 @@ def scan(

"""
if not inplace:
dems = dems.copy()
# deepcopy except for data
dems = dems.copy(data=dems.data)

is_cut = np.zeros_like(dems.scan, dtype=bool)
is_div = xr.zeros_like(dems.scan, dtype=bool)

if by == "state":
state = dems.state.values
is_cut |= np.hstack([False, state[1:] != state[:-1]])
ref = dems.coords[by].data
is_div[1:] |= ref[1:] != ref[:-1]

if dt is not None:
is_cut |= np.hstack([False, np.diff(dems.time) >= dt])
is_div[1:] |= np.diff(dems.time) >= dt

dems.scan.values[:] = np.cumsum(is_cut)
return dems
new_scan = is_div.cumsum().astype(dems.scan.dtype)
return dems.assign_coords(scan=new_scan)
85 changes: 44 additions & 41 deletions decode/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


# standard library
from typing import Optional, Union
from typing import Optional, Sequence, TypeVar, Union


# dependencies
Expand All @@ -12,90 +12,90 @@


# type hints
UnitLike = Union[Unit, str]
T = TypeVar("T")
Multiple = Union[Sequence[T], T]
UnitLike = Union[xr.DataArray, Unit, str]


def coord_units(
da: xr.DataArray,
coord_name: str,
coord_names: Multiple[str],
new_units: UnitLike,
/,
*,
equivalencies: Optional[Equivalency] = None,
) -> xr.DataArray:
"""Convert units of a coordinate of a DataArray.
"""Convert the units of coordinate(s) of a DataArray.

Args:
da: Input DataArray.
coord_name: Name of the coordinate to be converted.
coord_names: Name(s) of the coordinate(s) to be converted.
new_units: Units to be converted from the current ones.
A DataArray that has units attribute is also accepted.
equivalencies: Optional Astropy equivalencies.

Returns:
DataArray with the units of the coordinate converted.

"""
new_coord = units(da[coord_name], new_units, equivalencies=equivalencies)
return da.assign_coords({coord_name: new_coord})
# deepcopy except for data
da = da.copy(data=da.data)

if isinstance(coord_names, str):
coord_names = [coord_names]

def frame(
dems: xr.DataArray,
new_frame: str,
/,
*,
inplace: bool = False,
) -> xr.DataArray:
"""Convert skycoord frame of DEMS.
for coord_name in coord_names:
coord = da.coords[coord_name]
new_coord = units(coord, new_units, equivalencies)
da = da.assign_coords({coord_name: new_coord})

return da


def frame(da: xr.DataArray, new_frame: str, /) -> xr.DataArray:
"""Convert the skycoord frame of a DataArray.

Args:
dems: Target DEMS DataArray.
new_frame: Skycoord frame to be converted from the current ones.
inplace: Whether the skycoord frame are converted in-place.
da: Input DataArray.
new_frame: Frame to be converted from the current one.

Returns:
DEMS DataArray with the skycoord frame converted.
DataArray with the skycoord frame converted.

"""
if not inplace:
# deepcopy except for data
dems = dems.copy(data=dems.data)
# deepcopy except for data
da = da.copy(data=da.data)

if not new_frame == "relative":
raise ValueError("Relative is only available.")

lon, lon_origin = dems["lon"], dems["lon_origin"]
lat, lat_origin = dems["lat"], dems["lat_origin"]
cos = np.cos(Quantity(lat, lat.attrs["units"]).to("rad"))

if lon.attrs["units"] != lon_origin.attrs["units"]:
raise ValueError("Units of lon and lon_origin must be same.")

if lat.attrs["units"] != lat_origin.attrs["units"]:
raise ValueError("Units of lat and lat_origin must be same.")
lon = da.coords["lon"]
lat = da.coords["lat"]
lon_origin = da.coords["lon_origin"]
lat_origin = da.coords["lat_origin"]

# do not change the order below!
lon -= lon_origin
lon *= cos
lat -= lat_origin
lon_origin[:] = 0.0
lat_origin[:] = 0.0
lon -= units(lon_origin, lon)
lon *= np.cos(units(lat, "rad"))
lat -= units(lat_origin, lat)
lon_origin *= 0.0
lat_origin *= 0.0

return dems.assign_coords(frame=dems.frame.copy(False, new_frame))
new_frame = da.frame.copy(data=new_frame)
return da.assign_coords(frame=new_frame)


def units(
da: xr.DataArray,
new_units: UnitLike,
/,
*,
equivalencies: Optional[Equivalency] = None,
) -> xr.DataArray:
"""Convert units of a DataArray.
"""Convert the units of a DataArray.

Args:
da: Input DataArray.
new_units: Units to be converted from the current ones.
A DataArray that has units attribute is also accepted.
equivalencies: Optional Astropy equivalencies.

Returns:
Expand All @@ -105,5 +105,8 @@ def units(
if (units := da.attrs.get("units")) is None:
raise ValueError("Units must exist in DataArray attrs.")

if isinstance(new_units, xr.DataArray):
new_units = new_units.attrs["units"]

new_data = Quantity(da, units).to(new_units, equivalencies)
return da.copy(False, new_data).assign_attrs(units=str(new_units))
return da.copy(data=new_data).assign_attrs(units=new_units)
Loading