From 2cca3e4be99b1aff0050e0bc092591c32914bc02 Mon Sep 17 00:00:00 2001 From: Benjamin Alan Weaver Date: Tue, 1 Oct 2024 16:36:38 -0700 Subject: [PATCH] copy back-patch code into patch.py --- doc/changes.rst | 5 +++++ py/specprodDB/patch.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/doc/changes.rst b/doc/changes.rst index 73d496e..897a0d6 100644 --- a/doc/changes.rst +++ b/doc/changes.rst @@ -8,6 +8,11 @@ Change Log *Planned*: Support loading ongoing daily reductions, in particular, updates to tiles already in the database. +1.2.1 (unreleased) +------------------ + +* Finalize patches of ``tiles-daily`` and ``exposures-daily`` files. + 1.2.0 (2024-09-26) ------------------ diff --git a/py/specprodDB/patch.py b/py/specprodDB/patch.py index 9ccdd0a..ce88629 100644 --- a/py/specprodDB/patch.py +++ b/py/specprodDB/patch.py @@ -367,6 +367,48 @@ def patch_tiles(src_tiles, dst_tiles, timestamp): return dst_tiles_patched +def back_patch_inconsistent_values(patched): + """When the primary round of patching is done, copy some values back + into the exposures and frames files. + + Parameters + ---------- + patched : :class:`dict` + A dictionary containing tables for further patching. + + Returns + ------- + :class:`tuple` + A tuple containing the back-patched exposures and frames tables. + Not strictly necessary as this function will modify the tables in + `patched` in-place. + """ + log = get_logger() + back_patch = {'tiles': 'exposures', 'exposures': 'frames'} + for s, d in back_patch.items(): + for row in patched[s]: + key = 'TILEID' if s == 'tiles' else 'EXPID' + w = np.where(patched[d][key] == row[key])[0] + for column in ('SURVEY', 'PROGRAM', 'FAPRGRM', 'FAFLAVOR', 'GOALTYPE'): + if column in patched[d].colnames: + if (patched[d][column][w] != row[column]).any(): + log.info("Patching %s associated with %s %d with %s = '%s'.", + d, ('tile' if s == 'tiles' else 'exposure'), row[key], + column, row[column]) + patched[d][column][w] = row[column] + # + # Run a QA step. + # + for s, d in back_patch.items(): + for row in patched[s]: + key = 'TILEID' if s == 'tiles' else 'EXPID' + w = np.where(patched[d][key] == row[key])[0] + for column in ('SURVEY', 'PROGRAM', 'FAPRGRM', 'FAFLAVOR', 'GOALTYPE'): + if column in patched[d].colnames: + assert (patched[d][column][w] == row[column]).all() + return (patched['exposures'], patched['frames']) + + def get_data(options): """Read in source and destination data.