Skip to content

Commit

Permalink
#189 Update options of qlook commands (data_type → measure)
Browse files Browse the repository at this point in the history
  • Loading branch information
astropenguin committed Aug 10, 2024
1 parent 3da7c1a commit cf46a8b
Showing 1 changed file with 32 additions and 51 deletions.
83 changes: 32 additions & 51 deletions decode/qlook.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

# constants
DATA_FORMATS = "csv", "nc", "zarr", "zarr.zip"
DEFAULT_DATA_TYPE = "auto"
DEFAULT_DEBUG = False
DEFAULT_FIGSIZE = 12, 4
DEFAULT_FORMAT = "png"
Expand All @@ -42,6 +41,7 @@
DEFAULT_INCL_MKID_IDS = None
DEFAULT_MIN_FREQUENCY = None
DEFAULT_MAX_FREQUENCY = None
DEFAULT_MEASURE = "brightness"
DEFAULT_ROLLING_TIME = 200
DEFAULT_OUTDIR = Path()
DEFAULT_OVERWRITE = False
Expand Down Expand Up @@ -122,7 +122,7 @@ def daisy(
exclude_mkid_ids: Optional[Sequence[int]] = DEFAULT_EXCL_MKID_IDS,
min_frequency: Optional[str] = DEFAULT_MIN_FREQUENCY,
max_frequency: Optional[str] = DEFAULT_MAX_FREQUENCY,
data_type: Literal["auto", "brightness", "df/f"] = DEFAULT_DATA_TYPE,
measure: Literal["brightness", "df/f"] = DEFAULT_MEASURE,
# options for analysis
rolling_time: int = DEFAULT_ROLLING_TIME,
source_radius: str = "60 arcsec",
Expand Down Expand Up @@ -151,8 +151,7 @@ def daisy(
Defaults to no minimum frequency bound.
max_frequency: Maximum frequency to be included in analysis.
Defaults to no maximum frequency bound.
data_type: Data type of the input DEMS file.
Defaults to the ``long_name`` attribute in it.
measure: Measure in analysis (either ``'brightness'`` or ``'df/f'``).
rolling_time: Moving window size.
source_radius: Radius of the on-source area.
Other areas are considered off-source in sky subtraction.
Expand Down Expand Up @@ -187,7 +186,7 @@ def daisy(
exclude_mkid_ids=exclude_mkid_ids,
min_frequency=min_frequency,
max_frequency=max_frequency,
data_type=data_type,
measure=measure,
skycoord_units=skycoord_units,
)
da = select.by(da, "state", exclude="GRAD")
Expand Down Expand Up @@ -312,7 +311,7 @@ def pswsc(
exclude_mkid_ids: Optional[Sequence[int]] = DEFAULT_EXCL_MKID_IDS,
min_frequency: Optional[str] = DEFAULT_MIN_FREQUENCY,
max_frequency: Optional[str] = DEFAULT_MAX_FREQUENCY,
data_type: Literal["auto", "brightness", "df/f"] = DEFAULT_DATA_TYPE,
measure: Literal["brightness", "df/f"] = DEFAULT_MEASURE,
frequency_units: str = DEFAULT_FREQUENCY_UNITS,
# options for saving
format: str = DEFAULT_FORMAT,
Expand All @@ -335,8 +334,7 @@ def pswsc(
Defaults to no minimum frequency bound.
max_frequency: Maximum frequency to be included in analysis.
Defaults to no maximum frequency bound.
data_type: Data type of the input DEMS file.
Defaults to the ``long_name`` attribute in it.
measure: Measure in analysis (either ``'brightness'`` or ``'df/f'``).
frequency_units: Units of the frequency axis.
format: Output data format of the quick-look result.
outdir: Output directory for the quick-look result.
Expand All @@ -360,7 +358,7 @@ def pswsc(
exclude_mkid_ids=exclude_mkid_ids,
min_frequency=min_frequency,
max_frequency=max_frequency,
data_type=data_type,
measure=measure,
frequency_units=frequency_units,
)

Expand Down Expand Up @@ -402,7 +400,7 @@ def raster(
exclude_mkid_ids: Optional[Sequence[int]] = DEFAULT_EXCL_MKID_IDS,
min_frequency: Optional[str] = DEFAULT_MIN_FREQUENCY,
max_frequency: Optional[str] = DEFAULT_MAX_FREQUENCY,
data_type: Literal["auto", "brightness", "df/f"] = DEFAULT_DATA_TYPE,
measure: Literal["brightness", "df/f"] = DEFAULT_MEASURE,
# options for analysis
chan_weight: Literal["uniform", "std", "std/tx"] = "std/tx",
pwv: Literal["0.5", "1.0", "2.0", "3.0", "4.0", "5.0"] = "5.0",
Expand All @@ -429,8 +427,7 @@ def raster(
Defaults to no minimum frequency bound.
max_frequency: Maximum frequency to be included in analysis.
Defaults to no maximum frequency bound.
data_type: Data type of the input DEMS file.
Defaults to the ``long_name`` attribute in it.
measure: Measure in analysis (either ``'brightness'`` or ``'df/f'``).
chan_weight: Weighting method along the channel axis.
uniform: Uniform weight (i.e. no channel dependence).
std: Inverse square of temporal standard deviation of sky.
Expand Down Expand Up @@ -462,7 +459,7 @@ def raster(
exclude_mkid_ids=exclude_mkid_ids,
min_frequency=min_frequency,
max_frequency=max_frequency,
data_type=data_type,
measure=measure,
skycoord_units=skycoord_units,
)

Expand Down Expand Up @@ -573,7 +570,7 @@ def skydip(
exclude_mkid_ids: Optional[Sequence[int]] = DEFAULT_EXCL_MKID_IDS,
min_frequency: Optional[str] = DEFAULT_MIN_FREQUENCY,
max_frequency: Optional[str] = DEFAULT_MAX_FREQUENCY,
data_type: Literal["auto", "brightness", "df/f"] = DEFAULT_DATA_TYPE,
measure: Literal["brightness", "df/f"] = DEFAULT_MEASURE,
# options for analysis
chan_weight: Literal["uniform", "std", "std/tx"] = "std/tx",
pwv: Literal["0.5", "1.0", "2.0", "3.0", "4.0", "5.0"] = "5.0",
Expand All @@ -598,8 +595,7 @@ def skydip(
Defaults to no minimum frequency bound.
max_frequency: Maximum frequency to be included in analysis.
Defaults to no maximum frequency bound.
data_type: Data type of the input DEMS file.
Defaults to the ``long_name`` attribute in it.
measure: Measure in analysis (either ``'brightness'`` or ``'df/f'``).
chan_weight: Weighting method along the channel axis.
uniform: Uniform weight (i.e. no channel dependence).
std: Inverse square of temporal standard deviation of sky.
Expand Down Expand Up @@ -629,7 +625,7 @@ def skydip(
exclude_mkid_ids=exclude_mkid_ids,
min_frequency=min_frequency,
max_frequency=max_frequency,
data_type=data_type,
measure=measure,
)

# make continuum series
Expand Down Expand Up @@ -670,7 +666,7 @@ def still(
exclude_mkid_ids: Optional[Sequence[int]] = DEFAULT_EXCL_MKID_IDS,
min_frequency: Optional[str] = DEFAULT_MIN_FREQUENCY,
max_frequency: Optional[str] = DEFAULT_MAX_FREQUENCY,
data_type: Literal["auto", "brightness", "df/f"] = DEFAULT_DATA_TYPE,
measure: Literal["brightness", "df/f"] = DEFAULT_MEASURE,
# options for analysis
chan_weight: Literal["uniform", "std", "std/tx"] = "std/tx",
pwv: Literal["0.5", "1.0", "2.0", "3.0", "4.0", "5.0"] = "5.0",
Expand All @@ -695,8 +691,7 @@ def still(
Defaults to no minimum frequency bound.
max_frequency: Maximum frequency to be included in analysis.
Defaults to no maximum frequency bound.
data_type: Data type of the input DEMS file.
Defaults to the ``long_name`` attribute in it.
measure: Measure in analysis (either ``'brightness'`` or ``'df/f'``).
chan_weight: Weighting method along the channel axis.
uniform: Uniform weight (i.e. no channel dependence).
std: Inverse square of temporal standard deviation of sky.
Expand Down Expand Up @@ -726,7 +721,7 @@ def still(
exclude_mkid_ids=exclude_mkid_ids,
min_frequency=min_frequency,
max_frequency=max_frequency,
data_type=data_type,
measure=measure,
)

# make continuum series
Expand Down Expand Up @@ -766,7 +761,7 @@ def xscan(
exclude_mkid_ids: Optional[Sequence[int]] = DEFAULT_EXCL_MKID_IDS,
min_frequency: Optional[str] = DEFAULT_MIN_FREQUENCY,
max_frequency: Optional[str] = DEFAULT_MAX_FREQUENCY,
data_type: Literal["auto", "brightness", "df/f"] = DEFAULT_DATA_TYPE,
measure: Literal["brightness", "df/f"] = DEFAULT_MEASURE,
# options for analysis
chan_weight: Literal["uniform", "std", "std/tx"] = "std/tx",
pwv: Literal["0.5", "1.0", "2.0", "3.0", "4.0", "5.0"] = "5.0",
Expand All @@ -791,8 +786,7 @@ def xscan(
Defaults to no minimum frequency bound.
max_frequency: Maximum frequency to be included in analysis.
Defaults to no maximum frequency bound.
data_type: Data type of the input DEMS file.
Defaults to the ``long_name`` attribute in it.
measure: Measure in analysis (either ``'brightness'`` or ``'df/f'``).
chan_weight: Weighting method along the channel axis.
uniform: Uniform weight (i.e. no channel dependence).
std: Inverse square of temporal standard deviation of sky.
Expand Down Expand Up @@ -823,7 +817,7 @@ def xscan(
exclude_mkid_ids=exclude_mkid_ids,
min_frequency=min_frequency,
max_frequency=max_frequency,
data_type=data_type,
measure=measure,
# options for analysis
chan_weight=chan_weight,
pwv=pwv,
Expand All @@ -845,7 +839,7 @@ def yscan(
exclude_mkid_ids: Optional[Sequence[int]] = DEFAULT_EXCL_MKID_IDS,
min_frequency: Optional[str] = DEFAULT_MIN_FREQUENCY,
max_frequency: Optional[str] = DEFAULT_MAX_FREQUENCY,
data_type: Literal["auto", "brightness", "df/f"] = DEFAULT_DATA_TYPE,
measure: Literal["brightness", "df/f"] = DEFAULT_MEASURE,
# options for analysis
chan_weight: Literal["uniform", "std", "std/tx"] = "std/tx",
pwv: Literal["0.5", "1.0", "2.0", "3.0", "4.0", "5.0"] = "5.0",
Expand All @@ -870,8 +864,7 @@ def yscan(
Defaults to no minimum frequency bound.
max_frequency: Maximum frequency to be included in analysis.
Defaults to no maximum frequency bound.
data_type: Data type of the input DEMS file.
Defaults to the ``long_name`` attribute in it.
measure: Measure in analysis (either ``'brightness'`` or ``'df/f'``).
chan_weight: Weighting method along the channel axis.
uniform: Uniform weight (i.e. no channel dependence).
std: Inverse square of temporal standard deviation of sky.
Expand Down Expand Up @@ -902,7 +895,7 @@ def yscan(
exclude_mkid_ids=exclude_mkid_ids,
min_frequency=min_frequency,
max_frequency=max_frequency,
data_type=data_type,
measure=measure,
# options for analysis
chan_weight=chan_weight,
pwv=pwv,
Expand All @@ -924,7 +917,7 @@ def zscan(
exclude_mkid_ids: Optional[Sequence[int]] = DEFAULT_EXCL_MKID_IDS,
min_frequency: Optional[str] = DEFAULT_MIN_FREQUENCY,
max_frequency: Optional[str] = DEFAULT_MAX_FREQUENCY,
data_type: Literal["auto", "brightness", "df/f"] = DEFAULT_DATA_TYPE,
measure: Literal["brightness", "df/f"] = DEFAULT_MEASURE,
# options for analysis
chan_weight: Literal["uniform", "std", "std/tx"] = "std/tx",
pwv: Literal["0.5", "1.0", "2.0", "3.0", "4.0", "5.0"] = "5.0",
Expand All @@ -949,8 +942,7 @@ def zscan(
Defaults to no minimum frequency bound.
max_frequency: Maximum frequency to be included in analysis.
Defaults to no maximum frequency bound.
data_type: Data type of the input DEMS file.
Defaults to the ``long_name`` attribute in it.
measure: Measure in analysis (either ``'brightness'`` or ``'df/f'``).
chan_weight: Weighting method along the channel axis.
uniform: Uniform weight (i.e. no channel dependence).
std: Inverse square of temporal standard deviation of sky.
Expand Down Expand Up @@ -981,7 +973,7 @@ def zscan(
exclude_mkid_ids=exclude_mkid_ids,
min_frequency=min_frequency,
max_frequency=max_frequency,
data_type=data_type,
measure=measure,
# options for analysis
chan_weight=chan_weight,
pwv=pwv,
Expand All @@ -1005,7 +997,7 @@ def _scan(
exclude_mkid_ids: Optional[Sequence[int]] = DEFAULT_EXCL_MKID_IDS,
min_frequency: Optional[str] = DEFAULT_MIN_FREQUENCY,
max_frequency: Optional[str] = DEFAULT_MAX_FREQUENCY,
data_type: Literal["auto", "brightness", "df/f"] = DEFAULT_DATA_TYPE,
measure: Literal["brightness", "df/f"] = DEFAULT_MEASURE,
# options for analysis
chan_weight: Literal["uniform", "std", "std/tx"] = "std/tx",
pwv: Literal["0.5", "1.0", "2.0", "3.0", "4.0", "5.0"] = "5.0",
Expand All @@ -1031,8 +1023,7 @@ def _scan(
Defaults to no minimum frequency bound.
max_frequency: Maximum frequency to be included in analysis.
Defaults to no maximum frequency bound.
data_type: Data type of the input DEMS file.
Defaults to the ``long_name`` attribute in it.
measure: Measure in analysis (either ``'brightness'`` or ``'df/f'``).
chan_weight: Weighting method along the channel axis.
uniform: Uniform weight (i.e. no channel dependence).
std: Inverse square of temporal standard deviation of sky.
Expand Down Expand Up @@ -1062,7 +1053,7 @@ def _scan(
exclude_mkid_ids=exclude_mkid_ids,
min_frequency=min_frequency,
max_frequency=max_frequency,
data_type=data_type,
measure=measure,
)

# make continuum series
Expand Down Expand Up @@ -1187,7 +1178,7 @@ def load_dems(
exclude_mkid_ids: Optional[Sequence[int]] = DEFAULT_EXCL_MKID_IDS,
min_frequency: Optional[str] = DEFAULT_MIN_FREQUENCY,
max_frequency: Optional[str] = DEFAULT_MAX_FREQUENCY,
data_type: Literal["auto", "brightness", "df/f"] = DEFAULT_DATA_TYPE,
measure: Literal["brightness", "df/f"] = DEFAULT_MEASURE,
frequency_units: str = DEFAULT_FREQUENCY_UNITS,
skycoord_units: str = DEFAULT_SKYCOORD_UNITS,
) -> xr.DataArray:
Expand All @@ -1203,16 +1194,15 @@ def load_dems(
Defaults to no minimum frequency bound.
max_frequency: Maximum frequency to be included in analysis.
Defaults to no maximum frequency bound.
data_type: Data type of the input DEMS file.
Defaults to the ``long_name`` attribute in it.
measure: Measure of the DataArray (either brightness or df/f).
frequency_units: Units of the frequency.
skycoord_units: Units of the sky coordinate axes.
Returns:
DEMS as a DataArray with given conversion and selections.
"""
da = load.dems(dems, chunks=None)
da = load.dems(dems, measure=measure, chunks=None)

if min_frequency is not None:
min_frequency = Quantity(min_frequency).to(frequency_units).value
Expand Down Expand Up @@ -1253,16 +1243,7 @@ def load_dems(
max=max_frequency,
)

if data_type == "auto" and "units" in da.attrs:
return da

if data_type == "brightness":
return da.assign_attrs(long_name="Brightness", units="K")

if data_type == "df/f":
return da.assign_attrs(long_name="df/f", units="dimensionless")

raise ValueError("Data type could not be inferred.")
return da


def save_qlook(
Expand Down

0 comments on commit cf46a8b

Please sign in to comment.