diff --git a/CITATION.cff b/CITATION.cff index 3d24c7b..0f817e8 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.9.0 +version: 2.9.1 date-released: 2023-11-25 license: "MIT" doi: "10.5281/zenodo.3384216" diff --git a/README.md b/README.md index fc2b423..6b561b2 100644 --- a/README.md +++ b/README.md @@ -11,5 +11,5 @@ DESHIMA code for data analysis ## Installation ```shell -pip install decode==2.9.0 +pip install decode==2.9.1 ``` diff --git a/decode/__init__.py b/decode/__init__.py index 3277d48..e4f640e 100644 --- a/decode/__init__.py +++ b/decode/__init__.py @@ -10,7 +10,7 @@ "select", "utils", ] -__version__ = "2.9.0" +__version__ = "2.9.1" # submodules diff --git a/decode/qlook.py b/decode/qlook.py index e5cec6c..53649f2 100644 --- a/decode/qlook.py +++ b/decode/qlook.py @@ -162,7 +162,7 @@ def raster( da_sub = da_on - da_base.values # make continuum series - weight = calc_chan_weight(da_off, method=chan_weight, pwv=pwv) + weight = get_chan_weight(da_off, method=chan_weight, pwv=pwv) series = da_sub.weighted(weight.fillna(0)).mean("chan") # make continuum map @@ -174,7 +174,7 @@ def raster( cont = cube.weighted(weight.fillna(0)).mean("chan") # save result - filename = Path(dems).with_suffix(f".pswsc.{format}").name + filename = Path(dems).with_suffix(f".raster.{format}").name if format in DATA_FORMATS: return save_qlook(cont, Path(outdir) / filename) @@ -251,7 +251,7 @@ def skydip( # make continuum series da_on = select.by(da, "state", include="SCAN") da_off = select.by(da, "state", exclude="SCAN") - weight = calc_chan_weight(da_off, method=chan_weight, pwv=pwv) + weight = get_chan_weight(da_off, method=chan_weight, pwv=pwv) series = da_on.weighted(weight.fillna(0)).mean("chan") # save result @@ -321,7 +321,7 @@ def still( # make continuum series da_off = select.by(da, "state", exclude=["ON", "SCAN"]) - weight = calc_chan_weight(da_off, method=chan_weight, pwv=pwv) + weight = get_chan_weight(da_off, method=chan_weight, pwv=pwv) series = da.weighted(weight.fillna(0)).mean("chan") # save result @@ -392,10 +392,10 @@ def zscan( # make continuum series da_on = select.by(da, "state", include="ON") da_off = select.by(da, "state", exclude="ON") - weight = calc_chan_weight(da_off, method=chan_weight, pwv=pwv) + weight = get_chan_weight(da_off, method=chan_weight, pwv=pwv) series = da_on.weighted(weight.fillna(0)).mean("chan") - # save output + # save result filename = Path(dems).with_suffix(f".zscan.{format}").name if format in DATA_FORMATS: @@ -417,7 +417,31 @@ def zscan( return save_qlook(fig, Path(outdir) / filename) -def calc_chan_weight( +def mean_in_time(dems: xr.DataArray) -> xr.DataArray: + """Similar to DataArray.mean but keeps middle time.""" + middle = dems[len(dems) // 2 : len(dems) // 2 + 1] + return xr.zeros_like(middle) + dems.mean("time") + + +def subtract_per_scan(dems: xr.DataArray) -> xr.DataArray: + """Apply source-sky subtraction to a single-scan DEMS.""" + if len(states := np.unique(dems.state)) != 1: + raise ValueError("State must be unique.") + + if (state := states[0]) == "ON": + src = select.by(dems, "beam", include="A") + sky = select.by(dems, "beam", include="B") + return src.mean("time") - sky.mean("time").data + + if state == "OFF": + src = select.by(dems, "beam", include="B") + sky = select.by(dems, "beam", include="A") + return src.mean("time") - sky.mean("time").data + + raise ValueError("State must be either ON or OFF.") + + +def get_chan_weight( dems: xr.DataArray, /, *, @@ -459,30 +483,6 @@ def calc_chan_weight( raise ValueError("Method must be either uniform, std, or std/tx.") -def mean_in_time(dems: xr.DataArray) -> xr.DataArray: - """Similar to DataArray.mean but keeps middle time.""" - middle = dems[len(dems) // 2 : len(dems) // 2 + 1] - return xr.zeros_like(middle) + dems.mean("time") - - -def subtract_per_scan(dems: xr.DataArray) -> xr.DataArray: - """Apply source-sky subtraction to a single-scan DEMS.""" - if len(states := np.unique(dems.state)) != 1: - raise ValueError("State must be unique.") - - if (state := states[0]) == "ON": - src = select.by(dems, "beam", include="A") - sky = select.by(dems, "beam", include="B") - return src.mean("time") - sky.mean("time").data - - if state == "OFF": - src = select.by(dems, "beam", include="B") - sky = select.by(dems, "beam", include="A") - return src.mean("time") - sky.mean("time").data - - raise ValueError("State must be either ON or OFF.") - - def get_robust_lim(da: xr.DataArray) -> tuple[float, float]: """Calculate a robust limit for plotting.""" sigma = SIGMA_OVER_MAD * utils.mad(da) diff --git a/pyproject.toml b/pyproject.toml index edde958..360c19a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "decode" -version = "2.9.0" +version = "2.9.1" description = "DESHIMA code for data analysis" authors = ["Akio Taniguchi "] keywords = [