Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_trace():
"""How do we handle trace reports"""
assert precipitation("0000", "IN").string() == "Trace"
assert precipitation("0000", "IN").istrace()
assert not precipitation("0010", "IN").istrace()
def test_trace():
"""How do we handle trace reports"""
assert precipitation("0000", "IN").string() == "Trace"
assert precipitation("0000", "IN").istrace()
assert not precipitation("0010", "IN").istrace()
def test_trace():
"""How do we handle trace reports"""
assert precipitation("0000", "IN").string() == "Trace"
assert precipitation("0000", "IN").istrace()
assert not precipitation("0010", "IN").istrace()
def value(self, units=None):
"""Return the precipitation in the specified units."""
if not units:
return self._value
else:
if not units.upper() in precipitation.legal_units:
raise UnitsError("unrecognized precipitation unit: '" + units + "'")
units = units.upper()
if units == self._units:
return self._value
if self._units == "CM":
i_value = self._value * 2.54
else:
i_value = self._value
if units == "CM":
return i_value * 2.54
else:
return i_value
def _handlePrecip24hrRemark(self, d):
"""
Parse a 3-, 6- or 24-hour cumulative preciptation remark group.
"""
value = float(d["precip"]) / 100.0
if d["type"] == "6":
if self.cycle in [3, 9, 15, 21]:
self.precip_3hr = precipitation(value, "IN")
else:
self.precip_6hr = precipitation(value, "IN")
else:
self.precip_24hr = precipitation(value, "IN")
def _handlePrecip24hrRemark(self, d):
"""
Parse a 3-, 6- or 24-hour cumulative preciptation remark group.
"""
value = float(d["precip"]) / 100.0
if d["type"] == "6":
if self.cycle in [3, 9, 15, 21]:
self.precip_3hr = precipitation(value, "IN")
else:
self.precip_6hr = precipitation(value, "IN")
else:
self.precip_24hr = precipitation(value, "IN")
self._units = "IN"
else:
if not units.upper() in precipitation.legal_units:
raise UnitsError("unrecognized precipitation unit: '" + units + "'")
self._units = units.upper()
try:
if value.startswith("M"):
value = value[1:]
gtlt = "<"
elif value.startswith("P"):
value = value[1:]
gtlt = ">"
except:
pass
if gtlt and gtlt not in precipitation.legal_gtlt:
raise ValueError(
"unrecognized greater-than/less-than symbol: '" + gtlt + "'"
)
self._gtlt = gtlt
self._value = float(value)
# In METAR world, a string of just four or three zeros denotes trace
self._istrace = value in ["0000", "000"]
def _handlePrecip1hrRemark(self, d):
"""Parse an hourly precipitation remark group."""
value = float(d["precip"]) / 100.0
self.precip_1hr = precipitation(value, "IN")
def _handlePrecip24hrRemark(self, d):
"""
Parse a 3-, 6- or 24-hour cumulative preciptation remark group.
"""
value = float(d["precip"]) / 100.0
if d["type"] == "6":
if self.cycle in [3, 9, 15, 21]:
self.precip_3hr = precipitation(value, "IN")
else:
self.precip_6hr = precipitation(value, "IN")
else:
self.precip_24hr = precipitation(value, "IN")
def _handleIceAccretionRemark(self, d):
"""
Parse the I/ group ice accretion report.
"""
myattr = "ice_accretion_%shr" % (d["ice_accretion_hours"],)
value = precipitation(float(d["ice_accretion_depth"]) / 100.0, "IN")
setattr(self, myattr, value)