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

Fix V&V processing error with Sqsh #303

Merged
merged 2 commits into from
Oct 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 17 additions & 19 deletions mica/vv/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,16 +194,15 @@ def _aiid_info(self, save_cols=save_asol_header):
# this should probably be handled in mica.archive.asp_l1
@staticmethod
def _asp1_lookup(obsid, obi, revision):
apstat = Sqsh(dbi="sybase", server="sqlsao", database="axafapstat")
# take these from the first aspect solution file header
aspect_1 = apstat.fetchall(
"""SELECT * FROM aspect_1
WHERE obsid = {obsid}
AND obi = {obi}
AND revision = {revision}
""".format(obsid=obsid, obi=obi, revision=revision)
)
apstat.conn.close()
with Sqsh(dbi="sybase", server="sqlsao", database="axafapstat") as apstat:
# take these from the first aspect solution file header
aspect_1 = apstat.fetchall(
"""SELECT * FROM aspect_1
WHERE obsid = {obsid}
AND obi = {obi}
AND revision = {revision}
""".format(obsid=obsid, obi=obi, revision=revision)
)
if len(aspect_1) > 1:
raise ValueError("More than one entry found for obsid/obi/rev in aspect_1")
if len(aspect_1) == 0:
Expand Down Expand Up @@ -269,7 +268,7 @@ def _save_info_json(self, file=None):
logger.info("Saved JSON to {}".format(file))

def slots_to_db(self):
if self.info()["aspect_1_id"] is None:
if self.info().get("aspect_1_id") is None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you using get instead of __getitem__? Is it that at some point you had this?

if self.info().get("aspect_1_id", None) is None

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought using get() was the recommended dictionary public access to just get me the value and not throw an key error if the key is undefined and I thought the current code is equivalent to the line you've written for the "did you have this at some point" line. What would __getitem__ buy here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just making sure it was on purpose and not left from unrelated edit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah - you can see it was on purpose from my commit history but it is a good point that I didn't call this out in the description!

logger.warning(
"Database save not implemented for obsids without aspect_1_ids"
)
Expand Down Expand Up @@ -301,7 +300,7 @@ def _get_ccd_temp(tstart, tstop):

def slots_to_table(self):
save = self.info()
if save["aspect_1_id"] is None:
if save.get("aspect_1_id") is None:
logger.warning("Table save not implemented for obsids without aspect_1_ids")
return
mean_aacccdpt = self._get_ccd_temp(save["tstart"], save["tstop"])
Expand Down Expand Up @@ -932,13 +931,12 @@ def _get_prop(self, propname, propstring):
def _read_ocat_stars(self):
obsid = int(self.asol_header["OBS_ID"])
obi = int(self.asol_header["OBI_NUM"])
ocat_db = Sqsh(dbi="sybase", server="sqlsao", database="axafocat")
stars = ocat_db.fetchall(
"select * from stars where "
"obsid = {} and obi = {} "
"and type != 0".format(obsid, obi)
)
ocat_db.conn.close()
with Sqsh(dbi="sybase", server="sqlsao", database="axafocat") as ocat_db:
stars = ocat_db.fetchall(
"select * from stars where "
"obsid = {} and obi = {} "
"and type != 0".format(obsid, obi)
)
if len(np.unique(stars["obi"])) > 1:
raise ValueError(
"Multi-obi observation. OCAT stars unhelpful to identify missing slot"
Expand Down