Skip to content

Commit

Permalink
Merge pull request #174 from desihub/fix-sync
Browse files Browse the repository at this point in the history
Fix desimodel_sync script failure to update fp model
  • Loading branch information
sbailey authored Sep 17, 2024
2 parents f668126 + 6ae355c commit fc4dbff
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 23 deletions.
7 changes: 3 additions & 4 deletions py/desimodel/inputs/focalplane_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ def create_from_calibs(
newt = Column(
name="TIME",
length=len(st["TIME"]),
dtype=np.dtype("a30"),
dtype=np.dtype("U30"),
description="The timestamp of the event (UTC, ISO format)",
)
for row, oldt in enumerate(st["TIME"]):
Expand Down Expand Up @@ -524,9 +524,8 @@ def create_from_calibs(
st.add_row(row)
n_new_states += 1

new_excl = str(
df["new"]["EXCLUSION"].tobytes().rstrip(b"\x00"), encoding="utf-8"
)
new_excl = df["new"]["EXCLUSION"]
new_excl = str(new_excl)
if new_excl not in oldexcl:
oldexcl[new_excl] = excl[new_excl]
n_new_excl += 1
Expand Down
38 changes: 20 additions & 18 deletions py/desimodel/inputs/focalplane_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,20 +431,22 @@ def device_compare(fpold, fpnew, check):
"""
out = dict()
olddiff = np.setdiff1d(fpold["LOCATION"], fpnew["LOCATION"])
rows = np.arange(len(fpold), dtype=np.int)[fpold["LOCATION"] in olddiff]
for r in rows:
loc = fpold[r]["LOCATION"]
out[loc] = dict()
out[loc]["old"] = fpold[r]
out[loc]["new"] = None
if len(olddiff) > 0:
rows = np.arange(len(fpold), dtype=np.int32)[fpold["LOCATION"] in olddiff]
for r in rows:
loc = fpold[r]["LOCATION"]
out[loc] = dict()
out[loc]["old"] = fpold[r]
out[loc]["new"] = None
totdiff = set(olddiff)
newdiff = np.setdiff1d(fpnew["LOCATION"], fpold["LOCATION"])
rows = np.arange(len(fpnew), dtype=np.int)[fpnew["LOCATION"] in newdiff]
for r in rows:
loc = fnew[r]["LOCATION"]
out[loc] = dict()
out[loc]["new"] = fpnew[r]
out[loc]["old"] = None
if len(newdiff) > 0:
rows = np.arange(len(fpnew), dtype=np.int32)[fpnew["LOCATION"] in newdiff]
for r in rows:
loc = fnew[r]["LOCATION"]
out[loc] = dict()
out[loc]["new"] = fpnew[r]
out[loc]["old"] = None
totdiff.update(newdiff)

# Go through locations found in both tables and look for differences in
Expand Down Expand Up @@ -597,7 +599,7 @@ def create_tables(n_fp_rows, n_state_rows=None):
"""
if n_fp_rows is None or n_fp_rows < 1:
raise ValueError("number of focaplane table rows must be an integer > 0")
raise ValueError("number of focalplane table rows must be an integer > 0")
if n_state_rows is None:
n_state_rows = n_fp_rows

Expand Down Expand Up @@ -633,14 +635,14 @@ def create_tables(n_fp_rows, n_state_rows=None):
Column(
name="DEVICE_ID",
length=n_fp_rows,
dtype=np.dtype("a9"),
dtype=np.dtype("U9"),
data=["UNKNOWN" for x in range(n_fp_rows)],
description="The physical device ID string",
),
Column(
name="DEVICE_TYPE",
length=n_fp_rows,
dtype=np.dtype("a3"),
dtype=np.dtype("U3"),
data=["NA" for x in range(n_fp_rows)],
description="The device type (POS, ETC, FIF)",
),
Expand Down Expand Up @@ -668,7 +670,7 @@ def create_tables(n_fp_rows, n_state_rows=None):
Column(
name="CONDUIT",
length=n_fp_rows,
dtype=np.dtype("a3"),
dtype=np.dtype("U3"),
data=["NA" for x in range(n_fp_rows)],
description="The conduit",
),
Expand Down Expand Up @@ -757,7 +759,7 @@ def create_tables(n_fp_rows, n_state_rows=None):
Column(
name="TIME",
length=n_state_rows,
dtype=np.dtype("a30"),
dtype=np.dtype("U30"),
data=["UNKNOWN" for x in range(n_state_rows)],
description="The timestamp of the event (UTC, ISO format)",
),
Expand Down Expand Up @@ -820,7 +822,7 @@ def create_tables(n_fp_rows, n_state_rows=None):
Column(
name="EXCLUSION",
length=n_state_rows,
dtype=np.dtype("a16"),
dtype=np.dtype("U16"),
data=["UNKNOWN" for x in range(n_state_rows)],
description="The exclusion polygon for this device",
),
Expand Down
2 changes: 1 addition & 1 deletion py/desimodel/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ def ensure_focalplane_loaded():
fpdir = os.path.join(datadir(), "focalplane")
fppat = re.compile(r"^desi-focalplane_(.*)\.ecsv$")
stpat = re.compile(r"^desi-state_(.*)\.ecsv$")
expat = re.compile(r"^desi-exclusion_(.*)\.(?:yaml|json).*$")
expat = re.compile(r"^desi-exclusion_(.*)\.(?:yaml|json)(\.gz)?$")
fpraw = dict()
msg = "Loading focalplanes from {}".format(fpdir)
log.debug(msg)
Expand Down

0 comments on commit fc4dbff

Please sign in to comment.