Skip to content

Commit

Permalink
Adds ORM for sqla for sdss5db (#224)
Browse files Browse the repository at this point in the history
* adding apogee schema to post connect reflect

* adding init for sdss5db in sqla

* adding init orm for targetdb and apogeedb

* add schema for opsdb

* updating orms

* updating some docs

* fixing opsdb schema

* updating apogee drp

* adding init schema of catalogdb

* remove duplicate tables, add s to status

* adding boss_drp orm

* updating docs for boss_drp

* linting

* fixing linting

* remove sqa instrument duplciate

* updating array fields in boss

* adding a note to revised_magnitude table

---------

Co-authored-by: johndonor3 <[email protected]>
  • Loading branch information
havok2063 and johndonor3 authored Sep 28, 2023
1 parent 3d044fc commit 417d88c
Show file tree
Hide file tree
Showing 15 changed files with 12,046 additions and 4 deletions.
29 changes: 27 additions & 2 deletions docs/sphinx/intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ Currently, we support the following databases and schemas:
* **sdss5db**: the SDSS-V development database.
* *catalogdb*: schema for source catalogues used for target selection.
* *targetdb*: schema with the results of the target selection and positioner information.
* *opsdb*: schema for the operations database
* *apogee_drpdb*: schema with the results of the MWM DRP
* *boss_drp*: schema with the results of the BHM DRP

* **archive**: the SDSS science archive database.
* *sas*: schema for SAS.

Expand Down Expand Up @@ -119,16 +123,37 @@ Note that the level of readiness is not necessarily identical in both Peewee and
<td class="active">sdss5db</td>
<td class="active">catalogdb</td>
<td class="success"></td>
<td class="danger"></td>
<td class="success"></td>
<td align="center"><a class="glyphicon glyphicon-download-alt" href="https://github.com/sdss/sdssdb/raw/main/schema/sdss5db/catalogdb/sdss5db.catalogdb.pdf" alt="catalogdb full version"></a> <a class="glyphicon glyphicon-download-alt" style="color:green" href="https://github.com/sdss/sdssdb/raw/main/schema/sdss5db/catalogdb/sdss5db.catalogdb_lite.pdf" alt="catalogdb reduced version"></td>
</tr>
<tr>
<td></td>
<td class="active">targetdb</td>
<td class="success"></td>
<td class="danger"></td>
<td class="success"></td>
<td align="center"><a class="glyphicon glyphicon-download-alt" href="https://github.com/sdss/sdssdb/raw/main/schema/sdss5db/targetdb/sdss5db.targetdb.pdf"></a></td>
</tr>
<tr>
<td></td>
<td class="active">opsdb</td>
<td class="success"></td>
<td class="success"></td>
<td align="center"><a class="glyphicon glyphicon-download-alt" href="https://github.com/sdss/sdssdb/raw/main/schema/sdss5db/opsdb/sdss5db.opsdb.pdf"></a></td>
</tr>
<tr>
<td></td>
<td class="active">apogee_drpdb</td>
<td class="success"></td>
<td class="success"></td>
<td align="center"><a class="glyphicon glyphicon-download-alt" href="https://github.com/sdss/sdssdb/raw/main/schema/sdss5db/apogee_drpdb/sdss5db.apogee_drpdb.pdf"></a></td>
</tr>
<tr>
<td></td>
<td class="active">boss_drp</td>
<td class="success"></td>
<td class="success"></td>
<td align="center"><a class="glyphicon glyphicon-download-alt" href="https://github.com/sdss/sdssdb/raw/main/schema/sdss5db/boss_drp/sdss5db.boss_drp.pdf"></a></td>
</tr>
<tr>
<td class="active">archive</td>
<td class="active">sas</td>
Expand Down
3 changes: 2 additions & 1 deletion python/sdssdb/peewee/sdss5db/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def post_connect(self):

modules = ['sdssdb.peewee.sdss5db.catalogdb',
'sdssdb.peewee.sdss5db.targetdb',
'sdssdb.peewee.sdss5db.opsdb']
'sdssdb.peewee.sdss5db.opsdb',
'sdssdb.peewee.sdss5db.apogee_drpdb']

for module in modules:
if module in sys.modules:
Expand Down
317 changes: 317 additions & 0 deletions python/sdssdb/peewee/sdss5db/boss_drp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,317 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#

