Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions sdarray/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@


# submodules
from . import coords
from . import dims
from . import array


# aliases
from .array import Array
9 changes: 9 additions & 0 deletions sdarray/array/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# submodules
from . import array
from . import coords
from . import dims
from . import utils


# aliases
from .array import Array
85 changes: 85 additions & 0 deletions sdarray/array/array.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# standard library
from dataclasses import dataclass
from typing import Any, Tuple


# dependencies
from xarray_dataclasses import AsDataArray, Coordof, Data


# submodules
from . import coords
from . import dims
from .utils import KeywordOnly


# dataclasses
@dataclass
class Array(AsDataArray, KeywordOnly):
"""Common single-dish data structure."""

data: Data[Tuple[dims.time, dims.chan], Any]
"""Two-dimensional array data."""

mask: Coordof[coords.Mask] = False
"""Mask of array data."""

sigma: Coordof[coords.Sigma] = 0.0
"""Uncertainty of array data."""

weight: Coordof[coords.Weight] = 1.0
"""Weight of array data."""

time: Coordof[dims.Time] = "2000-01-01"
"""Start time in UTC."""

obs: Coordof[coords.Obs] = "0"
"""Observation label."""

scan: Coordof[coords.Scan] = "0"
"""Scan label."""

mode: Coordof[coords.Mode] = "0"
"""Mode label."""

exposure: Coordof[coords.Exposure] = 0.0
"""Exposure time."""

interval: Coordof[coords.Interval] = 0.0
"""Interval time."""

longitude: Coordof[coords.Longitude] = 0.0
"""Sky longitude."""

latitude: Coordof[coords.Latitude] = 0.0
"""Sky latitude."""

chan: Coordof[dims.Chan] = 0
"""Channel number."""

beam: Coordof[coords.Beam] = "0"
"""Beam label."""

spw: Coordof[coords.SpW] = "0"
"""Spectral window label."""

pol: Coordof[coords.Pol] = "0"
"""Polarization label."""

lon_offset: Coordof[coords.LonOffset] = 0.0
"""Offset from sky longitude."""

lat_offset: Coordof[coords.LatOffset] = 0.0
"""Offset from sky latitude."""

center_freq: Coordof[coords.CenterFreq] = 0.0
"""Center frequency."""

ref_freq: Coordof[coords.RefFreq] = 0.0
"""Reference frequency."""

resolution: Coordof[coords.Resolution] = 0.0
"""Spectral resolution."""

width: Coordof[coords.Width] = 0.0
"""Channel width."""
159 changes: 73 additions & 86 deletions sdarray/coords.py → sdarray/array/coords.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,3 @@
__all__ = [
"Scan",
"Mode",
"Exposure",
"Interval",
"Longitude",
"Latitude",
"Beam",
"SpW",
"Pol",
"CenterFreq",
"RefFreq",
"Resolution",
"Width",
"LonOffset",
"LatOffset",
"Mask",
"Sigma",
"Weight",
]


# standard library
from dataclasses import dataclass
from typing import Tuple
Expand All @@ -31,15 +9,52 @@


# submodules
from .dims import time, chan
from . import dims


# dataclasses (time-chan data)
@dataclass
class Mask:
"""Mask of array data."""

data: Data[Tuple[dims.time, dims.chan], np.bool_]
long_name: Attr[str] = "Mask for array data"
short_name: Attr[str] = "mask"


@dataclass
class Sigma:
"""Uncertainty of array data."""

data: Data[Tuple[dims.time, dims.chan], np.float64]
long_name: Attr[str] = "Uncertainty of array data"
short_name: Attr[str] = "sigma"


@dataclass
class Weight:
"""Weight of array data."""

data: Data[Tuple[dims.time, dims.chan], np.float64]
long_name: Attr[str] = "Weight for array data"
short_name: Attr[str] = "weight"


# dataclasses (time labels)
@dataclass
class Obs:
"""Observation label."""

data: Data[dims.time, np.str_]
long_name: Attr[str] = "Observation label"
short_name: Attr[str] = "obs"


@dataclass
class Scan:
"""Scan label."""

data: Data[time, np.str_]
data: Data[dims.time, np.str_]
long_name: Attr[str] = "Scan label"
short_name: Attr[str] = "scan"

Expand All @@ -48,17 +63,17 @@ class Scan:
class Mode:
"""Mode label."""

data: Data[time, np.str_]
data: Data[dims.time, np.str_]
long_name: Attr[str] = "Mode label"
short_name: Attr[str] = "mode"


# dataclasses (time observables)
# dataclasses (time data)
@dataclass
class Exposure:
"""Exposure time."""

