Skip to content

Commit

Permalink
Merge pull request #962 from nickssl/master
Browse files Browse the repository at this point in the history
Refactored __init__.py file to dscovr
  • Loading branch information
nickssl authored Aug 2, 2024
2 parents 1ae08d2 + ab4ceb9 commit ed0f1f7
Show file tree
Hide file tree
Showing 5 changed files with 243 additions and 462 deletions.
16 changes: 10 additions & 6 deletions pyspedas/dscovr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,43 @@ from pytplot import tplot
#### Magnetometer (MAG)

```python
mag_vars = pyspedas.dscovr.mag(trange=['2018-11-5', '2018-11-6'])

from pyspedas.dscovr import mag
mag_vars = mag(trange=['2018-11-5', '2018-11-6'])
tplot('dsc_h0_mag_B1GSE')
```

#### Faraday cup (FC)

```python
fc_vars = pyspedas.dscovr.fc(trange=['2018-11-5', '2018-11-6'])
from pyspedas.dscovr import fc
fc_vars = fc(trange=['2018-11-5', '2018-11-6'])

tplot(['dsc_h1_fc_V_GSE', 'dsc_h1_fc_THERMAL_SPD', 'dsc_h1_fc_Np', 'dsc_h1_fc_THERMAL_TEMP'])
```

#### Orbit data

```python
orb_vars = pyspedas.dscovr.orb(trange=['2018-11-5', '2018-11-6'])
from pyspedas.dscovr import orb
orb_vars = orb(trange=['2018-11-5', '2018-11-6'])

tplot(['dsc_orbit_SUN_R', 'dsc_orbit_GCI_POS', 'dsc_orbit_GCI_VEL', 'dsc_orbit_GSE_POS', 'dsc_orbit_MOON_GSE_POS'])
```

#### Attitude data

```python
att_vars = pyspedas.dscovr.att(trange=['2018-11-5', '2018-11-6'])
from pyspedas.dscovr import att
att_vars = att(trange=['2018-11-5', '2018-11-6'])

tplot(['dsc_att_GSE_Yaw', 'dsc_att_GSE_Pitch', 'dsc_att_GSE_Roll'])
```

#### Load all data at once

```python
all_vars = pyspedas.dscovr.all(trange=['2018-11-5', '2018-11-6'])
from pyspedas.dscovr import all
all_vars = all(trange=['2018-11-5', '2018-11-6'])

tplot(['dsc_h0_mag_B1GSE', 'dsc_h1_fc_V_GSE', 'dsc_h1_fc_THERMAL_SPD', 'dsc_h1_fc_Np', 'dsc_orbit_GSE_POS'])
```
332 changes: 23 additions & 309 deletions pyspedas/dscovr/__init__.py
Original file line number Diff line number Diff line change
@@ -1,310 +1,24 @@
from .load import load
from functools import update_wrapper
from pyspedas.dscovr.load import load
from pyspedas.utilities.datasets import find_datasets


def mag(trange=['2018-10-16', '2018-10-17'],
datatype='h0',
suffix='',
get_support_data=False,
varformat=None,
varnames=[],
downloadonly=False,
notplot=False,
no_update=False,
time_clip=False,
force_download=False):
"""
This function loads DSCOVR Fluxgate Magnetometer data
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']
datatype: str
Data type; Valid options:
'h0': 1-sec Definitive Data (default)
suffix: str
The tplot variable names will be given this suffix. By default,
no suffix is added.
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".
varformat: str
The file variable formats to load into tplot. Wildcard character
"*" is accepted. By default, all variables are loaded in.
varnames: list of str
List of variable names to load (if not specified,
all data variables are loaded)
downloadonly: bool
Set this flag to download the CDF files, but not load them into
tplot variables
notplot: bool
Return the data in hash tables instead of creating tplot variables
no_update: bool
If set, only load data from your local cache
time_clip: bool
Time clip the variables to exactly the range specified in the trange keyword
force_download: bool
Download file even if local version is more recent than server version
Default: False
Returns
----------
List of tplot variables created.
"""
return load(instrument='mag', prefix='dsc_'+datatype+'_mag_', trange=trange, 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, force_download=force_download)

def fc(trange=['2018-10-16', '2018-10-17'],
datatype='h1',
suffix='',
get_support_data=False,
varformat=None,
varnames=[],
downloadonly=False,
notplot=False,
no_update=False,
time_clip=False,
force_download=False):
"""
This function loads DSCOVR Faraday Cup data
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']
datatype: str
Data type; Valid options:
'h1': 1-minute Isotropic Maxwellian parameters for solar wind protons (default)
suffix: str
The tplot variable names will be given this suffix. By default,
no suffix is added.
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".
varformat: str
The file variable formats to load into tplot. Wildcard character
"*" is accepted. By default, all variables are loaded in.
varnames: list of str
List of variable names to load (if not specified,
all data variables are loaded)
downloadonly: bool
Set this flag to download the CDF files, but not load them into
tplot variables
notplot: bool
Return the data in hash tables instead of creating tplot variables
no_update: bool
If set, only load data from your local cache
time_clip: bool
Time clip the variables to exactly the range specified in the trange keyword
force_download: bool
Download file even if local version is more recent than server version
Default: False
Returns
----------
List of tplot variables created.
"""
return load(instrument='faraday_cup', prefix='dsc_'+datatype+'_fc_', trange=trange, 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, force_download=force_download)