# Code generated by:
# python -m pwiz -e postgresql sdss5db -s boss_drp -i -o -H localhost -p 6000 -u u0857802
# Date: September 28, 2023 11:13AM
# Database: sdss5db
# Peewee version: 3.15.1


from peewee import (AutoField, BigIntegerField, BlobField, BooleanField, CharField, DateTimeField,
FloatField, ForeignKeyField, IntegerField, DoubleField, SmallIntegerField)
from peewee import SQL
from playhouse.postgres_ext import ArrayField

from .. import BaseModel
from . import database # noqa


class BossBase(BaseModel):

class Meta:
schema = 'boss_drp'
database = database


class BossVersion(BossBase):
id = AutoField()
ipl = SmallIntegerField(null=True)
run2d = CharField(null=True)
run1d = CharField(null=True)
is_default = BooleanField(null=True)
is_epoch = BooleanField(null=True)
is_custom = BooleanField(null=True)
custom_name = CharField(null=True)
created = DateTimeField(null=True)
modified = DateTimeField(constraints=[SQL("DEFAULT now()")], null=True)

class Meta:
table_name = 'boss_version'


class BossField(BossBase):
id = AutoField()
boss_version = ForeignKeyField(column_name='boss_version_id', field='id', model=BossVersion)
field = IntegerField(null=True)
designs = CharField(null=True)
configs = CharField(null=True)
mjd = IntegerField(null=True)
observatory = CharField(null=True)
run2d = CharField(null=True)
run1d = CharField(null=True)
racen = FloatField(null=True)
deccen = FloatField(null=True)
epoch = FloatField(null=True)
cartid = CharField(null=True)
tai = DoubleField(null=True)
tai_beg = DoubleField(null=True)
tai_end = DoubleField(null=True)
airmass = FloatField(null=True)
exptime = FloatField(null=True)
mapname = CharField(null=True)
tileid = IntegerField(null=True)
designid = IntegerField(null=True)
survey = CharField(null=True)
programname = CharField(null=True)
chunk = CharField(null=True)
fieldquality = CharField(null=True)
fieldsn2 = FloatField(null=True)
deredsn2 = FloatField(null=True)
qsurvey = IntegerField(null=True)
mjdlist = CharField(null=True)
nexp = IntegerField(null=True)
nexp_b1 = IntegerField(null=True)
nexp_r1 = IntegerField(null=True)
nexp_b2 = IntegerField(null=True)
nexp_r2 = IntegerField(null=True)
expt_b1 = FloatField(null=True)
expt_r1 = FloatField(null=True)
expt_b2 = FloatField(null=True)
expt_r2 = FloatField(null=True)
sn2_g1 = FloatField(null=True)
sn2_r1 = FloatField(null=True)
sn2_i1 = FloatField(null=True)
sn2_g2 = FloatField(null=True)
sn2_r2 = FloatField(null=True)
sn2_i2 = FloatField(null=True)
goffstd = FloatField(null=True)
grmsstd = FloatField(null=True)
roffstd = FloatField(null=True)
rrmsstd = FloatField(null=True)
ioffstd = FloatField(null=True)
irmsstd = FloatField(null=True)
groffstd = FloatField(null=True)
grrmsstd = FloatField(null=True)
rioffstd = FloatField(null=True)
rirmsstd = FloatField(null=True)
goffgal = FloatField(null=True)
grmsgal = FloatField(null=True)
roffgal = FloatField(null=True)
rrmsgal = FloatField(null=True)
ioffgal = FloatField(null=True)
irmsgal = FloatField(null=True)
groffgal = FloatField(null=True)
grrmsgal = FloatField(null=True)
rioffgal = FloatField(null=True)
rirmsgal = FloatField(null=True)
nguide = IntegerField(null=True)
seeing20 = FloatField(null=True)
seeing50 = FloatField(null=True)
seeing80 = FloatField(null=True)
rmsoff20 = FloatField(null=True)
rmsoff50 = FloatField(null=True)
rmsoff80 = FloatField(null=True)
airtemp = FloatField(null=True)
xsigma = FloatField(null=True)
xsigmin = FloatField(null=True)
xsigmax = FloatField(null=True)
wsigma = FloatField(null=True)
wsigmin = FloatField(null=True)
wsigmax = FloatField(null=True)
xchi2 = FloatField(null=True)
xchi2min = FloatField(null=True)
xchi2max = FloatField(null=True)
skychi2 = FloatField(null=True)
schi2min = FloatField(null=True)
schi2max = FloatField(null=True)
fbadpix = FloatField(null=True)
fbadpix1 = FloatField(null=True)
fbadpix2 = FloatField(null=True)
n_total = IntegerField(null=True)
n_galaxy = IntegerField(null=True)
n_qso = IntegerField(null=True)
n_star = IntegerField(null=True)
n_unknown = IntegerField(null=True)
n_sky = IntegerField(null=True)
n_std = IntegerField(null=True)
n_target_qso = IntegerField(null=True)
n_target_main = IntegerField(null=True)
n_target_lrg1 = IntegerField(null=True)
n_target_elg = IntegerField(null=True)
success_main = FloatField(null=True)
success_lrg1 = FloatField(null=True)
success_lrg2 = FloatField(null=True)
success_elg = FloatField(null=True)
success_qso = FloatField(null=True)
status2d = CharField(null=True)
statuscombine = CharField(null=True)
status1d = CharField(null=True)
public = CharField(null=True)
qualcomments = CharField(null=True)
moon_frac = FloatField(null=True)
created = DateTimeField(null=True)
modified = DateTimeField(constraints=[SQL("DEFAULT now()")], null=True)

