Skip to content

Commit

Permalink
Merge pull request #52 from lsst-dm/tickets/DM-47443
Browse files Browse the repository at this point in the history
Migrations for recent sdm_schemas: psf, pixelscale, mountjitter, magnitude limits
  • Loading branch information
Vebop authored Nov 28, 2024
2 parents 55de4cb + db81f21 commit 593b437
Show file tree
Hide file tree
Showing 14 changed files with 2,299 additions and 12 deletions.
20 changes: 8 additions & 12 deletions alembic-autogenerate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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!
==========================================
"""
)
12 changes: 12 additions & 0 deletions alembic.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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 ###
Loading

0 comments on commit 593b437

Please sign in to comment.