data: Data[time, np.float64]
data: Data[dims.time, np.float64]
long_name: Attr[str] = "Exposure time"
short_name: Attr[str] = "exposure"
units: Attr[str] = "s"
Expand All @@ -68,7 +83,7 @@ class Exposure:
class Interval:
"""Interval time."""

data: Data[time, np.float64]
data: Data[dims.time, np.float64]
long_name: Attr[str] = "Interval time"
short_name: Attr[str] = "interval"
units: Attr[str] = "s"
Expand All @@ -78,7 +93,7 @@ class Interval:
class Longitude:
"""Sky longitude."""

data: Data[time, np.float64]
data: Data[dims.time, np.float64]
long_name: Attr[str] = "Sky longitude" ""
short_name: Attr[str] = "longitude"
units: Attr[str] = "deg"
Expand All @@ -88,7 +103,7 @@ class Longitude:
class Latitude:
"""Sky latitude."""

data: Data[time, np.float64]
data: Data[dims.time, np.float64]
long_name: Attr[str] = "Sky latitude"
short_name: Attr[str] = "latitude"
units: Attr[str] = "deg"
Expand All @@ -99,7 +114,7 @@ class Latitude:
class Beam:
"""Beam label."""

data: Data[chan, np.str_]
data: Data[dims.chan, np.str_]
long_name: Attr[str] = "Beam label"
short_name: Attr[str] = "beam"

Expand All @@ -108,7 +123,7 @@ class Beam:
class SpW:
"""Spectral window label."""

data: Data[chan, np.str_]
data: Data[dims.chan, np.str_]
long_name: Attr[str] = "Spectral window label"
short_name: Attr[str] = "spw"

Expand All @@ -117,17 +132,37 @@ class SpW:
class Pol:
"""Polarization label."""

data: Data[chan, np.str_]
data: Data[dims.chan, np.str_]
long_name: Attr[str] = "Polarization label"
short_name: Attr[str] = "pol"


# dataclasses (chan observables)
# dataclasses (chan data)
@dataclass
class LonOffset:
"""Offset from sky longitude."""

data: Data[dims.chan, np.float64]
long_name: Attr[str] = "Offset from sky longitude"
short_name: Attr[str] = "lon_offset"
units: Attr[str] = "deg"


@dataclass
class LatOffset:
"""Offset from sky latitude."""

data: Data[dims.chan, np.float64]
long_name: Attr[str] = "Offset from sky latitude"
short_name: Attr[str] = "lat_offset"
units: Attr[str] = "deg"


@dataclass
class CenterFreq:
"""Center frequency."""

data: Data[chan, np.float64]
data: Data[dims.chan, np.float64]
long_name: Attr[str] = "Center frequency"
short_name: Attr[str] = "center_freq"
units: Attr[str] = "Hz"
Expand All @@ -137,7 +172,7 @@ class CenterFreq:
class RefFreq:
"""Reference frequency."""

data: Data[chan, np.float64]
data: Data[dims.chan, np.float64]
long_name: Attr[str] = "Reference frequency"
short_name: Attr[str] = "ref_freq"
units: Attr[str] = "Hz"
Expand All @@ -147,7 +182,7 @@ class RefFreq:
class Resolution:
"""Spectral resolution."""

data: Data[chan, np.float64]
data: Data[dims.chan, np.float64]
long_name: Attr[str] = "Spectral resolution"
short_name: Attr[str] = "resolution"
units: Attr[str] = "Hz"
Expand All @@ -157,55 +192,7 @@ class Resolution:
class Width:
"""Channel width."""

data: Data[chan, np.float64]
data: Data[dims.chan, np.float64]
long_name: Attr[str] = "Channel width"
short_name: Attr[str] = "width"
units: Attr[str] = "Hz"


@dataclass
class LonOffset:
"""Offset from sky longitude."""

data: Data[chan, np.float64]
long_name: Attr[str] = "Offset from sky longitude"
short_name: Attr[str] = "lon_offset"
units: Attr[str] = "deg"


@dataclass
class LatOffset:
"""Offset from sky latitude."""

data: Data[chan, np.float64]
long_name: Attr[str] = "Offset from sky latitude"
short_name: Attr[str] = "lat_offset"
units: Attr[str] = "deg"


# dataclasses (time-chan observables)
@dataclass
class Mask:
"""Mask for an array."""

data: Data[Tuple[time, chan], np.bool_]
long_name: Attr[str] = "Mask for an array"
short_name: Attr[str] = "mask"


@dataclass
class Sigma:
"""Uncertainty of an array."""

data: Data[Tuple[time, chan], np.float64]
long_name: Attr[str] = "Uncertainty of an array"
short_name: Attr[str] = "sigma"


@dataclass
class Weight:
"""Weight for an array."""

data: Data[Tuple[time, chan], np.float64]
long_name: Attr[str] = "Weight for an array"
short_name: Attr[str] = "weight"
Loading