class spacepy.pybats.LogFile(filename, starttime=(2000, 1, 1, 0, 0, 0), keep_case=True, *args, **kwargs)[source]

An object to read and handle SWMF-type logfiles.

LogFile objects read and hold all information in an SWMF ascii time-varying logfile. The file is read upon instantiation. Many SWMF codes produce flat ascii files that can be read by this class; the most frequently used ones have their own classes that inherit from this.

See spacepy.pybats.PbData for information on how to explore data contained within the returned object.

Usage: >>>data = spacepy.pybats.LogFile(‘filename.log’)




Manually set the start time of the data.

Time is handled by Python’s datetime package. Given that time may or may not be given in the logfile, there are three options for how time is returned:

1. if the full date and time are listed in the file, self['time'] is an array of datetime objects corresponding to the entries. The starttime kwarg is ignored.

2. If only the runtime (seconds from start of simulation) is given, self[‘time’] is an array of datetime objects that starts from the given starttime kwarg which defaults to 1/1/1 00:00UT.

3. If neither of the above are given, the time is assumed to advance one second per line starting from either the starttime kwarg or from 2000/1/1 00:00UT + the first iteration (if given in file.) As you can imagine, this is sketchy at best.

This time issue is output dependent: some SWMF models place the full date and time into the log by default while others will almost never include the full date and time. The variable self['runtime'] contains the more generic seconds from simulation start values.

Example usage:

>>> import spacepy.pybats as pb
>>> import pylab as plt
>>> import datetime as dt
>>> time1 = dt.datetime(2009,11,30,9,0)
>>> file1 = pb.logfile('satfile_n000000.dat', starttime=time1)
>>> plt.plot(file1['time'], file1['dst'])