-
-
Notifications
You must be signed in to change notification settings - Fork 407
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #173 from ColCarroll/move_to_netcdf
Add an `InferenceData` object
- Loading branch information
Showing
25 changed files
with
252 additions
and
144 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
# pylint: disable=wildcard-import | ||
# pylint: disable=wildcard-import,invalid-name,wrong-import-position | ||
__version__ = '0.1.0' | ||
from matplotlib.pyplot import style | ||
|
||
config = {'default_data_directory': '.arviz_data'} | ||
|
||
from .inference_data import InferenceData | ||
from .plots import * | ||
from .stats import * | ||
from .utils import trace_to_dataframe, save_data, load_data, convert_to_xarray, load_arviz_data | ||
from .utils import trace_to_dataframe, load_data, convert_to_netcdf, load_arviz_data |
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,40 @@ | ||
import netCDF4 as nc | ||
import xarray as xr | ||
|
||
|
||
class InferenceData(): | ||
"""Container for accessing netCDF files using xarray.""" | ||
|
||
def __init__(self, filename): | ||
"""Attach to a netcdf file. | ||
This will inspect the netcdf for the available groups, so that they can be | ||
later loaded into memory. | ||
Parameters: | ||
----------- | ||
filename : str | ||
netcdf4 file that contains groups for accessing with xarray. | ||
""" | ||
if filename == '': # netcdf freezes in this case | ||
raise FileNotFoundError("No such file b''") | ||
self._filename = filename | ||
self._nc_dataset = nc.Dataset(filename, mode='r') | ||
self._groups = self._nc_dataset.groups | ||
|
||
def __repr__(self): | ||
return 'Inference data from "{filename}" with groups:\n\t> {options}'.format( | ||
filename=self._filename, | ||
options='\n\t> '.join(self._groups) | ||
) | ||
|
||
def __getattr__(self, name): | ||
"""Lazy load xarray DataSets when they are requested""" | ||
if name in self._groups: | ||
setattr(self, name, xr.open_dataset(self._filename, group=name)) | ||
return getattr(self, name) | ||
return self.__getattribute__(name) | ||
|
||
def __dir__(self): | ||
"""Enable tab-completion in iPython and Jupyter environments""" | ||
return super(InferenceData, self).__dir__() + list(self._groups.keys()) |
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
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
Oops, something went wrong.