def test_query(self): some_email = "*****@*****.**" msg = emaillib.create_email( to="*****@*****.**", fr=some_email, body="send GFS:30s,35s,175e,175w|0.5,0.5|0,3..12|WIND" ) emails = [] # use a mocked emaillib to make sure an email was sent with self.get_request(emails) as request: request.process_email(msg.as_string(), fail_hard=True) assert len(emails) == 1 parser = Parser.Parser() email = parser.parsestr(emails.pop().args[0].as_string()) # make sure we are sending responses from ensembleweather self.assertEqual(email["From"], "*****@*****.**") # make sure we are responding to the right person self.assertEqual(email["To"], some_email) # here we pull out the expected attachment body, attach = email.get_payload() bytes = attach.get_payload() # inflate it back into an xray Dataset fcst = compress.decompress_dataset(base64.b64decode(bytes)) # make sure we're actually compressing the file. self.assertLessEqual(len(bytes), len(zlib.compress(fcst.to_netcdf()))) # make sure the lats are what we expect expected_lats = np.linspace(-35.0, -30.0, 11) np.testing.assert_array_equal(fcst["latitude"].values, expected_lats) self.assertEqual(fcst["latitude"].attrs["units"].lower(), "degrees north") # and the lons expected_lons = np.mod(np.linspace(175.0, 185.0, 21) + 180, 360) - 180 np.testing.assert_array_equal(fcst["longitude"].values, expected_lons) self.assertEqual(fcst["longitude"].attrs["units"].lower(), "degrees east") # and the time expected_time = np.linspace(0, 12, 5) expected_time = xray.conventions.decode_cf_datetime(expected_time, fcst["time"].encoding["units"]) np.testing.assert_array_equal(fcst["time"].values, expected_time) self.assertIn("hours", fcst["time"].encoding["units"])
def test_spot_forecast(self): some_email = "*****@*****.**" msg = emaillib.create_email( to="*****@*****.**", fr=some_email, body="send spot:gefs:8.53S,115.54E|8,6|wind" ) emails = [] # use a mocked emaillib to make sure an email was sent with self.get_request(emails) as request: request.process_email(msg.as_string(), fail_hard=True) assert len(emails) == 1 parser = Parser.Parser() email = parser.parsestr(emails.pop().args[0].as_string()) # make sure we are sending responses from ensembleweather self.assertEqual(email["From"], "*****@*****.**") # make sure we are responding to the right person self.assertEqual(email["To"], some_email) # here we pull out the expected attachment body, attach = email.get_payload() bytes = attach.get_payload() # inflate it back into an xray Dataset fcst = compress.decompress_dataset(base64.b64decode(bytes)) # make sure we're actually compressing the file. self.assertLessEqual(len(bytes), len(zlib.compress(fcst.to_netcdf()))) # make sure the lats are what we expect np.testing.assert_array_almost_equal(fcst["latitude"].values, np.array([-8.53]), 3) self.assertEqual(fcst["latitude"].attrs["units"].lower(), "degrees north") # and the lons np.testing.assert_array_almost_equal(fcst["longitude"].values, np.array([115.54]), 3) self.assertEqual(fcst["longitude"].attrs["units"].lower(), "degrees east") # and the time expected_time = np.linspace(0, 192, 33) expected_time = xray.conventions.decode_cf_datetime(expected_time, fcst["time"].encoding["units"]) np.testing.assert_array_equal(fcst["time"].values, expected_time) self.assertIn("hours", fcst["time"].encoding["units"])