Skip to content

Commit

Permalink
Docs and unit tests are fixed! Testing the docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
bryan-harter committed Feb 17, 2022
1 parent e081e61 commit 829b403
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 11 deletions.
49 changes: 39 additions & 10 deletions cdflib/cdf_to_xarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,22 +596,18 @@ def _verify_dimension_sizes(created_data_vars, created_coord_vars):

def cdf_to_xarray(filename, to_datetime=False, to_unixtime=False, fillval_to_nan=False):
"""
This function converts CDF files into XArray Dataset Objects
This function converts CDF files into XArray Dataset Objects.
Parameters:
filename : str
The CDF file to read into memory
to_datetime : bool, optional
Whether or not to convert CDF_EPOCH/EPOCH_16/TT2000 to datetime, or leave them as is
to_unixtime : bool, optional
Whether or not to convert CDF_EPOCH/EPOCH_16/TT2000 to unixtime, or leave them as is
fillval_to_nan : bool, optional
If True, any data values that match the FILLVAL attribute for a variable will be set to NaN
filename (str): The path to the CDF file to read
to_datetime (bool, optional): Whether or not to convert CDF_EPOCH/EPOCH_16/TT2000 to datetime, or leave them as is
to_unixtime (bool, optional): Whether or not to convert CDF_EPOCH/EPOCH_16/TT2000 to unixtime, or leave them as is
fillval_to_nan (bool, optional): If True, any data values that match the FILLVAL attribute for a variable will be set to NaN
Returns:
An XArray Dataset Object
Example:
Example MMS:
>>> #Import necessary libraries
>>> import cdflib
>>> import xarray as xr
Expand All @@ -627,6 +623,39 @@ def cdf_to_xarray(filename, to_datetime=False, to_unixtime=False, fillval_to_nan
>>> #Load in and display the CDF file
>>> mms_data = cdflib.cdf_to_xarray("mms2_fgm_srvy_l2_20160809_v4.47.0.cdf", to_unixtime=True, fillval_to_nan=True)
>>> print(mms_data)
>>> # Show off XArray functionality
>>>
>>> # Slice the data using built in XArray functions
>>> mms_data2 = mms_data.isel(dim0=0)
>>> # Plot the sliced data using built in XArray functions
>>> mms_data2['mms2_fgm_b_gse_srvy_l2'].plot()
>>> # Zoom in on the slices data in time using built in XArray functions
>>> mms_data3 = mms_data2.isel(Epoch=slice(716000,717000))
>>> # Plot the zoomed in sliced data using built in XArray functionality
>>> mms_data3['mms2_fgm_b_gse_srvy_l2'].plot()
Example THEMIS:
>>> #Import necessary libraries
>>> import cdflib
>>> import xarray as xr
>>> import os
>>> import urllib.request
>>> #Download a CDF file
>>> fname = 'thg_l2_mag_amd_20070323_v01.cdf'
>>> url = ("https://lasp.colorado.edu/maven/sdc/public/data/sdc/web/cdflib_testing/thg_l2_mag_amd_20070323_v01.cdf")
>>> if not os.path.exists(fname):
>>> urllib.request.urlretrieve(url, fname)
>>> #Load in and display the CDF file
>>> thg_data = cdflib.cdf_to_xarray(fname, to_unixtime=True, fillval_to_nan=True)
>>> print(thg_data)
Processing Steps:
1. asdf
2. asdfasdf
3. asdfasdfasdf
"""


Expand Down
2 changes: 1 addition & 1 deletion doc/modules/cdf_to_xarray.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ cdf_to_xarray function

This module is comprised of a single function which takes a CDF file and converts it to an XArray Dataset object.

This will attempt to determine any `ISTP Complaince <https://spdf.gsfc.nasa.gov/istp_guide/istp_guide.html>`_ within the file, and incorporate that into the Dataset object.
This will attempt to determine any `ISTP Compliance <https://spdf.gsfc.nasa.gov/istp_guide/istp_guide.html>`_ within the file, and incorporate that into the Dataset object.

.. autofunction:: cdflib.cdf_to_xarray

0 comments on commit 829b403

Please sign in to comment.