Reading in Data

Manual Input

pytplot.store_data(name, data=None, delete=False, newname=None, attr_dict={})[source]

Create a “Tplot Variable” (similar to the IDL SPEDAS concept) based on the inputs, and stores this data in memory. Tplot Variables store all of the information needed to generate a plot.

Parameters:
  • name (str) – Name of the tplot variable that will be created

  • data (dict or list[str]) – A python dictionary object for creating a single variable, or a list of base variables to combine them into a ‘pseudovariable’

    ‘x’ should be a 1-dimensional array that represents the data’s x axis. If x is a numeric type, it is interpreted as seconds since the Unix epoch. x can also be passed as Pandas Series object, datetime.datetime, numpy.datetime64, or strings. represented in seconds since epoch (January 1st 1970)

    ‘y’ should be the data values. This can be 2 dimensions if multiple lines or a spectrogram are desired.

    ‘v’ is optional, and is only used for spectrogram plots. This will be a list of bins to be used. If this is provided, then ‘y’ should have dimensions of x by z.

    ‘v1/v2/v3/etc’ are also optional, and are only used for to spectrogram plots. These will act as the coordinates for ‘y’ if ‘y’ has numerous dimensions. By default, ‘v2’ is plotted in spectrogram plots.

  • delete (bool, optional) – If True, deletes the tplot variable matching the “name” parameter Default: False

  • newname (str) – If set, renames TVar to new name Default: False

  • attr_dict (dict) – A dictionary object of attributes (these do not affect routines in pytplot, this is merely to keep metadata alongside the file) Default: {} (empty dictionary)

Note

If you want to combine multiple tplot variables into one, simply supply the list of tplot variables to the “data” parameter. This will cause the data to overlay when plotted.

Returns:

True if successful, False otherwise

Return type:

bool

Examples

>>> # Store a single line
>>> import pyspedas
>>> x_data = [1,2,3,4,5]
>>> y_data = [1,2,3,4,5]
>>> pyspedas.store_data("Variable1", data={'x':x_data, 'y':y_data})
>>> # Store two lines
>>> x_data = [1,2,3,4,5]
>>> y_data = [[1,5],[2,4],[3,3],[4,2],[5,1]]
>>> pyspedas.store_data("Variable2", data={'x':x_data, 'y':y_data})
>>> # Store a spectrogram
>>> x_data = [1,2,3]
>>> y_data = [ [1,2,3] , [4,5,6], [7,8,9] ]
>>> v_data = [1,2,3]
>>> pyspedas.store_data("Variable3", data={'x':x_data, 'y':y_data, 'v':v_data})
>>> # Combine two different line plots
>>> pyspedas.store_data("Variable1and2", data=['Variable1', 'Variable2'])
>>> #Rename TVar
>>> pyspedas.store_data('a', data={'x':[0,4,8,12,16], 'y':[1,2,3,4,5]})
>>> pyspedas.store_data('a',newname='f')

CDF Reader

pytplot.cdf_to_tplot(filenames, mastercdf=None, varformat=None, exclude_format=None, get_support_data=False, get_metadata=False, get_ignore_data=False, string_encoding='ascii', prefix='', suffix='', plot=False, merge=False, center_measurement=False, notplot=False, varnames=[])[source]

This function will automatically create tplot variables from CDF files. In general, the files should be ISTP compliant for this importer to work. Each variable is read into a new tplot variable (a.k.a an xarray DataArray), and all associated file/variable metadata is read into the attrs dictionary.

Note

Variables must have an attribute named “VAR_TYPE”. If the attribute entry is “data” (or “support_data”), then they will be added as tplot variables. Additionally, data variables should have attributes named “DEPEND_TIME” or “DEPEND_0” that describes which variable is x axis. If the data is 2D, then an attribute “DEPEND_1” must describe which variable contains the secondary axis.

Parameters:
  • filenames – str/list of str The file names and full paths of CDF files.

  • mastercdf – str The file name of a master CDF to be used, if any

  • varformat – str or list[str] The file variable formats to load into tplot. Wildcard character “*” is accepted. By default, all variables are loaded in.

  • exclude_format – str or list[str] The file variable formats to exclude from loading into tplot. Wildcard character “*” is accepted. By default, no variables are excluded.

  • 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”.

  • prefix – str The tplot variable names will be given this prefix. By default, no prefix is added.

  • suffix – str The tplot variable names will be given this suffix. By default, no suffix is added.

  • plot – bool The data is plotted immediately after being generated. All tplot variables generated from this function will be on the same plot.

  • merge – bool If True, then data from different cdf files will be merged into a single tplot variable.

  • get_ignore_data – bool Data with an attribute “VAR_TYPE” with a value of “ignore_data” will be loaded into tplot. By default, only loads in data with a “VAR_TYPE” attribute of “data”.

  • center_measurement – bool If True, the CDF epoch variables are time-shifted to the middle of the accumulation interval by their DELTA_PLUS_VAR and DELTA_MINUS_VAR variable attributes

  • notplot – bool If True, then data are returned in a hash table instead of being stored in tplot variables (useful for debugging, and access to multi-dimensional data products)

  • varnames – str or list of str Load these variables only. If [] or [‘*’], then load everything.

Returns:

List of tplot variables created (unless notplot keyword is used).

NetCDF Reader

pytplot.netcdf_to_tplot(filenames, time='', prefix='', suffix='', plot=False, merge=False, strict_time=True)[source]

Create tplot variables from netCDF files.

Parameters:
  • filenames (str or list of str) – The file names and full paths of netCDF files.

  • time (str, optional) – This is not used anymore. Remains here for backward compatibility. Currently, the name of the time variable is found in the netCDF variables themselves.

  • prefix (str, optional) – The tplot variable names will be given this prefix. By default, no prefix is added.

  • suffix (str, optional) – The tplot variable names will be given this suffix. By default, no suffix is added.

  • plot (bool, optional) – If True, the data is plotted immediately after being generated. All tplot variables generated from this function will be on the same plot. By default, a plot is not created.

  • merge (bool, optional) – If True, then data from ‘filenames’ will be merged into existing tplot variables. If False (default), then data from ‘filenames’ will overwrite existing tplot variables. Data in ‘filenames’ will always be merged/combined by themselves.

  • strict_time (bool, optional) – If True (default), variables will be loaded into tplot variables only if their data length matches the time length. If False, all variables will be loaded. This is useful because some variables may contain general information, like satellite longitude.

Returns:

stored_variables – List of tplot variables created.

Return type:

list of str

Examples

Create tplot variables from a GOES netCDF file:

>>> import pyspedas
>>> file = "/Users/user_name/goes_files/g15_epead_a16ew_1m_20171201_20171231.nc"
>>> pyspedas.netcdf_to_tplot(file, prefix='mvn_')

Add a prefix, and plot immediately:

>>> import pyspedas
>>> file = "/Users/user_name/goes_files/g15_epead_a16ew_1m_20171201_20171231.nc"
>>> pyspedas.netcdf_to_tplot(file, prefix='goes_prefix_', plot=True)

IDL Restore

pytplot.tplot_restore(filename)[source]

This function will restore tplot variables that have been saved with the “tplot_save” command.

Note

This function is compatible with the IDL tplot_save routine. If you have a “.tplot” file generated from IDL, this procedure will restore the data contained in the file. Not all plot options will transfer over at this time.

Parameters:

filename – str The file name and full path generated by the “tplot_save” command.

Returns:

None

Examples

>>> # Restore the saved data from the tplot_save example
>>> import pyspedas
>>> pyspedas.tplot_restore('C:/temp/variable1.pytplot')