-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added some logic to deal with rasterio objects in addition to filepaths #2589
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
35c5afb
added some logic to deal with rasterio objects in addition to filepat…
scottyhq 35f9947
added no network test, pep8 compliance, whatsnew.rst
scottyhq ce56d35
removed subclass, added to base RasterioArrayWrapper
scottyhq cd6fcb9
Merge branch 'master' into open-rasterio-vrt
shoyer a113b50
upped rasterio test version to > 1
scottyhq de21485
Merge branch 'open-rasterio-vrt' of https://github.com/scottyhq/xarra…
scottyhq dde9428
specified rasterio version should be greater than 1
scottyhq ea068fe
Merge branch 'master' into open-rasterio-vrt
shoyer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -233,9 +233,9 @@ def check_dtypes_roundtripped(self, expected, actual): | |
actual_dtype = actual.variables[k].dtype | ||
# TODO: check expected behavior for string dtypes more carefully | ||
string_kinds = {'O', 'S', 'U'} | ||
assert (expected_dtype == actual_dtype or | ||
(expected_dtype.kind in string_kinds and | ||
actual_dtype.kind in string_kinds)) | ||
assert (expected_dtype == actual_dtype | ||
or (expected_dtype.kind in string_kinds and | ||
actual_dtype.kind in string_kinds)) | ||
|
||
def test_roundtrip_test_data(self): | ||
expected = create_test_data() | ||
|
@@ -410,17 +410,17 @@ def test_roundtrip_cftime_datetime_data(self): | |
with self.roundtrip(expected, save_kwargs=kwds) as actual: | ||
abs_diff = abs(actual.t.values - expected_decoded_t) | ||
assert (abs_diff <= np.timedelta64(1, 's')).all() | ||
assert (actual.t.encoding['units'] == | ||
'days since 0001-01-01 00:00:00.000000') | ||
assert (actual.t.encoding['calendar'] == | ||
expected_calendar) | ||
assert (actual.t.encoding['units'] | ||
== 'days since 0001-01-01 00:00:00.000000') | ||
assert (actual.t.encoding['calendar'] | ||
== expected_calendar) | ||
|
||
abs_diff = abs(actual.t0.values - expected_decoded_t0) | ||
assert (abs_diff <= np.timedelta64(1, 's')).all() | ||
assert (actual.t0.encoding['units'] == | ||
'days since 0001-01-01') | ||
assert (actual.t.encoding['calendar'] == | ||
expected_calendar) | ||
assert (actual.t0.encoding['units'] | ||
== 'days since 0001-01-01') | ||
assert (actual.t.encoding['calendar'] | ||
== expected_calendar) | ||
|
||
def test_roundtrip_timedelta_data(self): | ||
time_deltas = pd.to_timedelta(['1h', '2h', 'NaT']) | ||
|
@@ -668,24 +668,24 @@ def test_roundtrip_mask_and_scale(self, decoded_fn, encoded_fn): | |
|
||
with self.roundtrip(decoded) as actual: | ||
for k in decoded.variables: | ||
assert (decoded.variables[k].dtype == | ||
actual.variables[k].dtype) | ||
assert (decoded.variables[k].dtype | ||
== actual.variables[k].dtype) | ||
assert_allclose(decoded, actual, decode_bytes=False) | ||
|
||
with self.roundtrip(decoded, | ||
open_kwargs=dict(decode_cf=False)) as actual: | ||
# TODO: this assumes that all roundtrips will first | ||
# encode. Is that something we want to test for? | ||
for k in encoded.variables: | ||
assert (encoded.variables[k].dtype == | ||
actual.variables[k].dtype) | ||
assert (encoded.variables[k].dtype | ||
== actual.variables[k].dtype) | ||
assert_allclose(encoded, actual, decode_bytes=False) | ||
|
||
with self.roundtrip(encoded, | ||
open_kwargs=dict(decode_cf=False)) as actual: | ||
for k in encoded.variables: | ||
assert (encoded.variables[k].dtype == | ||
actual.variables[k].dtype) | ||
assert (encoded.variables[k].dtype | ||
== actual.variables[k].dtype) | ||
assert_allclose(encoded, actual, decode_bytes=False) | ||
|
||
# make sure roundtrip encoding didn't change the | ||
|
@@ -2621,8 +2621,8 @@ def myatts(**attrs): | |
'ULOD_FLAG': '-7777', 'ULOD_VALUE': 'N/A', | ||
'LLOD_FLAG': '-8888', | ||
'LLOD_VALUE': ('N/A, N/A, N/A, N/A, 0.025'), | ||
'OTHER_COMMENTS': ('www-air.larc.nasa.gov/missions/etc/' + | ||
'IcarttDataFormat.htm'), | ||
'OTHER_COMMENTS': ('www-air.larc.nasa.gov/missions/etc/' | ||
+ 'IcarttDataFormat.htm'), | ||
'REVISION': 'R0', | ||
'R0': 'No comments for this revision.', | ||
'TFLAG': 'Start_UTC' | ||
|
@@ -2711,8 +2711,8 @@ def test_uamiv_format_read(self): | |
expected = xr.Variable(('TSTEP',), data, | ||
dict(bounds='time_bounds', | ||
long_name=('synthesized time coordinate ' + | ||
'from SDATE, STIME, STEP ' + | ||
'global attributes'))) | ||
'from SDATE, STIME, STEP ' | ||
+ 'global attributes'))) | ||
actual = camxfile.variables['time'] | ||
assert_allclose(expected, actual) | ||
camxfile.close() | ||
|
@@ -2741,8 +2741,8 @@ def test_uamiv_format_mfread(self): | |
data = np.concatenate([data1] * 2, axis=0) | ||
attrs = dict(bounds='time_bounds', | ||
long_name=('synthesized time coordinate ' + | ||
'from SDATE, STIME, STEP ' + | ||
'global attributes')) | ||
'from SDATE, STIME, STEP ' | ||
+ 'global attributes')) | ||
expected = xr.Variable(('TSTEP',), data, attrs) | ||
actual = camxfile.variables['time'] | ||
assert_allclose(expected, actual) | ||
|
@@ -3158,6 +3158,73 @@ def test_http_url(self): | |
import dask.array as da | ||
assert isinstance(actual.data, da.Array) | ||
|
||
def test_rasterio_environment(self): | ||
import rasterio | ||
with create_tmp_geotiff() as (tmp_file, expected): | ||
# Should fail with error since suffix not allowed | ||
with pytest.raises(Exception): | ||
with rasterio.Env(GDAL_SKIP='GTiff'): | ||
with xr.open_rasterio(tmp_file) as actual: | ||
assert_allclose(actual, expected) | ||
|
||
def test_rasterio_vrt(self): | ||
import rasterio | ||
# tmp_file default crs is UTM: CRS({'init': 'epsg:32618'} | ||
with create_tmp_geotiff() as (tmp_file, expected): | ||
with rasterio.open(tmp_file) as src: | ||
with rasterio.vrt.WarpedVRT(src, crs='epsg:4326') as vrt: | ||
expected_shape = (vrt.width, vrt.height) | ||
expected_crs = vrt.crs | ||
print(expected_crs) | ||
expected_res = vrt.res | ||
# Value of single pixel in center of image | ||
lon, lat = vrt.xy(vrt.width // 2, vrt.height // 2) | ||
expected_val = next(vrt.sample([(lon, lat)])) | ||
with xr.open_rasterio(vrt) as da: | ||
actual_shape = (da.sizes['x'], da.sizes['y']) | ||
actual_crs = da.crs | ||
print(actual_crs) | ||
actual_res = da.res | ||
actual_val = da.sel(dict(x=lon, y=lat), | ||
method='nearest').data | ||
|
||
assert actual_crs == expected_crs | ||
assert actual_res == expected_res | ||
assert actual_shape == expected_shape | ||
assert expected_val.all() == actual_val.all() | ||
|
||
@network | ||
def test_rasterio_vrt_network(self): | ||
import rasterio | ||
|
||
url = 'https://storage.googleapis.com/\ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't even know this form of line-wrapping for strings was possible in Python :) |
||
gcp-public-data-landsat/LC08/01/047/027/\ | ||
LC08_L1TP_047027_20130421_20170310_01_T1/\ | ||
LC08_L1TP_047027_20130421_20170310_01_T1_B4.TIF' | ||
env = rasterio.Env(GDAL_DISABLE_READDIR_ON_OPEN='EMPTY_DIR', | ||
CPL_VSIL_CURL_USE_HEAD=False, | ||
CPL_VSIL_CURL_ALLOWED_EXTENSIONS='TIF') | ||
with env: | ||
with rasterio.open(url) as src: | ||
with rasterio.vrt.WarpedVRT(src, crs='epsg:4326') as vrt: | ||
expected_shape = (vrt.width, vrt.height) | ||
expected_crs = vrt.crs | ||
expected_res = vrt.res | ||
# Value of single pixel in center of image | ||
lon, lat = vrt.xy(vrt.width // 2, vrt.height // 2) | ||
expected_val = next(vrt.sample([(lon, lat)])) | ||
with xr.open_rasterio(vrt) as da: | ||
actual_shape = (da.sizes['x'], da.sizes['y']) | ||
actual_crs = da.crs | ||
actual_res = da.res | ||
actual_val = da.sel(dict(x=lon, y=lat), | ||
method='nearest').data | ||
|
||
assert_equal(actual_shape, expected_shape) | ||
assert_equal(actual_crs, expected_crs) | ||
assert_equal(actual_res, expected_res) | ||
assert_equal(expected_val, actual_val) | ||
|
||
|
||
class TestEncodingInvalid(object): | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For network tests we have a special decorator (
@network
), see https://github.com/pydata/xarray/blob/55f21deff4c2b42bd6ead4dbe26a1b123337913a/xarray/tests/test_tutorial.py (although that's the only use of it as it seems?)