Skip to content

Commit

Permalink
Added docstrings and type hints for TWINS load routines
Browse files Browse the repository at this point in the history
  • Loading branch information
jameswilburlewis committed Feb 14, 2024
1 parent 7cfff58 commit 85eb8ec
Show file tree
Hide file tree
Showing 3 changed files with 171 additions and 54 deletions.
14 changes: 9 additions & 5 deletions pyspedas/twins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,23 @@ The routines in this module can be used to load data from the TWINS mission.
- Ephemeris

### Examples
Get started by importing pyspedas and tplot; these are required to load and plot the data:

#### Imager

```python
import pyspedas
from pytplot import tplot
```

#### Imager

```python
img_vars = pyspedas.twins.imager(trange=['2018-11-5', '2018-11-6'])
tplot('smooth_image_val')
```

#### Lyman-alpha Detector (LAD)

```python
import pyspedas
from pytplot import tplot

lad_vars = pyspedas.twins.lad(trange=['2018-11-5/6:00', '2018-11-5/6:20'], time_clip=True)

tplot(['lad1_data', 'lad2_data'])
Expand All @@ -32,6 +33,9 @@ tplot(['lad1_data', 'lad2_data'])
#### Ephemeris

```python
import pyspedas
from pytplot import tplot

ephem_vars = pyspedas.twins.ephemeris(trange=['2018-11-5', '2018-11-6'])

