Skip to content

Commit

Permalink
store units value
Browse files Browse the repository at this point in the history
  • Loading branch information
arahlin committed Mar 20, 2024
1 parent e08be6d commit 4e0df8d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions calibration/python/bolopropertiesutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def set_format(self, precision=0, units="GHz"):
"""
self._precision = int(precision)
assert hasattr(core.G3Units, units), "Invalid units {}".format(units)
self._units = units
self._units = getattr(core.G3Units, self._units)
self._format = "%%.%df%s" % (precision if precision > 0 else 0, units)
prx = r"\.[0-9]{%d}" % precision if precision > 0 else ""
self._pattern = "([0-9]+%s)%s" % (prx, units)
Expand All @@ -69,7 +69,7 @@ def to_string(self, value):
the appropriate precision and units name."""
if not np.isfinite(value) or value < 0:
return ""
value = np.round(value / getattr(core.G3Units, self._units), self._precision)
value = np.round(value / self._units, self._precision)
return self._format % value

def to_value(self, value):
Expand All @@ -78,7 +78,7 @@ def to_value(self, value):
m = self._regex.match(value)
if not m:
raise ValueError("Invalid band {}".format(value))
return float(m.group(1)) * getattr(core.G3Units, self._units)
return float(m.group(1)) * self._units

def extract_string(self, value):
"""Return the band substring from the input string, or None if not
Expand All @@ -94,7 +94,7 @@ def extract_value(self, value):
m = self._regex.search(value)
if not m:
return None
return float(m.group(1)) * getattr(core.G3Units, self._units)
return float(m.group(1)) * self._units


# global instance used by functions below
Expand Down

0 comments on commit 4e0df8d

Please sign in to comment.