Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions mapcat/database/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,31 @@
Table definitions
"""

from .atomic_coadd import AtomicMapCoaddTable
from .atomic_map import AtomicMapTable
from .depth_one_coadd import DepthOneCoaddTable
from .depth_one_map import DepthOneMapTable
from .pipeline_information import PipelineInformationTable
from .pointing_residual import PointingResidualTable
from .sky_coverage import SkyCoverageTable
from .time_domain_processing import TimeDomainProcessingTable
from .tod import TODDepthOneTable
from .planet_map import PlanetMapTable
from .planet_todfit import PlanetTodFitTable

Check failure on line 15 in mapcat/database/__init__.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (unsorted-imports)

mapcat/database/__init__.py:5:1: unsorted-imports: Import block is un-sorted or un-formatted help: Organize imports

Check failure on line 15 in mapcat/database/__init__.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (unsorted-imports)

mapcat/database/__init__.py:5:1: unsorted-imports: Import block is un-sorted or un-formatted help: Organize imports

__all__ = [
"AtomicMapCoaddTable",
"AtomicMapTable",
"DepthOneCoaddTable",
"DepthOneMapTable",
"PipelineInformationTable",
"PointingResidualTable",
"SkyCoverageTable",
"TODDepthOneTable",
"TimeDomainProcessingTable",
"PlanetMapTable",
"PlanetTodFitTable",
]

Check failure on line 29 in mapcat/database/__init__.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (unsorted-dunder-all)

mapcat/database/__init__.py:17:11: unsorted-dunder-all: `__all__` is not sorted help: Apply an isort-style sorting to `__all__`

Check failure on line 29 in mapcat/database/__init__.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (unsorted-dunder-all)

mapcat/database/__init__.py:17:11: unsorted-dunder-all: `__all__` is not sorted help: Apply an isort-style sorting to `__all__`

ALL_TABLES = [
AtomicMapTable,
Expand All @@ -34,4 +38,6 @@
TODDepthOneTable,
PipelineInformationTable,
SkyCoverageTable,
PlanetMapTable,
PlanetTodFitTable,
]
176 changes: 176 additions & 0 deletions mapcat/database/planet_map.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
"""
Table for planet maps.
"""

from datetime import datetime
from typing import TYPE_CHECKING, Any

Check failure on line 6 in mapcat/database/planet_map.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (unused-import)

mapcat/database/planet_map.py:6:20: unused-import: `typing.TYPE_CHECKING` imported but unused help: Remove unused import: `typing.TYPE_CHECKING`

Check failure on line 6 in mapcat/database/planet_map.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (unused-import)

mapcat/database/planet_map.py:6:20: unused-import: `typing.TYPE_CHECKING` imported but unused help: Remove unused import: `typing.TYPE_CHECKING`
import json

Check failure on line 7 in mapcat/database/planet_map.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (unused-import)

mapcat/database/planet_map.py:7:8: unused-import: `json` imported but unused help: Remove unused import: `json`

Check failure on line 7 in mapcat/database/planet_map.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (unused-import)

mapcat/database/planet_map.py:7:8: unused-import: `json` imported but unused help: Remove unused import: `json`

from astropy.time import Time
from astropydantic import AstroPydanticTime
from sqlmodel import Field, Relationship, SQLModel

Check failure on line 11 in mapcat/database/planet_map.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (unused-import)

mapcat/database/planet_map.py:11:29: unused-import: `sqlmodel.Relationship` imported but unused help: Remove unused import: `sqlmodel.Relationship`

Check failure on line 11 in mapcat/database/planet_map.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (unused-import)

mapcat/database/planet_map.py:11:29: unused-import: `sqlmodel.Relationship` imported but unused help: Remove unused import: `sqlmodel.Relationship`
from sqlalchemy import Column, JSON

Check failure on line 12 in mapcat/database/planet_map.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (unsorted-imports)

mapcat/database/planet_map.py:5:1: unsorted-imports: Import block is un-sorted or un-formatted help: Organize imports

Check failure on line 12 in mapcat/database/planet_map.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (unsorted-imports)

mapcat/database/planet_map.py:5:1: unsorted-imports: Import block is un-sorted or un-formatted help: Organize imports

class PlanetMap(SQLModel):
obs_id: str
telescope: str
freq_channel: str
wafer: str
ctime: AstroPydanticTime
dtime: datetime
source: str

hit_path: str | None
map_path: str | None
weight_path: str | None
weighted_map_path: str | None

azimuth: float | None
elevation: float | None
duration: float| None
pwv: float | None
pwv_std: float | None
pwv_p2p: float | None
pwv_apex: float | None
pwv_apex_std: float | None
pwv_apex_p2p: float | None

f_hwp: float | None
roll_angle: float | None
scan_speed: float | None
scan_acc: float | None
sun_distance: float | None
moon_distance: float | None
wind_speed: float | None
wind_direction: float | None
ambient_temperature: float | None
uv: float | None

detnum_before_fitselection: int | None
total_detnum: int | None
recenter: bool | None
yc: float | None
xc: float | None

Tmap_variance: float | None
Qmap_variance: float | None
Umap_variance: float | None

proc: dict[str, Any] | list[Any] | None = None
detnum: list[int] | None = None
detid: list[str] | None = None


class PlanetMapTable(SQLModel, table=True):
__tablename__ = "planet_map"

obs_id: str = Field(primary_key=True)
telescope: str = Field(primary_key=True)
freq_channel: str = Field(primary_key=True)
wafer: str = Field(primary_key=True)
ctime: float = Field(nullable=False, primary_key=True)
source: str = Field(primary_key=True)
dtime: datetime = Field()

hit_path: str | None = Field()
map_path: str | None = Field()
weight_path: str | None = Field()
weighted_map_path: str | None = Field()

elevation: float | None = Field()
duration: float | None = Field()
azimuth: float | None = Field()
pwv: float | None = Field()
pwv_std: float | None = Field()
pwv_p2p: float | None = Field()
pwv_apex: float | None = Field()
pwv_apex_std: float | None = Field()
pwv_apex_p2p: float | None = Field()
f_hwp: float | None = Field()
roll_angle: float | None = Field()
scan_speed: float | None = Field()
scan_acc: float | None = Field()
sun_distance: float | None = Field()
moon_distance: float | None = Field()
wind_speed: float | None = Field()
wind_direction: float | None = Field()
ambient_temperature: float | None = Field()
uv: float | None = Field()

detnum_before_fitselection: int | None = Field()
total_detnum: int | None = Field()
recenter: bool | None = Field()
yc: float | None = Field()
xc: float | None = Field()

Tmap_variance: float | None = Field()
Qmap_variance: float | None = Field()
Umap_variance: float | None = Field()

proc: dict[str, Any] | list[Any] | None = Field(
default=None,
sa_column=Column(JSON, nullable=True),
)
detnum: list[int] | None = Field(
default=None,
sa_column=Column(JSON, nullable=True),
)
detid: list[str] | None = Field(
default=None,
sa_column=Column(JSON, nullable=True),
)



def to_model(self) -> PlanetMap:
"""
Return an PlanetMap model from this table entry.

