DADAFileNameSequencer¶
- class baseband.dada.DADAFileNameSequencer(template, header={})[source] [edit on github]¶
Bases:
FileNameSequencer
List-like generator of DADA filenames using a template.
The template is formatted, filling in any items in curly brackets with values from the header, as well as possibly a file number equal to the indexing value, indicated with ‘{file_nr}’. The value ‘{obs_offset}’ is treated specially, in being calculated using
header['OBS_OFFSET'] + file_nr * header['FILE_SIZE']
, whereheader['FILE_SIZE']
is the file size in bytes.The length of the instance will be the number of files that exist that match the template for increasing values of the file number (when writing, it is the number of files that have so far been generated).
- Parameters:
- templatestr
Template to format to get specific filenames. Curly bracket item keywords are not case-sensitive.
- headerdict-like
Structure holding key’d values that are used to fill in the format. Keys must be in all caps (eg.
DATE
), as with DADA header keys.
Examples
>>> from baseband import dada >>> dfs = dada.DADAFileNameSequencer( ... '{date}_{file_nr:03d}.dada', {'DATE': "2018-01-01"}) >>> dfs[10] '2018-01-01_010.dada' >>> from baseband.data import SAMPLE_DADA >>> with open(SAMPLE_DADA, 'rb') as fh: ... header = dada.DADAHeader.fromfile(fh) >>> template = '{utc_start}.{obs_offset:016d}.000000.dada' >>> dfs = dada.DADAFileNameSequencer(template, header) >>> dfs[0] '2013-07-02-01:37:40.0000006400000000.000000.dada' >>> dfs[1] '2013-07-02-01:37:40.0000006400064000.000000.dada' >>> dfs[10] '2013-07-02-01:37:40.0000006400640000.000000.dada'