-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✅ Properly tested deltatime_to_utctime function
Turn the ICESat-2 delta_time to utc_time conversion code in our jupyter notebook into a well tested function! The cool bit is that we can pass in either a dask or numpy backed xarray.DataArray, and get the equivalent output, with dimensions and coordinates preserved! Gotta love [NEP18](https://numpy.org/neps/nep-0018-array-function-protocol.html). Added a chunks statement to test_catalog.yaml, and ensure the file is cached in a relative path. Had to make sure to read the test atl11_dataset using dask and close it properly after each test (?) or subsequent tests will fail, seeing a numpy.array instead of a dask.array (?). Should do proper setup/teardown next time. Also bumping up cftime from 1.1.1.2 to 1.1.3 and certifi from 2019.11.28 to 2020.4.5.1 to bust the CI cache, just in case.
- Loading branch information
Showing
8 changed files
with
103 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
""" | ||
Tests various conversions between geospatial and temporal units | ||
""" | ||
import datetime | ||
|
||
import dask | ||
import numpy as np | ||
import numpy.testing as npt | ||
import pandas as pd | ||
import xarray as xr | ||
|
||
from deepicedrain import catalog, deltatime_to_utctime | ||
|
||
|
||
def test_deltatime_to_utctime(): | ||
""" | ||
Test that converting from ICESat-2 delta_time to utc_time works, | ||
and that the xarray dimensions are preserved in the process. | ||
""" | ||
atl11_dataset: xr.Dataset = catalog.test_data.atl11_test_case.to_dask() | ||
|
||
utc_time: xr.DataArray = deltatime_to_utctime(dataarray=atl11_dataset.delta_time) | ||
|
||
assert utc_time.shape == (1404, 2) | ||
assert utc_time.dims == ("ref_pt", "cycle_number") | ||
assert dask.is_dask_collection(utc_time) | ||
|
||
utc_time = utc_time.compute() | ||
|
||
npt.assert_equal( | ||
actual=utc_time.data.min(), | ||
desired=np.datetime64("2019-05-19T20:53:51.039891534"), | ||
) | ||
npt.assert_equal( | ||
actual=np.datetime64(pd.DataFrame(utc_time.data)[0].mean()), | ||
desired=np.datetime64("2019-05-19 20:54:00.925868"), | ||
) | ||
npt.assert_equal( | ||
actual=np.datetime64(pd.DataFrame(utc_time.data)[1].mean()), | ||
desired=np.datetime64("2019-08-18 16:33:47.791226"), | ||
) | ||
npt.assert_equal( | ||
actual=utc_time.data.max(), | ||
desired=np.datetime64("2019-08-18T16:33:57.834610209"), | ||
) | ||
|
||
atl11_dataset.close() |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.