From bd2e947afa8093474e4456f1c38d50f4cce9b383 Mon Sep 17 00:00:00 2001 From: John Date: Wed, 17 Dec 2025 03:08:29 +0000 Subject: [PATCH] handle W/m2 unit and extend test with more accurate CRD test --- crmprtd/align.py | 2 ++ crmprtd/tests/test_crd_normalize.py | 39 ++++++++++++++++++++--------- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/crmprtd/align.py b/crmprtd/align.py index 85ea717f..c5747aaa 100644 --- a/crmprtd/align.py +++ b/crmprtd/align.py @@ -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_) diff --git a/crmprtd/tests/test_crd_normalize.py b/crmprtd/tests/test_crd_normalize.py index a3ead669..b671ded4 100644 --- a/crmprtd/tests/test_crd_normalize.py +++ b/crmprtd/tests/test_crd_normalize.py @@ -13,21 +13,36 @@ 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": "" @@ -35,9 +50,9 @@ def test_normalize_good_data(): """ # 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))