DADAFileNameSequencer

class baseband.dada.base.DADAFileNameSequencer(template, header)[source] [edit on github]

List-like generator of 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'], where header['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.

Parameters:

template : str

Template to format to get specific filenames.

header : dict-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.base.DADAFileNameSequencer('a{file_nr:03d}.dada', {})
>>> dfs[10]
'a010.dada'
>>> dfs = dada.base.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 = 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'