-
Notifications
You must be signed in to change notification settings - Fork 43
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 #141 from dstansby/cdf-docstring
Fix doc build
- Loading branch information
Showing
16 changed files
with
113 additions
and
93 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,10 @@ | ||
from pathlib import Path | ||
|
||
from . import cdfread, cdfwrite | ||
from .cdf_factory import CDF | ||
from .cdf_to_xarray import cdf_to_xarray | ||
from .epochs import CDFepoch as cdfepoch # noqa: F401 | ||
from .epochs_astropy import CDFAstropy as cdfastropy | ||
from .xarray_to_cdf import xarray_to_cdf | ||
|
||
# This function determines if we are reading or writing a file | ||
|
||
|
||
def CDF(path, cdf_spec=None, delete=False, validate=None, string_encoding='ascii'): | ||
""" | ||
This is a wrapper function for the cdfread and cdfwrite modules. If you specify a file that exists, it returns a CDF reading class. | ||
If you specify a file that does not yet exist, one will be created and this function will return a CDF writing class. | ||
Parameters: | ||
path (str): The path to a cdf file that exists -or- to one you wish to create | ||
cdf_spec (dict, optional): If you are writing a CDF file, this specifies general parameters about data is written. See the cdfwrite class for more details. | ||
delete (bool, optional): Delete the file if it exists and return immediately | ||
validate (bool, optional): | ||
string_encoding (str, optional): How strings are encoded in a CDF file that you are reading. Another common encoding is 'utf-8'. | ||
Returns: | ||
A CDF object that can be used for reading a file (if it exists) or writing to a file (if it does not exist) | ||
Note: | ||
With this library, you cannot both read and write a file at the same time. You need to choose one or the other! | ||
Example: | ||
>>> # Simply open an existing CDF file and get some data from a variable | ||
>>> import cdflib | ||
>>> cdf_file = cdflib.CDF('/path/to/existing/cdf_file.cdf') | ||
>>> x = cdf_file.varget("NameOfVariable", startrec = 0, endrec = 150) | ||
""" | ||
path = Path(path).resolve().expanduser() | ||
|
||
if path.is_file(): | ||
if delete: | ||
path.unlink() | ||
return | ||
else: | ||
return cdfread.CDF(path, validate=validate, string_encoding=string_encoding) | ||
else: | ||
return cdfwrite.CDF(path, cdf_spec=cdf_spec, delete=delete) | ||
|
||
try: | ||
from .cdf_to_xarray import cdf_to_xarray | ||
from .epochs_astropy import CDFAstropy as cdfastropy | ||
from .xarray_to_cdf import xarray_to_cdf | ||
except Exception: | ||
pass | ||
__all__ = ['CDF', 'xarray_to_cdf', 'cdf_to_xarray'] |
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,58 @@ | ||
from pathlib import Path | ||
|
||
from . import cdfread, cdfwrite | ||
from .epochs import CDFepoch as cdfepoch # noqa: F401 | ||
|
||
|
||
# This function determines if we are reading or writing a file | ||
def CDF(path, cdf_spec=None, delete=False, validate=None, | ||
string_encoding='ascii'): | ||
""" | ||
A wrapper function for cdfread and cdfwrite modules. | ||
If you specify a file that exists, it returns a CDF reading class. | ||
If you specify a file that does not yet exist, one will be created and this | ||
function will return a CDF writing class. | ||
Parameters | ||
---------- | ||
path : str | ||
The path to a cdf file that exists or to one you wish to create | ||
cdf_spec : dict, optional | ||
If you are writing a CDF file, this specifies general parameters about | ||
data is written. See the cdfwrite class for more details. | ||
delete : bool, optional | ||
Delete the file if it exists and return immediately. | ||
validate : bool, optional | ||
string_encoding : str, optional | ||
How strings are encoded in a CDF file that you are reading. | ||
Another common encoding is 'utf-8'. | ||
Returns | ||
------- | ||
A CDF object that can be used for reading a file (if it exists) or writing | ||
to a file (if it does not exist) | ||
Notes | ||
----- | ||
With this library, you cannot both read and write a file at the same time. | ||
You need to choose one or the other! | ||
Examples | ||
-------- | ||
Open an existing CDF file and get some data from a variable | ||
>>> import cdflib | ||
>>> cdf_file = cdflib.CDF('/path/to/existing/cdf_file.cdf') | ||
>>> x = cdf_file.varget("NameOfVariable", startrec = 0, endrec = 150) | ||
""" | ||
path = Path(path).resolve().expanduser() | ||
|
||
if path.is_file(): | ||
if delete: | ||
path.unlink() | ||
return | ||
else: | ||
return cdfread.CDF(path, validate=validate, string_encoding=string_encoding) | ||
else: | ||
return cdfwrite.CDF(path, cdf_spec=cdf_spec, delete=delete) |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Developing cdflib | ||
================= | ||
|
||
Documentation | ||
------------- | ||
To build the documentation you will need to install the documentation | ||
requirements using:: | ||
|
||
pip install .[docs] | ||
|
||
This will install cdflib and all the packages need to make the documenation. |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,4 @@ | ||
CDF | ||
=== | ||
|
||
.. autofunction:: cdflib.CDF |
Empty file.
Empty file.
Empty file.
Empty file.
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,13 @@ | ||
Working with XArray | ||
=================== | ||
|
||
There are two functions for working with XArray DataSets, one for converting | ||
a CDF to a DataSet, and one for going the other way. | ||
|
||
These 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 | ||
|
||
.. autofunction:: cdflib.xarray_to_cdf |
This file was deleted.
Oops, something went wrong.