diff --git a/alembic-autogenerate.py b/alembic-autogenerate.py index d8732590..92e1ad7f 100755 --- a/alembic-autogenerate.py +++ b/alembic-autogenerate.py @@ -8,20 +8,18 @@ # setup -r /path/to/sdm_schemas # 2. From the root of the consdb git repo, invoke the script. Supply a # revision message as the command line argument: -# python alembic-autogenerate.py this is my revision message "\n" \ -# the message can span multiple lines "\n" \ -# if desired -# 3. Heed the message at the end to revise your auto-generated code as needed. +# python alembic-autogenerate.py DM-12345 +# 3. Revise your auto-generated code as needed. # import os import sys -from alembic.config import Config -from alembic import command +from felis.tests.postgresql import setup_postgres_test_db from sqlalchemy.sql import text -from felis.tests.postgresql import setup_postgres_test_db +from alembic import command +from alembic.config import Config if len(sys.argv) <= 1: print( @@ -65,11 +63,9 @@ print( """ ========================================== - Don't forget to edit your migration - files! You'll need to remove the visit1 - and ccdvisit1 tables, and you might need - to shuffle data around to accomodate the - new schema! + Don't forget to edit your migration files. + You might need to shuffle data around + to accommodate the new schema! ========================================== """ ) diff --git a/alembic.ini b/alembic.ini index 7f341872..bda61f2b 100644 --- a/alembic.ini +++ b/alembic.ini @@ -124,3 +124,15 @@ consdb.schema_name = cdb_lsstcomcam [lsstcam] script_location = alembic/lsstcam consdb.schema_name = cdb_lsstcam + +[startrackerwide] +script_location = alembic/startrackerwide +consdb.schema_name = cdb_startrackerwide + +[startrackernarrow] +script_location = alembic/startrackernarrow +consdb.schema_name = cdb_startrackernarrow + +[startrackerfast] +script_location = alembic/startrackerfast +consdb.schema_name = cdb_startrackerfast diff --git a/alembic/latiss/versions/47c0b5ce839e_add_psf_pixelscale_mountjitter_to_.py b/alembic/latiss/versions/47c0b5ce839e_add_psf_pixelscale_mountjitter_to_.py new file mode 100644 index 00000000..b9b91b61 --- /dev/null +++ b/alembic/latiss/versions/47c0b5ce839e_add_psf_pixelscale_mountjitter_to_.py @@ -0,0 +1,200 @@ +"""Add psf, pixelscale, mountjitter to quicklooks + +Revision ID: 47c0b5ce839e +Revises: e9fd2cdb9c12 +Create Date: 2024-11-20 01:32:09.210537+00:00 + +""" + +from typing import Sequence, Union + +import sqlalchemy as sa +from sqlalchemy.dialects import mysql + +from alembic import op + +# revision identifiers, used by Alembic. +revision: str = "47c0b5ce839e" +down_revision: Union[str, None] = "e9fd2cdb9c12" +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.create_table( + "exposure_quicklook", + sa.Column( + "exposure_id", + sa.BIGINT().with_variant(mysql.BIGINT(), "mysql").with_variant(sa.BIGINT(), "postgresql"), + nullable=False, + comment="Unique identifier.", + ), + sa.Column( + "day_obs", + sa.INTEGER().with_variant(mysql.INTEGER(), "mysql").with_variant(sa.INTEGER(), "postgresql"), + nullable=False, + comment="Day of observation.", + ), + sa.Column( + "seq_num", + sa.INTEGER().with_variant(mysql.INTEGER(), "mysql").with_variant(sa.INTEGER(), "postgresql"), + nullable=False, + comment="Sequence number.", + ), + sa.Column( + "postisr_pixel_median", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Median postISR pixel value.", + ), + sa.Column( + "mount_motion_image_degradation", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Image degradation due to mount motion.", + ), + sa.Column( + "mount_motion_image_degradation_az", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Image degradation due to mount motion in azimuth.", + ), + sa.Column( + "mount_motion_image_degradation_el", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Image degradation due to mount motion in elevation.", + ), + sa.Column( + "mount_jitter_rms", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="RMS mount jitter.", + ), + sa.Column( + "mount_jitter_rms_az", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Azimuth RMS mount jitter.", + ), + sa.Column( + "mount_jitter_rms_el", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Elevation RMS mount jitter.", + ), + sa.Column( + "mount_jitter_rms_rot", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Rotator RMS mount jitter.", + ), + sa.ForeignKeyConstraint( + ["day_obs", "seq_num"], + ["cdb_latiss.exposure.day_obs", "cdb_latiss.exposure.seq_num"], + name="fk_exposure_quicklook_day_obs_seq_num", + ), + sa.ForeignKeyConstraint( + ["exposure_id"], ["cdb_latiss.exposure.exposure_id"], name="fk_exposure_quicklook_obs_id" + ), + sa.PrimaryKeyConstraint("day_obs", "seq_num"), + schema="cdb_latiss", + mysql_engine="MyISAM", + ) + op.add_column( + "ccdvisit1_quicklook", + sa.Column( + "pixel_scale", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Measured detector pixel scale.", + ), + schema="cdb_latiss", + ) + op.add_column( + "ccdvisit1_quicklook", + sa.Column( + "psf_ap_flux_delta", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Delta (max - min) of model psf aperture flux (with aperture radius of max(2, 3*psfSigma)) values evaluated on a grid of unmasked pixels.", + ), + schema="cdb_latiss", + ) + op.add_column( + "ccdvisit1_quicklook", + sa.Column( + "psf_ap_corr_sigma_scaled_delta", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Delta (max - min) of psf flux aperture correction factors scaled (divided) by the psfSigma evaluated on a grid of unmasked pixels.", + ), + schema="cdb_latiss", + ) + op.add_column( + "visit1_quicklook", + sa.Column( + "pixel_scale", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Measured detector pixel scale.", + ), + schema="cdb_latiss", + ) + op.add_column( + "visit1_quicklook", + sa.Column( + "stats_mag_lim", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Magnitude limit at fixed SNR (default SNR=5) calculated from exposure summary stats.", + ), + schema="cdb_latiss", + ) + op.add_column( + "visit1_quicklook", + sa.Column( + "psf_ap_flux_delta", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Delta (max - min) of model psf aperture flux (with aperture radius of max(2, 3*psfSigma)) values evaluated on a grid of unmasked pixels.", + ), + schema="cdb_latiss", + ) + op.add_column( + "visit1_quicklook", + sa.Column( + "psf_ap_corr_sigma_scaled_delta", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Delta (max - min) of psf flux aperture correction factors scaled (divided) by the psfSigma evaluated on a grid of unmasked pixels.", + ), + schema="cdb_latiss", + ) + op.drop_column("visit1_quicklook", "postisr_pixel_median", schema="cdb_latiss") + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.add_column( + "visit1_quicklook", + sa.Column( + "postisr_pixel_median", + sa.DOUBLE_PRECISION(precision=53), + autoincrement=False, + nullable=True, + comment="Median postISR pixel value.", + ), + schema="cdb_latiss", + ) + op.drop_column("visit1_quicklook", "psf_ap_corr_sigma_scaled_delta", schema="cdb_latiss") + op.drop_column("visit1_quicklook", "psf_ap_flux_delta", schema="cdb_latiss") + op.drop_column("visit1_quicklook", "stats_mag_lim", schema="cdb_latiss") + op.drop_column("visit1_quicklook", "pixel_scale", schema="cdb_latiss") + op.drop_column("ccdvisit1_quicklook", "psf_ap_corr_sigma_scaled_delta", schema="cdb_latiss") + op.drop_column("ccdvisit1_quicklook", "psf_ap_flux_delta", schema="cdb_latiss") + op.drop_column("ccdvisit1_quicklook", "pixel_scale", schema="cdb_latiss") + op.drop_table("exposure_quicklook", schema="cdb_latiss") + # ### end Alembic commands ### diff --git a/alembic/lsstcomcam/versions/12f0d22a2347_add_psf_pixelscale_mountjitter_to_.py b/alembic/lsstcomcam/versions/12f0d22a2347_add_psf_pixelscale_mountjitter_to_.py new file mode 100644 index 00000000..a8b8fe9d --- /dev/null +++ b/alembic/lsstcomcam/versions/12f0d22a2347_add_psf_pixelscale_mountjitter_to_.py @@ -0,0 +1,371 @@ +"""Add psf, pixelscale, mountjitter to quicklooks + +Revision ID: 12f0d22a2347 +Revises: 0490d793fc1a +Create Date: 2024-11-20 01:32:10.315345+00:00 + +""" + +from typing import Sequence, Union + +import sqlalchemy as sa +from sqlalchemy.dialects import mysql + +from alembic import op + +# revision identifiers, used by Alembic. +revision: str = "12f0d22a2347" +down_revision: Union[str, None] = "0490d793fc1a" +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.create_table( + "exposure_quicklook", + sa.Column( + "exposure_id", + sa.BIGINT().with_variant(mysql.BIGINT(), "mysql").with_variant(sa.BIGINT(), "postgresql"), + nullable=False, + comment="Unique identifier.", + ), + sa.Column( + "day_obs", + sa.INTEGER().with_variant(mysql.INTEGER(), "mysql").with_variant(sa.INTEGER(), "postgresql"), + nullable=False, + comment="Day of observation.", + ), + sa.Column( + "seq_num", + sa.INTEGER().with_variant(mysql.INTEGER(), "mysql").with_variant(sa.INTEGER(), "postgresql"), + nullable=False, + comment="Sequence number.", + ), + sa.Column( + "postisr_pixel_median_median", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Median postISR pixel value (median across all detectors).", + ), + sa.Column( + "postisr_pixel_median_mean", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Median postISR pixel value (mean across all detectors).", + ), + sa.Column( + "postisr_pixel_median_max", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Median postISR pixel value (max across all detectors).", + ), + sa.Column( + "mount_motion_image_degradation", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Image degradation due to mount motion.", + ), + sa.Column( + "mount_motion_image_degradation_az", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Image degradation due to mount motion in azimuth.", + ), + sa.Column( + "mount_motion_image_degradation_rot", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Image degradation due to rotator jitter.", + ), + sa.Column( + "mount_jitter_rms", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="RMS mount jitter.", + ), + sa.Column( + "mount_jitter_rms_az", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Azimuth RMS mount jitter.", + ), + sa.Column( + "mount_jitter_rms_el", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Elevation RMS mount jitter.", + ), + sa.Column( + "mount_jitter_rms_rot", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Rotator RMS mount jitter.", + ), + sa.ForeignKeyConstraint( + ["day_obs", "seq_num"], + ["cdb_lsstcomcam.exposure.day_obs", "cdb_lsstcomcam.exposure.seq_num"], + name="fk_exposure_quicklook_day_obs_seq_num", + ), + sa.ForeignKeyConstraint( + ["exposure_id"], ["cdb_lsstcomcam.exposure.exposure_id"], name="fk_exposure_quicklook_obs_id" + ), + sa.PrimaryKeyConstraint("day_obs", "seq_num"), + schema="cdb_lsstcomcam", + mysql_engine="MyISAM", + ) + op.create_table( + "ccdexposure_quicklook", + sa.Column( + "ccdexposure_id", + sa.BIGINT().with_variant(mysql.BIGINT(), "mysql").with_variant(sa.BIGINT(), "postgresql"), + nullable=False, + comment="Unique identifier.", + ), + sa.Column( + "postisr_pixel_median", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Median postISR pixel value.", + ), + sa.ForeignKeyConstraint( + ["ccdexposure_id"], + ["cdb_lsstcomcam.ccdexposure.ccdexposure_id"], + name="fk_ccdexposure_quicklook_obs_id", + ), + sa.PrimaryKeyConstraint("ccdexposure_id"), + schema="cdb_lsstcomcam", + mysql_engine="MyISAM", + ) + op.add_column( + "ccdvisit1_quicklook", + sa.Column( + "pixel_scale", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Measured detector pixel scale.", + ), + schema="cdb_lsstcomcam", + ) + op.add_column( + "ccdvisit1_quicklook", + sa.Column( + "stats_mag_lim", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Magnitude limit at fixed SNR (default SNR=5) calculated from exposure summary stats.", + ), + schema="cdb_lsstcomcam", + ) + op.add_column( + "ccdvisit1_quicklook", + sa.Column( + "psf_ap_flux_delta", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Delta (max - min) of model psf aperture flux (with aperture radius of max(2, 3*psfSigma)) values evaluated on a grid of unmasked pixels.", + ), + schema="cdb_lsstcomcam", + ) + op.add_column( + "ccdvisit1_quicklook", + sa.Column( + "psf_ap_corr_sigma_scaled_delta", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Delta (max - min) of psf flux aperture correction factors scaled (divided) by the psfSigma evaluated on a grid of unmasked pixels.", + ), + schema="cdb_lsstcomcam", + ) + op.drop_column("ccdvisit1_quicklook", "postisr_pixel_median", schema="cdb_lsstcomcam") + op.add_column( + "visit1_quicklook", + sa.Column( + "pixel_scale_min", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Measured detector pixel scale (minimum across all detectors).", + ), + schema="cdb_lsstcomcam", + ) + op.add_column( + "visit1_quicklook", + sa.Column( + "pixel_scale_max", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Measured detector pixel scale (maximum across all detectors).", + ), + schema="cdb_lsstcomcam", + ) + op.add_column( + "visit1_quicklook", + sa.Column( + "pixel_scale_median", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Measured detector pixel scale (median across all detectors).", + ), + schema="cdb_lsstcomcam", + ) + op.add_column( + "visit1_quicklook", + sa.Column( + "stats_mag_lim_min", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Magnitude limit at fixed SNR (default SNR=5) calculated from exposure summary stats (minimum across all detectors).", + ), + schema="cdb_lsstcomcam", + ) + op.add_column( + "visit1_quicklook", + sa.Column( + "stats_mag_lim_max", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Magnitude limit at fixed SNR (default SNR=5) calculated from exposure summary stats (maximum across all detectors).", + ), + schema="cdb_lsstcomcam", + ) + op.add_column( + "visit1_quicklook", + sa.Column( + "stats_mag_lim_median", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Magnitude limit at fixed SNR (default SNR=5) calculated from exposure summary stats (median across all detectors).", + ), + schema="cdb_lsstcomcam", + ) + op.add_column( + "visit1_quicklook", + sa.Column( + "psf_ap_flux_delta_min", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Delta (max - min) of model psf aperture flux (with aperture radius of max(2, 3*psfSigma)) values evaluated on a grid of unmasked pixels (minimum across all detectors).", + ), + schema="cdb_lsstcomcam", + ) + op.add_column( + "visit1_quicklook", + sa.Column( + "psf_ap_flux_delta_max", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Delta (max - min) of model psf aperture flux (with aperture radius of max(2, 3*psfSigma)) values evaluated on a grid of unmasked pixels (maximum across all detectors).", + ), + schema="cdb_lsstcomcam", + ) + op.add_column( + "visit1_quicklook", + sa.Column( + "psf_ap_flux_delta_median", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Delta (max - min) of model psf aperture flux (with aperture radius of max(2, 3*psfSigma)) values evaluated on a grid of unmasked pixels (median across all detectors).", + ), + schema="cdb_lsstcomcam", + ) + op.add_column( + "visit1_quicklook", + sa.Column( + "psf_ap_corr_sigma_scaled_delta_min", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Delta (max - min) of psf flux aperture correction factors scaled (divided) by the psfSigma evaluated on a grid of unmasked pixels (minimum across all detectors).", + ), + schema="cdb_lsstcomcam", + ) + op.add_column( + "visit1_quicklook", + sa.Column( + "psf_ap_corr_sigma_scaled_delta_max", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Delta (max - min) of psf flux aperture correction factors scaled (divided) by the psfSigma evaluated on a grid of unmasked pixels (maximum across all detectors).", + ), + schema="cdb_lsstcomcam", + ) + op.add_column( + "visit1_quicklook", + sa.Column( + "psf_ap_corr_sigma_scaled_delta_median", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Delta (max - min) of psf flux aperture correction factors scaled (divided) by the psfSigma evaluated on a grid of unmasked pixels (median across all detectors).", + ), + schema="cdb_lsstcomcam", + ) + op.drop_column("visit1_quicklook", "postisr_pixel_median_mean", schema="cdb_lsstcomcam") + op.drop_column("visit1_quicklook", "postisr_pixel_median_max", schema="cdb_lsstcomcam") + op.drop_column("visit1_quicklook", "postisr_pixel_median_median", schema="cdb_lsstcomcam") + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.add_column( + "visit1_quicklook", + sa.Column( + "postisr_pixel_median_median", + sa.DOUBLE_PRECISION(precision=53), + autoincrement=False, + nullable=True, + comment="Median postISR pixel value (median across all detectors).", + ), + schema="cdb_lsstcomcam", + ) + op.add_column( + "visit1_quicklook", + sa.Column( + "postisr_pixel_median_max", + sa.DOUBLE_PRECISION(precision=53), + autoincrement=False, + nullable=True, + comment="Median postISR pixel value (max across all detectors).", + ), + schema="cdb_lsstcomcam", + ) + op.add_column( + "visit1_quicklook", + sa.Column( + "postisr_pixel_median_mean", + sa.DOUBLE_PRECISION(precision=53), + autoincrement=False, + nullable=True, + comment="Median postISR pixel value (mean across all detectors).", + ), + schema="cdb_lsstcomcam", + ) + op.drop_column("visit1_quicklook", "psf_ap_corr_sigma_scaled_delta_median", schema="cdb_lsstcomcam") + op.drop_column("visit1_quicklook", "psf_ap_corr_sigma_scaled_delta_max", schema="cdb_lsstcomcam") + op.drop_column("visit1_quicklook", "psf_ap_corr_sigma_scaled_delta_min", schema="cdb_lsstcomcam") + op.drop_column("visit1_quicklook", "psf_ap_flux_delta_median", schema="cdb_lsstcomcam") + op.drop_column("visit1_quicklook", "psf_ap_flux_delta_max", schema="cdb_lsstcomcam") + op.drop_column("visit1_quicklook", "psf_ap_flux_delta_min", schema="cdb_lsstcomcam") + op.drop_column("visit1_quicklook", "stats_mag_lim_median", schema="cdb_lsstcomcam") + op.drop_column("visit1_quicklook", "stats_mag_lim_max", schema="cdb_lsstcomcam") + op.drop_column("visit1_quicklook", "stats_mag_lim_min", schema="cdb_lsstcomcam") + op.drop_column("visit1_quicklook", "pixel_scale_median", schema="cdb_lsstcomcam") + op.drop_column("visit1_quicklook", "pixel_scale_max", schema="cdb_lsstcomcam") + op.drop_column("visit1_quicklook", "pixel_scale_min", schema="cdb_lsstcomcam") + op.add_column( + "ccdvisit1_quicklook", + sa.Column( + "postisr_pixel_median", + sa.DOUBLE_PRECISION(precision=53), + autoincrement=False, + nullable=True, + comment="Median postISR pixel value.", + ), + schema="cdb_lsstcomcam", + ) + op.drop_column("ccdvisit1_quicklook", "psf_ap_corr_sigma_scaled_delta", schema="cdb_lsstcomcam") + op.drop_column("ccdvisit1_quicklook", "psf_ap_flux_delta", schema="cdb_lsstcomcam") + op.drop_column("ccdvisit1_quicklook", "stats_mag_lim", schema="cdb_lsstcomcam") + op.drop_column("ccdvisit1_quicklook", "pixel_scale", schema="cdb_lsstcomcam") + op.drop_table("ccdexposure_quicklook", schema="cdb_lsstcomcam") + op.drop_table("exposure_quicklook", schema="cdb_lsstcomcam") + # ### end Alembic commands ### diff --git a/alembic/lsstcomcamsim/versions/cb09b95e12fb_add_psf_pixelscale_mountjitter_to_.py b/alembic/lsstcomcamsim/versions/cb09b95e12fb_add_psf_pixelscale_mountjitter_to_.py new file mode 100644 index 00000000..acd8f0dc --- /dev/null +++ b/alembic/lsstcomcamsim/versions/cb09b95e12fb_add_psf_pixelscale_mountjitter_to_.py @@ -0,0 +1,206 @@ +"""Add psf, pixelscale, mountjitter to quicklooks + +Revision ID: cb09b95e12fb +Revises: cff7da7ec8ed +Create Date: 2024-11-20 01:32:11.478651+00:00 + +""" + +from typing import Sequence, Union + +import sqlalchemy as sa +from sqlalchemy.dialects import mysql + +from alembic import op + +# revision identifiers, used by Alembic. +revision: str = "cb09b95e12fb" +down_revision: Union[str, None] = "cff7da7ec8ed" +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.add_column( + "ccdvisit1_quicklook", + sa.Column( + "pixel_scale", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Measured detector pixel scale.", + ), + schema="cdb_lsstcomcamsim", + ) + op.add_column( + "ccdvisit1_quicklook", + sa.Column( + "stats_mag_lim", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Magnitude limit at fixed SNR (default SNR=5) calculated from exposure summary stats.", + ), + schema="cdb_lsstcomcamsim", + ) + op.add_column( + "ccdvisit1_quicklook", + sa.Column( + "psf_ap_flux_delta", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Delta (max - min) of model psf aperture flux (with aperture radius of max(2, 3*psfSigma)) values evaluated on a grid of unmasked pixels.", + ), + schema="cdb_lsstcomcamsim", + ) + op.add_column( + "ccdvisit1_quicklook", + sa.Column( + "psf_ap_corr_sigma_scaled_delta", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Delta (max - min) of psf flux aperture correction factors scaled (divided) by the psfSigma evaluated on a grid of unmasked pixels.", + ), + schema="cdb_lsstcomcamsim", + ) + op.add_column( + "visit1_quicklook", + sa.Column( + "pixel_scale_min", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Measured detector pixel scale (minimum across all detectors).", + ), + schema="cdb_lsstcomcamsim", + ) + op.add_column( + "visit1_quicklook", + sa.Column( + "pixel_scale_max", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Measured detector pixel scale (maximum across all detectors).", + ), + schema="cdb_lsstcomcamsim", + ) + op.add_column( + "visit1_quicklook", + sa.Column( + "pixel_scale_median", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Measured detector pixel scale (median across all detectors).", + ), + schema="cdb_lsstcomcamsim", + ) + op.add_column( + "visit1_quicklook", + sa.Column( + "stats_mag_lim_min", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Magnitude limit at fixed SNR (default SNR=5) calculated from exposure summary stats (minimum across all detectors).", + ), + schema="cdb_lsstcomcamsim", + ) + op.add_column( + "visit1_quicklook", + sa.Column( + "stats_mag_lim_max", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Magnitude limit at fixed SNR (default SNR=5) calculated from exposure summary stats (maximum across all detectors).", + ), + schema="cdb_lsstcomcamsim", + ) + op.add_column( + "visit1_quicklook", + sa.Column( + "stats_mag_lim_median", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Magnitude limit at fixed SNR (default SNR=5) calculated from exposure summary stats (median across all detectors).", + ), + schema="cdb_lsstcomcamsim", + ) + op.add_column( + "visit1_quicklook", + sa.Column( + "psf_ap_flux_delta_min", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Delta (max - min) of model psf aperture flux (with aperture radius of max(2, 3*psfSigma)) values evaluated on a grid of unmasked pixels (minimum across all detectors).", + ), + schema="cdb_lsstcomcamsim", + ) + op.add_column( + "visit1_quicklook", + sa.Column( + "psf_ap_flux_delta_max", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Delta (max - min) of model psf aperture flux (with aperture radius of max(2, 3*psfSigma)) values evaluated on a grid of unmasked pixels (maximum across all detectors).", + ), + schema="cdb_lsstcomcamsim", + ) + op.add_column( + "visit1_quicklook", + sa.Column( + "psf_ap_flux_delta_median", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Delta (max - min) of model psf aperture flux (with aperture radius of max(2, 3*psfSigma)) values evaluated on a grid of unmasked pixels (median across all detectors).", + ), + schema="cdb_lsstcomcamsim", + ) + op.add_column( + "visit1_quicklook", + sa.Column( + "psf_ap_corr_sigma_scaled_delta_min", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Delta (max - min) of psf flux aperture correction factors scaled (divided) by the psfSigma evaluated on a grid of unmasked pixels (minimum across all detectors).", + ), + schema="cdb_lsstcomcamsim", + ) + op.add_column( + "visit1_quicklook", + sa.Column( + "psf_ap_corr_sigma_scaled_delta_max", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Delta (max - min) of psf flux aperture correction factors scaled (divided) by the psfSigma evaluated on a grid of unmasked pixels (maximum across all detectors).", + ), + schema="cdb_lsstcomcamsim", + ) + op.add_column( + "visit1_quicklook", + sa.Column( + "psf_ap_corr_sigma_scaled_delta_median", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Delta (max - min) of psf flux aperture correction factors scaled (divided) by the psfSigma evaluated on a grid of unmasked pixels (median across all detectors).", + ), + schema="cdb_lsstcomcamsim", + ) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column("visit1_quicklook", "psf_ap_corr_sigma_scaled_delta_median", schema="cdb_lsstcomcamsim") + op.drop_column("visit1_quicklook", "psf_ap_corr_sigma_scaled_delta_max", schema="cdb_lsstcomcamsim") + op.drop_column("visit1_quicklook", "psf_ap_corr_sigma_scaled_delta_min", schema="cdb_lsstcomcamsim") + op.drop_column("visit1_quicklook", "psf_ap_flux_delta_median", schema="cdb_lsstcomcamsim") + op.drop_column("visit1_quicklook", "psf_ap_flux_delta_max", schema="cdb_lsstcomcamsim") + op.drop_column("visit1_quicklook", "psf_ap_flux_delta_min", schema="cdb_lsstcomcamsim") + op.drop_column("visit1_quicklook", "stats_mag_lim_median", schema="cdb_lsstcomcamsim") + op.drop_column("visit1_quicklook", "stats_mag_lim_max", schema="cdb_lsstcomcamsim") + op.drop_column("visit1_quicklook", "stats_mag_lim_min", schema="cdb_lsstcomcamsim") + op.drop_column("visit1_quicklook", "pixel_scale_median", schema="cdb_lsstcomcamsim") + op.drop_column("visit1_quicklook", "pixel_scale_max", schema="cdb_lsstcomcamsim") + op.drop_column("visit1_quicklook", "pixel_scale_min", schema="cdb_lsstcomcamsim") + op.drop_column("ccdvisit1_quicklook", "psf_ap_corr_sigma_scaled_delta", schema="cdb_lsstcomcamsim") + op.drop_column("ccdvisit1_quicklook", "psf_ap_flux_delta", schema="cdb_lsstcomcamsim") + op.drop_column("ccdvisit1_quicklook", "stats_mag_lim", schema="cdb_lsstcomcamsim") + op.drop_column("ccdvisit1_quicklook", "pixel_scale", schema="cdb_lsstcomcamsim") + # ### end Alembic commands ### diff --git a/alembic/startrackerfast/env.py b/alembic/startrackerfast/env.py new file mode 120000 index 00000000..74b15c93 --- /dev/null +++ b/alembic/startrackerfast/env.py @@ -0,0 +1 @@ +../env.py \ No newline at end of file diff --git a/alembic/startrackerfast/script.py.mako b/alembic/startrackerfast/script.py.mako new file mode 120000 index 00000000..9ffd8c36 --- /dev/null +++ b/alembic/startrackerfast/script.py.mako @@ -0,0 +1 @@ +../script.py.mako \ No newline at end of file diff --git a/alembic/startrackerfast/versions/14a00ef0cbc3_add_startracker_tables.py b/alembic/startrackerfast/versions/14a00ef0cbc3_add_startracker_tables.py new file mode 100644 index 00000000..da168c68 --- /dev/null +++ b/alembic/startrackerfast/versions/14a00ef0cbc3_add_startracker_tables.py @@ -0,0 +1,498 @@ +"""Add startracker tables + +Revision ID: 14a00ef0cbc3 +Revises: +Create Date: 2024-11-12 18:36:02.453009+00:00 + +""" + +from typing import Sequence, Union + +import sqlalchemy as sa +from sqlalchemy.dialects import mysql, postgresql + +from alembic import op + +# revision identifiers, used by Alembic. +revision: str = "14a00ef0cbc3" +down_revision: Union[str, None] = None +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.create_table( + "exposure", + sa.Column( + "exposure_id", + sa.BIGINT().with_variant(mysql.BIGINT(), "mysql").with_variant(sa.BIGINT(), "postgresql"), + nullable=False, + comment="Unique identifier.", + ), + sa.Column( + "day_obs", + sa.INTEGER().with_variant(mysql.INTEGER(), "mysql").with_variant(sa.INTEGER(), "postgresql"), + nullable=False, + comment="Day of observation.", + ), + sa.Column( + "seq_num", + sa.INTEGER().with_variant(mysql.INTEGER(), "mysql").with_variant(sa.INTEGER(), "postgresql"), + nullable=False, + comment="Sequence number.", + ), + sa.Column( + "s_ra", + sa.DOUBLE() + .with_variant(mysql.DOUBLE(asdecimal=True), "mysql") + .with_variant(sa.DOUBLE_PRECISION(), "postgresql"), + nullable=True, + comment="Central Spatial Position in ICRS; Right ascension of targeted focal plane center.", + ), + sa.Column( + "s_dec", + sa.DOUBLE() + .with_variant(mysql.DOUBLE(asdecimal=True), "mysql") + .with_variant(sa.DOUBLE_PRECISION(), "postgresql"), + nullable=True, + comment="Central Spatial Position in ICRS; Declination of targeted focal plane center.", + ), + sa.Column( + "sky_rotation", + sa.DOUBLE() + .with_variant(mysql.DOUBLE(asdecimal=True), "mysql") + .with_variant(sa.DOUBLE_PRECISION(), "postgresql"), + nullable=True, + comment="Targeted sky rotation angle.", + ), + sa.Column( + "azimuth_start", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Azimuth of focal plane center at the start of the exposure.", + ), + sa.Column( + "azimuth_end", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Azimuth of focal plane center at the end of the exposure.", + ), + sa.Column( + "azimuth", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Azimuth of focal plane center at the middle of the exposure.", + ), + sa.Column( + "altitude_start", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Altitude of focal plane center at the start of the exposure.", + ), + sa.Column( + "altitude_end", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Altitude of focal plane center at the end of the exposure.", + ), + sa.Column( + "altitude", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Altitude of focal plane center at the middle of the exposure.", + ), + sa.Column( + "zenith_distance_start", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Zenith distance at the start of the exposure.", + ), + sa.Column( + "zenith_distance_end", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Zenith distance at the end of the exposure.", + ), + sa.Column( + "zenith_distance", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Zenith distance at the middle of the exposure.", + ), + sa.Column( + "airmass", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Airmass of the observed line of sight at the middle of the exposure.", + ), + sa.Column( + "exp_midpt", + sa.TIMESTAMP() + .with_variant(mysql.DATETIME(fsp=6), "mysql") + .with_variant(postgresql.TIMESTAMP(precision=6), "postgresql"), + nullable=True, + comment="Midpoint time for exposure at the fiducial center of the focal plane. array. TAI, accurate to 10ms.", + ), + sa.Column( + "exp_midpt_mjd", + sa.DOUBLE() + .with_variant(mysql.DOUBLE(asdecimal=True), "mysql") + .with_variant(sa.DOUBLE_PRECISION(), "postgresql"), + nullable=True, + comment="Midpoint time for exposure at the fiducial center of the focal plane. array in MJD. TAI, accurate to 10ms.", + ), + sa.Column( + "obs_start", + sa.TIMESTAMP() + .with_variant(mysql.DATETIME(fsp=6), "mysql") + .with_variant(postgresql.TIMESTAMP(precision=6), "postgresql"), + nullable=True, + comment="Start time of the exposure at the fiducial center of the focal plane. array, TAI, accurate to 10ms.", + ), + sa.Column( + "obs_start_mjd", + sa.DOUBLE() + .with_variant(mysql.DOUBLE(asdecimal=True), "mysql") + .with_variant(sa.DOUBLE_PRECISION(), "postgresql"), + nullable=True, + comment="Start of the exposure in MJD, TAI, accurate to 10ms.", + ), + sa.Column( + "obs_end", + sa.TIMESTAMP() + .with_variant(mysql.DATETIME(fsp=6), "mysql") + .with_variant(postgresql.TIMESTAMP(precision=6), "postgresql"), + nullable=True, + comment="End time of the exposure at the fiducial center of the focal plane. array, TAI, accurate to 10ms.", + ), + sa.Column( + "obs_end_mjd", + sa.DOUBLE() + .with_variant(mysql.DOUBLE(asdecimal=True), "mysql") + .with_variant(sa.DOUBLE_PRECISION(), "postgresql"), + nullable=True, + comment="End of the exposure in MJD, TAI, accurate to 10ms.", + ), + sa.Column( + "exp_time", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Spatially-averaged duration of exposure, accurate to 10ms.", + ), + sa.Column( + "img_type", + sa.VARCHAR(length=64) + .with_variant(mysql.VARCHAR(length=64), "mysql") + .with_variant(sa.VARCHAR(length=64), "postgresql"), + nullable=True, + comment="Type of exposure taken.", + ), + sa.Column( + "target_name", + sa.VARCHAR(length=64) + .with_variant(mysql.VARCHAR(length=64), "mysql") + .with_variant(sa.VARCHAR(length=64), "postgresql"), + nullable=True, + comment="Target of the observation.", + ), + sa.Column( + "air_temp", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Outside air temperature in degC.", + ), + sa.Column( + "pressure", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Outside air pressure.", + ), + sa.Column( + "humidity", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Outside relative humidity.", + ), + sa.Column( + "wind_speed", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Outside wind speed.", + ), + sa.Column( + "wind_dir", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Wind direction.", + ), + sa.Column( + "dimm_seeing", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Seeing as measured by external DIMM (FWHM).", + ), + sa.Column( + "dome_azimuth", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Dome azimuth.", + ), + sa.Column( + "vignette", + sa.VARCHAR(length=10) + .with_variant(mysql.VARCHAR(length=10), "mysql") + .with_variant(sa.VARCHAR(length=10), "postgresql"), + nullable=True, + comment="Instrument blocked from the sky: UNKNOWN, NO, PARTIALLY, FULLY.", + ), + sa.Column( + "vignette_min", + sa.VARCHAR(length=10) + .with_variant(mysql.VARCHAR(length=10), "mysql") + .with_variant(sa.VARCHAR(length=10), "postgresql"), + nullable=True, + comment="Lowest amount of instrument vignetting detected during the exposure: UNKNOWN, NO, PARTIALLY, FULLY.", + ), + sa.PrimaryKeyConstraint("exposure_id"), + sa.UniqueConstraint("day_obs", "seq_num", name="un_day_obs_seq_num"), + schema="cdb_startrackerfast", + mysql_engine="MyISAM", + ) + op.create_table( + "exposure_flexdata_schema", + sa.Column( + "key", + sa.VARCHAR(length=128) + .with_variant(mysql.VARCHAR(length=128), "mysql") + .with_variant(sa.VARCHAR(length=128), "postgresql"), + nullable=False, + comment="Name of key.", + ), + sa.Column( + "dtype", + sa.VARCHAR(length=64) + .with_variant(mysql.VARCHAR(length=64), "mysql") + .with_variant(sa.VARCHAR(length=64), "postgresql"), + nullable=False, + comment="Name of the data type of the value, one of bool, int, float, str.", + ), + sa.Column( + "doc", + sa.TEXT().with_variant(mysql.LONGTEXT(), "mysql").with_variant(sa.TEXT(), "postgresql"), + nullable=False, + comment="Documentation string.", + ), + sa.Column( + "unit", + sa.VARCHAR(length=128) + .with_variant(mysql.VARCHAR(length=128), "mysql") + .with_variant(sa.VARCHAR(length=128), "postgresql"), + nullable=True, + comment="Unit for the value. Should be from the IVOA (https://www.ivoa.net/documents/VOUnits/) or astropy.", + ), + sa.Column( + "ucd", + sa.VARCHAR(length=128) + .with_variant(mysql.VARCHAR(length=128), "mysql") + .with_variant(sa.VARCHAR(length=128), "postgresql"), + nullable=True, + comment="IVOA Unified Content Descriptor (https://www.ivoa.net/documents/UCD1+/).", + ), + sa.PrimaryKeyConstraint("key"), + schema="cdb_startrackerfast", + mysql_engine="MyISAM", + ) + op.create_table( + "exposure_flexdata", + sa.Column( + "obs_id", + sa.BIGINT().with_variant(mysql.BIGINT(), "mysql").with_variant(sa.BIGINT(), "postgresql"), + nullable=False, + comment="Unique identifier.", + ), + sa.Column( + "key", + sa.VARCHAR(length=128) + .with_variant(mysql.VARCHAR(length=128), "mysql") + .with_variant(sa.VARCHAR(length=128), "postgresql"), + nullable=False, + comment="Name of key.", + ), + sa.Column( + "value", + sa.TEXT().with_variant(mysql.LONGTEXT(), "mysql").with_variant(sa.TEXT(), "postgresql"), + nullable=True, + comment="Content of value as a string.", + ), + sa.ForeignKeyConstraint( + ["key"], ["cdb_startrackerfast.exposure_flexdata_schema.key"], name="fk_exposure_flexdata_key" + ), + sa.ForeignKeyConstraint( + ["obs_id"], ["cdb_startrackerfast.exposure.exposure_id"], name="fk_exposure_flexdata_obs_id" + ), + sa.PrimaryKeyConstraint("obs_id", "key"), + schema="cdb_startrackerfast", + mysql_engine="MyISAM", + ) + op.create_table( + "exposure_quicklook", + sa.Column( + "exposure_id", + sa.BIGINT().with_variant(mysql.BIGINT(), "mysql").with_variant(sa.BIGINT(), "postgresql"), + nullable=False, + comment="Unique identifier.", + ), + sa.Column( + "ra", + sa.DOUBLE() + .with_variant(mysql.DOUBLE(asdecimal=True), "mysql") + .with_variant(sa.DOUBLE_PRECISION(), "postgresql"), + nullable=True, + comment="Central Spatial Position in ICRS; Right ascension of fitted WCS.", + ), + sa.Column( + "dec", + sa.DOUBLE() + .with_variant(mysql.DOUBLE(asdecimal=True), "mysql") + .with_variant(sa.DOUBLE_PRECISION(), "postgresql"), + nullable=True, + comment="Central Spatial Position in ICRS; Declination of fitted WCS.", + ), + sa.Column( + "astrom_offset_mean", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Mean offset of astrometric calibration matches.", + ), + sa.Column( + "astrom_offset_std", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Standard deviation of offsets of astrometric calibration matches.", + ), + sa.Column( + "mean_var", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Mean of the variance plane.", + ), + sa.Column( + "n_psf_star", + sa.INTEGER().with_variant(mysql.INTEGER(), "mysql").with_variant(sa.INTEGER(), "postgresql"), + nullable=True, + comment="Number of stars used for PSF model.", + ), + sa.Column( + "psf_area", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="PSF area.", + ), + sa.Column( + "psf_ixx", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="PSF Ixx moment.", + ), + sa.Column( + "psf_ixy", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="PSF Ixy moment.", + ), + sa.Column( + "psf_iyy", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="PSF Iyy moment", + ), + sa.Column( + "psf_sigma", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="PSF sigma.", + ), + sa.Column( + "psf_star_delta_e1_median", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Median E1 residual (starE1 - psfE1) for PSF stars.", + ), + sa.Column( + "psf_star_delta_e1_scatter", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Scatter (via MAD) of E1 residual (starE1 - psfE1) for PSF stars.", + ), + sa.Column( + "psf_star_delta_e2_median", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Median E2 residual (starE2 - psfE2) for PSF stars.", + ), + sa.Column( + "psf_star_delta_e2_scatter", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Scatter (via MAD) of E2 residual (starE2 - psfE2) for PSF stars.", + ), + sa.Column( + "psf_star_delta_size_median", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Median size residual (starSize - psfSize) for PSF stars.", + ), + sa.Column( + "psf_star_delta_size_scatter", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Scatter (via MAD) of size residual (starSize - psfSize) for stars.", + ), + sa.Column( + "psf_star_scaled_delta_size_scatter", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Scatter (via MAD) of size residual scaled by median size squared.", + ), + sa.Column( + "psf_trace_radius_delta", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Delta (max - min) of model PSF trace radius values evaluated on a grid of unmasked pixels.", + ), + sa.Column( + "sky_bg", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Average sky background.", + ), + sa.Column( + "sky_noise", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="RMS noise of the sky background.", + ), + sa.Column( + "source_count", + sa.INTEGER().with_variant(mysql.INTEGER(), "mysql").with_variant(sa.INTEGER(), "postgresql"), + nullable=True, + comment="Count of sources.", + ), + sa.ForeignKeyConstraint( + ["exposure_id"], ["cdb_startrackerfast.exposure.exposure_id"], name="fk_exposure_quicklook_obs_id" + ), + sa.PrimaryKeyConstraint("exposure_id"), + schema="cdb_startrackerfast", + mysql_engine="MyISAM", + ) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_table("exposure_quicklook", schema="cdb_startrackerfast") + op.drop_table("exposure_flexdata", schema="cdb_startrackerfast") + op.drop_table("exposure_flexdata_schema", schema="cdb_startrackerfast") + op.drop_table("exposure", schema="cdb_startrackerfast") + # ### end Alembic commands ### diff --git a/alembic/startrackernarrow/env.py b/alembic/startrackernarrow/env.py new file mode 120000 index 00000000..74b15c93 --- /dev/null +++ b/alembic/startrackernarrow/env.py @@ -0,0 +1 @@ +../env.py \ No newline at end of file diff --git a/alembic/startrackernarrow/script.py.mako b/alembic/startrackernarrow/script.py.mako new file mode 120000 index 00000000..9ffd8c36 --- /dev/null +++ b/alembic/startrackernarrow/script.py.mako @@ -0,0 +1 @@ +../script.py.mako \ No newline at end of file diff --git a/alembic/startrackernarrow/versions/c12dd2beb619_add_startracker_tables.py b/alembic/startrackernarrow/versions/c12dd2beb619_add_startracker_tables.py new file mode 100644 index 00000000..74d77f72 --- /dev/null +++ b/alembic/startrackernarrow/versions/c12dd2beb619_add_startracker_tables.py @@ -0,0 +1,500 @@ +"""Add startracker tables + +Revision ID: c12dd2beb619 +Revises: +Create Date: 2024-11-12 18:36:01.553449+00:00 + +""" + +from typing import Sequence, Union + +import sqlalchemy as sa +from sqlalchemy.dialects import mysql, postgresql + +from alembic import op + +# revision identifiers, used by Alembic. +revision: str = "c12dd2beb619" +down_revision: Union[str, None] = None +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.create_table( + "exposure", + sa.Column( + "exposure_id", + sa.BIGINT().with_variant(mysql.BIGINT(), "mysql").with_variant(sa.BIGINT(), "postgresql"), + nullable=False, + comment="Unique identifier.", + ), + sa.Column( + "day_obs", + sa.INTEGER().with_variant(mysql.INTEGER(), "mysql").with_variant(sa.INTEGER(), "postgresql"), + nullable=False, + comment="Day of observation.", + ), + sa.Column( + "seq_num", + sa.INTEGER().with_variant(mysql.INTEGER(), "mysql").with_variant(sa.INTEGER(), "postgresql"), + nullable=False, + comment="Sequence number.", + ), + sa.Column( + "s_ra", + sa.DOUBLE() + .with_variant(mysql.DOUBLE(asdecimal=True), "mysql") + .with_variant(sa.DOUBLE_PRECISION(), "postgresql"), + nullable=True, + comment="Central Spatial Position in ICRS; Right ascension of targeted focal plane center.", + ), + sa.Column( + "s_dec", + sa.DOUBLE() + .with_variant(mysql.DOUBLE(asdecimal=True), "mysql") + .with_variant(sa.DOUBLE_PRECISION(), "postgresql"), + nullable=True, + comment="Central Spatial Position in ICRS; Declination of targeted focal plane center.", + ), + sa.Column( + "sky_rotation", + sa.DOUBLE() + .with_variant(mysql.DOUBLE(asdecimal=True), "mysql") + .with_variant(sa.DOUBLE_PRECISION(), "postgresql"), + nullable=True, + comment="Targeted sky rotation angle.", + ), + sa.Column( + "azimuth_start", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Azimuth of focal plane center at the start of the exposure.", + ), + sa.Column( + "azimuth_end", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Azimuth of focal plane center at the end of the exposure.", + ), + sa.Column( + "azimuth", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Azimuth of focal plane center at the middle of the exposure.", + ), + sa.Column( + "altitude_start", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Altitude of focal plane center at the start of the exposure.", + ), + sa.Column( + "altitude_end", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Altitude of focal plane center at the end of the exposure.", + ), + sa.Column( + "altitude", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Altitude of focal plane center at the middle of the exposure.", + ), + sa.Column( + "zenith_distance_start", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Zenith distance at the start of the exposure.", + ), + sa.Column( + "zenith_distance_end", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Zenith distance at the end of the exposure.", + ), + sa.Column( + "zenith_distance", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Zenith distance at the middle of the exposure.", + ), + sa.Column( + "airmass", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Airmass of the observed line of sight at the middle of the exposure.", + ), + sa.Column( + "exp_midpt", + sa.TIMESTAMP() + .with_variant(mysql.DATETIME(fsp=6), "mysql") + .with_variant(postgresql.TIMESTAMP(precision=6), "postgresql"), + nullable=True, + comment="Midpoint time for exposure at the fiducial center of the focal plane. array. TAI, accurate to 10ms.", + ), + sa.Column( + "exp_midpt_mjd", + sa.DOUBLE() + .with_variant(mysql.DOUBLE(asdecimal=True), "mysql") + .with_variant(sa.DOUBLE_PRECISION(), "postgresql"), + nullable=True, + comment="Midpoint time for exposure at the fiducial center of the focal plane. array in MJD. TAI, accurate to 10ms.", + ), + sa.Column( + "obs_start", + sa.TIMESTAMP() + .with_variant(mysql.DATETIME(fsp=6), "mysql") + .with_variant(postgresql.TIMESTAMP(precision=6), "postgresql"), + nullable=True, + comment="Start time of the exposure at the fiducial center of the focal plane. array, TAI, accurate to 10ms.", + ), + sa.Column( + "obs_start_mjd", + sa.DOUBLE() + .with_variant(mysql.DOUBLE(asdecimal=True), "mysql") + .with_variant(sa.DOUBLE_PRECISION(), "postgresql"), + nullable=True, + comment="Start of the exposure in MJD, TAI, accurate to 10ms.", + ), + sa.Column( + "obs_end", + sa.TIMESTAMP() + .with_variant(mysql.DATETIME(fsp=6), "mysql") + .with_variant(postgresql.TIMESTAMP(precision=6), "postgresql"), + nullable=True, + comment="End time of the exposure at the fiducial center of the focal plane. array, TAI, accurate to 10ms.", + ), + sa.Column( + "obs_end_mjd", + sa.DOUBLE() + .with_variant(mysql.DOUBLE(asdecimal=True), "mysql") + .with_variant(sa.DOUBLE_PRECISION(), "postgresql"), + nullable=True, + comment="End of the exposure in MJD, TAI, accurate to 10ms.", + ), + sa.Column( + "exp_time", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Spatially-averaged duration of exposure, accurate to 10ms.", + ), + sa.Column( + "img_type", + sa.VARCHAR(length=64) + .with_variant(mysql.VARCHAR(length=64), "mysql") + .with_variant(sa.VARCHAR(length=64), "postgresql"), + nullable=True, + comment="Type of exposure taken.", + ), + sa.Column( + "target_name", + sa.VARCHAR(length=64) + .with_variant(mysql.VARCHAR(length=64), "mysql") + .with_variant(sa.VARCHAR(length=64), "postgresql"), + nullable=True, + comment="Target of the observation.", + ), + sa.Column( + "air_temp", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Outside air temperature in degC.", + ), + sa.Column( + "pressure", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Outside air pressure.", + ), + sa.Column( + "humidity", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Outside relative humidity.", + ), + sa.Column( + "wind_speed", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Outside wind speed.", + ), + sa.Column( + "wind_dir", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Wind direction.", + ), + sa.Column( + "dimm_seeing", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Seeing as measured by external DIMM (FWHM).", + ), + sa.Column( + "dome_azimuth", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Dome azimuth.", + ), + sa.Column( + "vignette", + sa.VARCHAR(length=10) + .with_variant(mysql.VARCHAR(length=10), "mysql") + .with_variant(sa.VARCHAR(length=10), "postgresql"), + nullable=True, + comment="Instrument blocked from the sky: UNKNOWN, NO, PARTIALLY, FULLY.", + ), + sa.Column( + "vignette_min", + sa.VARCHAR(length=10) + .with_variant(mysql.VARCHAR(length=10), "mysql") + .with_variant(sa.VARCHAR(length=10), "postgresql"), + nullable=True, + comment="Lowest amount of instrument vignetting detected during the exposure: UNKNOWN, NO, PARTIALLY, FULLY.", + ), + sa.PrimaryKeyConstraint("exposure_id"), + sa.UniqueConstraint("day_obs", "seq_num", name="un_day_obs_seq_num"), + schema="cdb_startrackernarrow", + mysql_engine="MyISAM", + ) + op.create_table( + "exposure_flexdata_schema", + sa.Column( + "key", + sa.VARCHAR(length=128) + .with_variant(mysql.VARCHAR(length=128), "mysql") + .with_variant(sa.VARCHAR(length=128), "postgresql"), + nullable=False, + comment="Name of key.", + ), + sa.Column( + "dtype", + sa.VARCHAR(length=64) + .with_variant(mysql.VARCHAR(length=64), "mysql") + .with_variant(sa.VARCHAR(length=64), "postgresql"), + nullable=False, + comment="Name of the data type of the value, one of bool, int, float, str.", + ), + sa.Column( + "doc", + sa.TEXT().with_variant(mysql.LONGTEXT(), "mysql").with_variant(sa.TEXT(), "postgresql"), + nullable=False, + comment="Documentation string.", + ), + sa.Column( + "unit", + sa.VARCHAR(length=128) + .with_variant(mysql.VARCHAR(length=128), "mysql") + .with_variant(sa.VARCHAR(length=128), "postgresql"), + nullable=True, + comment="Unit for the value. Should be from the IVOA (https://www.ivoa.net/documents/VOUnits/) or astropy.", + ), + sa.Column( + "ucd", + sa.VARCHAR(length=128) + .with_variant(mysql.VARCHAR(length=128), "mysql") + .with_variant(sa.VARCHAR(length=128), "postgresql"), + nullable=True, + comment="IVOA Unified Content Descriptor (https://www.ivoa.net/documents/UCD1+/).", + ), + sa.PrimaryKeyConstraint("key"), + schema="cdb_startrackernarrow", + mysql_engine="MyISAM", + ) + op.create_table( + "exposure_flexdata", + sa.Column( + "obs_id", + sa.BIGINT().with_variant(mysql.BIGINT(), "mysql").with_variant(sa.BIGINT(), "postgresql"), + nullable=False, + comment="Unique identifier.", + ), + sa.Column( + "key", + sa.VARCHAR(length=128) + .with_variant(mysql.VARCHAR(length=128), "mysql") + .with_variant(sa.VARCHAR(length=128), "postgresql"), + nullable=False, + comment="Name of key.", + ), + sa.Column( + "value", + sa.TEXT().with_variant(mysql.LONGTEXT(), "mysql").with_variant(sa.TEXT(), "postgresql"), + nullable=True, + comment="Content of value as a string.", + ), + sa.ForeignKeyConstraint( + ["key"], ["cdb_startrackernarrow.exposure_flexdata_schema.key"], name="fk_exposure_flexdata_key" + ), + sa.ForeignKeyConstraint( + ["obs_id"], ["cdb_startrackernarrow.exposure.exposure_id"], name="fk_exposure_flexdata_obs_id" + ), + sa.PrimaryKeyConstraint("obs_id", "key"), + schema="cdb_startrackernarrow", + mysql_engine="MyISAM", + ) + op.create_table( + "exposure_quicklook", + sa.Column( + "exposure_id", + sa.BIGINT().with_variant(mysql.BIGINT(), "mysql").with_variant(sa.BIGINT(), "postgresql"), + nullable=False, + comment="Unique identifier.", + ), + sa.Column( + "ra", + sa.DOUBLE() + .with_variant(mysql.DOUBLE(asdecimal=True), "mysql") + .with_variant(sa.DOUBLE_PRECISION(), "postgresql"), + nullable=True, + comment="Central Spatial Position in ICRS; Right ascension of fitted WCS.", + ), + sa.Column( + "dec", + sa.DOUBLE() + .with_variant(mysql.DOUBLE(asdecimal=True), "mysql") + .with_variant(sa.DOUBLE_PRECISION(), "postgresql"), + nullable=True, + comment="Central Spatial Position in ICRS; Declination of fitted WCS.", + ), + sa.Column( + "astrom_offset_mean", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Mean offset of astrometric calibration matches.", + ), + sa.Column( + "astrom_offset_std", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Standard deviation of offsets of astrometric calibration matches.", + ), + sa.Column( + "mean_var", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Mean of the variance plane.", + ), + sa.Column( + "n_psf_star", + sa.INTEGER().with_variant(mysql.INTEGER(), "mysql").with_variant(sa.INTEGER(), "postgresql"), + nullable=True, + comment="Number of stars used for PSF model.", + ), + sa.Column( + "psf_area", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="PSF area.", + ), + sa.Column( + "psf_ixx", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="PSF Ixx moment.", + ), + sa.Column( + "psf_ixy", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="PSF Ixy moment.", + ), + sa.Column( + "psf_iyy", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="PSF Iyy moment", + ), + sa.Column( + "psf_sigma", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="PSF sigma.", + ), + sa.Column( + "psf_star_delta_e1_median", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Median E1 residual (starE1 - psfE1) for PSF stars.", + ), + sa.Column( + "psf_star_delta_e1_scatter", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Scatter (via MAD) of E1 residual (starE1 - psfE1) for PSF stars.", + ), + sa.Column( + "psf_star_delta_e2_median", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Median E2 residual (starE2 - psfE2) for PSF stars.", + ), + sa.Column( + "psf_star_delta_e2_scatter", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Scatter (via MAD) of E2 residual (starE2 - psfE2) for PSF stars.", + ), + sa.Column( + "psf_star_delta_size_median", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Median size residual (starSize - psfSize) for PSF stars.", + ), + sa.Column( + "psf_star_delta_size_scatter", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Scatter (via MAD) of size residual (starSize - psfSize) for stars.", + ), + sa.Column( + "psf_star_scaled_delta_size_scatter", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Scatter (via MAD) of size residual scaled by median size squared.", + ), + sa.Column( + "psf_trace_radius_delta", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Delta (max - min) of model PSF trace radius values evaluated on a grid of unmasked pixels.", + ), + sa.Column( + "sky_bg", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Average sky background.", + ), + sa.Column( + "sky_noise", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="RMS noise of the sky background.", + ), + sa.Column( + "source_count", + sa.INTEGER().with_variant(mysql.INTEGER(), "mysql").with_variant(sa.INTEGER(), "postgresql"), + nullable=True, + comment="Count of sources.", + ), + sa.ForeignKeyConstraint( + ["exposure_id"], + ["cdb_startrackernarrow.exposure.exposure_id"], + name="fk_exposure_quicklook_obs_id", + ), + sa.PrimaryKeyConstraint("exposure_id"), + schema="cdb_startrackernarrow", + mysql_engine="MyISAM", + ) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_table("exposure_quicklook", schema="cdb_startrackernarrow") + op.drop_table("exposure_flexdata", schema="cdb_startrackernarrow") + op.drop_table("exposure_flexdata_schema", schema="cdb_startrackernarrow") + op.drop_table("exposure", schema="cdb_startrackernarrow") + # ### end Alembic commands ### diff --git a/alembic/startrackerwide/env.py b/alembic/startrackerwide/env.py new file mode 120000 index 00000000..74b15c93 --- /dev/null +++ b/alembic/startrackerwide/env.py @@ -0,0 +1 @@ +../env.py \ No newline at end of file diff --git a/alembic/startrackerwide/script.py.mako b/alembic/startrackerwide/script.py.mako new file mode 120000 index 00000000..9ffd8c36 --- /dev/null +++ b/alembic/startrackerwide/script.py.mako @@ -0,0 +1 @@ +../script.py.mako \ No newline at end of file diff --git a/alembic/startrackerwide/versions/b7c7dc55439d_add_startracker_tables.py b/alembic/startrackerwide/versions/b7c7dc55439d_add_startracker_tables.py new file mode 100644 index 00000000..b05b8dad --- /dev/null +++ b/alembic/startrackerwide/versions/b7c7dc55439d_add_startracker_tables.py @@ -0,0 +1,498 @@ +"""Add startracker tables + +Revision ID: b7c7dc55439d +Revises: +Create Date: 2024-11-12 18:36:00.641218+00:00 + +""" + +from typing import Sequence, Union + +import sqlalchemy as sa +from sqlalchemy.dialects import mysql, postgresql + +from alembic import op + +# revision identifiers, used by Alembic. +revision: str = "b7c7dc55439d" +down_revision: Union[str, None] = None +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.create_table( + "exposure", + sa.Column( + "exposure_id", + sa.BIGINT().with_variant(mysql.BIGINT(), "mysql").with_variant(sa.BIGINT(), "postgresql"), + nullable=False, + comment="Unique identifier.", + ), + sa.Column( + "day_obs", + sa.INTEGER().with_variant(mysql.INTEGER(), "mysql").with_variant(sa.INTEGER(), "postgresql"), + nullable=False, + comment="Day of observation.", + ), + sa.Column( + "seq_num", + sa.INTEGER().with_variant(mysql.INTEGER(), "mysql").with_variant(sa.INTEGER(), "postgresql"), + nullable=False, + comment="Sequence number.", + ), + sa.Column( + "s_ra", + sa.DOUBLE() + .with_variant(mysql.DOUBLE(asdecimal=True), "mysql") + .with_variant(sa.DOUBLE_PRECISION(), "postgresql"), + nullable=True, + comment="Central Spatial Position in ICRS; Right ascension of targeted focal plane center.", + ), + sa.Column( + "s_dec", + sa.DOUBLE() + .with_variant(mysql.DOUBLE(asdecimal=True), "mysql") + .with_variant(sa.DOUBLE_PRECISION(), "postgresql"), + nullable=True, + comment="Central Spatial Position in ICRS; Declination of targeted focal plane center.", + ), + sa.Column( + "sky_rotation", + sa.DOUBLE() + .with_variant(mysql.DOUBLE(asdecimal=True), "mysql") + .with_variant(sa.DOUBLE_PRECISION(), "postgresql"), + nullable=True, + comment="Targeted sky rotation angle.", + ), + sa.Column( + "azimuth_start", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Azimuth of focal plane center at the start of the exposure.", + ), + sa.Column( + "azimuth_end", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Azimuth of focal plane center at the end of the exposure.", + ), + sa.Column( + "azimuth", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Azimuth of focal plane center at the middle of the exposure.", + ), + sa.Column( + "altitude_start", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Altitude of focal plane center at the start of the exposure.", + ), + sa.Column( + "altitude_end", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Altitude of focal plane center at the end of the exposure.", + ), + sa.Column( + "altitude", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Altitude of focal plane center at the middle of the exposure.", + ), + sa.Column( + "zenith_distance_start", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Zenith distance at the start of the exposure.", + ), + sa.Column( + "zenith_distance_end", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Zenith distance at the end of the exposure.", + ), + sa.Column( + "zenith_distance", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Zenith distance at the middle of the exposure.", + ), + sa.Column( + "airmass", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Airmass of the observed line of sight at the middle of the exposure.", + ), + sa.Column( + "exp_midpt", + sa.TIMESTAMP() + .with_variant(mysql.DATETIME(fsp=6), "mysql") + .with_variant(postgresql.TIMESTAMP(precision=6), "postgresql"), + nullable=True, + comment="Midpoint time for exposure at the fiducial center of the focal plane. array. TAI, accurate to 10ms.", + ), + sa.Column( + "exp_midpt_mjd", + sa.DOUBLE() + .with_variant(mysql.DOUBLE(asdecimal=True), "mysql") + .with_variant(sa.DOUBLE_PRECISION(), "postgresql"), + nullable=True, + comment="Midpoint time for exposure at the fiducial center of the focal plane. array in MJD. TAI, accurate to 10ms.", + ), + sa.Column( + "obs_start", + sa.TIMESTAMP() + .with_variant(mysql.DATETIME(fsp=6), "mysql") + .with_variant(postgresql.TIMESTAMP(precision=6), "postgresql"), + nullable=True, + comment="Start time of the exposure at the fiducial center of the focal plane. array, TAI, accurate to 10ms.", + ), + sa.Column( + "obs_start_mjd", + sa.DOUBLE() + .with_variant(mysql.DOUBLE(asdecimal=True), "mysql") + .with_variant(sa.DOUBLE_PRECISION(), "postgresql"), + nullable=True, + comment="Start of the exposure in MJD, TAI, accurate to 10ms.", + ), + sa.Column( + "obs_end", + sa.TIMESTAMP() + .with_variant(mysql.DATETIME(fsp=6), "mysql") + .with_variant(postgresql.TIMESTAMP(precision=6), "postgresql"), + nullable=True, + comment="End time of the exposure at the fiducial center of the focal plane. array, TAI, accurate to 10ms.", + ), + sa.Column( + "obs_end_mjd", + sa.DOUBLE() + .with_variant(mysql.DOUBLE(asdecimal=True), "mysql") + .with_variant(sa.DOUBLE_PRECISION(), "postgresql"), + nullable=True, + comment="End of the exposure in MJD, TAI, accurate to 10ms.", + ), + sa.Column( + "exp_time", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Spatially-averaged duration of exposure, accurate to 10ms.", + ), + sa.Column( + "img_type", + sa.VARCHAR(length=64) + .with_variant(mysql.VARCHAR(length=64), "mysql") + .with_variant(sa.VARCHAR(length=64), "postgresql"), + nullable=True, + comment="Type of exposure taken.", + ), + sa.Column( + "target_name", + sa.VARCHAR(length=64) + .with_variant(mysql.VARCHAR(length=64), "mysql") + .with_variant(sa.VARCHAR(length=64), "postgresql"), + nullable=True, + comment="Target of the observation.", + ), + sa.Column( + "air_temp", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Outside air temperature in degC.", + ), + sa.Column( + "pressure", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Outside air pressure.", + ), + sa.Column( + "humidity", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Outside relative humidity.", + ), + sa.Column( + "wind_speed", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Outside wind speed.", + ), + sa.Column( + "wind_dir", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Wind direction.", + ), + sa.Column( + "dimm_seeing", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Seeing as measured by external DIMM (FWHM).", + ), + sa.Column( + "dome_azimuth", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Dome azimuth.", + ), + sa.Column( + "vignette", + sa.VARCHAR(length=10) + .with_variant(mysql.VARCHAR(length=10), "mysql") + .with_variant(sa.VARCHAR(length=10), "postgresql"), + nullable=True, + comment="Instrument blocked from the sky: UNKNOWN, NO, PARTIALLY, FULLY.", + ), + sa.Column( + "vignette_min", + sa.VARCHAR(length=10) + .with_variant(mysql.VARCHAR(length=10), "mysql") + .with_variant(sa.VARCHAR(length=10), "postgresql"), + nullable=True, + comment="Lowest amount of instrument vignetting detected during the exposure: UNKNOWN, NO, PARTIALLY, FULLY.", + ), + sa.PrimaryKeyConstraint("exposure_id"), + sa.UniqueConstraint("day_obs", "seq_num", name="un_day_obs_seq_num"), + schema="cdb_startrackerwide", + mysql_engine="MyISAM", + ) + op.create_table( + "exposure_flexdata_schema", + sa.Column( + "key", + sa.VARCHAR(length=128) + .with_variant(mysql.VARCHAR(length=128), "mysql") + .with_variant(sa.VARCHAR(length=128), "postgresql"), + nullable=False, + comment="Name of key.", + ), + sa.Column( + "dtype", + sa.VARCHAR(length=64) + .with_variant(mysql.VARCHAR(length=64), "mysql") + .with_variant(sa.VARCHAR(length=64), "postgresql"), + nullable=False, + comment="Name of the data type of the value, one of bool, int, float, str.", + ), + sa.Column( + "doc", + sa.TEXT().with_variant(mysql.LONGTEXT(), "mysql").with_variant(sa.TEXT(), "postgresql"), + nullable=False, + comment="Documentation string.", + ), + sa.Column( + "unit", + sa.VARCHAR(length=128) + .with_variant(mysql.VARCHAR(length=128), "mysql") + .with_variant(sa.VARCHAR(length=128), "postgresql"), + nullable=True, + comment="Unit for the value. Should be from the IVOA (https://www.ivoa.net/documents/VOUnits/) or astropy.", + ), + sa.Column( + "ucd", + sa.VARCHAR(length=128) + .with_variant(mysql.VARCHAR(length=128), "mysql") + .with_variant(sa.VARCHAR(length=128), "postgresql"), + nullable=True, + comment="IVOA Unified Content Descriptor (https://www.ivoa.net/documents/UCD1+/).", + ), + sa.PrimaryKeyConstraint("key"), + schema="cdb_startrackerwide", + mysql_engine="MyISAM", + ) + op.create_table( + "exposure_flexdata", + sa.Column( + "obs_id", + sa.BIGINT().with_variant(mysql.BIGINT(), "mysql").with_variant(sa.BIGINT(), "postgresql"), + nullable=False, + comment="Unique identifier.", + ), + sa.Column( + "key", + sa.VARCHAR(length=128) + .with_variant(mysql.VARCHAR(length=128), "mysql") + .with_variant(sa.VARCHAR(length=128), "postgresql"), + nullable=False, + comment="Name of key.", + ), + sa.Column( + "value", + sa.TEXT().with_variant(mysql.LONGTEXT(), "mysql").with_variant(sa.TEXT(), "postgresql"), + nullable=True, + comment="Content of value as a string.", + ), + sa.ForeignKeyConstraint( + ["key"], ["cdb_startrackerwide.exposure_flexdata_schema.key"], name="fk_exposure_flexdata_key" + ), + sa.ForeignKeyConstraint( + ["obs_id"], ["cdb_startrackerwide.exposure.exposure_id"], name="fk_exposure_flexdata_obs_id" + ), + sa.PrimaryKeyConstraint("obs_id", "key"), + schema="cdb_startrackerwide", + mysql_engine="MyISAM", + ) + op.create_table( + "exposure_quicklook", + sa.Column( + "exposure_id", + sa.BIGINT().with_variant(mysql.BIGINT(), "mysql").with_variant(sa.BIGINT(), "postgresql"), + nullable=False, + comment="Unique identifier.", + ), + sa.Column( + "ra", + sa.DOUBLE() + .with_variant(mysql.DOUBLE(asdecimal=True), "mysql") + .with_variant(sa.DOUBLE_PRECISION(), "postgresql"), + nullable=True, + comment="Central Spatial Position in ICRS; Right ascension of fitted WCS.", + ), + sa.Column( + "dec", + sa.DOUBLE() + .with_variant(mysql.DOUBLE(asdecimal=True), "mysql") + .with_variant(sa.DOUBLE_PRECISION(), "postgresql"), + nullable=True, + comment="Central Spatial Position in ICRS; Declination of fitted WCS.", + ), + sa.Column( + "astrom_offset_mean", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Mean offset of astrometric calibration matches.", + ), + sa.Column( + "astrom_offset_std", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Standard deviation of offsets of astrometric calibration matches.", + ), + sa.Column( + "mean_var", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Mean of the variance plane.", + ), + sa.Column( + "n_psf_star", + sa.INTEGER().with_variant(mysql.INTEGER(), "mysql").with_variant(sa.INTEGER(), "postgresql"), + nullable=True, + comment="Number of stars used for PSF model.", + ), + sa.Column( + "psf_area", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="PSF area.", + ), + sa.Column( + "psf_ixx", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="PSF Ixx moment.", + ), + sa.Column( + "psf_ixy", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="PSF Ixy moment.", + ), + sa.Column( + "psf_iyy", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="PSF Iyy moment", + ), + sa.Column( + "psf_sigma", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="PSF sigma.", + ), + sa.Column( + "psf_star_delta_e1_median", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Median E1 residual (starE1 - psfE1) for PSF stars.", + ), + sa.Column( + "psf_star_delta_e1_scatter", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Scatter (via MAD) of E1 residual (starE1 - psfE1) for PSF stars.", + ), + sa.Column( + "psf_star_delta_e2_median", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Median E2 residual (starE2 - psfE2) for PSF stars.", + ), + sa.Column( + "psf_star_delta_e2_scatter", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Scatter (via MAD) of E2 residual (starE2 - psfE2) for PSF stars.", + ), + sa.Column( + "psf_star_delta_size_median", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Median size residual (starSize - psfSize) for PSF stars.", + ), + sa.Column( + "psf_star_delta_size_scatter", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Scatter (via MAD) of size residual (starSize - psfSize) for stars.", + ), + sa.Column( + "psf_star_scaled_delta_size_scatter", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Scatter (via MAD) of size residual scaled by median size squared.", + ), + sa.Column( + "psf_trace_radius_delta", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Delta (max - min) of model PSF trace radius values evaluated on a grid of unmasked pixels.", + ), + sa.Column( + "sky_bg", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="Average sky background.", + ), + sa.Column( + "sky_noise", + sa.FLOAT().with_variant(mysql.FLOAT(), "mysql").with_variant(sa.FLOAT(), "postgresql"), + nullable=True, + comment="RMS noise of the sky background.", + ), + sa.Column( + "source_count", + sa.INTEGER().with_variant(mysql.INTEGER(), "mysql").with_variant(sa.INTEGER(), "postgresql"), + nullable=True, + comment="Count of sources.", + ), + sa.ForeignKeyConstraint( + ["exposure_id"], ["cdb_startrackerwide.exposure.exposure_id"], name="fk_exposure_quicklook_obs_id" + ), + sa.PrimaryKeyConstraint("exposure_id"), + schema="cdb_startrackerwide", + mysql_engine="MyISAM", + ) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_table("exposure_quicklook", schema="cdb_startrackerwide") + op.drop_table("exposure_flexdata", schema="cdb_startrackerwide") + op.drop_table("exposure_flexdata_schema", schema="cdb_startrackerwide") + op.drop_table("exposure", schema="cdb_startrackerwide") + # ### end Alembic commands ###