-
-
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.
🚚 Rename geo to spatiotemporal, and BBox to Region
Found a better name than geo.py - spatiotemporal.py! Because time matters. Also renaming the BBox class to Region as the double capital letters in a row didn't look Pythonic. The Region.subset function has been revamped to be a lot more user friendly, giving the actual subsetted xr.Dataset instead of just the boolean array.
- Loading branch information
Showing
5 changed files
with
42 additions
and
35 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
__version__ = "0.1.0" | ||
|
||
from deepicedrain.geo import BBox | ||
from deepicedrain.deltamath import calculate_delta | ||
from deepicedrain.spatiotemporal import Region |
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 |
---|---|---|
@@ -1,58 +1,58 @@ | ||
""" | ||
Tests behaviour of the BBox class | ||
Tests behaviour of the Region class | ||
""" | ||
import numpy as np | ||
import pytest | ||
import xarray as xr | ||
|
||
from deepicedrain import BBox | ||
from deepicedrain import Region | ||
|
||
|
||
def test_bbox_scale(): | ||
def test_region_scale(): | ||
""" | ||
Tests that a map scale is output based on the BBox region. | ||
Tests that a map scale is output based on the region. | ||
""" | ||
region = BBox("Antarctica", -2700000, 2800000, -2200000, 2300000) | ||
region = Region("Antarctica", -2700000, 2800000, -2200000, 2300000) | ||
assert region.scale == 27500000 | ||
|
||
|
||
def test_bbox_bounds_lrbt(): | ||
def test_region_bounds_lrbt(): | ||
""" | ||
Tests that PyGMT style bounds are given (by default). | ||
""" | ||
region = BBox("Siple Coast", -1000000, 250000, -1000000, -100000) | ||
region = Region("Siple Coast", -1000000, 250000, -1000000, -100000) | ||
assert region.bounds() == (-1000000, 250000, -1000000, -100000) | ||
|
||
|
||
def test_bbox_bounds_lbrt(): | ||
def test_region_bounds_lbrt(): | ||
""" | ||
Tests that Shapely style bounds are given | ||
""" | ||
region = BBox("Whillans Ice Stream", -350000, -100000, -700000, -450000) | ||
region = Region("Whillans Ice Stream", -350000, -100000, -700000, -450000) | ||
assert region.bounds(style="lbrt") == (-350000, -700000, -100000, -450000) | ||
|
||
|
||
def test_bbox_bounds_ltrb(): | ||
def test_region_bounds_ltrb(): | ||
""" | ||
Tests that error is raised when passing in a style that is not implemented. | ||
""" | ||
region = BBox("Kamb Ice Stream", -500000, -400000, -600000, -500000) | ||
region = Region("Kamb Ice Stream", -500000, -400000, -600000, -500000) | ||
with pytest.raises(NotImplementedError): | ||
print(region.bounds(style="ltrb")) | ||
|
||
|
||
def test_bbox_subset(): | ||
def test_region_subset(): | ||
""" | ||
Test that we can subset an xarray.Dataset based on the region's bounds | ||
""" | ||
region = BBox("South Pole", -100, 100, -100, 100) | ||
region = Region("South Pole", -100, 100, -100, 100) | ||
dataset = xr.Dataset( | ||
data_vars={"h_corr": (["x", "y"], np.random.rand(50, 50))}, | ||
coords={ | ||
"x": np.linspace(start=-200, stop=200, num=50), | ||
"y": np.linspace(start=-160, stop=160, num=50), | ||
}, | ||
) | ||
ds_subset = dataset.where(cond=region.subset(ds=dataset), drop=True) | ||
ds_subset = region.subset(ds=dataset) | ||
assert isinstance(ds_subset, xr.Dataset) | ||
assert ds_subset.h_corr.shape == (24, 30) |