Skip to content

Commit

Permalink
#141 Merge pull request from deshima-dev/astropenguin/issue140
Browse files Browse the repository at this point in the history
Fix qlook module
  • Loading branch information
astropenguin committed Nov 25, 2023
2 parents e8bdfff + 4e4f896 commit bec117c
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 35 deletions.
2 changes: 1 addition & 1 deletion CITATION.cff
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -11,5 +11,5 @@ DESHIMA code for data analysis
## Installation

```shell
pip install decode==2.9.0
pip install decode==2.9.1
```
2 changes: 1 addition & 1 deletion decode/__init__.py
Expand Up @@ -10,7 +10,7 @@
"select",
"utils",
]
__version__ = "2.9.0"
__version__ = "2.9.1"


# submodules
Expand Down
62 changes: 31 additions & 31 deletions decode/qlook.py
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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,
/,
*,
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion 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 <taniguchi@a.phys.nagoya-u.ac.jp>"]
keywords = [
Expand Down

0 comments on commit bec117c

Please sign in to comment.