Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update targetdb schema with changes to cadence, carton_to_target, and others #66

Merged
merged 11 commits into from
Feb 24, 2021
83 changes: 47 additions & 36 deletions python/sdssdb/peewee/sdss5db/targetdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Meta:
database = database


AssignmentDeferred = DeferredThroughModel()
# AssignmentDeferred = DeferredThroughModel()
CartonToTargetDeferred = DeferredThroughModel()


Expand All @@ -39,14 +39,16 @@ class Meta:


class Cadence(TargetdbBase):
label = TextField(null=False)
nepochs = IntegerField(null=True)
delta = ArrayField(field_class=FloatField, null=True)
delta_max = ArrayField(field_class=FloatField, null=True)
delta_min = ArrayField(field_class=FloatField, null=True)
instrument_pk = ArrayField(field_class=IntegerField, null=True)
label = TextField(null=False)
nexposures = SmallIntegerField(null=True)
# instrument_pk = ArrayField(field_class=IntegerField, null=True)
nexp = ArrayField(field_class=SmallIntegerField, null=True)
pk = AutoField()
skybrightness = ArrayField(field_class=FloatField, null=True)
max_length = ArrayField(field_class=FloatField, null=True)

class Meta:
table_name = 'cadence'
Expand All @@ -62,9 +64,11 @@ class Meta:

class Field(TargetdbBase):
pk = AutoField()
field_id = IntegerField(null=False)
racen = DoubleField(null=False)
deccen = DoubleField(null=False)
position_angle = FloatField(null=True)
slots_exposures = ArrayField(field_class=IntegerField, null=True)
cadence = ForeignKeyField(column_name='cadence_pk',
field='pk',
model=Cadence,
Expand Down Expand Up @@ -182,43 +186,24 @@ class Target(TargetdbBase):
pmdec = FloatField(null=True)
pmra = FloatField(null=True)
ra = DoubleField(null=True)
designs = ManyToManyField(Design,
through_model=AssignmentDeferred,
backref='targets')
positioners = ManyToManyField(Positioner,
through_model=AssignmentDeferred,
backref='targets')
instruments = ManyToManyField(Instrument,
through_model=AssignmentDeferred,
backref='targets')
cadences = ManyToManyField(Cadence,
through_model=CartonToTargetDeferred,
backref='targets')
# designs = ManyToManyField(Design,
# through_model=AssignmentDeferred,
# backref='targets')
# positioners = ManyToManyField(Positioner,
# through_model=AssignmentDeferred,
# backref='targets')
# instruments = ManyToManyField(Instrument,
# through_model=AssignmentDeferred,
# backref='targets')
# cadences = ManyToManyField(Cadence,
# through_model=CartonToTargetDeferred,
# backref='targets')
parallax = FloatField(null=True)

class Meta:
table_name = 'target'


class Assignment(TargetdbBase):
design = ForeignKeyField(Design,
column_name='design_pk',
field='pk')
instrument = ForeignKeyField(Instrument,
column_name='instrument_pk',
field='pk')
pk = AutoField()
positioner = ForeignKeyField(Positioner,
column_name='positioner_pk',
field='pk')
target = ForeignKeyField(Target,
column_name='target_pk',
field='pk')

class Meta:
table_name = 'assignment'


class CartonToTarget(TargetdbBase):
cadence = ForeignKeyField(Cadence,
column_name='cadence_pk',
Expand All @@ -234,11 +219,33 @@ class CartonToTarget(TargetdbBase):
on_delete='CASCADE')
priority = IntegerField()
value = FloatField()
instrument_pk = ForeignKeyField(Instrument,
column_name='instrument_pk',
field='pk')

class Meta:
table_name = 'carton_to_target'


class Assignment(TargetdbBase):
design = ForeignKeyField(Design,
column_name='design_pk',
field='pk')
instrument = ForeignKeyField(Instrument,
column_name='instrument_pk',
field='pk')
pk = AutoField()
positioner = ForeignKeyField(Positioner,
column_name='positioner_pk',
field='pk')
carton_to_target = ForeignKeyField(CartonToTarget,
column_name='carton_to_target_pk',
field='pk')

class Meta:
table_name = 'assignment'


class Magnitude(TargetdbBase):
bp = FloatField(null=True)
g = FloatField(null=True)
Expand All @@ -248,6 +255,10 @@ class Magnitude(TargetdbBase):
pk = AutoField()
r = FloatField(null=True)
rp = FloatField(null=True)
gaia_g = FloatField(null=True)
j = FloatField(null=True)
k = FloatField(null=True)
optical_prov = TextField(null=True)
carton_to_target = ForeignKeyField(column_name='carton_to_target_pk',
field='pk',
model=CartonToTarget,
Expand All @@ -257,5 +268,5 @@ class Meta:
table_name = 'magnitude'


AssignmentDeferred.set_model(Assignment)
# AssignmentDeferred.set_model(Assignment)
CartonToTargetDeferred.set_model(CartonToTarget)
Loading