class Meta:
table_name = 'boss_field'


class BossSpectrum(BossBase):
id = AutoField()
boss_version = ForeignKeyField(column_name='boss_version_id', field='id', model=BossVersion)
field = SmallIntegerField(null=True)
mjd = IntegerField(null=True)
mjd_final = FloatField(null=True)
obs = CharField(null=True)
run2d = CharField(null=True)
run1d = CharField(null=True)
nexp = SmallIntegerField(null=True)
exptime = FloatField(null=True)
target_index = IntegerField(null=True)
spec_file = CharField(null=True)
programname = CharField(null=True)
survey = CharField(null=True)
cadence = CharField(null=True)
firstcarton = CharField(null=True)
sdss5_target_flags = BlobField(null=True)
objtype = CharField(null=True)
catalogid = BigIntegerField(null=True)
sdss_id = BigIntegerField(null=True)
specobjid = BigIntegerField(null=True)
calibflux = FloatField(null=True)
calibflux_ivar = FloatField(null=True)
optical_prov = CharField(null=True)
mag = ArrayField(FloatField, null=True) # ARRAY
psfmag = ArrayField(FloatField, null=True) # ARRAY
fiber2mag = ArrayField(FloatField, null=True) # ARRAY
catdb_mag = ArrayField(FloatField, null=True) # ARRAY
gaia_bp_mag = FloatField(null=True)
gaia_rp_mag = FloatField(null=True)
gaia_g_mag = FloatField(null=True)
gaia_id = BigIntegerField(null=True)
wise_mag = ArrayField(FloatField, null=True) # ARRAY
twomass_mag = ArrayField(FloatField, null=True) # ARRAY
guvcat_mag = ArrayField(FloatField, null=True) # ARRAY
ebv = FloatField(null=True)
ebv_type = CharField(null=True)
fiber_ra = DoubleField(null=True)
fiber_dec = DoubleField(null=True)
plug_ra = DoubleField(null=True)
plug_dec = DoubleField(null=True)
racat = DoubleField(null=True)
deccat = DoubleField(null=True)
coord_epoch = FloatField(null=True)
pmra = FloatField(null=True)
pmdec = FloatField(null=True)
parallax = FloatField(null=True)
fiber_offset = IntegerField(null=True)
lambda_eff = FloatField(null=True)
healpix = IntegerField(null=True)
healpixgrp = SmallIntegerField(null=True)
healpix_dir = CharField(null=True)
fieldquality = CharField(null=True)
exp_disp_med = DoubleField(null=True)
fieldsn2 = FloatField(null=True)
spec1_g = FloatField(null=True)
spec1_r = FloatField(null=True)
spec1_i = FloatField(null=True)
spec2_g = FloatField(null=True)
spec2_r = FloatField(null=True)
spec2_i = FloatField(null=True)
sn_median = ArrayField(FloatField, null=True) # ARRAY
sn_median_all = FloatField(null=True)
airmass = FloatField(null=True)
seeing20 = FloatField(null=True)
seeing50 = FloatField(null=True)
seeing80 = FloatField(null=True)
moon_dist = FloatField(null=True)
moon_phase = FloatField(null=True)
assigned = BooleanField(null=True)
on_target = BooleanField(null=True)
valid = BooleanField(null=True)
decollided = BooleanField(null=True)
anyandmask = IntegerField(null=True)
anyormask = IntegerField(null=True)
specprimary = SmallIntegerField(null=True)
specboss = SmallIntegerField(null=True)
boss_specobj_id = IntegerField(null=True)
nspecobs = SmallIntegerField(null=True)
spectroflux = ArrayField(FloatField, null=True) # ARRAY
spectroflux_ivar = ArrayField(FloatField, null=True) # ARRAY
spectrosynflux = ArrayField(FloatField, null=True) # ARRAY
spectrosynflux_ivar = ArrayField(FloatField, null=True) # ARRAY
spectroskyflux = ArrayField(FloatField, null=True) # ARRAY
wavemin = FloatField(null=True)
wavemax = FloatField(null=True)
wcoverage = FloatField(null=True)
objclass = CharField(null=True)
subclass = CharField(null=True)
z = FloatField(null=True)
z_err = FloatField(null=True)
zwarning = IntegerField(null=True)
rchi2 = FloatField(null=True)
dof = IntegerField(null=True)
rchi2diff = FloatField(null=True)
tfile = CharField(null=True)
vdisp = FloatField(null=True)
vdisp_err = FloatField(null=True)
vdispz = FloatField(null=True)
vdispz_err = FloatField(null=True)
vdispchi2 = FloatField(null=True)
vdispnpix = FloatField(null=True)
vdispdof = IntegerField(null=True)
chi68p = FloatField(null=True)
z_noqso = FloatField(null=True)
z_err_noqso = FloatField(null=True)
znum_noqso = IntegerField(null=True)
zwarning_noqso = IntegerField(null=True)
class_noqso = CharField(null=True)
subclass_noqso = CharField(null=True)
rchi2diff_noqso = FloatField(null=True)
xcsao_rv = FloatField(null=True)
xcsao_erv = FloatField(null=True)
xcsao_rxc = FloatField(null=True)
xcsao_teff = FloatField(null=True)
xcsao_eteff = FloatField(null=True)
xcsao_logg = FloatField(null=True)
xcsao_elogg = FloatField(null=True)
xcsao_feh = FloatField(null=True)
xcsao_efeh = FloatField(null=True)
created = DateTimeField(null=True)
modified = DateTimeField(constraints=[SQL("DEFAULT now()")], null=True)

