From 05275d2241f221114c145dbccfbf07d0fabe2973 Mon Sep 17 00:00:00 2001 From: Akio Taniguchi Date: Mon, 6 Nov 2023 23:03:30 +0000 Subject: [PATCH 1/5] #116 Update specification for de:code cubes --- decode/make.py | 76 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 64 insertions(+), 12 deletions(-) diff --git a/decode/make.py b/decode/make.py index 518c463..712e637 100644 --- a/decode/make.py +++ b/decode/make.py @@ -10,28 +10,80 @@ import numpy as np import xarray as xr from astropy.units import Quantity -from xarray_dataclasses import AsDataArray, Coord, Data +from xarray_dataclasses import AsDataArray, Attr, Coordof, Data # type hints Angle = Union[Quantity, str] -Chan = Literal["chan"] -Lat = Literal["lat"] -Lon = Literal["lon"] -_ = Tuple[()] +Ch = Literal["chan"] +Lt = Literal["lat"] +Ln = Literal["lon"] + + +@dataclass +class Weight: + data: Data[Tuple[Ch, Lt, Ln], float] + long_name: Attr[str] = "Data weights" + + +@dataclass +class Lon: + data: Data[Ln, float] + long_name: Attr[str] = "Sky longitude" + units: Attr[str] = "deg" + + +@dataclass +class Lat: + data: Data[Lt, float] + long_name: Attr[str] = "Sky latitude" + units: Attr[str] = "deg" + + +@dataclass +class Chan: + data: Data[Ch, int] + long_name: Attr[str] = "Channel ID" + + +@dataclass +class Frame: + data: Data[Tuple[()], str] + long_name: Attr[str] = "Sky coordinate frame" + + +@dataclass +class D2MkidID: + data: Data[Ch, int] + long_name: Attr[str] = "[DESHIMA 2.0] MKID ID" + + +@dataclass +class D2MkidType: + data: Data[Ch, str] + long_name: Attr[str] = "[DESHIMA 2.0] MKID type" + + +@dataclass +class D2MkidFrequency: + data: Data[Ch, float] + long_name: Attr[str] = "[DESHIMA 2.0] MKID center frequency" + units: Attr[str] = "Hz" @dataclass class Cube(AsDataArray): """Cube of DESHIMA 2.0.""" - data: Data[Tuple[Lon, Lat, Chan], Any] - lon: Coord[Lon, float] = 0.0 - lat: Coord[Lat, float] = 0.0 - frame: Coord[_, str] = "altaz" - d2_mkid_frequency: Coord[Chan, float] = 0.0 - d2_mkid_id: Coord[Chan, int] = 0 - d2_mkid_type: Coord[Chan, str] = "" + data: Data[Tuple[Ch, Lt, Ln], Any] + weight: Coordof[Weight] = 1.0 + lon: Coordof[Lon] = 0.0 + lat: Coordof[Lat] = 0.0 + chan: Coordof[Chan] = 0 + frame: Coordof[Frame] = "altaz" + d2_mkid_frequency: Coordof[D2MkidFrequency] = 0.0 + d2_mkid_id: Coordof[D2MkidID] = 0.0 + d2_mkid_type: Coordof[D2MkidType] = "" def cube( From 400c0a6d5e88633aef3183db8add02808648cc3b Mon Sep 17 00:00:00 2001 From: Akio Taniguchi Date: Mon, 6 Nov 2023 23:12:30 +0000 Subject: [PATCH 2/5] #116 Remove wrong sky coordinate conversion in make.cube --- decode/make.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/decode/make.py b/decode/make.py index 712e637..5253e86 100644 --- a/decode/make.py +++ b/decode/make.py @@ -104,12 +104,6 @@ def cube( Cube DataArray. """ - dems = dems.copy() - cos = np.cos(np.deg2rad(dems["lat"])) - dems["lon"] -= dems["lon_origin"] - dems["lat"] -= dems["lat_origin"] - dems["lon"] *= cos - dlon = Quantity(gridsize_lon).to("deg").value dlat = Quantity(gridsize_lat).to("deg").value lon_min = np.floor(dems.lon.min() / dlon) * dlon From bfb7dac9a6de1a2b3754033673eb62b87cfd6db6 Mon Sep 17 00:00:00 2001 From: Akio Taniguchi Date: Tue, 7 Nov 2023 13:13:45 +0000 Subject: [PATCH 3/5] #116 Add skycoord options to make.cube --- decode/make.py | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/decode/make.py b/decode/make.py index 5253e86..fa0f710 100644 --- a/decode/make.py +++ b/decode/make.py @@ -9,20 +9,22 @@ # dependencies import numpy as np import xarray as xr -from astropy.units import Quantity +from astropy.units import Quantity, Unit from xarray_dataclasses import AsDataArray, Attr, Coordof, Data +from . import convert # type hints -Angle = Union[Quantity, str] -Ch = Literal["chan"] -Lt = Literal["lat"] +QuantityLike = Union[Quantity, str] +UnitLike = Union[Unit, str] Ln = Literal["lon"] +Lt = Literal["lat"] +Ch = Literal["chan"] @dataclass class Weight: - data: Data[Tuple[Ch, Lt, Ln], float] + data: Data[Tuple[Ln, Lt, Ch], float] long_name: Attr[str] = "Data weights" @@ -75,7 +77,7 @@ class D2MkidFrequency: class Cube(AsDataArray): """Cube of DESHIMA 2.0.""" - data: Data[Tuple[Ch, Lt, Ln], Any] + data: Data[Tuple[Ln, Lt, Ch], Any] weight: Coordof[Weight] = 1.0 lon: Coordof[Lon] = 0.0 lat: Coordof[Lat] = 0.0 @@ -90,22 +92,22 @@ def cube( dems: xr.DataArray, /, *, - gridsize_lon: Angle = "3 arcsec", - gridsize_lat: Angle = "3 arcsec", + skycoord_grid: QuantityLike = "6 arcsec", + skycoord_units: UnitLike = "arcsec", ) -> xr.DataArray: """Make a cube from DEMS. Args: - dems: Input DEMS DataArray. - gridsize_lon: Grid size of the longitude axis. - gridsize_lat: Grid size of the latitude axis. + dems: Input DEMS DataArray to be converted. + skycoord_grid: Grid size of the sky coordinate axes. + skycoord_units: Units of the sky coordinate axes. Returns: Cube DataArray. """ - dlon = Quantity(gridsize_lon).to("deg").value - dlat = Quantity(gridsize_lat).to("deg").value + dlon = Quantity(skycoord_grid).to(dems.lon.attrs["units"]).values + dlat = Quantity(skycoord_grid).to(dems.lat.attrs["units"]).values lon_min = np.floor(dems.lon.min() / dlon) * dlon lon_max = np.ceil(dems.lon.max() / dlon) * dlon lat_min = np.floor(dems.lat.min() / dlat) * dlat @@ -119,7 +121,7 @@ def cube( j = np.abs(dems.lat - lat).argmin("grid") index = (i + n_lon * j).compute() - dems = dems.copy() + dems = dems.copy(data=dems.data) dems.coords.update({"index": index}) grid = dems.groupby("index").mean("time") @@ -127,7 +129,7 @@ def cube( temp[grid.index.values] = grid.values data = temp.reshape((n_lat, n_lon, n_chan)).swapaxes(0, 1) - return Cube.new( + cube = Cube.new( data=data, lon=lon.values, lat=lat.values, @@ -136,3 +138,6 @@ def cube( d2_mkid_frequency=dems.d2_mkid_frequency.values, d2_mkid_type=dems.d2_mkid_type.values, ) + cube = convert.units(cube, "lon", skycoord_units) + cube = convert.units(cube, "lat", skycoord_units) + return cube From 5f7a6881f9e4185e557d29c3eb5f37988889b666 Mon Sep 17 00:00:00 2001 From: Akio Taniguchi Date: Tue, 7 Nov 2023 13:21:21 +0000 Subject: [PATCH 4/5] =?UTF-8?q?Update=20package=20version=20(2.5.2=20?= =?UTF-8?q?=E2=86=92=202.5.3)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CITATION.cff | 2 +- README.md | 2 +- decode/__init__.py | 2 +- pyproject.toml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CITATION.cff b/CITATION.cff index 669669c..8b5d036 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -3,7 +3,7 @@ message: "If you use this software, please cite it as below." title: "de:code" abstract: "DESHIMA code for data analysis" -version: 2.5.2 +version: 2.5.3 date-released: 2023-11-06 license: "MIT" doi: "10.5281/zenodo.3384216" diff --git a/README.md b/README.md index 8c41f89..4bc9933 100644 --- a/README.md +++ b/README.md @@ -11,5 +11,5 @@ DESHIMA code for data analysis ## Installation ```shell -pip install decode==2.5.2 +pip install decode==2.5.3 ``` diff --git a/decode/__init__.py b/decode/__init__.py index 8f39cf2..71bd62b 100644 --- a/decode/__init__.py +++ b/decode/__init__.py @@ -8,7 +8,7 @@ "plot", "select", ] -__version__ = "2.5.2" +__version__ = "2.5.3" # submodules diff --git a/pyproject.toml b/pyproject.toml index 13c1a04..91e4137 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "decode" -version = "2.5.2" +version = "2.5.3" description = "DESHIMA code for data analysis" authors = ["Akio Taniguchi "] keywords = [ From cd50aa56d817c843538f8f379a0414fba3083298 Mon Sep 17 00:00:00 2001 From: Akio Taniguchi Date: Tue, 7 Nov 2023 13:21:40 +0000 Subject: [PATCH 5/5] #116 Update release date --- CITATION.cff | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CITATION.cff b/CITATION.cff index 8b5d036..f8e228c 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -4,7 +4,7 @@ message: "If you use this software, please cite it as below." title: "de:code" abstract: "DESHIMA code for data analysis" version: 2.5.3 -date-released: 2023-11-06 +date-released: 2023-11-07 license: "MIT" doi: "10.5281/zenodo.3384216" url: "https://github.com/deshima-dev/decode"