def orb(trange=['2018-10-16', '2018-10-17'],
datatype='orbit',
suffix='',
get_support_data=False,
varformat=None,
varnames=[],
downloadonly=False,
notplot=False,
no_update=False,
time_clip=False,
force_download=False):
"""
This function loads DSCOVR Ephemeris data
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']
suffix: str
The tplot variable names will be given this suffix. By default,
no suffix is added.
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".
varformat: str
The file variable formats to load into tplot. Wildcard character
"*" is accepted. By default, all variables are loaded in.
varnames: list of str
List of variable names to load (if not specified,
all data variables are loaded)
downloadonly: bool
Set this flag to download the CDF files, but not load them into
tplot variables
notplot: bool
Return the data in hash tables instead of creating tplot variables
no_update: bool
If set, only load data from your local cache
time_clip: bool
Time clip the variables to exactly the range specified in the trange keyword
force_download: bool
Download file even if local version is more recent than server version
Default: False
Returns
----------
List of tplot variables created.
"""
return load(instrument='pre_or', prefix='dsc_orbit_', trange=trange, 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, force_download=force_download)

def att(trange=['2018-10-16', '2018-10-17'],
datatype='orbit',
suffix='',
get_support_data=False,
varformat=None,
varnames=[],
downloadonly=False,
notplot=False,
no_update=False,
time_clip=False,
force_download=False):
"""
This function loads DSCOVR Attitude data
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']
suffix: str
The tplot variable names will be given this suffix. By default,
no suffix is added.
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".
varformat: str
The file variable formats to load into tplot. Wildcard character
"*" is accepted. By default, all variables are loaded in.
varnames: list of str
List of variable names to load (if not specified,
all data variables are loaded)
downloadonly: bool
Set this flag to download the CDF files, but not load them into
tplot variables
notplot: bool
Return the data in hash tables instead of creating tplot variables
no_update: bool
If set, only load data from your local cache
time_clip: bool
Time clip the variables to exactly the range specified in the trange keyword
force_download: bool
Download file even if local version is more recent than server version
Default: False
Returns
----------
List of tplot variables created.
"""
return load(instrument='def_at', prefix='dsc_att_', trange=trange, 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)

def all(trange=['2018-10-16', '2018-10-17'],
downloadonly=False,
suffix='',
no_update=False,
time_clip=False,
force_download=False):
"""
This function loads all DSCOVR data
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']
downloadonly: bool
Set this flag to download the CDF files, but not load them into
tplot variables
no_update: bool
If set, only load data from your local cache
time_clip: bool
Time clip the variables to exactly the range specified in the trange keyword
force_download: bool
Download file even if local version is more recent than server version
Default: False
Returns
----------
List of tplot variables created.
"""
att_vars = att(trange=trange, downloadonly=downloadonly, time_clip=time_clip, no_update=no_update, force_download=force_download)
orb_vars = orb(trange=trange, downloadonly=downloadonly, time_clip=time_clip, no_update=no_update, force_download=force_download)
mag_vars = mag(trange=trange, downloadonly=downloadonly, time_clip=time_clip, no_update=no_update, force_download=force_download)
fc_vars = fc(trange=trange, downloadonly=downloadonly, time_clip=time_clip, no_update=no_update, force_download=force_download)
return att_vars + orb_vars + mag_vars + fc_vars


def datasets(instrument=None, label=True):
return find_datasets(mission='DSCOVR', instrument=instrument, label=label)
from pyspedas.utilities.pyspedas_functools import better_partial


# Define partial wrappers for other load routines, fixing the instrument parameter
# 'better_partial' works better with PyCharm autocompletion than functools.partial
# update_wrapper() is necessary for help() to show info for the wrapped function,
# rather than the partial() object.

mag = better_partial(load, instrument="mag")
update_wrapper(mag, load)
fc = better_partial(load, instrument="fc")
update_wrapper(mag, load)
orb = better_partial(load, instrument="orb")
update_wrapper(orb, load)
att = better_partial(load, instrument="att")
update_wrapper(att, load)
all = better_partial(load, instrument="all")
update_wrapper(all, load)

datasets = better_partial(find_datasets, mission="DSCOVR", label=True)
update_wrapper(datasets, find_datasets)
7 changes: 3 additions & 4 deletions pyspedas/dscovr/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
'remote_data_dir': 'https://spdf.gsfc.nasa.gov/pub/data/dscovr/'}

# override local data directory with environment variables
if os.environ.get('SPEDAS_DATA_DIR'):
CONFIG['local_data_dir'] = os.sep.join([os.environ['SPEDAS_DATA_DIR'], 'dscovr'])

if os.environ.get('DSC_DATA_DIR'):
CONFIG['local_data_dir'] = os.environ['DSC_DATA_DIR']
CONFIG['local_data_dir'] = os.environ['DSC_DATA_DIR']
elif os.environ.get('SPEDAS_DATA_DIR'):
CONFIG['local_data_dir'] = os.sep.join([os.environ['SPEDAS_DATA_DIR'], 'dscovr'])
Loading

0 comments on commit ed0f1f7

Please sign in to comment.