class Meta:
table_name = 'boss_spectrum'


class BossSpectrumLine(BossBase):
id = AutoField()
boss_version = ForeignKeyField(column_name='boss_version_id', field='id', model=BossVersion)
field = IntegerField(null=True)
mjd = IntegerField(null=True)
target_index = IntegerField(null=True)
catalogid = BigIntegerField(null=True)
sdss_id = BigIntegerField(null=True)
linename = CharField(null=True)
linewave = DoubleField(null=True)
linez = FloatField(null=True)
linez_err = FloatField(null=True)
linesigma = FloatField(null=True)
linesigma_err = FloatField(null=True)
linearea = FloatField(null=True)
linearea_err = FloatField(null=True)
lineew = FloatField(null=True)
lineew_err = FloatField(null=True)
linecontlevel = FloatField(null=True)
linecontlevel_err = FloatField(null=True)
linenpixleft = IntegerField(null=True)
linenpixright = IntegerField(null=True)
linedof = FloatField(null=True)
linechi2 = FloatField(null=True)
created = DateTimeField(null=True)
modified = DateTimeField(constraints=[SQL("DEFAULT now()")], null=True)

class Meta:
table_name = 'boss_spectrum_line'
9 changes: 9 additions & 0 deletions python/sdssdb/peewee/sdss5db/targetdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,15 @@ class Meta:


class RevisedMagnitude(TargetdbBase):
"""Revised optical magnitudes.
This table contains SDSS g,r,i,z magnitudes calculated from Gaia DR3 XP
spectra (see Gaia_dr3_synthetic_photometry_gspc). This only applies
to v0.1 and v0.5. For v1 targets with r<15 automatically use XP synthetic
magnitudes.
"""

bp = FloatField(null=True)
g = FloatField(null=True)
h = FloatField(null=True)
Expand Down
Loading

0 comments on commit 417d88c

Please sign in to comment.