Skip to content

Commit

Permalink
Modifying the XArray docs
Browse files Browse the repository at this point in the history
  • Loading branch information
bryan-harter committed Feb 21, 2022
1 parent 5067f23 commit 4563029
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 58 deletions.
6 changes: 3 additions & 3 deletions cdflib/cdf_to_xarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,12 +654,12 @@ def cdf_to_xarray(filename, to_datetime=False, to_unixtime=False, fillval_to_nan
>>> print(thg_data)
Processing Steps:
1. For each variable in the CDF file -
1. Determine the name of the dimension that spans the data "records". This can be done in a few ways -
1. For each variable in the CDF file
1. Determine the name of the dimension that spans the data "records". This can be done in a few ways
1. Check if the variable itself might be a dimension
2. The DEPEND_0 likely points to the approrpiate dimensions
3. If neither of the above, we create a new dimensions named "recordX"
2. Determine the name of the other dimensions of the variable, if they exist. This is done by -
2. Determine the name of the other dimensions of the variable, if they exist. This is done by
1. Checking if the variable name itself might be a dimension
2. The DEPEND_X probably points to the appropriate dimensions for that variable, so we check those
3. If either of the above are time varying, the code appends "_dim" to the end of the name
Expand Down
56 changes: 1 addition & 55 deletions cdflib/xarray_to_cdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,61 +472,7 @@ def xarray_to_cdf(xarray_dataset, file_name, from_unixtime=False, from_datetime=
Returns:
None, but generates a CDF file
Example:
>>> # Import the needed libraries
>>> import cdflib
>>> import xarray as xr
>>> import os
>>> import urllib.request
Example:
>>> # Import the needed libraries
>>> import cdflib
>>> import xarray as xr
>>> import os
>>> import urllib.request
>>> # Create some fake data
>>> var_data = [[1, 2, 3], [1, 2, 3], [1, 2, 3]]
>>> var_dims = ['epoch', 'direction']
>>> data = xr.Variable(var_dims, var_data)
>>> # Create fake epoch data
>>> epoch_data = [1, 2, 3]
>>> epoch_dims = ['epoch']
>>> epoch = xr.Variable(epoch_dims, epoch_data)
>>> # Combine the two into an xarray Dataset and export as CDF (this will print out many ISTP warnings)
>>> ds = xr.Dataset(data_vars={'data': data, 'epoch': epoch})
>>> cdflib.xarray_to_cdf(ds, 'hello.cdf')
>>> # Add some global attributes
>>> global_attributes = {'Project': 'Hail Mary',
>>> 'Source_name': 'Thin Air',
>>> 'Discipline': 'None',
>>> 'Data_type': 'counts',
>>> 'Descriptor': 'Midichlorians in unicorn blood',
>>> 'Data_version': '3.14',
>>> 'Logical_file_id': 'SEVENTEEN',
>>> 'PI_name': 'Darth Vader',
>>> 'PI_affiliation': 'Dark Side',
>>> 'TEXT': 'AHHHHH',
>>> 'Instrument_type': 'Banjo',
>>> 'Mission_group': 'Impossible',
>>> 'Logical_source': ':)',
>>> 'Logical_source_description': ':('}
>>> # Lets add a new coordinate variable for the "direction"
>>> dir_data = [1, 2, 3]
>>> dir_dims = ['direction']
>>> direction = xr.Variable(dir_dims, dir_data)
>>> # Recreate the Dataset with this new objects, and recreate the CDF
>>> ds = xr.Dataset(data_vars={'data': data, 'epoch': epoch, 'direction':direction}, attrs=global_attributes)
>>> os.remove('hello.cdf')
>>> cdflib.xarray_to_cdf(ds, 'hello.cdf')
Examples:
Example CDF file from scratch:
>>> # Import the needed libraries
>>> import cdflib
>>> import xarray as xr
Expand Down

0 comments on commit 4563029

Please sign in to comment.