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 9, 2024
1 parent d704d30 commit 26fbf06
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 @@ -311,7 +310,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 @@ -334,8 +333,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 @@ -359,7 +357,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 @@ -401,7 +399,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 @@ -428,8 +426,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 @@ -461,7 +458,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 @@ -571,7 +568,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 @@ -596,8 +593,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 @@ -627,7 +623,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 @@ -668,7 +664,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 @@ -693,8 +689,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 @@ -724,7 +719,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 @@ -764,7 +759,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 @@ -789,8 +784,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 @@ -821,7 +815,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 @@ -843,7 +837,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 @@ -868,8 +862,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 @@ -900,7 +893,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 @@ -922,7 +915,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 @@ -947,8 +940,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 @@ -979,7 +971,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 @@ -1003,7 +995,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 @@ -1029,8 +1021,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 @@ -1060,7 +1051,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 @@ -1185,7 +1176,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 @@ -1201,16 +1192,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 @@ -1251,16 +1241,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 26fbf06

Please sign in to comment.