GUPPIFileNameSequencer

class baseband.guppi.base.GUPPIFileNameSequencer(template, header={})[source] [edit on github]

Bases: FileNameSequencer

List-like generator of GUPPI 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 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 GUPPI header keys.

Examples

>>> from baseband import guppi
>>> gfs = guppi.GUPPIFileNameSequencer(
...     '{date}_{file_nr:03d}.raw', {'DATE': "2018-01-01"})
>>> gfs[10]
'2018-01-01_010.raw'
>>> from baseband.data import SAMPLE_PUPPI
>>> with open(SAMPLE_PUPPI, 'rb') as fh:
...     header = guppi.GUPPIHeader.fromfile(fh)
>>> template = 'puppi_{stt_imjd}_{src_name}_{scannum}.{file_nr:04d}.raw'
>>> gfs = guppi.GUPPIFileNameSequencer(template, header)
>>> gfs[0]
'puppi_58132_J1810+1744_2176.0000.raw'
>>> gfs[10]
'puppi_58132_J1810+1744_2176.0010.raw'