spacepy.pybats.ImfInput

class spacepy.pybats.ImfInput(filename=False, load=True, npoints=0, *args, **kwargs)[source]

A class to read, write, manipulate, and visualize solar wind upstream input files for SWMF simulations. More about such files can be found in the SWMF/BATS-R-US documentation for the #SOLARWINDFILE command.

Creating an ImfInput object is simple:

>>> from spacepy import pybats
>>> obj=pybats.ImfInput(filename='test.dat', load=True)

Upon instantiation, if filename is a valid file AND kwarg load is set to boolean True, the contents of filename are loaded into the object and no other work needs to be done.

If filename is False or load is False, a blank ImfInput file is created for the user to manipulate. The user can set the time array and the associated data values (see obj.attrs[‘var’] for a list) to any values desired and use the method obj.write() to dump the contents to an SWMF formatted input file. See the documentation for the write method for more details.

Like most pybats objects, you may interact with ImfInput objects as if they were specialized dictionaries. Access data like so:

>>> obj.keys()
['bx', 'by', 'bz', 'vx', 'vy', 'vz', 'rho', 'temp']
>>> density=obj['rho']

Adding new data entries is equally simple so long as you have the values and the name for the values:

>>> import numpy as np
>>> v = np.sqrt(obj['vx']**2 + obj['vy']**2 + obj['vz']**2)
>>> obj['v']=v

Kwarg

Description

filename

Set the input/output file name.

load

Read file upon instantiation? Defaults to True

npoints

For empty data sets, sets number of points (default is 0)