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 withImfInput
objects as if they were specialized dictionaries. Access data like so:>>> obj.keys() ['bx', 'by', 'bz', 'vx', 'vy', 'vz', 'n', 't'] >>> density=obj['n']
Adding new data entries is equally simple so long as you have the values and the name for the values:
>>> import numpy as np >>> u = np.sqrt(obj['ux']**2 + obj['uy']**2 + obj['uz']**2) >>> obj['u']=u
If new data entries are added as
dmarray
objects, thelabel
andunits
attributes can be set to enhance plotting.>>> from spacepy import datamodel >>> u = np.sqrt(obj['ux']**2 + obj['uy']**2 + obj['uz']**2) >>> obj['u']= datamodel.dmarray(u, {'units': '$km/s$', 'label': '|U|'})