Returns
-------
PlanetMap : PlanetMap
The PlanetMap model corresponding to this table entry.
"""
return PlanetMap(
obs_id=self.obs_id,
telescope=self.telescope,
freq_channel=self.freq_channel,
wafer=self.wafer,
ctime=Time(self.ctime, format="unix", scale="utc"),
dtime=self.dtime,
source=self.source,
hit_path=self.hit_path,
map_path=self.map_path,
weight_path=self.weight_path,
weighted_map_path=self.weight_map_path,
azimuth=self.azimuth,
elevation=self.elevation,
duration=self.duration,
pwv=self.pwv,
pwv_std=self.pwv_std,
pwv_p2p=self.pwv_p2p,
pwv_apex=self.pwv_apex,
pwv_apex_std=self.pwv_apex_std,
pwv_apex_p2p=self.pwv_apex_p2p,
f_hwp=self.f_hwp,
roll_angle=self.roll_angle,
scan_speed=self.scan_speed,
scan_acc=self.scan_acc,
sun_distance=self.sun_distance,
moon_distance=self.moon_distance,
wind_speed=self.wind_speed,
wind_direction=self.wind_direction,
ambient_temperature=self.ambient_temperature,
uv=self.uv,
detnum_before_fitselection=self.detnum_before_fitselection,
total_detnum=self.total_detnum,
recenter=self.recenter,
yc=self.yc,
xc=self.xc,
Tmap_variance=self.Tmap_variance,
Qmap_variance=self.Qmap_variance,
Umap_variance=self.Umap_variance,
proc=self.proc,
detnum=self.detnum,
detid=self.detid,
)
120 changes: 120 additions & 0 deletions mapcat/database/planet_todfit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
"""
Table for planet todfit.
"""

from datetime import datetime
from typing import TYPE_CHECKING, Any

Check failure on line 6 in mapcat/database/planet_todfit.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (unused-import)

mapcat/database/planet_todfit.py:6:35: unused-import: `typing.Any` imported but unused help: Remove unused import

Check failure on line 6 in mapcat/database/planet_todfit.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (unused-import)

mapcat/database/planet_todfit.py:6:20: unused-import: `typing.TYPE_CHECKING` imported but unused help: Remove unused import

Check failure on line 6 in mapcat/database/planet_todfit.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (unused-import)

mapcat/database/planet_todfit.py:6:35: unused-import: `typing.Any` imported but unused help: Remove unused import

Check failure on line 6 in mapcat/database/planet_todfit.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (unused-import)

mapcat/database/planet_todfit.py:6:20: unused-import: `typing.TYPE_CHECKING` imported but unused help: Remove unused import
import json

Check failure on line 7 in mapcat/database/planet_todfit.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (unused-import)

mapcat/database/planet_todfit.py:7:8: unused-import: `json` imported but unused help: Remove unused import: `json`

Check failure on line 7 in mapcat/database/planet_todfit.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (unused-import)

mapcat/database/planet_todfit.py:7:8: unused-import: `json` imported but unused help: Remove unused import: `json`

from astropy.time import Time
from astropydantic import AstroPydanticTime
from sqlmodel import Field, Relationship, SQLModel

Check failure on line 11 in mapcat/database/planet_todfit.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (unsorted-imports)

mapcat/database/planet_todfit.py:5:1: unsorted-imports: Import block is un-sorted or un-formatted help: Organize imports

Check failure on line 11 in mapcat/database/planet_todfit.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (unsorted-imports)

mapcat/database/planet_todfit.py:5:1: unsorted-imports: Import block is un-sorted or un-formatted help: Organize imports

class PlanetTodFit(SQLModel):
obs_id: str
telescope: str
freq_channel: str
wafer: str
ctime: AstroPydanticTime
dtime: datetime
source: str
detid: str

amplitude: float | None
xo: float | None
yo: float | None
sigmax: float | None
sigmay: float | None
theta: float | None
defla: float | None
deflp: float | None
amplitude_err: float | None
xo_err: float | None
yo_err: float | None
sigmax_err: float | None
sigmay_err: float | None
theta_err: float | None
defla_err: float | None
deflp_err: float | None
chisq: float | None
dof: int | None
xi: float | None
eta: float | None
gamma: float | None


class PlanetTodFitTable(SQLModel, table=True):
__tablename__ = "planet_todfit"

obs_id: str = Field(primary_key=True)
telescope: str = Field(primary_key=True)
freq_channel: str = Field(primary_key=True)
wafer: str = Field(primary_key=True)
ctime: float = Field(nullable=False, primary_key=True)
source: str = Field(primary_key=True)
detid: str = Field(primary_key=True)
dtime: datetime = Field()

amplitude: float | None = Field()
xo: float | None = Field()
yo: float | None = Field()
sigmax: float | None = Field()
sigmay: float | None = Field()
theta: float | None = Field()
defla: float | None = Field()
deflp: float | None = Field()
amplitude_err: float | None = Field()
xo_err: float | None = Field()
yo_err: float | None = Field()
sigmax_err: float | None = Field()
sigmay_err: float | None = Field()
theta_err: float | None = Field()
defla_err: float | None = Field()
deflp_err: float | None = Field()
chisq: float | None = Field()
dof: int | None = Field()
xi: float | None = Field()
eta: float | None = Field()
gamma: float | None = Field()


def to_model(self) -> PlanetTodFit:
"""
Return an PlanetTodFit model from this table entry.

Returns
-------
PlanetTodFit : PlanetTodFit
The PlanetTodFit model corresponding to this table entry.
"""
return PlanetTodFit(
obs_id=self.obs_id,
telescope=self.telescope,
freq_channel=self.freq_channel,
wafer=self.wafer,
ctime=Time(self.ctime, format="unix", scale="utc"),
dtime=self.dtime,
source=self.source,
detid=self.detid,
amplitude=self.amplitude,
xo=self.xo,
yo=self.yo,
sigmax=self.sigmax,
sigmay=self.sigmay,
theta=self.theta,
defla=self.defla,
deflp=self.deflp,
amplitude_err=self.amplitude_err,
xo_err=self.xo_err,
yo_err=self.yo_err,
sigmax_err=self.sigmax_err,
sigmay_err=self.sigmay_err,
theta_err=self.theta_err,
defla_err=self.defla_err,
deflp_err=self.deflp_err,
chisq=self.chisq,
dof=self.dof,
xi=self.xi,
eta=self.eta,
gamma=self.gamma,
)
Loading