tplot('FSCGSM')
Expand Down
121 changes: 86 additions & 35 deletions pyspedas/twins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,45 +20,66 @@ def ephemeris(trange=['2018-11-5', '2018-11-6'],
----------
trange : list of str
time range of interest [starttime, endtime] with the format
'YYYY-MM-DD','YYYY-MM-DD'] or to specify more or less than a day
['YYYY-MM-DD','YYYY-MM-DD'] or to specify more or less than a day
['YYYY-MM-DD/hh:mm:ss','YYYY-MM-DD/hh:mm:ss']
Default: ['2018-11-5', '2018-11-6']
probe: str or list of str
Probe to load. Valid options: '1', '2'
Default: '1'
datatype: str
Data type; Valid options:
Default: 'or'
suffix: str
The tplot variable names will be given this suffix. By default,
no suffix is added.
The tplot variable names will be given this suffix.
Default: ''
get_support_data: bool
Data with an attribute "VAR_TYPE" with a value of "support_data"
will be loaded into tplot. By default, only loads in data with a
"VAR_TYPE" attribute of "data".
If True, data with an attribute "VAR_TYPE" with a value of "support_data"
will be loaded into tplot.
Default: False
varformat: str
The file variable formats to load into tplot. Wildcard character
"*" is accepted. By default, all variables are loaded in.
"*" is accepted.
Default: '' (all variables will be loaded)
varnames: list of str
List of variable names to load (if not specified,
all data variables are loaded)
List of variable names to load
Default: [] (all variables will be loaded)
downloadonly: bool
Set this flag to download the CDF files, but not load them into
tplot variables
Default: False
notplot: bool
Return the data in hash tables instead of creating tplot variables
Default: False
no_update: bool
If set, only load data from your local cache
Default: False
time_clip: bool
Time clip the variables to exactly the range specified in the trange keyword
Default: False
Returns
----------
List of tplot variables created.
-------
list of str
List of tplot variables created.
Examples
--------
>>> import pyspedas
>>> from pytplot import tplot
>>> # Note: variables have the same names for both probes, so only load one at a time
>>> ephem_vars = pyspedas.twins.ephemeris(probe=['1'],trange=['2008-04-01','2008-04-02'])
>>> tplot('FEQUATORIALGSM')
"""
return load(instrument='ephemeris', trange=trange, probe=probe, datatype=datatype, suffix=suffix, get_support_data=get_support_data, varformat=varformat, varnames=varnames, downloadonly=downloadonly, notplot=notplot, time_clip=time_clip, no_update=no_update)
Expand All @@ -81,45 +102,60 @@ def lad(trange=['2018-11-5', '2018-11-6'],
----------
trange : list of str
time range of interest [starttime, endtime] with the format
'YYYY-MM-DD','YYYY-MM-DD'] or to specify more or less than a day
['YYYY-MM-DD','YYYY-MM-DD'] or to specify more or less than a day
['YYYY-MM-DD/hh:mm:ss','YYYY-MM-DD/hh:mm:ss']
Default: ['2018-11-5', '2018-11-6']
datatype: str
Data type; Valid options:
Data type; Valid options: ''
Default: ''
suffix: str
The tplot variable names will be given this suffix. By default,
no suffix is added.
The tplot variable names will be given this suffix.
Default: ''
get_support_data: bool
Data with an attribute "VAR_TYPE" with a value of "support_data"
will be loaded into tplot. By default, only loads in data with a
"VAR_TYPE" attribute of "data".
If True, data with an attribute "VAR_TYPE" with a value of "support_data"
will be loaded into tplot.
Default: False
varformat: str
The file variable formats to load into tplot. Wildcard character
"*" is accepted. By default, all variables are loaded in.
"*" is accepted.
Default: '' (all variables loaded)
varnames: list of str
List of variable names to load (if not specified,
all data variables are loaded)
List of variable names to load
Default: [] (all variables loaded)
downloadonly: bool
Set this flag to download the CDF files, but not load them into
tplot variables
Default: False
notplot: bool
Return the data in hash tables instead of creating tplot variables
Default: False
no_update: bool
If set, only load data from your local cache
Default: False
time_clip: bool
Time clip the variables to exactly the range specified in the trange keyword
Default: False
Returns
----------
List of tplot variables created.
--------
list of str
List of tplot variables created.
Examples
--------
>>> import pyspedas
>>> from pytplot import tplot
>>> lad_vars = pyspedas.twins.lad(trange=['2018-11-5/6:00', '2018-11-5/6:20'], time_clip=True)
>>> tplot(['lad1_data', 'lad2_data'])
"""
return load(instrument='lad', trange=trange, probe=probe, datatype=datatype, suffix=suffix, get_support_data=get_support_data, varformat=varformat, varnames=varnames, downloadonly=downloadonly, notplot=notplot, time_clip=time_clip, no_update=no_update)
Expand All @@ -142,45 +178,60 @@ def imager(trange=['2018-11-5', '2018-11-6'],
----------
trange : list of str
time range of interest [starttime, endtime] with the format
'YYYY-MM-DD','YYYY-MM-DD'] or to specify more or less than a day
['YYYY-MM-DD','YYYY-MM-DD'] or to specify more or less than a day
['YYYY-MM-DD/hh:mm:ss','YYYY-MM-DD/hh:mm:ss']
datatype: str
Data type; Valid options:
Data type; Valid options: ''
Default: ''
suffix: str
The tplot variable names will be given this suffix. By default,
no suffix is added.
The tplot variable names will be given this suffix.
Default: ''
get_support_data: bool
Data with an attribute "VAR_TYPE" with a value of "support_data"
will be loaded into tplot. By default, only loads in data with a
"VAR_TYPE" attribute of "data".
If True, data with an attribute "VAR_TYPE" with a value of "support_data"
will be loaded into tplot.
Default: False
varformat: str
The file variable formats to load into tplot. Wildcard character
"*" is accepted. By default, all variables are loaded in.
"*" is accepted.
Default: '' (all variables loaded)
varnames: list of str
List of variable names to load (if not specified,
all data variables are loaded)
List of variable names to load
Default: [] (all variables will be loaded)
downloadonly: bool
Set this flag to download the CDF files, but not load them into
tplot variables
Default: False
notplot: bool
Return the data in hash tables instead of creating tplot variables
Default: False
no_update: bool
If set, only load data from your local cache
Default: False
time_clip: bool
Time clip the variables to exactly the range specified in the trange keyword
Default: False
Returns
----------
List of tplot variables created.
--------
list of str
List of tplot variables created.
Examples
--------
>>> import pyspedas
>>> from pytplot import tplot
>>> img_vars = pyspedas.twins.imager(trange=['2018-11-5', '2018-11-6'])
>>> tplot('smooth_image_val')
"""
return load(instrument='imager', trange=trange, probe=probe, datatype=datatype, suffix=suffix, get_support_data=get_support_data, varformat=varformat, varnames=varnames, downloadonly=downloadonly, notplot=notplot, time_clip=time_clip, no_update=no_update)
Expand Down
90 changes: 76 additions & 14 deletions pyspedas/twins/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,84 @@
from pyspedas.utilities.download import download
from pytplot import time_clip as tclip
from pytplot import cdf_to_tplot

from typing import List, Union
from .config import CONFIG

def load(trange=['2018-11-5', '2018-11-6'],
probe='1',
instrument='lad',
datatype='',
suffix='',
get_support_data=False,
varformat=None,
varnames=[],
downloadonly=False,
notplot=False,
no_update=False,
time_clip=False):
"""
def load(trange:List[str]=['2018-11-5', '2018-11-6'],
probe:Union[str,List[str]]='1',
instrument:str='lad',
datatype:str='',
suffix:str='',
get_support_data:bool=False,
varformat:str=None,
varnames:List[str]=[],
downloadonly:bool=False,
notplot:bool=False,
no_update:bool=False,
time_clip:bool=False) -> List[str]:
"""Load data from the TWINS mission
Parameters
----------
trange : list of str
time range of interest [starttime, endtime] with the format
['YYYY-MM-DD','YYYY-MM-DD'] or to specify more or less than a day
['YYYY-MM-DD/hh:mm:ss','YYYY-MM-DD/hh:mm:ss']
Default: ['2018-11-5', '2018-11-6']
probe: str or list of str
Probe to load. Valid options: '1', '2'
Default: '1'
instrument : str
The instrument to load. Valid options: 'lad', 'imager', 'ephemeris'
Default: 'lad'
datatype: str
Data type; Valid options: ''
Default: ''
suffix: str
The tplot variable names will be given this suffix.
Default: ''
get_support_data: bool
If True, data with an attribute "VAR_TYPE" with a value of "support_data"
will be loaded into tplot.
Default: False
varformat: str
The file variable formats to load into tplot. Wildcard character
"*" is accepted.
Default: '' (all variables loaded)
varnames: list of str
List of variable names to load
Default: [] (all variables will be loaded)
downloadonly: bool
Set this flag to download the CDF files, but not load them into
tplot variables
Default: False
notplot: bool
Return the data in hash tables instead of creating tplot variables
Default: False
no_update: bool
If set, only load data from your local cache
Default: False
time_clip: bool
Time clip the variables to exactly the range specified in the trange keyword
Default: False
Returns
--------
list of str
List of tplot variables created.
Notes
-----
This function loads TWINS data; this function is not meant
to be called directly; instead, see the wrappers:
pyspedas.twins.lad
Expand Down

0 comments on commit 85eb8ec

Please sign in to comment.