irfpy.vnpd.vnpddata

Data access for VEX/NPD

Preparation

The preparation is

Setup .irfpyrc file.

[vnpd]
ncdfbase = /path/to/ncdf

Simple usage is as follows.

>>> import datetime
>>> from irfpy.vnpd import vnpddata
>>> dc = vnpddata.DataCenterRawMode(1, _get_basedir())
>>> obstime, data = dc.nearest(datetime.datetime(2009, 1, 4, 21, 27, 30))
>>> print(obstime)
2009-01-04 21:27:30.242400
>>> print(data)
<NpdRawPacket: 2009-01-04T21:27:30 cnts=103 147 204 79 1 400>

The obtained data is with the NpdRawPacket class.

You can use get_array or iter for getting multiple data.

>>> obstime, data = dc.get_array(datetime.datetime(2009, 1, 4, 21, 27),
...                              datetime.datetime(2009, 1, 4, 21, 28))
>>> from pprint import pprint
>>> pprint(obstime)    
[datetime.datetime(2009, 1, 4, 21, 27, 0, 249690),
 datetime.datetime(2009, 1, 4, 21, 27, 0, 577370),
...
 datetime.datetime(2009, 1, 4, 21, 27, 59, 126480),
 datetime.datetime(2009, 1, 4, 21, 27, 59, 454160)]
>>> pprint(data)   
[<NpdRawPacket: 2009-01-04T21:27:00 cnts=102 111 186 74 1 343>,
 <NpdRawPacket: 2009-01-04T21:27:00 cnts=117 130 188 85 2 376>,
...
 <NpdRawPacket: 2009-01-04T21:27:59 cnts=95 127 157 77 1 337>,
 <NpdRawPacket: 2009-01-04T21:27:59 cnts=92 124 180 75 2 358>]
>>> for obstime, data in dc.iter(datetime.datetime(2009, 1, 4, 21, 27),
...                              datetime.datetime(2009, 1, 4, 21, 28)):
...     print(obstime, data)    
2009-01-04 21:27:00.249690 <NpdRawPacket: 2009-01-04T21:27:00 cnts=102 111 186 74 1 343>
2009-01-04 21:27:00.577370 <NpdRawPacket: 2009-01-04T21:27:00 cnts=117 130 188 85 2 376>
...
2009-01-04 21:27:59.126480 <NpdRawPacket: 2009-01-04T21:27:59 cnts=95 127 157 77 1 337>
2009-01-04 21:27:59.454160 <NpdRawPacket: 2009-01-04T21:27:59 cnts=92 124 180 75 2 358>

The DataCenterRawMode is an implementation of irfpy data center. See also the data center tutorial and data center API for more details.

class irfpy.vnpd.vnpddata.DataCenterRawMode(npd_number, basedir=None)[source]

Bases: irfpy.util.datacenter.BaseDataCenter

Datacenter for RAW mode file.

Initializer.

Parameters
  • cache_size – Size of the ring cache.

  • name – The name of the

  • copy – Boolean if the returned data is to be deep-copied (True) or reference (False). It is good to return the data after the copy, since then the data is always original. Returning reference is possibly faster, while there are side effect that the post-processing will destroy the original data. Therefore, it is recommended to set True always. The copy value can be overwritten by each method as necessity.

search_files()[source]

Search the data files, returning a list of data file.

This method searches the data files under the base_folder. This method should return a list / tuple of the data file name (usually a full path).

This method is called only once when __init__() was called.

Returns

A list / tuple of the data file. It should be full path (or relative path from the current path), and sorted from earlier data to later data.

approximate_starttime(filename)[source]

Start time should be guessed for each file.

A guessed start time should be returned. It is OK if it is very approximate, but the orders of the guessed-start and the exact-start should be identical. This method must be very fast, because it is called for all the files in the data base (i.e. all the files retuned by search_files() method).

A practical suggestion for implementation is to guess the time from the filename.

Parameters

filename – A string, filename.

Returns

An approximate, guessed start time of the file

Return type

datetime.datetime

read_file(filename)[source]

The file is read, and return the contents as a tuple with size 2, (tlist, dlist).

This method is an abstract method, meaning that the developer of the data center should implement it. See SampleDataCenter for more details.

The implementation of this method should follow:

  • Returned value is a tuple with a size of 2. - The first element is a tuple/list specifying the time (with each element as datetime.datetime object) - The second element is a tuple/list specifying the data, with any format. - The length of both two elements should be the same.

If the given filename is corrupted or empty, a two empty tuple would be returned (i.e., return (), ()). In this case, return None for the exact_starttime() method.

Parameters

filename – File name

Returns

The contents of the data file

Return type

tuple