-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Added PNC backend to xarray #1905
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
Merged
Merged
Changes from all commits
Commits
Show all changes
59 commits
Select commit
Hold shift + click to select a range
eeeb3a5
Added PNC backend to xarray
barronh 5caea63
Fast Forwarding Branch to Make PNC-updates to enable auto merge
barronh 5ac4b6f
Added whats-new documentation
barronh f73436d
Updating pnc_ to remove DunderArrayMixin dependency
barronh 9507303
Adding basic tests for pnc
barronh ef22872
Updating for flake8 compliance
barronh 56f087c
flake does not like unused e
barronh 3c023a0
Merge branch 'master' of https://github.com/pydata/xarray into pnc-ba…
barronh 5a3c62d
Updating pnc to PseudoNetCDF
barronh 8eb427d
Remove outer except
barronh ca75c76
Updating pnc to PseudoNetCDF
barronh 196c03f
Added open and updated init
barronh 751ba1e
Merging to address indexing
barronh 282408f
Updated indexing and test fix
barronh b1890b1
Added PseudoNetCDF to doc/io.rst
barronh eda629f
Changing test subtype
barronh 816c7da
Changing test subtype
barronh c8b2ca3
pnc test case requires netcdf3only
barronh 85ac334
adding backend_kwargs default as dict
barronh c46caeb
Upgrading tests to CFEncodedDataTest
barronh 6838885
Not currently supporting autoclose
barronh c3b7c82
Minor updates for flake8
barronh 7906492
Explicit skipping
barronh 4df9fba
removing trailing whitespace from pytest skip
barronh e4900ab
Merge branch 'master' of https://github.com/pydata/xarray into pnc-ba…
barronh ec95a3a
Adding pip support
barronh ad7b709
Addressing comments
barronh 26dd0f9
Bypassing pickle, mask/scale, and object
barronh d999de1
Added uamiv test
barronh 87e8612
Adding support for autoclose
barronh dd94be5
Adding bakcend_kwargs to all backends
barronh 2311701
Small tweaks to PNC backend
shoyer 9791b8a
Merge branch 'master' into pnc-backend
shoyer 1d7ad4a
remove warning and update whats-new
barronh 229715a
Merged so that whats-new could be updated
barronh 68997e0
Separating isntall and io pnc doc and updating whats new
barronh d007bc6
merging renames
barronh 70968ca
fixing line length in test
barronh c2788b2
updating whats-new and merging
barronh 1f3287e
Tests now use non-netcdf files
barronh abacc1d
Removing unknown meta-data netcdf support.
barronh a136ea3
Merge branch 'master' of https://github.com/pydata/xarray into pnc-ba…
barronh 7d8a8ee
flake8 cleanup
barronh 24c8376
Using python 2 and 3 compat testing
barronh 214f51c
Disabling mask_and_scale by default
barronh 5786291
consistent with 3.0.0
barronh 066cdd5
Updating readers and line length
barronh 9231e3f
Updating readers and line length
barronh 80d03a7
Updating readers and line length
barronh d2c01de
Adding open_mfdataset test
barronh e12288d
merging and updating time test
barronh a179c25
Merge branch 'master' of https://github.com/pydata/xarray into pnc-ba…
barronh eaa37fe
Using conda version of PseudoNetCDF
barronh 590e919
Removing xfail for netcdf
barronh 0df1e60
Merge branch 'master' of https://github.com/pydata/xarray into pnc-ba…
barronh 989fa4b
Moving pseudonetcdf to v0.15
barronh d71bb60
Updating what's new
barronh b9b64ca
Fixing open_dataarray CF options
barronh 10c9bfa
Merge branch 'master' into pnc-backend
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 hidden or 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 |
---|---|---|
|
@@ -20,6 +20,7 @@ dependencies: | |
- rasterio | ||
- bottleneck | ||
- zarr | ||
- pseudonetcdf>=3.0.1 | ||
- pip: | ||
- coveralls | ||
- pytest-cov | ||
|
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,101 @@ | ||
from __future__ import absolute_import | ||
from __future__ import division | ||
from __future__ import print_function | ||
|
||
import functools | ||
|
||
import numpy as np | ||
|
||
from .. import Variable | ||
from ..core.pycompat import OrderedDict | ||
from ..core.utils import (FrozenOrderedDict, Frozen) | ||
from ..core import indexing | ||
|
||
from .common import AbstractDataStore, DataStorePickleMixin, BackendArray | ||
|
||
|
||
class PncArrayWrapper(BackendArray): | ||
|
||
def __init__(self, variable_name, datastore): | ||
self.datastore = datastore | ||
self.variable_name = variable_name | ||
array = self.get_array() | ||
self.shape = array.shape | ||
self.dtype = np.dtype(array.dtype) | ||
|
||
def get_array(self): | ||
self.datastore.assert_open() | ||
return self.datastore.ds.variables[self.variable_name] | ||
|
||
def __getitem__(self, key): | ||
key, np_inds = indexing.decompose_indexer( | ||
key, self.shape, indexing.IndexingSupport.OUTER_1VECTOR) | ||
|
||
with self.datastore.ensure_open(autoclose=True): | ||
array = self.get_array()[key.tuple] # index backend array | ||
|
||
if len(np_inds.tuple) > 0: | ||
# index the loaded np.ndarray | ||
array = indexing.NumpyIndexingAdapter(array)[np_inds] | ||
return array | ||
|
||
|
||
class PseudoNetCDFDataStore(AbstractDataStore, DataStorePickleMixin): | ||
"""Store for accessing datasets via PseudoNetCDF | ||
""" | ||
@classmethod | ||
def open(cls, filename, format=None, writer=None, | ||
autoclose=False, **format_kwds): | ||
from PseudoNetCDF import pncopen | ||
opener = functools.partial(pncopen, filename, **format_kwds) | ||
ds = opener() | ||
mode = format_kwds.get('mode', 'r') | ||
return cls(ds, mode=mode, writer=writer, opener=opener, | ||
autoclose=autoclose) | ||
|
||
def __init__(self, pnc_dataset, mode='r', writer=None, opener=None, | ||
autoclose=False): | ||
|
||
if autoclose and opener is None: | ||
raise ValueError('autoclose requires an opener') | ||
|
||
self._ds = pnc_dataset | ||
self._autoclose = autoclose | ||
self._isopen = True | ||
self._opener = opener | ||
self._mode = mode | ||
super(PseudoNetCDFDataStore, self).__init__() | ||
|
||
def open_store_variable(self, name, var): | ||
with self.ensure_open(autoclose=False): | ||
data = indexing.LazilyOuterIndexedArray( | ||
PncArrayWrapper(name, self) | ||
) | ||
attrs = OrderedDict((k, getattr(var, k)) for k in var.ncattrs()) | ||
return Variable(var.dimensions, data, attrs) | ||
|
||
def get_variables(self): | ||
with self.ensure_open(autoclose=False): | ||
return FrozenOrderedDict((k, self.open_store_variable(k, v)) | ||
for k, v in self.ds.variables.items()) | ||
|
||
def get_attrs(self): | ||
with self.ensure_open(autoclose=True): | ||
return Frozen(dict([(k, getattr(self.ds, k)) | ||
for k in self.ds.ncattrs()])) | ||
|
||
def get_dimensions(self): | ||
with self.ensure_open(autoclose=True): | ||
return Frozen(self.ds.dimensions) | ||
|
||
def get_encoding(self): | ||
encoding = {} | ||
encoding['unlimited_dims'] = set( | ||
[k for k in self.ds.dimensions | ||
if self.ds.dimensions[k].isunlimited()]) | ||
return encoding | ||
|
||
def close(self): | ||
if self._isopen: | ||
self.ds.close() | ||
self._isopen = False |
This file contains hidden or 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 hidden or 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,31 @@ | ||
27, 1001 | ||
Henderson, Barron | ||
U.S. EPA | ||
Example file with artificial data | ||
JUST_A_TEST | ||
1, 1 | ||
2018, 04, 27, 2018, 04, 27 | ||
0 | ||
Start_UTC | ||
7 | ||
1, 1, 1, 1, 1 | ||
-9999, -9999, -9999, -9999, -9999 | ||
lat, degrees_north | ||
lon, degrees_east | ||
elev, meters | ||
TEST_ppbv, ppbv | ||
TESTM_ppbv, ppbv | ||
0 | ||
8 | ||
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 | ||
REVISION: R0 | ||
R0: No comments for this revision. | ||
Start_UTC, lat, lon, elev, TEST_ppbv, TESTM_ppbv | ||
43200, 41.00000, -71.00000, 5, 1.2345, 2.220 | ||
46800, 42.00000, -72.00000, 15, 2.3456, -9999 | ||
50400, 42.00000, -73.00000, 20, 3.4567, -7777 | ||
50400, 42.00000, -74.00000, 25, 4.5678, -8888 |
Binary file not shown.
Oops, something went wrong.
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.
Actually, let's do this for
decode_cf
instead ofmask_and_scale
. I don't think the other netCDF specific decoding like concatenating characters is relevant to psuedonetcdf, either.Also, let's be sure to change this for
open_mfdataset
(andopen_dataarray
) as well.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.
Next push:
mask_and_scale
todecode_cf
.open_mfdataset
uses a pass-through of keywords.open_dataarray
has been updatedFYI - This leads to an odd outcome -- if I want to
decode_times
, I have to explicitly enabledecode_cf
and then disable all the others individually, and enabledecode_times
.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.
Oh... I didn't realize you do want to decode times. In that case, I guess disabling only mask_and_scale is a reasonable choice.