From c6e898d393ba58227ca2afb4cdcf4b6122d4ef57 Mon Sep 17 00:00:00 2001 From: Yoshinori Sueno Date: Fri, 4 Sep 2026 15:47:58 -0400 Subject: [PATCH 1/4] add planet map and todfit database --- mapcat/database/planet_map.py | 182 +++++++++++++++++++++++++++++++ mapcat/database/planet_todfit.py | 125 +++++++++++++++++++++ 2 files changed, 307 insertions(+) create mode 100644 mapcat/database/planet_map.py create mode 100644 mapcat/database/planet_todfit.py diff --git a/mapcat/database/planet_map.py b/mapcat/database/planet_map.py new file mode 100644 index 0000000..be2d84f --- /dev/null +++ b/mapcat/database/planet_map.py @@ -0,0 +1,182 @@ +""" +Table for planet maps. +""" + +from datetime import datetime +from typing import TYPE_CHECKING, Any +import json + +from astropy.time import Time +from astropydantic import AstroPydanticTime +from sqlmodel import Field, Relationship, SQLModel +from sqlalchemy import Column, JSON + +class PlanetMap(SQLModel): + planet_map_id: int + + obs_id: str + telescope: str + freq_channel: str + wafer: str + ctime: AstroPydanticTime + source: str + + valid: bool | None + prefix_path: str | None + + hit_path: str | None + map_path: str | None + weight_path: str | None + weight_map_path: str | None + + azimuth: float | None + elevation: 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_maps" + + planet_map_id: int = Field(primary_key=True) + + obs_id: str = Field() + telescope: str = Field() + freq_channel: str = Field() + wafer: str = Field() + ctime: datetime = Field(nullable=False) + source: str = Field() + + prefix_path: str | None = Field() + hit_path: str | None = Field() + map_path: str | None = Field() + weight_path: str | None = Field() + weight_map_path: str | None = Field() + + valid: bool | None = Field() + elevation: 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( + planet_map_id=self.planet_map_id, + obs_id=self.obs_id, + telescope=self.telescope, + freq_channel=self.freq_channel, + wafer=self.wafer, + ctime=Time(self.ctime), + source=self.source, + valid=self.valid, + prefix_path=self.prefix_path, + hit_path=self.hit_path, + map_path=self.map_path, + weight_path=self.weight_path, + weight_map_path=self.weight_map_path, + azimuth=self.azimuth, + elevation=self.elevation, + 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, + ) diff --git a/mapcat/database/planet_todfit.py b/mapcat/database/planet_todfit.py new file mode 100644 index 0000000..105996d --- /dev/null +++ b/mapcat/database/planet_todfit.py @@ -0,0 +1,125 @@ +""" +Table for planet todfit. +""" + +from datetime import datetime +from typing import TYPE_CHECKING, Any +import json + +from astropy.time import Time +from astropydantic import AstroPydanticTime +from sqlmodel import Field, Relationship, SQLModel + +class PlanetTodFit(SQLModel): + planet_todfit_id: int + + obs_id: str + telescope: str + freq_channel: str + wafer: str + ctime: AstroPydanticTime + source: str + detid: str + + valid: bool | None + 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" + + planet_todfit_id: int = Field(primary_key=True) + + obs_id: str = Field() + telescope: str = Field() + freq_channel: str = Field() + wafer: str = Field() + ctime: datetime = Field(nullable=False) + source: str = Field() + detid: str = Field() + + valid: bool = Field() + amplitude: float = Field() + xo: float = Field() + yo: float = Field() + sigmax: float = Field() + sigmay: float = Field() + theta: float = Field() + defla: float = Field() + deflp: float = Field() + amplitude_err: float = Field() + xo_err: float = Field() + yo_err: float = Field() + sigmax_err: float = Field() + sigmay_err: float = Field() + theta_err: float = Field() + defla_err: float = Field() + deflp_err: float = Field() + chisq: float = Field() + dof: int = Field() + xi: float = Field() + eta: float = Field() + gamma: float = 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( + atomic_map_id=self.atomic_map_id, + obs_id=self.obs_id, + telescope=self.telescope, + freq_channel=self.freq_channel, + wafer=self.wafer, + ctime=Time(self.ctime), + source=self.source, + detid=self.detid, + valid=self.valid, + 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, + ) From 08fb12f469d254ebee9701cd7ea58431f29cd52e Mon Sep 17 00:00:00 2001 From: Yoshinori Sueno Date: Fri, 4 Sep 2026 15:58:57 -0400 Subject: [PATCH 2/4] add planet map and todfit database --- mapcat/database/__init__.py | 6 ++++++ mapcat/database/planet_map.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/mapcat/database/__init__.py b/mapcat/database/__init__.py index 6839745..94a6b16 100644 --- a/mapcat/database/__init__.py +++ b/mapcat/database/__init__.py @@ -11,6 +11,8 @@ 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 __all__ = [ "AtomicMapCoaddTable", @@ -22,6 +24,8 @@ "SkyCoverageTable", "TODDepthOneTable", "TimeDomainProcessingTable", + "PlanetMapTable", + "PlanetTodFitTable", ] ALL_TABLES = [ @@ -34,4 +38,6 @@ TODDepthOneTable, PipelineInformationTable, SkyCoverageTable, + PlanetMapTable, + PlanetTodFitTable, ] diff --git a/mapcat/database/planet_map.py b/mapcat/database/planet_map.py index be2d84f..ca90900 100644 --- a/mapcat/database/planet_map.py +++ b/mapcat/database/planet_map.py @@ -65,7 +65,7 @@ class PlanetMap(SQLModel): class PlanetMapTable(SQLModel, table=True): - __tablename__ = "planet_maps" + __tablename__ = "planet_map" planet_map_id: int = Field(primary_key=True) From 74d412e018e137e556ac9f85171d96753c3494b4 Mon Sep 17 00:00:00 2001 From: Yoshinori Sueno Date: Sun, 6 Sep 2026 22:12:46 -0400 Subject: [PATCH 3/4] fix a bug --- mapcat/database/planet_map.py | 9 +++++++-- mapcat/database/planet_todfit.py | 7 +++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/mapcat/database/planet_map.py b/mapcat/database/planet_map.py index ca90900..1318840 100644 --- a/mapcat/database/planet_map.py +++ b/mapcat/database/planet_map.py @@ -19,6 +19,7 @@ class PlanetMap(SQLModel): freq_channel: str wafer: str ctime: AstroPydanticTime + dtime: datetime source: str valid: bool | None @@ -31,6 +32,7 @@ class PlanetMap(SQLModel): azimuth: float | None elevation: float | None + duration: float| None pwv: float | None pwv_std: float | None pwv_p2p: float | None @@ -73,7 +75,8 @@ class PlanetMapTable(SQLModel, table=True): telescope: str = Field() freq_channel: str = Field() wafer: str = Field() - ctime: datetime = Field(nullable=False) + ctime: float = Field(nullable=False) + dtime: datetime = Field() source: str = Field() prefix_path: str | None = Field() @@ -84,6 +87,7 @@ class PlanetMapTable(SQLModel, table=True): valid: bool | None = Field() elevation: float | None = Field() + duration: float | None = Field() azimuth: float | None = Field() pwv: float | None = Field() pwv_std: float | None = Field() @@ -142,7 +146,7 @@ def to_model(self) -> PlanetMap: telescope=self.telescope, freq_channel=self.freq_channel, wafer=self.wafer, - ctime=Time(self.ctime), + ctime=Time(self.ctime, format="unix", scale="utc"), source=self.source, valid=self.valid, prefix_path=self.prefix_path, @@ -152,6 +156,7 @@ def to_model(self) -> PlanetMap: weight_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, diff --git a/mapcat/database/planet_todfit.py b/mapcat/database/planet_todfit.py index 105996d..935d3ff 100644 --- a/mapcat/database/planet_todfit.py +++ b/mapcat/database/planet_todfit.py @@ -18,6 +18,7 @@ class PlanetTodFit(SQLModel): freq_channel: str wafer: str ctime: AstroPydanticTime + dtime: datetime source: str detid: str @@ -54,7 +55,8 @@ class PlanetTodFitTable(SQLModel, table=True): telescope: str = Field() freq_channel: str = Field() wafer: str = Field() - ctime: datetime = Field(nullable=False) + ctime: float = Field(nullable=False) + dtime: datetime = Field() source: str = Field() detid: str = Field() @@ -97,7 +99,8 @@ def to_model(self) -> PlanetTodFit: telescope=self.telescope, freq_channel=self.freq_channel, wafer=self.wafer, - ctime=Time(self.ctime), + ctime=Time(self.ctime, format="unix", scale="utc"), + dtime=self.dtime, source=self.source, detid=self.detid, valid=self.valid, From 9fd500b8efab430a2fc0b642b4dc39a05a4067b2 Mon Sep 17 00:00:00 2001 From: Yoshinori Sueno Date: Mon, 7 Sep 2026 03:18:36 -0400 Subject: [PATCH 4/4] fix a bug --- mapcat/database/planet_map.py | 31 +++++----------- mapcat/database/planet_todfit.py | 64 ++++++++++++++------------------ 2 files changed, 38 insertions(+), 57 deletions(-) diff --git a/mapcat/database/planet_map.py b/mapcat/database/planet_map.py index 1318840..e45cde3 100644 --- a/mapcat/database/planet_map.py +++ b/mapcat/database/planet_map.py @@ -12,8 +12,6 @@ from sqlalchemy import Column, JSON class PlanetMap(SQLModel): - planet_map_id: int - obs_id: str telescope: str freq_channel: str @@ -22,13 +20,10 @@ class PlanetMap(SQLModel): dtime: datetime source: str - valid: bool | None - prefix_path: str | None - hit_path: str | None map_path: str | None weight_path: str | None - weight_map_path: str | None + weighted_map_path: str | None azimuth: float | None elevation: float | None @@ -69,23 +64,19 @@ class PlanetMap(SQLModel): class PlanetMapTable(SQLModel, table=True): __tablename__ = "planet_map" - planet_map_id: int = Field(primary_key=True) - - obs_id: str = Field() - telescope: str = Field() - freq_channel: str = Field() - wafer: str = Field() - ctime: float = Field(nullable=False) + 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() - source: str = Field() - prefix_path: str | None = Field() hit_path: str | None = Field() map_path: str | None = Field() weight_path: str | None = Field() - weight_map_path: str | None = Field() + weighted_map_path: str | None = Field() - valid: bool | None = Field() elevation: float | None = Field() duration: float | None = Field() azimuth: float | None = Field() @@ -141,19 +132,17 @@ def to_model(self) -> PlanetMap: The PlanetMap model corresponding to this table entry. """ return PlanetMap( - planet_map_id=self.planet_map_id, 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, - valid=self.valid, - prefix_path=self.prefix_path, hit_path=self.hit_path, map_path=self.map_path, weight_path=self.weight_path, - weight_map_path=self.weight_map_path, + weighted_map_path=self.weight_map_path, azimuth=self.azimuth, elevation=self.elevation, duration=self.duration, diff --git a/mapcat/database/planet_todfit.py b/mapcat/database/planet_todfit.py index 935d3ff..8b1ba9a 100644 --- a/mapcat/database/planet_todfit.py +++ b/mapcat/database/planet_todfit.py @@ -11,8 +11,6 @@ from sqlmodel import Field, Relationship, SQLModel class PlanetTodFit(SQLModel): - planet_todfit_id: int - obs_id: str telescope: str freq_channel: str @@ -22,7 +20,6 @@ class PlanetTodFit(SQLModel): source: str detid: str - valid: bool | None amplitude: float | None xo: float | None yo: float | None @@ -49,39 +46,36 @@ class PlanetTodFit(SQLModel): class PlanetTodFitTable(SQLModel, table=True): __tablename__ = "planet_todfit" - planet_todfit_id: int = Field(primary_key=True) - - obs_id: str = Field() - telescope: str = Field() - freq_channel: str = Field() - wafer: str = Field() - ctime: float = Field(nullable=False) + 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() - source: str = Field() - detid: str = Field() - valid: bool = Field() - amplitude: float = Field() - xo: float = Field() - yo: float = Field() - sigmax: float = Field() - sigmay: float = Field() - theta: float = Field() - defla: float = Field() - deflp: float = Field() - amplitude_err: float = Field() - xo_err: float = Field() - yo_err: float = Field() - sigmax_err: float = Field() - sigmay_err: float = Field() - theta_err: float = Field() - defla_err: float = Field() - deflp_err: float = Field() - chisq: float = Field() - dof: int = Field() - xi: float = Field() - eta: float = Field() - gamma: float = 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: @@ -94,7 +88,6 @@ def to_model(self) -> PlanetTodFit: The PlanetTodFit model corresponding to this table entry. """ return PlanetTodFit( - atomic_map_id=self.atomic_map_id, obs_id=self.obs_id, telescope=self.telescope, freq_channel=self.freq_channel, @@ -103,7 +96,6 @@ def to_model(self) -> PlanetTodFit: dtime=self.dtime, source=self.source, detid=self.detid, - valid=self.valid, amplitude=self.amplitude, xo=self.xo, yo=self.yo,