Skip to content

Commit

Permalink
add initial code for verifying designid_status
Browse files Browse the repository at this point in the history
  • Loading branch information
imedan committed May 27, 2024
1 parent 4ecc65e commit 7016a5e
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions python/mugatu/designmode.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from sdssdb.peewee.sdss5db.targetdb import DesignMode as DesignModeDB
from sdssdb.peewee.sdss5db import catalogdb
from sdssdb.peewee.sdss5db import targetdb
from sdssdb.peewee.sdss5db import opsdb


def ang_sep(ra1, dec1, ra2, dec2):
Expand Down Expand Up @@ -1642,3 +1643,56 @@ def design_mode_check_all(self, verbose=True):
verbose_output += 'Bright Neighbor Check (APOGEE): | %d out of %d\n' % (check_tot, design_tot)

print(verbose_output)


def check_design_to_status(design_id):
"""
check if the design_id is done
"""
dts = opsdb.DesignToStatus.get_or_none(design_id=design_id)
if dts is None:
return False
else:
if dts.status.label == 'done':
return True
else:
return False


def designid_status_valid(design_id, field_id, field_exposure):
"""
check if design_id assocatied in rsFieldAssignments file
is based on 'done' designs in database.
Parameters
----------
design_id: int
The design_id to be validated. If -1, then checks
all possible field_exposures in the field.
field_id: int
field_id for the design.
field_exposure: int
field_exposure for the design.
Returns
-------
status: bool
If the design_id is set correctly for the design_status.
"""
if design_id != -1:
status = check_design_to_status(design_id)
else:
# grab all design_ids for current field_exposure in all verisons
# of the field
designs = targetdb.DesignToField.select()\
.join(targetdb.Field)\
.where(targetdb.Field.field_id == field_id,
targetdb.DesignToField.field_exposure == field_exposure)
# check all of the designs to see if they are marked done
design_status = np.zeros(len(designs), dtype=bool)
for i, d in enumerate(designs):
design_status[i] = check_design_to_status(d.design_id)
status = ~np.any(design_status) # should all be False if design_id = -1
return status

0 comments on commit 7016a5e

Please sign in to comment.