Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions crmprtd/align.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
"degreeF = 5 / 9 * kelvin; offset: 255.372222",
"degreeK = degK; offset: 0",
"degree = π / 180 * radian = deg = Deg = arcdeg = arcdegree = angular_degree",
"square_meter = meter ** 2 = m2 = sqm",
"watt_per_square_metre = watt / square_meter = W/m2 = W/m^2"
):
ureg.define(def_)

Expand Down
39 changes: 27 additions & 12 deletions crmprtd/tests/test_crd_normalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,46 @@ def test_normalize_good_data():
"RainUnit": "millimetre",
"PrecipitationUnit": "millimetre",
"AirTemperatureUnit": "Celsius",
"WindSpeedUnit": "kilometres per hour"
"RelativeHumidityUnit": "percent",
"WindSpeedUnit": "kilometres per hour",
"WindDirectionUnit": "degree",
"SnowDepthUnit": "metre",
"SnowWaterEquivalentUnit": "millimetre",
"BarometricPressureUnit": "hectopascal",
"SolarRadiationUnit": "watt per square metre",
"SolarActiveRadiationUnit": "micromoles per square metre per second"
},
"_info": "",
"_info": "IMPORTANT NOTICE - DISCLAIMER - PLEASE READ CAREFULLY -- The Capital Regional District ('CRD') does not warrant or represent that the information contained in the data provided (the 'Information') is free from errors or omissions. The Information is provide 'AS IS' and made available to the User on the condition that the CRD will not be liable to the User for any loss, damage, cost or expense whatsoever incurred by the User or any other person or entity using or relying on the Information, whether it is caused by or results from any error, negligent act, omission or misrepresentation by the CRD, its officers, employees, agents, contractors or consultants. The use of the Information by the User or any other person or entity, will be entirely at their sole risk.",
"_disclaimerDocument": "https://webservices.crd.bc.ca/weatherdata/resources/CRDWeatherDataShareInstructions.pdf"
},
"DATA": [
{
"RecordID": "14G+20200316110000",
"RecordID": "14G+20251118000000",
"StationName": "14g",
"DateTime": 43906.4583333333,
"DateTimeString": "20200316110000",
"DateTime": 45979.0,
"DateTimeString": "20251118000000",
"Rain": 0.0,
"Precipitation": 1.0,
"AirTemperature": -9999,
"WindSpeed": null
"Precipitation": 0.1,
"AirTemperature": 2.7,
"RelativeHumidity": 100.0,
"WindSpeed": 3.9,
"WindDirection": 347.0,
"SnowDepth": 0.001,
"SnowWaterEquivalent": -9999.0,
"BarometricPressure": -9999.0,
"SolarRadiation": 0.0,
"SolarActiveRadiation": -9999.0,
"DataErrors": ""
}
],
"ERROR": ""
}
""" # noqa
tz = pytz.timezone("Canada/Pacific")
rows = [row for row in normalize(BytesIO(lines))]
assert len(rows) == 2
assert len(rows) == 8
for row in rows:
assert row.unit == "millimetre"
assert row.unit in ("millimetre", "Celsius", "percent", "kilometres per hour", "degree", "metre", "hectopascal", "watt per square metre", "micromoles per square metre per second")
assert row.station_id == "14g"
assert row.variable_name in ("Rain", "Precipitation")
assert row.time == tz.localize(datetime.datetime(2020, 3, 16, 11))
assert row.variable_name in ("Rain", "Precipitation", "AirTemperature", "RelativeHumidity", "WindSpeed", "WindDirection", "SnowDepth", "BarometricPressure", "SolarRadiation", "SolarActiveRadiation")
assert row.time == tz.localize(datetime.datetime(2025, 11, 18, 00))