def parent(self, type_: Optional[str] = None) -> Optional['<STR_LIT>']:

ancestors = self.ancestors(type_)<EOL>if ancestors:<EOL><INDENT>return ancestors[<NUM_LIT:0>]<EOL><DEDENT>return None<EOL>

Return the parent node of the current object.

        :param type_: the type of the desired parent object.
            Currently the following types are supported: {Template,
            ParserFunction, WikiLink, Comment, Parameter, ExtensionTag}.
            The default is None and means the first parent, of any type above.
        :return: parent WikiText object or None if no parent with the desired
            `type_` is found.


@property<EOL><INDENT>def attrs(self) -> Dict[str, str]:<DEDENT>

spans = self._attrs_match.spans<EOL>string = self.string<EOL>return dict(zip(<EOL>(string[s:e] for s, e in spans('<STR_LIT>')),<EOL>(string[s:e] for s, e in spans('<STR_LIT>')),<EOL>))<EOL>


def has_attr(self, attr_name: str) -> bool:

string = self.string<EOL>return attr_name in (<EOL>string[s:e] for s, e in self._attrs_match.spans('<STR_LIT>')<EOL>)<EOL>

Return True if self contains an attribute with the given name.


def get_attr(self, attr_name: str) -> Optional[str]:

spans = self._attrs_match.spans<EOL>string = self.string<EOL>for i, (s, e) in enumerate(reversed(spans('<STR_LIT>'))):<EOL><INDENT>if string[s:e] == attr_name:<EOL><INDENT>s, e = spans('<STR_LIT>')[-i - <NUM_LIT:1>]<EOL>return string[s:e]<EOL><DEDENT><DEDENT>return None<EOL>

Return the value of the last attribute with the given name.

        Return None if the attr_name does not exist in self.
        If there are already multiple attributes with the given name, only
        return the value of the last one.
        Return an empty string if the mentioned name is an empty attribute.


def set_attr(self, attr_name: str, attr_value: str) -> None:

match = self._attrs_match<EOL>string = self.string<EOL>for i, (s, e) in enumerate(reversed(match.spans('<STR_LIT>'))):<EOL><INDENT>if string[s:e] == attr_name:<EOL><INDENT>vs, ve = match.spans('<STR_LIT>')[-i - <NUM_LIT:1>]<EOL>q = <NUM_LIT:1> if match.string[ve] in b'<STR_LIT>' else <NUM_LIT:0><EOL>self[vs - q:ve + q] = '<STR_LIT>'.format(attr_value)<EOL>return<EOL><DEDENT><DEDENT>fmt = '<STR_LIT>' if attr_value else '<STR_LIT>'<EOL>self.insert(<EOL>match.end('<STR_LIT>'),<EOL>fmt.format(attr_name, attr_value)<EOL>)<EOL>return<EOL>

Set the value for the given attribute name.

        If there are already multiple attributes with the given name, only
        set the value for the last one.
        If attr_value == '', use the implicit empty attribute syntax.


def del_attr(self, attr_name: str) -> None:

match = self._attrs_match<EOL>string = self.string<EOL>for i, (s, e) in enumerate(reversed(match.spans('<STR_LIT>'))):<EOL><INDENT>if string[s:e] == attr_name:<EOL><INDENT>start, stop = match.spans('<STR_LIT>')[-i - <NUM_LIT:1>]<EOL>del self[start:stop]<EOL><DEDENT><DEDENT>

Delete all the attributes with the given name.

        Pass if the attr_name is not found in self.


@property<EOL><INDENT>def _match(self) -> Any:<DEDENT>

cached_match, cached_string = self._match_cache<EOL>string = self.string<EOL>if cached_string == string:<EOL><INDENT>return cached_match<EOL><DEDENT>match = TAG_FULLMATCH(self._shadow)<EOL>self._match_cache = match, string<EOL>return match<EOL>

Return the match object for the current tag. Cache the result.


@property<EOL><INDENT>def name(self) -> str:<DEDENT>

return self._match['<STR_LIT:name>'].decode()<EOL>


@name.setter<EOL><INDENT>def name(self, name: str) -> None:<DEDENT>

<EOL>span = self._match.span<EOL>start, end = span('<STR_LIT>')<EOL>if start != -<NUM_LIT:1>:<EOL><INDENT>self[start:end] = name<EOL><DEDENT>start, end = span('<STR_LIT:name>')<EOL>self[start:end] = name<EOL>


@property<EOL><INDENT>def contents(self) -> Optional[str]:<DEDENT>

s, e = self._match.span('<STR_LIT>')<EOL>return self.string[s:e]<EOL>


@contents.setter<EOL><INDENT>def contents(self, contents: str) -> None:<DEDENT>

match = self._match<EOL>start, end = match.span('<STR_LIT>')<EOL>if start != -<NUM_LIT:1>:<EOL><INDENT>self[start:end] = contents<EOL><DEDENT>else:<EOL><INDENT>s, e = match.span('<STR_LIT>')<EOL>self[s:e] = '<STR_LIT>'.format(contents, match['<STR_LIT:name>'].decode())<EOL><DEDENT>

Set new contents.

        Note that if the tag is self-closing, then it will be expanded to
        have a start tag and an end tag. For example:
        >>> t = Tag('<t/>')
        >>> t.contents = 'n'
        >>> t.string
        '<t>n</t>'


@property<EOL><INDENT>def parsed_contents(self) -> SubWikiText:<DEDENT>

span = self._match.span('<STR_LIT>')<EOL>spans = self._type_to_spans<EOL>swt_spans = spans.setdefault('<STR_LIT>', [span])<EOL>return SubWikiText(<EOL>self._lststr,<EOL>spans,<EOL>next(s for s in swt_spans if s == span),<EOL>'<STR_LIT>')<EOL>

Return the contents as a SubWikiText object.


cache_match, cache_string = self._match_cache<EOL>string = self.string<EOL>if cache_string == string:<EOL><INDENT>return cache_match<EOL><DEDENT>cache_match = fullmatch(<EOL>LIST_PATTERN_FORMAT.replace(b'<STR_LIT>', self.pattern.encode()),<EOL>self._shadow,<EOL>MULTILINE,<EOL>)<EOL>self._match_cache = cache_match, string<EOL>return cache_match<EOL>

Return the match object for the current list.


@property<EOL><INDENT>def items(self) -> List[str]:<DEDENT>

items = []  <EOL>append = items.append<EOL>string = self.string<EOL>match = self._match<EOL>ms = match.start()<EOL>for s, e in match.spans('<STR_LIT>'):<EOL><INDENT>append(string[s - ms:e - ms])<EOL><DEDENT>return items<EOL>

Return items as a list of strings.

        Don't include sub-items and the start pattern.


@property<EOL><INDENT>def fullitems(self) -> List[str]:<DEDENT>

fullitems = []  <EOL>append = fullitems.append<EOL>string = self.string<EOL>match = self._match<EOL>ms = match.start()<EOL>for s, e in match.spans('<STR_LIT>'):<EOL><INDENT>append(string[s - ms:e - ms])<EOL><DEDENT>return fullitems<EOL>

Return list of item strings. Includes their start and sub-items.


@property<EOL><INDENT>def level(self) -> int:<DEDENT>

return len(self._match['<STR_LIT>'])<EOL>

Return level of nesting for the current list.

        Level is a one-based index, for example the level for `* a` will be 1.


def sublists(<EOL>self, i: int = None, pattern: str = None<EOL>) -> List['<STR_LIT>']:

patterns = (r'<STR_LIT>', r'<STR_LIT>', '<STR_LIT>') if pattern is Noneelse (pattern,)  <EOL>self_pattern = self.pattern<EOL>lists = self.lists<EOL>sublists = []  <EOL>sublists_append = sublists.append<EOL>if i is None:<EOL><INDENT>for pattern in patterns:<EOL><INDENT>for lst in lists(self_pattern + pattern):<EOL><INDENT>sublists_append(lst)<EOL><DEDENT><DEDENT>return sublists<EOL><DEDENT>match = self._match<EOL>fullitem_spans = match.spans('<STR_LIT>')<EOL>ss = self._span[<NUM_LIT:0>]<EOL>ms = match.start()<EOL>s, e = fullitem_spans[i]<EOL>e -= ms - ss<EOL>s -= ms - ss<EOL>for pattern in patterns:<EOL><INDENT>for lst in lists(self_pattern + pattern):<EOL><INDENT>ls, le = lst._span<EOL>if s < ls and le <= e:<EOL><INDENT>sublists_append(lst)<EOL><DEDENT><DEDENT><DEDENT>return sublists<EOL>

Return the Lists inside the item with the given index.

        :param i: The index if the item which its sub-lists are desired.
            The performance is likely to be better if `i` is None.

        :param pattern: The starting symbol for the desired sub-lists.
            The `pattern` of the current list will be automatically added
            as prefix.
            Although this parameter is optional, but specifying it can improve
            the performance.


def convert(self, newstart: str) -> None:

match = self._match<EOL>ms = match.start()<EOL>for s, e in reversed(match.spans('<STR_LIT>')):<EOL><INDENT>self[s - ms:e - ms] = newstart<EOL><DEDENT>self.pattern = escape(newstart)<EOL>

Convert to another list type by replacing starting pattern.


@classmethod<EOL><INDENT>def readonly(cls, *args, **kwargs):<DEDENT>

fridge = cls(*args, **kwargs)<EOL>fridge.close()<EOL>return fridge<EOL>

Return an already closed read-only instance of Fridge.
Arguments are the same as for the constructor.


self._check_open()<EOL>try:<EOL><INDENT>data = json.load(self.file, **self.load_args)<EOL><DEDENT>except ValueError:<EOL><INDENT>data = {}<EOL><DEDENT>if not isinstance(data, dict):<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>self.clear()<EOL>self.update(data)<EOL>

Force reloading the data from the file.
All data in the in-memory dictionary is discarded.
This method is called automatically by the constructor, normally you
don't need to call it.


self._check_open()<EOL>self.file.truncate(<NUM_LIT:0>)<EOL>self.file.seek(<NUM_LIT:0>)<EOL>json.dump(self, self.file, **self.dump_args)<EOL>

Force saving the dictionary to the file.
All data in the file is discarded.
This method is called automatically by :meth:`close`.


if not self.closed:<EOL><INDENT>self.save()<EOL>if self.close_file:<EOL><INDENT>self.file.close()<EOL><DEDENT><DEDENT>self.closed = True<EOL>

Close the fridge.
Calls :meth:`save` and closes the underlying file object unless
an already open file was passed to the constructor.
This method has no effect if the object is already closed.

After the fridge is closed :meth:`save` and :meth:`load` will raise an exception
but you will still be able to use it as an ordinary dictionary.


print("<STR_LIT>"),<EOL>a = bl.Waterfall(voyager_h5)<EOL>b = bl.Waterfall(voyager_fil)<EOL>print("<STR_LIT:OK>")<EOL>print("<STR_LIT>")<EOL>print("<STR_LIT>")<EOL>pprint(a.header)<EOL>print("<STR_LIT>")<EOL>pprint(b.header)<EOL>print("<STR_LIT>")<EOL>print("<STR_LIT>"),<EOL>for key in b.header.keys():<EOL><INDENT>assert b.header[key] == a.header[key]<EOL><DEDENT>print("<STR_LIT:OK>")<EOL>print("<STR_LIT>"),<EOL>assert a.data.dtype == b.data.dtype<EOL>print("<STR_LIT:OK>")<EOL>print("<STR_LIT>"),<EOL>assert np.allclose(a.data, b.data)<EOL>assert a.data.dtype == b.data.dtype<EOL>print("<STR_LIT:OK>")<EOL>

Load Voyager dataset and test that both fil and hdf5 readers return same headers and data


a = bl.Waterfall(voyager_h5)<EOL>b = bl.Waterfall(voyager_fil)<EOL>print("<STR_LIT>")<EOL>assert a.beam_axis == b.beam_axis<EOL>assert a.freq_axis == b.freq_axis<EOL>assert a.time_axis == b.time_axis<EOL>assert a.calc_n_coarse_chan() == b.calc_n_coarse_chan()<EOL>assert a.file_shape == b.file_shape<EOL>assert a.n_channels_in_file == b.n_channels_in_file<EOL>assert a.n_ints_in_file == b.n_ints_in_file<EOL>assert a.selection_shape == b.selection_shape<EOL>print("<STR_LIT>")<EOL>a.populate_freqs()<EOL>a.populate_timestamps()<EOL>a.info()<EOL>a.blank_dc(<NUM_LIT:1>)<EOL>a.calibrate_band_pass_N1()<EOL>b.populate_freqs()<EOL>b.populate_timestamps()<EOL>b.info()<EOL>b.blank_dc(<NUM_LIT:1>)<EOL>b.calibrate_band_pass_N1()<EOL>dir_a = dir(a)<EOL>dir_b = dir(b)<EOL>print("<STR_LIT>")<EOL>for item in dir_a:<EOL><INDENT>if item not in dir_b:<EOL><INDENT>print(item)<EOL><DEDENT><DEDENT>print("<STR_LIT>")<EOL>for item in dir_b:<EOL><INDENT>if item not in dir_a:<EOL><INDENT>print(item)<EOL><DEDENT><DEDENT>


a = bl.Waterfall(voyager_h5)<EOL>b = bl.Waterfall(voyager_fil)<EOL>dir_a = dir(a.container)<EOL>dir_b = dir(b.container)<EOL>print("<STR_LIT>")<EOL>for item in dir_a:<EOL><INDENT>if item not in dir_b:<EOL><INDENT>print(item)<EOL><DEDENT><DEDENT>print("<STR_LIT>")<EOL>for item in dir_b:<EOL><INDENT>if item not in dir_a:<EOL><INDENT>print(item)<EOL><DEDENT><DEDENT>

Compare the two containers for fil.container and h5.container


print("<STR_LIT>"),<EOL>a = bl.Filterbank(voyager_h5)<EOL>b = bl.Filterbank(voyager_fil)<EOL>print("<STR_LIT:OK>")<EOL>print("<STR_LIT>")<EOL>print("<STR_LIT>")<EOL>pprint(a.header)<EOL>print("<STR_LIT>")<EOL>pprint(b.header)<EOL>print("<STR_LIT>")<EOL>print("<STR_LIT>"),<EOL>for key in b.header.keys():<EOL><INDENT>assert b.header[key] == a.header[key]<EOL><DEDENT>print("<STR_LIT:OK>")<EOL>print("<STR_LIT>"),<EOL>assert a.data.dtype == b.data.dtype<EOL>print("<STR_LIT:OK>")<EOL>print("<STR_LIT>"),<EOL>assert np.allclose(a.data, b.data)<EOL>assert a.data.dtype == b.data.dtype<EOL>print("<STR_LIT:OK>")<EOL>


script_text  = '<STR_LIT>'<EOL>with open('<STR_LIT>', '<STR_LIT:w>') as batch_script:<EOL><INDENT>batch_script.write(script_text)<EOL><DEDENT>os.chmod('<STR_LIT>', <NUM_LIT>)<EOL>

This creates a batch script for the heavy lifting


<EOL>filfile=open(filename,'<STR_LIT:rb>')<EOL>filfile.seek(<NUM_LIT:0>)<EOL>round1 = filfile.read(<NUM_LIT:1000>)<EOL>headersize = round1.find('<STR_LIT>')+len('<STR_LIT>')<EOL>return headersize<EOL>

Script to find the header size of a filterbank file


if '<STR_LIT>' in local_host:<EOL><INDENT>header_loc = '<STR_LIT>' <EOL><DEDENT>else:<EOL><INDENT>raise IOError('<STR_LIT>')<EOL><DEDENT>p = OptionParser()<EOL>p.set_usage('<STR_LIT>')<EOL>opts, args = p.parse_args(sys.argv[<NUM_LIT:1>:])<EOL>file1 = args[<NUM_LIT:0>]<EOL>file2 = args[<NUM_LIT:1>]<EOL>make_batch_script()<EOL>headersize1 = find_header_size(file1)<EOL>file_size1 = os.path.getsize(file1)<EOL>command=['<STR_LIT>',file1,str(file_size1-headersize1)]<EOL>print('<STR_LIT>'+'<STR_LIT:U+0020>'.join(command))<EOL>proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)<EOL>(out, err) = proc.communicate()<EOL>check_sum1 = out.split()[<NUM_LIT:0>]<EOL>print('<STR_LIT>', check_sum1)<EOL>if err:<EOL><INDENT>raise Error('<STR_LIT>')<EOL><DEDENT>out,err = reset_outs()<EOL>command=[header_loc,file1]<EOL>print('<STR_LIT>')<EOL>proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)<EOL>(out, err) = proc.communicate()<EOL>header1 = out<EOL>print(header1)<EOL>out,err = reset_outs()<EOL>headersize2 = find_header_size(file2)<EOL>file_size2 = os.path.getsize(file2)<EOL>command=['<STR_LIT>',file2,str(file_size2-headersize2)]<EOL>print('<STR_LIT>'+'<STR_LIT:U+0020>'.join(command))<EOL>proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)<EOL>(out, err) = proc.communicate()<EOL>check_sum2 = out.split()[<NUM_LIT:0>]<EOL>print('<STR_LIT>', check_sum2)<EOL>if err:<EOL><INDENT>raise Error('<STR_LIT>')<EOL><DEDENT>out,err = reset_outs()<EOL>command=[header_loc,file2]<EOL>print('<STR_LIT>')<EOL>proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)<EOL>(out, err) = proc.communicate()<EOL>header2 = out<EOL>print(header2)<EOL>if check_sum1 != check_sum2:<EOL><INDENT>print('<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>print('<STR_LIT>')<EOL><DEDENT>os.remove('<STR_LIT>')<EOL>

Command line tool to make a md5sum comparison of two .fil files.


<EOL>if feedtype=='<STR_LIT:l>':<EOL><INDENT>I = cross_dat[:,<NUM_LIT:0>,:]+cross_dat[:,<NUM_LIT:1>,:]<EOL>Q = cross_dat[:,<NUM_LIT:0>,:]-cross_dat[:,<NUM_LIT:1>,:]<EOL>U = <NUM_LIT:2>*cross_dat[:,<NUM_LIT:2>,:]<EOL>V = -<NUM_LIT:2>*cross_dat[:,<NUM_LIT:3>,:]<EOL><DEDENT>elif feedtype=='<STR_LIT:c>':<EOL><INDENT>I = cross_dat[:,<NUM_LIT:0>,:]+cross_dat[:,<NUM_LIT:1>,:]<EOL>Q = <NUM_LIT:2>*cross_dat[:,<NUM_LIT:2>,:]<EOL>U = -<NUM_LIT:2>*cross_dat[:,<NUM_LIT:3>,:]<EOL>V = cross_dat[:,<NUM_LIT:1>,:]-cross_dat[:,<NUM_LIT:0>,:]<EOL><DEDENT>else:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>I = np.expand_dims(I,axis=<NUM_LIT:1>)<EOL>Q = np.expand_dims(Q,axis=<NUM_LIT:1>)<EOL>U = np.expand_dims(U,axis=<NUM_LIT:1>)<EOL>V = np.expand_dims(V,axis=<NUM_LIT:1>)<EOL>return I,Q,U,V<EOL>

Output stokes parameters (I,Q,U,V) for a rawspec
    cross polarization filterbank file


<EOL>num_coarse = data.size/chan_per_coarse<EOL>data_shaped = np.array(np.reshape(data,(num_coarse,chan_per_coarse)))<EOL>return np.mean(data_shaped[:,<NUM_LIT:2>:-<NUM_LIT:1>],axis=<NUM_LIT:1>)<EOL>

Converts a data array with length n_chans to an array of length n_coarse_chans
by averaging over the coarse channels


<EOL>if feedtype=='<STR_LIT:l>':<EOL><INDENT>U_OFF,U_ON = foldcal(Udat,tsamp,**kwargs)<EOL>V_OFF,V_ON = foldcal(Vdat,tsamp,**kwargs)<EOL>Udiff = U_ON-U_OFF<EOL>Vdiff = V_ON-V_OFF<EOL>poffset = np.arctan2(-<NUM_LIT:1>*Vdiff,Udiff)<EOL><DEDENT>if feedtype=='<STR_LIT:c>':<EOL><INDENT>U_OFF,U_ON = foldcal(Udat,tsamp,**kwargs)<EOL>Q_OFF,Q_ON = foldcal(Qdat,tsamp,**kwargs)<EOL>Udiff = U_ON-U_OFF<EOL>Qdiff = Q_ON-Q_OFF<EOL>poffset = np.arctan2(Udiff,Qdiff)<EOL><DEDENT>coarse_p =  convert_to_coarse(poffset,chan_per_coarse)<EOL>y = coarse_p[:<NUM_LIT:6>]<EOL>x = np.arange(y.size)<EOL>m = np.polyfit(x,y,<NUM_LIT:1>)[<NUM_LIT:0>]<EOL>for i in range(coarse_p.size-<NUM_LIT:3>):<EOL><INDENT>if (m><NUM_LIT:0> and coarse_p[i+<NUM_LIT:1>]<coarse_p[i]) or (m<<NUM_LIT:0> and coarse_p[i+<NUM_LIT:1>]>coarse_p[i]):<EOL><INDENT>coarse_p[i+<NUM_LIT:1>] = <NUM_LIT:2>*coarse_p[i+<NUM_LIT:2>]-coarse_p[i+<NUM_LIT:3>]    <EOL><DEDENT><DEDENT>return coarse_p<EOL>

Calculates phase difference between X and Y feeds given U and V (U and Q for circular basis)
data from a noise diode measurement on the target


if feedtype=='<STR_LIT:l>':<EOL><INDENT>I_OFF,I_ON = foldcal(Idat,tsamp,**kwargs)<EOL>Q_OFF,Q_ON = foldcal(Qdat,tsamp,**kwargs)<EOL>XX_ON = (I_ON+Q_ON)/<NUM_LIT:2><EOL>XX_OFF = (I_OFF+Q_OFF)/<NUM_LIT:2><EOL>YY_ON = (I_ON-Q_ON)/<NUM_LIT:2><EOL>YY_OFF = (I_OFF-Q_OFF)/<NUM_LIT:2><EOL>G = (XX_OFF-YY_OFF)/(XX_OFF+YY_OFF)<EOL><DEDENT>if feedtype=='<STR_LIT:c>':<EOL><INDENT>I_OFF,I_ON = foldcal(Idat,tsamp,**kwargs)<EOL>V_OFF,V_ON = foldcal(Vdat,tsamp,**kwargs)<EOL>RR_ON = (I_ON+V_ON)/<NUM_LIT:2><EOL>RR_OFF = (I_OFF+V_OFF)/<NUM_LIT:2><EOL>LL_ON = (I_ON-V_ON)/<NUM_LIT:2><EOL>LL_OFF = (I_OFF-V_OFF)/<NUM_LIT:2><EOL>G = (RR_OFF-LL_OFF)/(RR_OFF+LL_OFF)<EOL><DEDENT>return convert_to_coarse(G,chan_per_coarse)<EOL>

Determines relative gain error in the X and Y feeds for an
observation given I and Q (I and V for circular basis) noise diode data.


def apply_Mueller(I,Q,U,V, gain_offsets, phase_offsets, chan_per_coarse, feedtype='<STR_LIT:l>'):

<EOL>shape = I.shape<EOL>ax0 = I.shape[<NUM_LIT:0>]<EOL>ax1 = I.shape[<NUM_LIT:1>]<EOL>nchans = I.shape[<NUM_LIT:2>]<EOL>ncoarse = nchans/chan_per_coarse<EOL>I = np.reshape(I,(ax0,ax1,ncoarse,chan_per_coarse))<EOL>Q = np.reshape(Q,(ax0,ax1,ncoarse,chan_per_coarse))<EOL>U = np.reshape(U,(ax0,ax1,ncoarse,chan_per_coarse))<EOL>V = np.reshape(V,(ax0,ax1,ncoarse,chan_per_coarse))<EOL>I = np.swapaxes(I,<NUM_LIT:2>,<NUM_LIT:3>)<EOL>Q = np.swapaxes(Q,<NUM_LIT:2>,<NUM_LIT:3>)<EOL>U = np.swapaxes(U,<NUM_LIT:2>,<NUM_LIT:3>)<EOL>V = np.swapaxes(V,<NUM_LIT:2>,<NUM_LIT:3>)<EOL>a = <NUM_LIT:1>/(<NUM_LIT:1>-gain_offsets**<NUM_LIT:2>)<EOL>if feedtype=='<STR_LIT:l>':<EOL><INDENT>Icorr = a*(I-gain_offsets*Q)<EOL>Qcorr = a*(-<NUM_LIT:1>*gain_offsets*I+Q)<EOL>I = None<EOL>Q = None<EOL><DEDENT>if feedtype=='<STR_LIT:c>':<EOL><INDENT>Icorr = a*(I-gain_offsets*V)<EOL>Vcorr = a*(-<NUM_LIT:1>*gain_offsets*I+V)<EOL>I = None<EOL>V = None<EOL><DEDENT>if feedtype=='<STR_LIT:l>':<EOL><INDENT>Ucorr = U*np.cos(phase_offsets)-V*np.sin(phase_offsets)<EOL>Vcorr = U*np.sin(phase_offsets)+V*np.cos(phase_offsets)<EOL>U = None<EOL>V = None<EOL><DEDENT>if feedtype=='<STR_LIT:c>':<EOL><INDENT>Qcorr = Q*np.cos(phase_offsets)+U*np.sin(phase_offsets)<EOL>Ucorr = -<NUM_LIT:1>*Q*np.sin(phase_offsets)+U*np.cos(phase_offsets)<EOL>Q = None<EOL>U = None<EOL><DEDENT>Icorr = np.reshape(np.swapaxes(Icorr,<NUM_LIT:2>,<NUM_LIT:3>),shape)<EOL>Qcorr = np.reshape(np.swapaxes(Qcorr,<NUM_LIT:2>,<NUM_LIT:3>),shape)<EOL>Ucorr = np.reshape(np.swapaxes(Ucorr,<NUM_LIT:2>,<NUM_LIT:3>),shape)<EOL>Vcorr = np.reshape(np.swapaxes(Vcorr,<NUM_LIT:2>,<NUM_LIT:3>),shape)<EOL>return Icorr,Qcorr,Ucorr,Vcorr<EOL>

Returns calibrated Stokes parameters for an observation given an array
of differential gains and phase differences.


<EOL>obs = Waterfall(diode_cross,max_load=<NUM_LIT>)<EOL>cross_dat = obs.data<EOL>tsamp = obs.header['<STR_LIT>']<EOL>dio_ncoarse = obs.calc_n_coarse_chan()<EOL>dio_nchans = obs.header['<STR_LIT>']<EOL>dio_chan_per_coarse = dio_nchans/dio_ncoarse<EOL>obs = None<EOL>Idat,Qdat,Udat,Vdat = get_stokes(cross_dat,feedtype)<EOL>cross_dat = None<EOL>print('<STR_LIT>')<EOL>gams = gain_offsets(Idat,Qdat,Udat,Vdat,tsamp,dio_chan_per_coarse,feedtype,**kwargs)<EOL>psis = phase_offsets(Idat,Qdat,Udat,Vdat,tsamp,dio_chan_per_coarse,feedtype,**kwargs)<EOL>Idat = None<EOL>Qdat = None<EOL>Udat = None<EOL>Vdat = None<EOL>print('<STR_LIT>'+cross_pols)<EOL>cross_obs = Waterfall(cross_pols,max_load=<NUM_LIT>)<EOL>obs_ncoarse = cross_obs.calc_n_coarse_chan()<EOL>obs_nchans = cross_obs.header['<STR_LIT>']<EOL>obs_chan_per_coarse = obs_nchans/obs_ncoarse<EOL>print('<STR_LIT>')<EOL>I,Q,U,V = get_stokes(cross_obs.data,feedtype)<EOL>print('<STR_LIT>')<EOL>I,Q,U,V = apply_Mueller(I,Q,U,V,gams,psis,obs_chan_per_coarse,feedtype)<EOL>if onefile==True:<EOL><INDENT>cross_obs.data[:,<NUM_LIT:0>,:] = np.squeeze(I)<EOL>cross_obs.data[:,<NUM_LIT:1>,:] = np.squeeze(Q)<EOL>cross_obs.data[:,<NUM_LIT:2>,:] = np.squeeze(U)<EOL>cross_obs.data[:,<NUM_LIT:3>,:] = np.squeeze(V)<EOL>cross_obs.write_to_fil(cross_pols[:-<NUM_LIT:15>]+'<STR_LIT>')<EOL>print('<STR_LIT>'+cross_pols[:-<NUM_LIT:15>]+'<STR_LIT>')<EOL>return<EOL><DEDENT>obs = Waterfall(obs_I,max_load=<NUM_LIT>)<EOL>obs.data = I<EOL>obs.write_to_fil(cross_pols[:-<NUM_LIT:15>]+'<STR_LIT>')   <EOL>print('<STR_LIT>'+cross_pols[:-<NUM_LIT:15>]+'<STR_LIT>')<EOL>obs.data = Q<EOL>obs.write_to_fil(cross_pols[:-<NUM_LIT:15>]+'<STR_LIT>')   <EOL>print('<STR_LIT>'+cross_pols[:-<NUM_LIT:15>]+'<STR_LIT>')<EOL>obs.data = U<EOL>obs.write_to_fil(cross_pols[:-<NUM_LIT:15>]+'<STR_LIT>')   <EOL>print('<STR_LIT>'+cross_pols[:-<NUM_LIT:15>]+'<STR_LIT>')<EOL>obs.data = V<EOL>obs.write_to_fil(cross_pols[:-<NUM_LIT:15>]+'<STR_LIT>')   <EOL>print('<STR_LIT>'+cross_pols[:-<NUM_LIT:15>]+'<STR_LIT>')<EOL>

Write Stokes-calibrated filterbank file for a given observation
with a calibrator noise diode measurement on the source

Parameters
----------
cross_pols : string
    Path to cross polarization filterbank file (rawspec output) for observation to be calibrated
diode_cross : string
    Path to cross polarization filterbank file of noise diode measurement ON the target
obsI : string
    Path to Stokes I filterbank file of main observation (only needed if onefile=False)
onefile : boolean
    True writes all calibrated Stokes parameters to a single filterbank file,
    False writes four separate files
feedtype : 'l' or 'c'
    Basis of antenna dipoles. 'c' for circular, 'l' for linear


I,Q,U,V,L=get_stokes(str, **kwargs)<EOL>return L/I,V/I<EOL>

Output fractional linear and circular polarizations for a
    rawspec cross polarization .fil file. NOT STANDARD USE


def write_stokefils(str, str_I, Ifil=False, Qfil=False, Ufil=False, Vfil=False, Lfil=False, **kwargs):

I,Q,U,V,L=get_stokes(str, **kwargs)<EOL>obs = Waterfall(str_I, max_load=<NUM_LIT>) <EOL>if Ifil:<EOL><INDENT>obs.data = I<EOL>obs.write_to_fil(str[:-<NUM_LIT:15>]+'<STR_LIT>')   <EOL><DEDENT>if Qfil:<EOL><INDENT>obs.data = Q<EOL>obs.write_to_fil(str[:-<NUM_LIT:15>]+'<STR_LIT>')   <EOL><DEDENT>if Ufil:<EOL><INDENT>obs.data = U<EOL>obs.write_to_fil(str[:-<NUM_LIT:15>]+'<STR_LIT>')   <EOL><DEDENT>if Vfil:<EOL><INDENT>obs.data = V<EOL>obs.write_to_fil(str[:-<NUM_LIT:15>]+'<STR_LIT>')   <EOL><DEDENT>if Lfil:<EOL><INDENT>obs.data = L<EOL>obs.write_to_fil(str[:-<NUM_LIT:15>]+'<STR_LIT>')<EOL><DEDENT>

Writes up to 5 new filterbank files corresponding to each Stokes
    parameter (and total linear polarization L) for a given cross polarization .fil file


def write_polfils(str, str_I, **kwargs):

lin,circ=fracpols(str, **kwargs)<EOL>obs = Waterfall(str_I, max_load=<NUM_LIT>)<EOL>obs.data = lin<EOL>obs.write_to_fil(str[:-<NUM_LIT:15>]+'<STR_LIT>')   <EOL>obs.data = circ<EOL>obs.write_to_fil(str[:-<NUM_LIT:15>]+'<STR_LIT>')<EOL>

Writes two new filterbank files containing fractional linear and
    circular polarization data


halfper = diode_p/<NUM_LIT><EOL>foldt = halfper/tsamp   <EOL>onesec = <NUM_LIT:1>/tsamp    <EOL>ints = np.arange(<NUM_LIT:0>,numsamps)<EOL>t_switch = (onesec+ints*foldt)<EOL>t_switch = t_switch.astype('<STR_LIT:int>')<EOL>ONints = np.array(np.reshape(t_switch[:],(numsamps/<NUM_LIT:2>,<NUM_LIT:2>)))<EOL>ONints[:,<NUM_LIT:0>] = ONints[:,<NUM_LIT:0>]+<NUM_LIT:1>   <EOL>OFFints = np.array(np.reshape(t_switch[<NUM_LIT:1>:-<NUM_LIT:1>],(numsamps/<NUM_LIT:2>-<NUM_LIT:1>,<NUM_LIT:2>)))<EOL>OFFints[:,<NUM_LIT:0>] = OFFints[:,<NUM_LIT:0>]+<NUM_LIT:1>   <EOL>av_ON = []<EOL>av_OFF = []<EOL>for i in ONints:<EOL><INDENT>if i[<NUM_LIT:1>]!=i[<NUM_LIT:0>]:<EOL><INDENT>av_ON.append(np.sum(data[i[<NUM_LIT:0>]:i[<NUM_LIT:1>],:,:],axis=<NUM_LIT:0>)/(i[<NUM_LIT:1>]-i[<NUM_LIT:0>]))<EOL><DEDENT><DEDENT>for i in OFFints:<EOL><INDENT>if i[<NUM_LIT:1>]!=i[<NUM_LIT:0>]:<EOL><INDENT>av_OFF.append(np.sum(data[i[<NUM_LIT:0>]:i[<NUM_LIT:1>],:,:],axis=<NUM_LIT:0>)/(i[<NUM_LIT:1>]-i[<NUM_LIT:0>]))<EOL><DEDENT><DEDENT>if switch==False:<EOL><INDENT>if inds==False:<EOL><INDENT>return np.squeeze(np.mean(av_ON,axis=<NUM_LIT:0>)), np.squeeze(np.mean(av_OFF,axis=<NUM_LIT:0>))<EOL><DEDENT>else:<EOL><INDENT>return np.squeeze(np.mean(av_ON,axis=<NUM_LIT:0>)), np.squeeze(np.mean(av_OFF,axis=<NUM_LIT:0>)),ONints,OFFints<EOL><DEDENT><DEDENT>if switch==True:<EOL><INDENT>if inds==False:<EOL><INDENT>return np.squeeze(np.mean(av_OFF,axis=<NUM_LIT:0>)), np.squeeze(np.mean(av_ON,axis=<NUM_LIT:0>))<EOL><DEDENT>else:<EOL><INDENT>return np.squeeze(np.mean(av_OFF,axis=<NUM_LIT:0>)), np.squeeze(np.mean(av_ON,axis=<NUM_LIT:0>)),OFFints,ONints<EOL><DEDENT><DEDENT>

Returns time-averaged spectra of the ON and OFF measurements in a
calibrator measurement with flickering noise diode

Parameters
----------
data : 2D Array object (float)
    2D dynamic spectrum for data (any Stokes parameter) with flickering noise diode.
tsamp : float
    Sampling time of data in seconds
diode_p : float
    Period of the flickering noise diode in seconds
numsamps : int
    Number of samples over which to average noise diode ON and OFF
switch : boolean
    Use switch=True if the noise diode "skips" turning from OFF to ON once or vice versa
inds : boolean
    Use inds=True to also return the indexes of the time series where the ND is ON and OFF


num_coarse = spec.size/chan_per_coarse     <EOL>spec_shaped = np.array(np.reshape(spec,(num_coarse,chan_per_coarse)))<EOL>freqs_shaped = np.array(np.reshape(freqs,(num_coarse,chan_per_coarse)))<EOL>return np.mean(spec_shaped[:,<NUM_LIT:1>:-<NUM_LIT:1>],axis=<NUM_LIT:1>)<EOL>

Integrates over each core channel of a given spectrum.
Important for calibrating data with frequency/time resolution different from noise diode data

Parameters
----------
spec : 1D Array (float)
    Spectrum (any Stokes parameter) to be integrated
freqs : 1D Array (float)
    Frequency values for each bin of the spectrum
chan_per_coarse: int
    Number of frequency bins per coarse channel


<EOL>obs = Waterfall(name,max_load=<NUM_LIT>)<EOL>data = obs.data<EOL>if fullstokes==False and data.shape[<NUM_LIT:1>]><NUM_LIT:1>:<EOL><INDENT>data = data[:,<NUM_LIT:0>,:]+data[:,<NUM_LIT:1>,:]<EOL>data = np.expand_dims(data,axis=<NUM_LIT:1>)<EOL><DEDENT>if fullstokes==True:<EOL><INDENT>data = data[:,<NUM_LIT:0>,:]<EOL>data = np.expand_dims(data,axis=<NUM_LIT:1>)<EOL><DEDENT>tsamp = obs.header['<STR_LIT>']<EOL>OFF,ON = foldcal(data,tsamp,**kwargs)<EOL>freqs = obs.populate_freqs()<EOL>ON_int = integrate_chans(ON,freqs,chan_per_coarse)<EOL>OFF_int = integrate_chans(OFF,freqs,chan_per_coarse)<EOL>if np.sum(ON_int)<np.sum(OFF_int):<EOL><INDENT>temp = ON_int<EOL>ON_int = OFF_int<EOL>OFF_int = temp<EOL><DEDENT>return OFF_int,ON_int<EOL>

Folds Stokes I noise diode data and integrates along coarse channels

Parameters
----------
name : str
    Path to noise diode filterbank file
chan_per_coarse : int
    Number of frequency bins per coarse channel
fullstokes : boolean
    Use fullstokes=True if data is in IQUV format or just Stokes I, use fullstokes=False if
    it is in cross_pols format


const = calflux/np.power(calfreq,spec_in)<EOL>if oneflux==False:<EOL><INDENT>return const*np.power(centerfreqs,spec_in)<EOL><DEDENT>else:<EOL><INDENT>return const*np.power(np.mean(centerfreqs),spec_in)<EOL><DEDENT>

Given properties of the calibrator source, calculate fluxes of the source
in a particular frequency range

Parameters
----------
calflux : float
    Known flux of calibrator source at a particular frequency
calfreq : float
    Frequency where calibrator source has flux calflux (see above)
spec_in : float
    Known power-law spectral index of calibrator source. Use convention flux(frequency) = constant * frequency^(spec_in)
centerfreqs : 1D Array (float)
    Central frequency values of each coarse channel
oneflux : boolean
    Use oneflux to choose between calculating the flux for each core channel (False)
    or using one value for the entire frequency range (True)


num_coarse = freqs.size/chan_per_coarse<EOL>freqs = np.reshape(freqs,(num_coarse,chan_per_coarse))<EOL>return np.mean(freqs,axis=<NUM_LIT:1>)<EOL>

Returns central frequency of each coarse channel

Parameters
----------
freqs : 1D Array (float)
    Frequency values for each bin of the spectrum
chan_per_coarse: int
    Number of frequency bins per coarse channel


<EOL>L_ON,H_ON = integrate_calib(calON_obs,chan_per_coarse,**kwargs)<EOL>L_OFF,H_OFF = integrate_calib(calOFF_obs,chan_per_coarse,**kwargs)<EOL>f_ON = H_ON/L_ON-<NUM_LIT:1><EOL>f_OFF = H_OFF/L_OFF-<NUM_LIT:1><EOL>return f_ON, f_OFF<EOL>

Calculate f_ON, and f_OFF as defined in van Straten et al. 2012 equations 2 and 3

Parameters
----------
calON_obs : str
    Path to filterbank file (any format) for observation ON the calibrator source
calOFF_obs : str
    Path to filterbank file (any format) for observation OFF the calibrator source


<EOL>obs = Waterfall(calON_obs,max_load=<NUM_LIT>)<EOL>freqs = obs.populate_freqs()<EOL>ncoarse = obs.calc_n_coarse_chan()<EOL>nchans = obs.header['<STR_LIT>']<EOL>chan_per_coarse = nchans/ncoarse<EOL>f_ON, f_OFF = f_ratios(calON_obs,calOFF_obs,chan_per_coarse,**kwargs)<EOL>centerfreqs = get_centerfreqs(freqs,chan_per_coarse)<EOL>calfluxes = get_calfluxes(calflux,calfreq,spec_in,centerfreqs,oneflux)<EOL>C_o = calfluxes/(<NUM_LIT:1>/f_ON-<NUM_LIT:1>/f_OFF)<EOL>Tsys = C_o/f_OFF<EOL>if average==True:<EOL><INDENT>return np.mean(C_o),np.mean(Tsys)<EOL><DEDENT>else:<EOL><INDENT>return C_o,Tsys<EOL><DEDENT>

Calculate the coarse channel spectrum and system temperature of the noise diode in Jy given two noise diode
measurements ON and OFF the calibrator source with the same frequency and time resolution

Parameters
----------
calON_obs : str
    (see f_ratios() above)
calOFF_obs : str
    (see f_ratios() above)
calflux : float
    Known flux of calibrator source at a particular frequency
calfreq : float
    Frequency where calibrator source has flux calflux (see above)
spec_in : float
    Known power-law spectral index of calibrator source. Use convention flux(frequency) = constant * frequency^(spec_in)
average : boolean
    Use average=True to return noise diode and Tsys spectra averaged over frequencies


return diode_spec(calON_obs,calOFF_obs,calflux,calfreq,spec_in,average=False,oneflux=False,**kwargs)[<NUM_LIT:1>]<EOL>

Returns frequency dependent system temperature given observations on and off a calibrator source

Parameters
----------
(See diode_spec())


<EOL>main_obs = Waterfall(main_obs_name,max_load=<NUM_LIT>)<EOL>ncoarse = main_obs.calc_n_coarse_chan()<EOL>dio_obs = Waterfall(dio_name,max_load=<NUM_LIT>)<EOL>dio_chan_per_coarse = dio_obs.header['<STR_LIT>']/ncoarse<EOL>dOFF,dON = integrate_calib(dio_name,dio_chan_per_coarse,fullstokes,**kwargs)<EOL>main_dat = main_obs.data<EOL>scale_facs = dspec/(dON-dOFF)<EOL>print(scale_facs)<EOL>nchans = main_obs.header['<STR_LIT>']<EOL>obs_chan_per_coarse = nchans/ncoarse<EOL>ax0_size = np.size(main_dat,<NUM_LIT:0>)<EOL>ax1_size = np.size(main_dat,<NUM_LIT:1>)<EOL>main_dat = np.reshape(main_dat,(ax0_size,ax1_size,ncoarse,obs_chan_per_coarse))<EOL>main_dat = np.swapaxes(main_dat,<NUM_LIT:2>,<NUM_LIT:3>)<EOL>main_dat = main_dat*scale_facs<EOL>main_dat = main_dat-Tsys<EOL>main_dat = np.swapaxes(main_dat,<NUM_LIT:2>,<NUM_LIT:3>)<EOL>main_dat = np.reshape(main_dat,(ax0_size,ax1_size,nchans))<EOL>main_obs.data = main_dat<EOL>main_obs.write_to_filterbank(main_obs_name[:-<NUM_LIT:4>]+'<STR_LIT>')<EOL>print('<STR_LIT>' + main_obs_name[:-<NUM_LIT:4>]+'<STR_LIT>')<EOL>

Produce calibrated Stokes I for an observation given a noise diode
measurement on the source and a diode spectrum with the same number of
coarse channels

Parameters
----------
main_obs_name : str
    Path to filterbank file containing final data to be calibrated
dio_name : str
    Path to filterbank file for observation on the target source with flickering noise diode
dspec : 1D Array (float) or float
    Coarse channel spectrum (or average) of the noise diode in Jy (obtained from diode_spec())
Tsys : 1D Array (float) or float
    Coarse channel spectrum (or average) of the system temperature in Jy
fullstokes: boolean
    Use fullstokes=True if data is in IQUV format or just Stokes I, use fullstokes=False if
    it is in cross_pols format


<EOL>obs = Waterfall(dio_cross,max_load=<NUM_LIT>)<EOL>freqs = obs.populate_freqs()<EOL>tsamp = obs.header['<STR_LIT>']<EOL>data = obs.data<EOL>obs = None<EOL>I,Q,U,V = get_stokes(data,feedtype)<EOL>I_OFF,I_ON = foldcal(I,tsamp,**kwargs)<EOL>Q_OFF,Q_ON = foldcal(Q,tsamp,**kwargs)<EOL>U_OFF,U_ON = foldcal(U,tsamp,**kwargs)<EOL>V_OFF,V_ON = foldcal(V,tsamp,**kwargs)<EOL>Idiff = I_ON-I_OFF<EOL>Qdiff = Q_ON-Q_OFF<EOL>Udiff = U_ON-U_OFF<EOL>Vdiff = V_ON-V_OFF<EOL>return Idiff,Qdiff,Udiff,Vdiff,freqs<EOL>

Returns ON-OFF for all Stokes parameters given a cross_pols noise diode measurement


Plots the uncalibrated full stokes spectrum of the noise diode.
Use diff=False to plot both ON and OFF, or diff=True for ON-OFF


<EOL>obs = Waterfall(dio_cross,max_load=<NUM_LIT>)<EOL>freqs = obs.populate_freqs()<EOL>tsamp = obs.header['<STR_LIT>']<EOL>data = obs.data<EOL>obs = None<EOL>I,Q,U,V = get_stokes(data,feedtype)<EOL>data = None<EOL>psis = phase_offsets(I,Q,U,V,tsamp,chan_per_coarse,feedtype,**kwargs)<EOL>G = gain_offsets(I,Q,U,V,tsamp,chan_per_coarse,feedtype,**kwargs)<EOL>I,Q,U,V = apply_Mueller(I,Q,U,V,G,psis,chan_per_coarse,feedtype)<EOL>I_OFF,I_ON = foldcal(I,tsamp,**kwargs)<EOL>Q_OFF,Q_ON = foldcal(Q,tsamp,**kwargs)<EOL>U_OFF,U_ON = foldcal(U,tsamp,**kwargs)<EOL>V_OFF,V_ON = foldcal(V,tsamp,**kwargs)<EOL>I = None<EOL>Q = None<EOL>U = None<EOL>V = None<EOL>plt.plot(freqs,I_ON-I_OFF,'<STR_LIT>',label='<STR_LIT:I>')<EOL>plt.plot(freqs,Q_ON-Q_OFF,'<STR_LIT>',label='<STR_LIT>')<EOL>plt.plot(freqs,U_ON-U_OFF,'<STR_LIT>',label='<STR_LIT>')<EOL>plt.plot(freqs,V_ON-V_OFF,'<STR_LIT>',label='<STR_LIT>')<EOL>plt.legend()<EOL>plt.xlabel('<STR_LIT>')<EOL>plt.title('<STR_LIT>')<EOL>plt.ylabel('<STR_LIT>')<EOL>

Plots the corrected noise diode spectrum for a given noise diode measurement
after application of the inverse Mueller matrix for the electronics chain.


<EOL>Idiff,Qdiff,Udiff,Vdiff,freqs = get_diff(dio_cross,feedtype,**kwargs)<EOL>obs = Waterfall(dio_cross,max_load=<NUM_LIT>)<EOL>tsamp = obs.header['<STR_LIT>']<EOL>data = obs.data<EOL>obs = None<EOL>I,Q,U,V = get_stokes(data,feedtype)<EOL>coarse_psis = phase_offsets(I,Q,U,V,tsamp,chan_per_coarse,feedtype,**kwargs)<EOL>coarse_freqs = convert_to_coarse(freqs,chan_per_coarse)<EOL>coarse_degs = np.degrees(coarse_psis)<EOL>if ax2==None:<EOL><INDENT>plt.subplot(<NUM_LIT>)<EOL><DEDENT>else:<EOL><INDENT>axPsi = plt.axes(ax2)<EOL>plt.setp(axPsi.get_xticklabels(),visible=False)<EOL><DEDENT>plt.plot(coarse_freqs,coarse_degs,'<STR_LIT>',markersize=<NUM_LIT:2>,label='<STR_LIT>')<EOL>plt.ylabel('<STR_LIT>')<EOL>plt.grid(True)<EOL>plt.title('<STR_LIT>')<EOL>if legend==True:<EOL><INDENT>plt.legend()<EOL><DEDENT>if ax1==None:<EOL><INDENT>plt.subplot(<NUM_LIT>)<EOL><DEDENT>else:<EOL><INDENT>axUV = plt.axes(ax1)<EOL><DEDENT>plt.plot(freqs,Udiff,'<STR_LIT>',label='<STR_LIT>')<EOL>if feedtype=='<STR_LIT:l>':<EOL><INDENT>plt.plot(freqs,Vdiff,'<STR_LIT>',label='<STR_LIT>')<EOL><DEDENT>if feedtype=='<STR_LIT:c>':<EOL><INDENT>plt.plot(freqs,Qdiff,'<STR_LIT>',label='<STR_LIT>')<EOL><DEDENT>plt.xlabel('<STR_LIT>')<EOL>plt.ylabel('<STR_LIT>')<EOL>plt.grid(True)<EOL>if legend==True:<EOL><INDENT>plt.legend()<EOL><DEDENT>

Plots the calculated phase offsets of each coarse channel along with
the UV (or QU) noise diode spectrum for comparison


<EOL>Idiff,Qdiff,Udiff,Vdiff,freqs = get_diff(dio_cross,feedtype,**kwargs)<EOL>obs = Waterfall(dio_cross,max_load=<NUM_LIT>)<EOL>tsamp = obs.header['<STR_LIT>']<EOL>data = obs.data<EOL>obs = None<EOL>I,Q,U,V = get_stokes(data,feedtype)<EOL>coarse_G = gain_offsets(I,Q,U,V,tsamp,dio_chan_per_coarse,feedtype,**kwargs)<EOL>coarse_freqs = convert_to_coarse(freqs,dio_chan_per_coarse)<EOL>XX_OFF,XX_ON = foldcal(np.expand_dims(data[:,<NUM_LIT:0>,:],axis=<NUM_LIT:1>),tsamp,**kwargs)<EOL>YY_OFF,YY_ON = foldcal(np.expand_dims(data[:,<NUM_LIT:1>,:],axis=<NUM_LIT:1>),tsamp,**kwargs)<EOL>if ax1==None:<EOL><INDENT>plt.subplot(<NUM_LIT>)<EOL><DEDENT>else:<EOL><INDENT>axG = plt.axes(ax1)<EOL>plt.setp(axG.get_xticklabels(),visible=False)<EOL><DEDENT>plt.plot(coarse_freqs,coarse_G,'<STR_LIT>',markersize=<NUM_LIT:2>)<EOL>plt.ylabel(r'<STR_LIT>',rotation=<NUM_LIT>)<EOL>if feedtype=='<STR_LIT:l>':<EOL><INDENT>plt.title('<STR_LIT>')<EOL><DEDENT>if feedtype=='<STR_LIT:c>':<EOL><INDENT>plt.title('<STR_LIT>')<EOL><DEDENT>plt.grid(True)<EOL>if ax2==None:<EOL><INDENT>plt.subplot(<NUM_LIT>)<EOL><DEDENT>else:<EOL><INDENT>axXY = plt.axes(ax2,sharex=axG)<EOL><DEDENT>if feedtype=='<STR_LIT:l>':<EOL><INDENT>plt.plot(freqs,XX_OFF,'<STR_LIT>',label='<STR_LIT>')<EOL>plt.plot(freqs,YY_OFF,'<STR_LIT>',label='<STR_LIT>')<EOL><DEDENT>if feedtype=='<STR_LIT:c>':<EOL><INDENT>plt.plot(freqs,XX_OFF,'<STR_LIT>',label='<STR_LIT>')<EOL>plt.plot(freqs,YY_OFF,'<STR_LIT>',label='<STR_LIT>')<EOL><DEDENT>plt.xlabel('<STR_LIT>')<EOL>plt.ylabel('<STR_LIT>')<EOL>if legend==True:<EOL><INDENT>plt.legend()<EOL><DEDENT>

Plots the calculated gain offsets of each coarse channel along with
the time averaged power spectra of the X and Y feeds


<EOL>obs = Waterfall(dio_cross,max_load=<NUM_LIT>)<EOL>tsamp = obs.header['<STR_LIT>']<EOL>data = obs.data<EOL>obs = None<EOL>I,Q,U,V = get_stokes(data,feedtype)<EOL>tseriesI = np.squeeze(np.mean(I,axis=<NUM_LIT:2>))<EOL>I_OFF,I_ON,OFFints,ONints = foldcal(I,tsamp,inds=True,**kwargs)<EOL>if bothfeeds==True:<EOL><INDENT>if feedtype=='<STR_LIT:l>':<EOL><INDENT>tseriesQ = np.squeeze(np.mean(Q,axis=<NUM_LIT:2>))<EOL>tseriesX = (tseriesI+tseriesQ)/<NUM_LIT:2><EOL>tseriesY = (tseriesI-tseriesQ)/<NUM_LIT:2><EOL><DEDENT>if feedtype=='<STR_LIT:c>':<EOL><INDENT>tseriesV = np.squeeze(np.mean(V,axis=<NUM_LIT:2>))<EOL>tseriesR = (tseriesI+tseriesV)/<NUM_LIT:2><EOL>tseriesL = (tseriesI-tseriesV)/<NUM_LIT:2><EOL><DEDENT><DEDENT>stop = ONints[-<NUM_LIT:1>,<NUM_LIT:1>]<EOL>if bothfeeds==False:<EOL><INDENT>plt.plot(tseriesI[<NUM_LIT:0>:stop],'<STR_LIT>',label='<STR_LIT>')<EOL>for i in ONints:<EOL><INDENT>plt.plot(np.arange(i[<NUM_LIT:0>],i[<NUM_LIT:1>]),np.full((i[<NUM_LIT:1>]-i[<NUM_LIT:0>]),np.mean(I_ON)),'<STR_LIT>')<EOL><DEDENT>for i in OFFints:<EOL><INDENT>plt.plot(np.arange(i[<NUM_LIT:0>],i[<NUM_LIT:1>]),np.full((i[<NUM_LIT:1>]-i[<NUM_LIT:0>]),np.mean(I_OFF)),'<STR_LIT>')<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if feedtype=='<STR_LIT:l>':<EOL><INDENT>diff = np.mean(tseriesX)-np.mean(tseriesY)<EOL>plt.plot(tseriesX[<NUM_LIT:0>:stop],'<STR_LIT>',label='<STR_LIT>')<EOL>plt.plot(tseriesY[<NUM_LIT:0>:stop]+diff,'<STR_LIT>',label='<STR_LIT>')<EOL><DEDENT>if feedtype=='<STR_LIT:c>':<EOL><INDENT>diff = np.mean(tseriesL)-np.mean(tseriesR)<EOL>plt.plot(tseriesL[<NUM_LIT:0>:stop],'<STR_LIT>',label='<STR_LIT>')<EOL>plt.plot(tseriesR[<NUM_LIT:0>:stop]+diff,'<STR_LIT>',label='<STR_LIT>')<EOL><DEDENT><DEDENT>if bothfeeds==False:<EOL><INDENT>lowlim = np.mean(I_OFF)-(np.mean(I_ON)-np.mean(I_OFF))/<NUM_LIT:2><EOL>hilim = np.mean(I_ON)+(np.mean(I_ON)-np.mean(I_OFF))/<NUM_LIT:2><EOL>plt.ylim((lowlim,hilim))<EOL><DEDENT>plt.xlim((min_samp,max_samp))<EOL>plt.xlabel('<STR_LIT>')<EOL>plt.ylabel('<STR_LIT>')<EOL>plt.title('<STR_LIT>')<EOL>if legend==True:<EOL><INDENT>plt.legend()<EOL><DEDENT>

Plots the calculated average power and time sampling of ON (red) and
OFF (blue) for a noise diode measurement over the observation time series


plt.figure("<STR_LIT>", figsize=(<NUM_LIT:12>,<NUM_LIT:9>))<EOL>left, width = <NUM_LIT>,<NUM_LIT><EOL>bottom, height = <NUM_LIT>,<NUM_LIT:0.5><EOL>width2 = <NUM_LIT><EOL>bottom2, height2 = <NUM_LIT>,<NUM_LIT><EOL>rect_uncal = [left,bottom,width,height]<EOL>rect_cal = [left+width+<NUM_LIT>,bottom,width,height]<EOL>rect_fold = [left,bottom2,width2,<NUM_LIT>]<EOL>rect_gain1 = [left+width2+<NUM_LIT:0.1>,bottom2,width2,height2]<EOL>rect_phase1 = [left+width2*<NUM_LIT:2>+<NUM_LIT:0.1>*<NUM_LIT:2>,bottom2,width2,height2]<EOL>rect_gain2 = [left+width2+<NUM_LIT:0.1>,bottom2+height2+<NUM_LIT>,width2,height2]<EOL>rect_phase2 = [left+width2*<NUM_LIT:2>+<NUM_LIT:0.1>*<NUM_LIT:2>,bottom2+height2+<NUM_LIT>,width2,height2]<EOL>axFold = plt.axes(rect_fold)<EOL>print('<STR_LIT>')<EOL>plot_diode_fold(dio_cross,bothfeeds=False,feedtype=feedtype,min_samp=<NUM_LIT>,max_samp=<NUM_LIT>,legend=False,**kwargs)<EOL>print('<STR_LIT>')<EOL>plot_gain_offsets(dio_cross,feedtype=feedtype,ax1=rect_gain2,ax2=rect_gain1,legend=False,**kwargs)<EOL>print('<STR_LIT>')<EOL>plot_phase_offsets(dio_cross,feedtype=feedtype,ax1=rect_phase1,ax2=rect_phase2,legend=False,**kwargs)<EOL>plt.ylabel('<STR_LIT>')<EOL>ax_uncal = plt.axes(rect_uncal)<EOL>print('<STR_LIT>')<EOL>plot_Stokes_diode(dio_cross,feedtype=feedtype,**kwargs)<EOL>ax_cal = plt.axes(rect_cal,sharey=ax_uncal)<EOL>print('<STR_LIT>')<EOL>plot_calibrated_diode(dio_cross,feedtype=feedtype,**kwargs)<EOL>plt.ylabel('<STR_LIT>')<EOL>plt.setp(ax_cal.get_yticklabels(),visible=False)<EOL>plt.savefig(dio_cross[:-<NUM_LIT:4>]+'<STR_LIT>',dpi=<NUM_LIT>)<EOL>plt.show()<EOL>

Generates and shows five plots: Uncalibrated diode, calibrated diode, fold information,
phase offsets, and gain offsets for a noise diode measurement. Most useful diagnostic plot to
make sure calibration proceeds correctly.


dspec = diode_spec(ON_obs,OFF_obs,calflux,calfreq,spec_in,**kwargs)<EOL>obs = Waterfall(ON_obs,max_load=<NUM_LIT>)<EOL>freqs = obs.populate_freqs()<EOL>chan_per_coarse = obs.header['<STR_LIT>']/obs.calc_n_coarse_chan()<EOL>coarse_freqs = convert_to_coarse(freqs,chan_per_coarse)<EOL>plt.ion()<EOL>plt.figure()<EOL>plt.plot(coarse_freqs,dspec)<EOL>plt.xlabel('<STR_LIT>')<EOL>plt.ylabel('<STR_LIT>'+units+'<STR_LIT:)>')<EOL>plt.title('<STR_LIT>')<EOL>

Plots the full-band Stokes I spectrum of the noise diode (ON-OFF)


from argparse import ArgumentParser<EOL>parser = ArgumentParser(description="<STR_LIT>")<EOL>parser.add_argument('<STR_LIT>', type=str, help='<STR_LIT>')<EOL>args = parser.parse_args()<EOL>if not HAS_BITSHUFFLE:<EOL><INDENT>print("<STR_LIT>")<EOL>exit()<EOL><DEDENT>filelist = glob.glob(os.path.join(args.dirname, '<STR_LIT>'))<EOL>for filename in filelist:<EOL><INDENT>if not os.path.exists(filename + '<STR_LIT>'):<EOL><INDENT>t0 = time.time()<EOL>print("<STR_LIT>" % filename)<EOL>fb = Filterbank(filename, load_data=False)<EOL>data_shape = (fb.n_ints_in_file, fb.header['<STR_LIT>'], fb.header['<STR_LIT>'])<EOL>data_dtype = fb.data.dtype<EOL>print(data_dtype)<EOL>print("<STR_LIT>" % str(data_shape))<EOL>block_size = <NUM_LIT:0><EOL>h5 = h5py.File(filename + '<STR_LIT>', '<STR_LIT:w>')<EOL>h5.attrs['<STR_LIT>'] = '<STR_LIT>'<EOL>dset = h5.create_dataset('<STR_LIT:data>',<EOL>shape=data_shape,<EOL>compression=bitshuffle.h5.H5FILTER,<EOL>compression_opts=(block_size, bitshuffle.h5.H5_COMPRESS_LZ4),<EOL>dtype=data_dtype)<EOL>dset_mask = h5.create_dataset('<STR_LIT>',<EOL>shape=data_shape,<EOL>compression=bitshuffle.h5.H5FILTER,<EOL>compression_opts=(block_size, bitshuffle.h5.H5_COMPRESS_LZ4),<EOL>dtype='<STR_LIT>')<EOL>dset.dims[<NUM_LIT:0>].label = "<STR_LIT>"<EOL>dset.dims[<NUM_LIT:1>].label = "<STR_LIT>"<EOL>dset.dims[<NUM_LIT:2>].label = "<STR_LIT:time>"<EOL>dset_mask.dims[<NUM_LIT:0>].label = "<STR_LIT>"<EOL>dset_mask.dims[<NUM_LIT:1>].label = "<STR_LIT>"<EOL>dset_mask.dims[<NUM_LIT:2>].label = "<STR_LIT:time>"<EOL>for key, value in fb.header.items():<EOL><INDENT>dset.attrs[key] = value<EOL><DEDENT>filesize = os.path.getsize(filename)<EOL>if filesize >= MAX_SIZE:<EOL><INDENT>n_int_per_read = int(filesize / MAX_SIZE / <NUM_LIT:2>)<EOL>print("<STR_LIT>" % n_int_per_read)<EOL>for ii in range(<NUM_LIT:0>, n_int_per_read):<EOL><INDENT>print("<STR_LIT>" % (ii + <NUM_LIT:1>, n_int_per_read))<EOL>fb = Filterbank(filename, t_start=ii*n_int_per_read, t_stop=(ii+<NUM_LIT:1>) * n_int_per_read)<EOL>dset[ii*n_int_per_read:(ii+<NUM_LIT:1>)*n_int_per_read] = fb.data[:]<EOL><DEDENT><DEDENT>else:<EOL><INDENT>fb = Filterbank(filename)<EOL>print(dset.shape, "<STR_LIT>", fb.data.shape)<EOL>dset[:] = fb.data[:]<EOL><DEDENT>h5.close()<EOL>t1 = time.time()<EOL>print("<STR_LIT>" % (t1- t0))<EOL><DEDENT><DEDENT>

Command line utility for creating HDF5 blimpy files.


def make_h5_file(filename,out_dir='<STR_LIT>', new_filename = None, max_load = None):

fil_file = Waterfall(filename, max_load = max_load)<EOL>if not new_filename:<EOL><INDENT>new_filename = out_dir+filename.replace('<STR_LIT>','<STR_LIT>').split('<STR_LIT:/>')[-<NUM_LIT:1>]<EOL><DEDENT>if '<STR_LIT>' not in new_filename:<EOL><INDENT>new_filename = new_filename+'<STR_LIT>'<EOL><DEDENT>fil_file.write_to_hdf5(new_filename)<EOL>

Converts file to HDF5 (.h5) format. Default saves output in current dir.


from argparse import ArgumentParser<EOL>parser = ArgumentParser(description="<STR_LIT>")<EOL>parser.add_argument('<STR_LIT:filename>', type=str, help='<STR_LIT>')<EOL>parser.add_argument('<STR_LIT>', dest='<STR_LIT>', type=str, default='<STR_LIT>', help='<STR_LIT>')<EOL>args = parser.parse_args()<EOL>r = GuppiRaw(args.filename)<EOL>r.print_stats()<EOL>bname = os.path.splitext(os.path.basename(args.filename))[<NUM_LIT:0>]<EOL>bname = os.path.join(args.outdir, bname)<EOL>r.plot_histogram(filename="<STR_LIT>" % bname)<EOL>r.plot_spectrum(filename="<STR_LIT>" % bname)<EOL>

Command line tool for plotting and viewing info on guppi raw files


if PYTHON3:<EOL><INDENT>self.file_obj = open(self.filename, '<STR_LIT:rb>')<EOL><DEDENT>else:<EOL><INDENT>self.file_obj = open(self.filename, '<STR_LIT:r>')<EOL><DEDENT>self.filesize = os.path.getsize(self.filename)<EOL>return self<EOL>

reopen the file each time a `with` block is entered
:return:


def __exit__(self, exception_type, exception_value, traceback):

closes the file after `with` block has exited
:param exception_type:
:param exception_value:
:param traceback:
:return:


start_idx = self.file_obj.tell()<EOL>key, val = '<STR_LIT>', '<STR_LIT>'<EOL>header_dict = {}<EOL>keep_reading = True<EOL>first_line = self.file_obj<EOL>try:<EOL><INDENT>while keep_reading:<EOL><INDENT>if start_idx + <NUM_LIT> > self.filesize:<EOL><INDENT>keep_reading = False<EOL>raise EndOfFileError("<STR_LIT>")<EOL><DEDENT>line = self.file_obj.read(<NUM_LIT>)<EOL>if PYTHON3:<EOL><INDENT>line = line.decode("<STR_LIT:utf-8>")<EOL><DEDENT>if line.startswith('<STR_LIT>'):<EOL><INDENT>keep_reading = False<EOL>break<EOL><DEDENT>else:<EOL><INDENT>key, val = line.split('<STR_LIT:=>')<EOL>key, val = key.strip(), val.strip()<EOL>if "<STR_LIT:'>" in val:<EOL><INDENT>val = str(val.strip("<STR_LIT:'>").strip())<EOL><DEDENT>elif "<STR_LIT:.>" in val:<EOL><INDENT>val = float(val)<EOL><DEDENT>else:<EOL><INDENT>val = int(val)<EOL><DEDENT><DEDENT>header_dict[key] = val<EOL><DEDENT><DEDENT>except ValueError:<EOL><INDENT>print("<STR_LIT>", line)<EOL>print("<STR_LIT>", start_idx)<EOL>print("<STR_LIT>", self.filesize)<EOL>print("<STR_LIT>")<EOL>print(self.file_obj.read(<NUM_LIT>))<EOL>raise<EOL><DEDENT>data_idx = self.file_obj.tell()<EOL>if "<STR_LIT>" in header_dict.keys():<EOL><INDENT>if int(header_dict["<STR_LIT>"]) == <NUM_LIT:1>:<EOL><INDENT>if data_idx % <NUM_LIT>:<EOL><INDENT>data_idx += (<NUM_LIT> - data_idx % <NUM_LIT>)<EOL><DEDENT><DEDENT><DEDENT>self.file_obj.seek(start_idx)<EOL>return header_dict, data_idx<EOL>

Read next header (multiple headers in file)

        Returns:
            (header, data_idx) - a dictionary of keyword:value header data and
            also the byte index of where the corresponding data block resides.


self.file_obj.seek(<NUM_LIT:0>)<EOL>header_dict, pos = self.read_header()<EOL>self.file_obj.seek(<NUM_LIT:0>)<EOL>return header_dict<EOL>

Read first header in file

        Returns:
            header (dict): keyword:value pairs of header metadata


with self as gr:<EOL><INDENT>while True:<EOL><INDENT>try:<EOL><INDENT>yield gr.read_next_data_block_int8()<EOL><DEDENT>except Exception as e:<EOL><INDENT>print("<STR_LIT>")<EOL>yield None, None, None<EOL><DEDENT><DEDENT><DEDENT>

returns a generator object that reads data a block at a time;
the generator prints "File depleted" and returns nothing when all data in the file has been read.
:return:


header, data_idx = self.read_header()<EOL>self.file_obj.seek(data_idx)<EOL>n_chan = int(header['<STR_LIT>'])<EOL>n_pol = int(header['<STR_LIT>'])<EOL>n_bit = int(header['<STR_LIT>'])<EOL>n_samples = int(int(header['<STR_LIT>']) / (n_chan * n_pol * (n_bit / <NUM_LIT:8>)))<EOL>d = np.fromfile(self.file_obj, count=header['<STR_LIT>'], dtype='<STR_LIT>')<EOL>if n_bit != <NUM_LIT:8>:<EOL><INDENT>d = unpack(d, n_bit)<EOL><DEDENT>d = d.reshape((n_chan, n_samples, n_pol))  <EOL>if self._d_x.shape != d[..., <NUM_LIT:0>:<NUM_LIT:2>].shape:<EOL><INDENT>self._d_x = np.ascontiguousarray(np.zeros(d[..., <NUM_LIT:0>:<NUM_LIT:2>].shape, dtype='<STR_LIT>'))<EOL>self._d_y = np.ascontiguousarray(np.zeros(d[..., <NUM_LIT:2>:<NUM_LIT:4>].shape, dtype='<STR_LIT>'))<EOL><DEDENT>self._d_x[:] = d[..., <NUM_LIT:0>:<NUM_LIT:2>]<EOL>self._d_y[:] = d[..., <NUM_LIT:2>:<NUM_LIT:4>]<EOL>return header, self._d_x, self._d_y<EOL>

Read the next block of data and its header

        Returns: (header, data)
            header (dict): dictionary of header metadata
            data (np.array): Numpy array of data, converted into to complex64.


header, data_idx = self.read_header()<EOL>self.file_obj.seek(data_idx)<EOL>n_chan = int(header['<STR_LIT>'])<EOL>n_pol = int(header['<STR_LIT>'])<EOL>n_bit = int(header['<STR_LIT>'])<EOL>n_samples = int(int(header['<STR_LIT>']) / (n_chan * n_pol * (n_bit / <NUM_LIT:8>)))<EOL>d = np.fromfile(self.file_obj, count=header['<STR_LIT>'], dtype='<STR_LIT>')<EOL>header, data_idx = self.read_header()<EOL>self.file_obj.seek(data_idx)<EOL>d2 = np.fromfile(self.file_obj, count=header['<STR_LIT>'], dtype='<STR_LIT>')<EOL>if n_bit != <NUM_LIT:8>:<EOL><INDENT>d = unpack(d, n_bit)<EOL><DEDENT>d = d.reshape((n_chan, n_samples, n_pol))  <EOL>d2 = d2.reshape((n_chan, n_samples, n_pol))<EOL>d = np.concatenate((d, d2), axis=<NUM_LIT:1>)<EOL>print(d.shape)<EOL>if self._d_x.shape != (n_chan, n_samples * <NUM_LIT:2>, n_pol):<EOL><INDENT>self._d_x = np.ascontiguousarray(np.zeros(d[..., <NUM_LIT:0>:<NUM_LIT:2>].shape, dtype='<STR_LIT>'))<EOL>self._d_y = np.ascontiguousarray(np.zeros(d[..., <NUM_LIT:2>:<NUM_LIT:4>].shape, dtype='<STR_LIT>'))<EOL><DEDENT>self._d_x[:] = d[..., <NUM_LIT:0>:<NUM_LIT:2>]<EOL>self._d_y[:] = d[..., <NUM_LIT:2>:<NUM_LIT:4>]<EOL>return header, self._d_x, self._d_y<EOL>


header, data_idx = self.read_header()<EOL>self.file_obj.seek(data_idx)<EOL>n_chan = int(header['<STR_LIT>'])<EOL>n_pol = int(header['<STR_LIT>'])<EOL>n_bit = int(header['<STR_LIT>'])<EOL>n_samples = int(int(header['<STR_LIT>']) / (n_chan * n_pol * (n_bit / <NUM_LIT:8>)))<EOL>d = np.ascontiguousarray(np.fromfile(self.file_obj, count=header['<STR_LIT>'], dtype='<STR_LIT>'))<EOL>if n_bit != <NUM_LIT:8>:<EOL><INDENT>d = unpack(d, n_bit)<EOL><DEDENT>dshape = self.read_next_data_block_shape()<EOL>d = d.reshape(dshape)  <EOL>if self._d.shape != d.shape:<EOL><INDENT>self._d = np.zeros(d.shape, dtype='<STR_LIT>')<EOL><DEDENT>self._d[:] = d<EOL>return header, self._d[:].view('<STR_LIT>')<EOL>


self.file_obj.seek(<NUM_LIT:0>)<EOL>header0, data_idx0 = self.read_header()<EOL>self.file_obj.seek(data_idx0)<EOL>block_size = int(header0['<STR_LIT>'])<EOL>n_bits = int(header0['<STR_LIT>'])<EOL>self.file_obj.seek(int(header0['<STR_LIT>']), <NUM_LIT:1>)<EOL>n_blocks = <NUM_LIT:1><EOL>end_found = False<EOL>while not end_found:<EOL><INDENT>try:<EOL><INDENT>header, data_idx = self.read_header()<EOL>self.file_obj.seek(data_idx)<EOL>self.file_obj.seek(header['<STR_LIT>'], <NUM_LIT:1>)<EOL>n_blocks += <NUM_LIT:1><EOL><DEDENT>except EndOfFileError:<EOL><INDENT>end_found = True<EOL>break<EOL><DEDENT><DEDENT>self.file_obj.seek(<NUM_LIT:0>)<EOL>return n_blocks<EOL>

Seek through the file to find how many data blocks there are in the file

        Returns:
            n_blocks (int): number of data blocks in the file


header, data = self.read_next_data_block()<EOL>data = data.view('<STR_LIT>')<EOL>print("<STR_LIT>" % data.mean())<EOL>print("<STR_LIT>" % data.std())<EOL>print("<STR_LIT>" % data.max())<EOL>print("<STR_LIT>" % data.min())<EOL>import pylab as plt<EOL>

Compute some basic stats on the next block of data


header, data = self.read_next_data_block()<EOL>data = data.view('<STR_LIT>')<EOL>plt.figure("<STR_LIT>")<EOL>plt.hist(data.flatten(), <NUM_LIT>, facecolor='<STR_LIT>')<EOL>if filename:<EOL><INDENT>plt.savefig(filename)<EOL><DEDENT>plt.show()<EOL>


def plot_spectrum(self, filename=None, plot_db=True):

header, data = self.read_next_data_block()<EOL>print("<STR_LIT>")<EOL>d_xx_fft = np.abs(np.fft.fft(data[..., <NUM_LIT:0>]))<EOL>d_xx_fft = d_xx_fft.flatten()<EOL>dec_fac_x = <NUM_LIT:1><EOL>if d_xx_fft.shape[<NUM_LIT:0>] > MAX_PLT_POINTS:<EOL><INDENT>dec_fac_x = d_xx_fft.shape[<NUM_LIT:0>] / MAX_PLT_POINTS<EOL><DEDENT>d_xx_fft = rebin(d_xx_fft, dec_fac_x)<EOL>print("<STR_LIT>")<EOL>if plot_db:<EOL><INDENT>plt.plot(<NUM_LIT:10> * np.log10(d_xx_fft))<EOL>plt.ylabel("<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>plt.plot(d_xx_fft)<EOL>plt.ylabel("<STR_LIT>")<EOL>plt.xlabel("<STR_LIT>")<EOL><DEDENT>plt.title(self.filename)<EOL>if filename:<EOL><INDENT>plt.savefig(filename)<EOL><DEDENT>plt.show()<EOL>

Do a (slow) numpy FFT and take power of data


def generate_filterbank_header(self, nchans=<NUM_LIT:1>, ):

gp_head = self.read_first_header()<EOL>fb_head = {}<EOL>telescope_str = gp_head.get("<STR_LIT>", "<STR_LIT>")<EOL>if telescope_str in ('<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>fb_head["<STR_LIT>"] = <NUM_LIT:6><EOL><DEDENT>elif telescope_str in ('<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>fb_head["<STR_LIT>"] = <NUM_LIT:7><EOL><DEDENT>else:<EOL><INDENT>fb_head["<STR_LIT>"] = <NUM_LIT:0><EOL><DEDENT>fb_head["<STR_LIT>"] = gp_head.get("<STR_LIT>", "<STR_LIT>")<EOL>fb_head["<STR_LIT>"] = gp_head.get("<STR_LIT>", <NUM_LIT:0>)<EOL>fb_head["<STR_LIT>"] = gp_head.get("<STR_LIT>", <NUM_LIT:0>)<EOL>fb_head["<STR_LIT>"] = Angle(str(gp_head.get("<STR_LIT>", <NUM_LIT:0.0>)) + "<STR_LIT>")<EOL>fb_head["<STR_LIT>"] = Angle(str(gp_head.get("<STR_LIT>", <NUM_LIT:0.0>)) + "<STR_LIT>")<EOL>fb_head["<STR_LIT>"] = self.filename<EOL>fb_head["<STR_LIT>"] = <NUM_LIT:20><EOL>fb_head["<STR_LIT>"] = <NUM_LIT:1>  <EOL>fb_head["<STR_LIT>"] = <NUM_LIT:0><EOL>fb_head["<STR_LIT>"] = <NUM_LIT:0><EOL>fb_head["<STR_LIT>"] = <NUM_LIT:32><EOL>fb_head["<STR_LIT>"] = <NUM_LIT:0.0><EOL>fb_head["<STR_LIT>"] = <NUM_LIT:1.0><EOL>fb_head["<STR_LIT>"] = <NUM_LIT:0.0><EOL>fb_head["<STR_LIT>"] = <NUM_LIT> / nchans<EOL>fb_head["<STR_LIT>"] = nchans<EOL>fb_head["<STR_LIT>"] = <NUM_LIT:1><EOL>fb_head["<STR_LIT>"] = <NUM_LIT:1><EOL>return fb_head<EOL>


from argparse import ArgumentParser<EOL>parser = ArgumentParser(description="<STR_LIT>")<EOL>parser.add_argument('<STR_LIT:filename>', type=str,<EOL>help='<STR_LIT>')<EOL>parser.add_argument('<STR_LIT>', action='<STR_LIT:store>',  default='<STR_LIT:a>', dest='<STR_LIT>', type=str,<EOL>help='<STR_LIT>')<EOL>parser.add_argument('<STR_LIT>', action='<STR_LIT:store>', default=None, dest='<STR_LIT>', type=float,<EOL>help='<STR_LIT>')<EOL>parser.add_argument('<STR_LIT>', action='<STR_LIT:store>', default=None, dest='<STR_LIT>', type=float,<EOL>help='<STR_LIT>')<EOL>parser.add_argument('<STR_LIT>', action='<STR_LIT:store>', default=None, dest='<STR_LIT>', type=int,<EOL>help='<STR_LIT>')<EOL>parser.add_argument('<STR_LIT>', action='<STR_LIT:store>', default=None, dest='<STR_LIT>', type=int,<EOL>help='<STR_LIT>')<EOL>parser.add_argument('<STR_LIT>', action='<STR_LIT:store_true>', default=False, dest='<STR_LIT>',<EOL>help='<STR_LIT>')<EOL>parser.add_argument('<STR_LIT>', action='<STR_LIT:store_true>', default=False, dest='<STR_LIT>',<EOL>help='<STR_LIT>')<EOL>parser.add_argument('<STR_LIT>', action='<STR_LIT:store>', default='<STR_LIT>', dest='<STR_LIT>', type=str,<EOL>help='<STR_LIT>')<EOL>parser.add_argument('<STR_LIT>', action='<STR_LIT:store_true>', default=False, dest='<STR_LIT>',<EOL>help='<STR_LIT>')<EOL>parser.add_argument('<STR_LIT>', action='<STR_LIT>', default=True, dest='<STR_LIT>',<EOL>help='<STR_LIT>')<EOL>parser.add_argument('<STR_LIT>', action='<STR_LIT:store_true>', default=False, dest='<STR_LIT>',<EOL>help='<STR_LIT>')<EOL>parser.add_argument('<STR_LIT>', action='<STR_LIT:store_true>', default=False, dest='<STR_LIT>',<EOL>help='<STR_LIT>')<EOL>parser.add_argument('<STR_LIT>', action='<STR_LIT:store>', default=None, dest='<STR_LIT>', type=str,<EOL>help='<STR_LIT>')<EOL>parser.add_argument('<STR_LIT>', action='<STR_LIT:store>', default=None, dest='<STR_LIT>', type=float,<EOL>help='<STR_LIT>')<EOL>if args is None:<EOL><INDENT>args = sys.argv[<NUM_LIT:1>:]<EOL><DEDENT>parse_args = parser.parse_args(args)<EOL>filename = parse_args.filename<EOL>load_data = not parse_args.info_only<EOL>info_only = parse_args.info_only<EOL>filename_out = parse_args.filename_out<EOL>fil = Waterfall(filename, f_start=parse_args.f_start, f_stop=parse_args.f_stop, t_start=parse_args.t_start, t_stop=parse_args.t_stop, load_data=load_data, max_load=parse_args.max_load)<EOL>fil.info()<EOL>if fil.container.isheavy() or parse_args.to_hdf5 or parse_args.to_fil:<EOL><INDENT>info_only = True<EOL><DEDENT>if not info_only:<EOL><INDENT>print('<STR_LIT>')<EOL>if parse_args.blank_dc:<EOL><INDENT>logger.info("<STR_LIT>")<EOL>n_coarse_chan = fil.calc_n_coarse_chan()<EOL>fil.blank_dc(n_coarse_chan)<EOL><DEDENT>if parse_args.what_to_plot == "<STR_LIT:w>":<EOL><INDENT>plt.figure("<STR_LIT>", figsize=(<NUM_LIT:8>, <NUM_LIT:6>))<EOL>fil.plot_waterfall(f_start=parse_args.f_start, f_stop=parse_args.f_stop)<EOL><DEDENT>elif parse_args.what_to_plot == "<STR_LIT:s>":<EOL><INDENT>plt.figure("<STR_LIT>", figsize=(<NUM_LIT:8>, <NUM_LIT:6>))<EOL>fil.plot_spectrum(logged=True, f_start=parse_args.f_start, f_stop=parse_args.f_stop, t='<STR_LIT:all>')<EOL><DEDENT>elif parse_args.what_to_plot == "<STR_LIT>":<EOL><INDENT>plt.figure("<STR_LIT>", figsize=(<NUM_LIT:8>, <NUM_LIT:6>))<EOL>fil.plot_spectrum_min_max(logged=True, f_start=parse_args.f_start, f_stop=parse_args.f_stop, t='<STR_LIT:all>')<EOL><DEDENT>elif parse_args.what_to_plot == "<STR_LIT:k>":<EOL><INDENT>plt.figure("<STR_LIT>", figsize=(<NUM_LIT:8>, <NUM_LIT:6>))<EOL>fil.plot_kurtosis(f_start=parse_args.f_start, f_stop=parse_args.f_stop)<EOL><DEDENT>elif parse_args.what_to_plot == "<STR_LIT:t>":<EOL><INDENT>plt.figure("<STR_LIT>", figsize=(<NUM_LIT:8>, <NUM_LIT:6>))<EOL>fil.plot_time_series(f_start=parse_args.f_start, f_stop=parse_args.f_stop,orientation='<STR_LIT:h>')<EOL><DEDENT>elif parse_args.what_to_plot == "<STR_LIT:a>":<EOL><INDENT>plt.figure("<STR_LIT>", figsize=(<NUM_LIT:12>, <NUM_LIT:9>),facecolor='<STR_LIT>')<EOL>fil.plot_all(logged=True, f_start=parse_args.f_start, f_stop=parse_args.f_stop, t='<STR_LIT:all>')<EOL><DEDENT>elif parse_args.what_to_plot == "<STR_LIT>":<EOL><INDENT>plt.figure("<STR_LIT>", figsize=(<NUM_LIT:12>, <NUM_LIT:9>),facecolor='<STR_LIT>')<EOL>fil.plot_all(logged=True, f_start=parse_args.f_start, f_stop=parse_args.f_stop, t='<STR_LIT:all>',kutosis=False)<EOL><DEDENT>if parse_args.plt_filename != '<STR_LIT>':<EOL><INDENT>plt.savefig(parse_args.plt_filename)<EOL><DEDENT>if not parse_args.save_only:<EOL><INDENT>if '<STR_LIT>' in os.environ.keys():<EOL><INDENT>plt.show()<EOL><DEDENT>else:<EOL><INDENT>logger.warning("<STR_LIT>")<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>if parse_args.to_hdf5 and parse_args.to_fil:<EOL><INDENT>raise Warning('<STR_LIT>')<EOL><DEDENT>if parse_args.to_hdf5:<EOL><INDENT>if not filename_out:<EOL><INDENT>filename_out = filename.replace('<STR_LIT>','<STR_LIT>')<EOL><DEDENT>elif '<STR_LIT>' not in filename_out:<EOL><INDENT>filename_out = filename_out.replace('<STR_LIT>','<STR_LIT>')+'<STR_LIT>'<EOL><DEDENT>logger.info('<STR_LIT>'%(filename_out))<EOL>fil.write_to_hdf5(filename_out)<EOL>logger.info('<STR_LIT>')<EOL><DEDENT>if parse_args.to_fil:<EOL><INDENT>if not filename_out:<EOL><INDENT>filename_out = filename.replace('<STR_LIT>','<STR_LIT>')<EOL><DEDENT>elif '<STR_LIT>' not in filename_out:<EOL><INDENT>filename_out = filename_out.replace('<STR_LIT>','<STR_LIT>')+'<STR_LIT>'<EOL><DEDENT>logger.info('<STR_LIT>'%(filename_out))<EOL>fil.write_to_fil(filename_out)<EOL>logger.info('<STR_LIT>')<EOL><DEDENT><DEDENT>

Command line tool for plotting and viewing info on blimpy files


def __init__(self, filename=None, f_start=None, f_stop=None,t_start=None, t_stop=None, load_data=True, max_load=<NUM_LIT:1.>, header_dict=None, data_array=None):

<INDENT>super(Waterfall, self).__init__()<EOL><DEDENT>if filename:<EOL><INDENT>self.filename = filename<EOL>self.ext = os.path.splitext(filename)[-<NUM_LIT:1>].lower()<EOL>self.container = fw.open_file(filename, f_start=f_start, f_stop=f_stop, t_start=t_start, t_stop=t_stop,<EOL>load_data=load_data, max_load=max_load)<EOL>self.file_header = self.container.header<EOL>self.header = self.file_header<EOL>self.n_ints_in_file = self.container.n_ints_in_file<EOL>self.file_shape = self.container.file_shape<EOL>self.file_size_bytes = self.container.file_size_bytes<EOL>self.selection_shape = self.container.selection_shape<EOL>self.n_channels_in_file = self.container.n_channels_in_file<EOL>self.freq_axis = <NUM_LIT:2><EOL>self.time_axis = <NUM_LIT:0><EOL>self.beam_axis = <NUM_LIT:1>  <EOL>self.stokes_axis = <NUM_LIT:4>  <EOL>self.__load_data()<EOL><DEDENT>elif header_dict is not None and data_array is not None:<EOL><INDENT>self.filename = b'<STR_LIT>'<EOL>self.header = header_dict<EOL>self.data = data_array<EOL>self.n_ints_in_file = <NUM_LIT:0><EOL>self._setup_freqs()<EOL><DEDENT>else:<EOL><INDENT>self.filename = b'<STR_LIT>'<EOL><DEDENT>

Class for loading and plotting blimpy data.

        This class parses the blimpy file and stores the header and data
        as objects:
            fb = Waterfall('filename_here.fil')
            fb.header        # blimpy header, as a dictionary
            fb.data          # blimpy data, as a numpy array

        Args:
            filename (str): filename of blimpy file.
            f_start (float): start frequency in MHz
            f_stop (float): stop frequency in MHz
            t_start (int): start integration ID
            t_stop (int): stop integration ID
            load_data (bool): load data. If set to False, only header will be read.
            max_load (float): maximum data to load in GB. Default: 1GB.
                              e.g. 0.1 is 100 MB
            header_dict (dict): Create blimpy from header dictionary + data array
            data_array (np.array): Create blimpy from header dict + data array


self.data = self.container.data<EOL>

Helper for loading data form a container. Should not be called manually.


def read_data(self, f_start=None, f_stop=None,t_start=None, t_stop=None):

self.container.read_data(f_start=f_start, f_stop=f_stop,t_start=t_start, t_stop=t_stop)<EOL>self.__load_data()<EOL>


<EOL>if self.header[b'<STR_LIT>'] < <NUM_LIT:0>:<EOL><INDENT>self.header[b'<STR_LIT>'] = self.container.f_stop<EOL><DEDENT>else:<EOL><INDENT>self.header[b'<STR_LIT>'] = self.container.f_start<EOL><DEDENT>self.header[b'<STR_LIT>'] = self.container.selection_shape[self.freq_axis]<EOL>self.header[b'<STR_LIT>'] = self.container.populate_timestamps(update_header=True)<EOL>

Updates the header information from the original file to the selection.


print("<STR_LIT>")<EOL>for key, val in self.file_header.items():<EOL><INDENT>if key == '<STR_LIT>':<EOL><INDENT>val = val.to_string(unit=u.hour, sep='<STR_LIT::>')<EOL><DEDENT>if key == '<STR_LIT>':<EOL><INDENT>val = val.to_string(unit=u.deg, sep='<STR_LIT::>')<EOL><DEDENT>print("<STR_LIT>" % (key, val))<EOL><DEDENT>print("<STR_LIT>" % ("<STR_LIT>", self.n_ints_in_file))<EOL>print("<STR_LIT>" % ("<STR_LIT>", self.file_shape))<EOL>print("<STR_LIT>")<EOL>print("<STR_LIT>" % ("<STR_LIT>", self.selection_shape))<EOL>print("<STR_LIT>" % ("<STR_LIT>", self.container.f_start))<EOL>print("<STR_LIT>" % ("<STR_LIT>", self.container.f_stop))<EOL>

Print header information and other derived information.


def write_to_fil(self, filename_out, *args, **kwargs):

<EOL>t0 = time.time()<EOL>self.__update_header()<EOL>if self.container.isheavy():<EOL><INDENT>self.__write_to_fil_heavy(filename_out)<EOL><DEDENT>else:<EOL><INDENT>self.__write_to_fil_light(filename_out)<EOL><DEDENT>t1 = time.time()<EOL>logger.info('<STR_LIT>' % (t1- t0))<EOL>

Write data to .fil file.
            It check the file size then decides how to write the file.

        Args:
            filename_out (str): Name of output file


def __write_to_fil_heavy(self, filename_out, *args, **kwargs):

<EOL>chunk_dim = self.__get_chunk_dimensions()<EOL>blob_dim = self.__get_blob_dimensions(chunk_dim)<EOL>n_blobs = self.container.calc_n_blobs(blob_dim)<EOL>n_bytes  = self.header[b'<STR_LIT>'] / <NUM_LIT:8><EOL>with open(filename_out, "<STR_LIT:wb>") as fileh:<EOL><INDENT>fileh.write(generate_sigproc_header(self)) <EOL><DEDENT>logger.info('<STR_LIT>'% n_blobs)<EOL>for ii in range(<NUM_LIT:0>, n_blobs):<EOL><INDENT>logger.info('<STR_LIT>' % (ii + <NUM_LIT:1>, n_blobs))<EOL>bob = self.container.read_blob(blob_dim,n_blob=ii)<EOL>with open(filename_out, "<STR_LIT:a>") as fileh:<EOL><INDENT>j = bob<EOL>if n_bytes == <NUM_LIT:4>:<EOL><INDENT>np.float32(j.ravel()).tofile(fileh)<EOL><DEDENT>elif n_bytes == <NUM_LIT:2>:<EOL><INDENT>np.int16(j.ravel()).tofile(fileh)<EOL><DEDENT>elif n_bytes == <NUM_LIT:1>:<EOL><INDENT>np.int8(j.ravel()).tofile(fileh)<EOL><DEDENT><DEDENT><DEDENT>

Write data to .fil file.

        Args:
            filename_out (str): Name of output file


def __write_to_fil_light(self, filename_out, *args, **kwargs):

n_bytes  = self.header[b'<STR_LIT>'] / <NUM_LIT:8><EOL>with open(filename_out, "<STR_LIT:wb>") as fileh:<EOL><INDENT>fileh.write(generate_sigproc_header(self)) <EOL>j = self.data<EOL>if n_bytes == <NUM_LIT:4>:<EOL><INDENT>np.float32(j.ravel()).tofile(fileh)<EOL><DEDENT>elif n_bytes == <NUM_LIT:2>:<EOL><INDENT>np.int16(j.ravel()).tofile(fileh)<EOL><DEDENT>elif n_bytes == <NUM_LIT:1>:<EOL><INDENT>np.int8(j.ravel()).tofile(fileh)<EOL><DEDENT><DEDENT>


def write_to_hdf5(self, filename_out, *args, **kwargs):

<EOL>t0 = time.time()<EOL>self.__update_header()<EOL>if self.container.isheavy():<EOL><INDENT>self.__write_to_hdf5_heavy(filename_out)<EOL><DEDENT>else:<EOL><INDENT>self.__write_to_hdf5_light(filename_out)<EOL><DEDENT>t1 = time.time()<EOL>logger.info('<STR_LIT>' % (t1- t0))<EOL>

Write data to HDF5 file.
            It check the file size then decides how to write the file.

        Args:
            filename_out (str): Name of output file


def __write_to_hdf5_heavy(self, filename_out, *args, **kwargs):

block_size = <NUM_LIT:0><EOL>chunk_dim = self.__get_chunk_dimensions()<EOL>blob_dim = self.__get_blob_dimensions(chunk_dim)<EOL>n_blobs = self.container.calc_n_blobs(blob_dim)<EOL>with h5py.File(filename_out, '<STR_LIT:w>') as h5:<EOL><INDENT>h5.attrs[b'<STR_LIT>'] = b'<STR_LIT>'<EOL>h5.attrs[b'<STR_LIT>'] = b'<STR_LIT:1.0>'<EOL>if HAS_BITSHUFFLE:<EOL><INDENT>bs_compression = bitshuffle.h5.H5FILTER<EOL>bs_compression_opts = (block_size, bitshuffle.h5.H5_COMPRESS_LZ4)<EOL><DEDENT>else:<EOL><INDENT>bs_compression = None<EOL>bs_compression_opts = None<EOL>logger.warning("<STR_LIT>")<EOL><DEDENT>dset = h5.create_dataset('<STR_LIT:data>',<EOL>shape=self.selection_shape,<EOL>chunks=chunk_dim,<EOL>compression=bs_compression,<EOL>compression_opts=bs_compression_opts,<EOL>dtype=self.data.dtype)<EOL>dset_mask = h5.create_dataset('<STR_LIT>',<EOL>shape=self.selection_shape,<EOL>chunks=chunk_dim,<EOL>compression=bs_compression,<EOL>compression_opts=bs_compression_opts,<EOL>dtype='<STR_LIT>')<EOL>dset.dims[<NUM_LIT:0>].label = b"<STR_LIT>"<EOL>dset.dims[<NUM_LIT:1>].label = b"<STR_LIT>"<EOL>dset.dims[<NUM_LIT:2>].label = b"<STR_LIT:time>"<EOL>dset_mask.dims[<NUM_LIT:0>].label = b"<STR_LIT>"<EOL>dset_mask.dims[<NUM_LIT:1>].label = b"<STR_LIT>"<EOL>dset_mask.dims[<NUM_LIT:2>].label = b"<STR_LIT:time>"<EOL>for key, value in self.header.items():<EOL><INDENT>dset.attrs[key] = value<EOL><DEDENT>if blob_dim[self.freq_axis] < self.selection_shape[self.freq_axis]:<EOL><INDENT>logger.info('<STR_LIT>'% n_blobs)<EOL>for ii in range(<NUM_LIT:0>, n_blobs):<EOL><INDENT>logger.info('<STR_LIT>' % (ii + <NUM_LIT:1>, n_blobs))<EOL>bob = self.container.read_blob(blob_dim,n_blob=ii)<EOL>c_start = self.container.chan_start_idx + ii*blob_dim[self.freq_axis]<EOL>t_start = self.container.t_start + (c_start/self.selection_shape[self.freq_axis])*blob_dim[self.time_axis]<EOL>t_stop = t_start + blob_dim[self.time_axis]<EOL><INDENT>if self.header['<STR_LIT>'] < <NUM_LIT:0>:<EOL><INDENT>c_stop = self.selection_shape[self.freq_axis] - (c_start)%self.selection_shape[self.freq_axis]<EOL>c_start = c_stop - blob_dim[self.freq_axis]<EOL><DEDENT>else:<EOL><DEDENT>c_start = (c_start)%self.selection_shape[self.freq_axis]<EOL>c_stop = c_start + blob_dim[self.freq_axis]<EOL>logger.debug(t_start,t_stop,c_start,c_stop)<EOL>dset[t_start:t_stop,<NUM_LIT:0>,c_start:c_stop] = bob[:]<EOL><DEDENT><DEDENT>else:<EOL><INDENT>logger.info('<STR_LIT>'% n_blobs)<EOL>for ii in range(<NUM_LIT:0>, n_blobs):<EOL><INDENT>logger.info('<STR_LIT>' % (ii + <NUM_LIT:1>, n_blobs))<EOL>bob = self.container.read_blob(blob_dim,n_blob=ii)<EOL>t_start = self.container.t_start + ii*blob_dim[self.time_axis]<EOL>if (ii+<NUM_LIT:1>)*blob_dim[self.time_axis] > self.n_ints_in_file:<EOL><INDENT>t_stop = self.n_ints_in_file<EOL><DEDENT>else:<EOL><INDENT>t_stop = (ii+<NUM_LIT:1>)*blob_dim[self.time_axis]<EOL><DEDENT>dset[t_start:t_stop] = bob[:]<EOL><DEDENT><DEDENT><DEDENT>

Write data to HDF5 file.

        Args:
            filename_out (str): Name of output file


def __write_to_hdf5_light(self, filename_out, *args, **kwargs):

block_size = <NUM_LIT:0><EOL>with h5py.File(filename_out, '<STR_LIT:w>') as h5:<EOL><INDENT>h5.attrs[b'<STR_LIT>']   = b'<STR_LIT>'<EOL>h5.attrs[b'<STR_LIT>'] = b'<STR_LIT:1.0>'<EOL>if HAS_BITSHUFFLE:<EOL><INDENT>bs_compression = bitshuffle.h5.H5FILTER<EOL>bs_compression_opts = (block_size, bitshuffle.h5.H5_COMPRESS_LZ4)<EOL><DEDENT>else:<EOL><INDENT>bs_compression = None<EOL>bs_compression_opts = None<EOL>logger.warning("<STR_LIT>")<EOL><DEDENT>dset = h5.create_dataset('<STR_LIT:data>',<EOL>data=self.data,<EOL>compression='<STR_LIT>')<EOL><INDENT>compression=bs_compression,<EOL>compression_opts=bs_compression_opts)<EOL>dset_mask = h5.create_dataset('<STR_LIT>',<EOL>shape=self.file_shape,<EOL><INDENT>compression='<STR_LIT>',<EOL><DEDENT>compression=bs_compression,<EOL>compression_opts=bs_compression_opts,<EOL>dtype='<STR_LIT>')<EOL>dset.dims[<NUM_LIT:0>].label = b"<STR_LIT>"<EOL>dset.dims[<NUM_LIT:1>].label = b"<STR_LIT>"<EOL>dset.dims[<NUM_LIT:2>].label = b"<STR_LIT:time>"<EOL>dset_mask.dims[<NUM_LIT:0>].label = b"<STR_LIT>"<EOL>dset_mask.dims[<NUM_LIT:1>].label = b"<STR_LIT>"<EOL>dset_mask.dims[<NUM_LIT:2>].label = b"<STR_LIT:time>"<EOL>for key, value in self.header.items():<EOL>dset.attrs[key] = value<EOL>

Write data to HDF5 file in one go.

        Args:
            filename_out (str): Name of output file


<EOL>if self.selection_shape[self.freq_axis] > chunk_dim[self.freq_axis]*MAX_BLOB_MB:<EOL><INDENT>freq_axis_size = self.selection_shape[self.freq_axis]<EOL><INDENT>while freq_axis_size > chunk_dim[self.freq_axis]*MAX_BLOB_MB:<EOL><INDENT>freq_axis_size /= <NUM_LIT:2><EOL><DEDENT><DEDENT>time_axis_size = <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>freq_axis_size = self.selection_shape[self.freq_axis]<EOL>time_axis_size = np.min([chunk_dim[self.time_axis] * MAX_BLOB_MB * chunk_dim[self.freq_axis] / freq_axis_size, self.selection_shape[self.time_axis]])<EOL><DEDENT>blob_dim = (int(time_axis_size), <NUM_LIT:1>, freq_axis_size)<EOL>return blob_dim<EOL>

Sets the blob dimmentions, trying to read around 1024 MiB at a time.
            This is assuming a chunk is about 1 MiB.


<EOL>if np.abs(self.header[b'<STR_LIT>']) < <NUM_LIT>:<EOL><INDENT>logger.info('<STR_LIT>')<EOL>chunk_dim = (<NUM_LIT:1>,<NUM_LIT:1>,<NUM_LIT>) <EOL>return chunk_dim<EOL><DEDENT>elif np.abs(self.header[b'<STR_LIT>']) < <NUM_LIT>:<EOL><INDENT>logger.info('<STR_LIT>')<EOL>chunk_dim = (<NUM_LIT>,<NUM_LIT:1>,<NUM_LIT>) <EOL>return chunk_dim<EOL><DEDENT>elif np.abs(self.header[b'<STR_LIT>']) < <NUM_LIT> and np.abs(self.header[b'<STR_LIT>'])  >= <NUM_LIT>:<EOL><INDENT>logger.info('<STR_LIT>')<EOL>chunk_dim = (<NUM_LIT:10>,<NUM_LIT:1>,<NUM_LIT>)  <EOL><INDENT>chunk_dim = (<NUM_LIT:1>,<NUM_LIT:1>,<NUM_LIT>/<NUM_LIT:4>)<EOL><DEDENT>return chunk_dim<EOL><DEDENT>else:<EOL><INDENT>logger.warning('<STR_LIT>')<EOL>chunk_dim = (<NUM_LIT:1>,<NUM_LIT:1>,<NUM_LIT>)<EOL>return chunk_dim<EOL><DEDENT>

Sets the chunking dimmentions depending on the file type.


n_coarse_chan = self.container.calc_n_coarse_chan(chan_bw)<EOL>return n_coarse_chan<EOL>

This makes an attempt to calculate the number of coarse channels in a given freq selection.
            It assumes for now that a single coarse channel is 2.9296875 MHz


def grab_data(self, f_start=None, f_stop=None,t_start=None, t_stop=None, if_id=<NUM_LIT:0>):

self.freqs = self.populate_freqs()<EOL>self.timestamps = self.populate_timestamps()<EOL>if f_start is None:<EOL><INDENT>f_start = self.freqs[<NUM_LIT:0>]<EOL><DEDENT>if f_stop is None:<EOL><INDENT>f_stop = self.freqs[-<NUM_LIT:1>]<EOL><DEDENT>i0 = np.argmin(np.abs(self.freqs - f_start))<EOL>i1 = np.argmin(np.abs(self.freqs - f_stop))<EOL>if i0 < i1:<EOL><INDENT>plot_f    = self.freqs[i0:i1 + <NUM_LIT:1>]<EOL>plot_data = np.squeeze(self.data[t_start:t_stop, ..., i0:i1 + <NUM_LIT:1>])<EOL><DEDENT>else:<EOL><INDENT>plot_f    = self.freqs[i1:i0 + <NUM_LIT:1>]<EOL>plot_data = np.squeeze(self.data[t_start:t_stop, ..., i1:i0 + <NUM_LIT:1>])<EOL><DEDENT>return plot_f, plot_data<EOL>

Extract a portion of data by frequency range.

        Args:
            f_start (float): start frequency in MHz
            f_stop (float): stop frequency in MHz
            if_id (int): IF input identification (req. when multiple IFs in file)

        Returns:
            (freqs, data) (np.arrays): frequency axis in MHz and data subset


parser = argparse.ArgumentParser(description='<STR_LIT>')<EOL>parser.add_argument('<STR_LIT>', '<STR_LIT>', action='<STR_LIT:store>', default=None, dest='<STR_LIT>', type=str, help='<STR_LIT>')<EOL>parser.add_argument('<STR_LIT>', action='<STR_LIT:store>', default=None, dest='<STR_LIT>', type=float, help='<STR_LIT>')<EOL>parser.add_argument('<STR_LIT>', action='<STR_LIT:store>', default=None, dest='<STR_LIT>', type=float, help='<STR_LIT>')<EOL>parser.add_argument('<STR_LIT>', '<STR_LIT>', action='<STR_LIT:store>', default=None, dest='<STR_LIT>', type=str, help='<STR_LIT>')<EOL>parser.add_argument('<STR_LIT>', '<STR_LIT>', action='<STR_LIT:store>', default=None, dest='<STR_LIT>', type=str, help='<STR_LIT>')<EOL>parser.add_argument('<STR_LIT>', action='<STR_LIT:store>', default=None, dest='<STR_LIT>', type=float,help='<STR_LIT>')<EOL>args = parser.parse_args()<EOL>if len(sys.argv) == <NUM_LIT:1>:<EOL><INDENT>logger.error('<STR_LIT>')<EOL>sys.exit()<EOL><DEDENT>if args.in_fname == None:<EOL><INDENT>logger.error('<STR_LIT>')<EOL>sys.exit()<EOL><DEDENT>if args.out_fname == None:<EOL><INDENT>if (args.out_format == None) or (args.out_format == '<STR_LIT>'):<EOL><INDENT>if args.in_fname[len(args.in_fname)-<NUM_LIT:4>:] == '<STR_LIT>':<EOL><INDENT>args.out_fname = args.in_fname<EOL>args.out_fname = args.out_fname.replace('<STR_LIT>','<STR_LIT>')<EOL><DEDENT>elif args.in_fname[len(args.in_fname)-<NUM_LIT:3>:] == '<STR_LIT>':<EOL><INDENT>args.out_fname = args.in_fname<EOL>args.out_fname = args.out_fname.replace('<STR_LIT>','<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>logger.error('<STR_LIT>')<EOL>sys.exit()<EOL><DEDENT><DEDENT>elif args.out_format == '<STR_LIT>':<EOL><INDENT>if args.in_fname[len(args.in_fname)-<NUM_LIT:4>:] == '<STR_LIT>':<EOL><INDENT>args.out_fname = args.in_fname<EOL>args.out_fname = args.out_fname.replace('<STR_LIT>','<STR_LIT>')<EOL><DEDENT>elif args.in_fname[len(args.in_fname)-<NUM_LIT:3>:] == '<STR_LIT>':<EOL><INDENT>args.out_fname = args.in_fname<EOL>args.out_fname = args.out_fname.replace('<STR_LIT>','<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>logger.error('<STR_LIT>')<EOL>sys.exit()<EOL><DEDENT><DEDENT>else:<EOL><INDENT>logger.error('<STR_LIT>')<EOL>sys.exit()<EOL><DEDENT><DEDENT>elif (args.out_fname[len(args.out_fname)-<NUM_LIT:4>:] == '<STR_LIT>') and (args.out_format == '<STR_LIT>'):<EOL><INDENT>logger.error('<STR_LIT>')<EOL>sys.exit()<EOL><DEDENT>elif (args.out_fname[len(args.out_fname)-<NUM_LIT:3>:] == '<STR_LIT>') and (args.out_format == '<STR_LIT>'):<EOL><INDENT>logger.error('<STR_LIT>')<EOL>sys.exit()<EOL><DEDENT>if (args.out_fname[len(args.out_fname)-<NUM_LIT:3>:] != '<STR_LIT>') and (args.out_fname[len(args.out_fname)-<NUM_LIT:4>:] != '<STR_LIT>'):<EOL><INDENT>logger.error('<STR_LIT>')<EOL>sys.exit()<EOL><DEDENT>if args.f_start == None and args.f_stop == None:<EOL><INDENT>logger.error('<STR_LIT>')<EOL>sys.exit()<EOL><DEDENT>if args.f_start == None:<EOL><INDENT>logger.warning('<STR_LIT>' + str(f_min_file) + '<STR_LIT>')<EOL><DEDENT>if args.f_stop == None:<EOL><INDENT>logger.warning('<STR_LIT>' + str(f_max_file) + '<STR_LIT>')<EOL><DEDENT>file_big = Waterfall(args.in_fname, max_load = args.max_load)<EOL>f_min_file = file_big.header['<STR_LIT>']<EOL>f_max_file = file_big.header['<STR_LIT>'] + file_big.header['<STR_LIT>']*file_big.header['<STR_LIT>']<EOL>if f_max_file < f_min_file:<EOL><INDENT>f_max_file,f_min_file = f_min_file,f_max_file<EOL><DEDENT>FreqBWFile = f_max_file-f_min_file<EOL>stdDF = FreqBWFile / float(file_big.calc_n_coarse_chan())   <EOL>if args.f_stop < args.f_start:<EOL><INDENT>args.f_stop,args.f_start = args.f_start,args.f_stop<EOL><DEDENT>if args.f_start < f_max_file and args.f_start > f_min_file and args.f_stop > f_max_file:<EOL><INDENT>args.f_stop = f_max_file<EOL>logger.warning('<STR_LIT>' + str(f_max_file) + '<STR_LIT>')<EOL><DEDENT>if args.f_stop < f_max_file and args.f_stop > f_min_file and args.f_start < f_min_file:<EOL><INDENT>args.f_start = f_min_file<EOL>logger.warning('<STR_LIT>' + str(f_min_file) + '<STR_LIT>')<EOL><DEDENT>if args.f_start < f_min_file and args.f_stop > f_max_file:<EOL><INDENT>args.f_start = f_min_file<EOL>args.f_stop = f_max_file<EOL>logger.warning('<STR_LIT>' + str(f_min_file) + '<STR_LIT>' + str(f_max_file) + '<STR_LIT>')<EOL><DEDENT>if min(args.f_start,args.f_stop) < f_min_file or max(args.f_start,args.f_stop) > f_max_file:<EOL><INDENT>logger.error('<STR_LIT>' + str(f_min_file) + '<STR_LIT>' + str(f_max_file) + '<STR_LIT>')<EOL>sys.exit()<EOL><DEDENT>f_start_real = math.floor((min(args.f_start,args.f_stop) - f_min_file)/stdDF)*stdDF + f_min_file<EOL>f_stop_real = f_max_file - math.floor((f_max_file - max(args.f_start,args.f_stop))/stdDF)*stdDF<EOL>logger.info('<STR_LIT>' + args.out_fname)<EOL>logger.info('<STR_LIT>' + str(f_start_real) + '<STR_LIT>' + str(f_stop_real) + '<STR_LIT>')<EOL>file_small = Waterfall(args.in_fname, f_start = f_start_real, f_stop = f_stop_real, max_load = args.max_load)<EOL>if args.out_fname[len(args.out_fname)-<NUM_LIT:4>:] == '<STR_LIT>':<EOL><INDENT>file_small.write_to_fil(args.out_fname)<EOL><DEDENT>elif args.out_fname[len(args.out_fname)-<NUM_LIT:3>:] == '<STR_LIT>':<EOL><INDENT>file_small.write_to_hdf5(args.out_fname)<EOL><DEDENT>else:<EOL><INDENT>logger.error('<STR_LIT>')<EOL>sys.exit()<EOL><DEDENT>

Read input and output frequency, and output file name


def make_fil_file(filename,out_dir='<STR_LIT>', new_filename=None, max_load = None):

fil_file = Waterfall(filename, max_load = max_load)<EOL>if not new_filename:<EOL><INDENT>new_filename = out_dir+filename.replace('<STR_LIT>','<STR_LIT>').split('<STR_LIT:/>')[-<NUM_LIT:1>]<EOL><DEDENT>if '<STR_LIT>' not in new_filename:<EOL><INDENT>new_filename = new_filename+'<STR_LIT>'<EOL><DEDENT>fil_file.write_to_fil(new_filename)<EOL>

Converts file to Sigproc filterbank (.fil) format.  Default saves output in current dir.


def open_file(filename, f_start=None, f_stop=None,t_start=None, t_stop=None,load_data=True,max_load=<NUM_LIT:1.>):

if not os.path.isfile(filename):<EOL><INDENT>type(filename)<EOL>print(filename)<EOL>raise IOError("<STR_LIT>" + filename)<EOL><DEDENT>filename = os.path.expandvars(os.path.expanduser(filename))<EOL>ext = filename.split("<STR_LIT:.>")[-<NUM_LIT:1>].strip().lower()<EOL>if six.PY3:<EOL><INDENT>ext = bytes(ext, '<STR_LIT:ascii>')<EOL><DEDENT>if h5py.is_hdf5(filename):<EOL><INDENT>return H5Reader(filename, f_start=f_start, f_stop=f_stop, t_start=t_start, t_stop=t_stop,<EOL>load_data=load_data, max_load=max_load)<EOL><DEDENT>elif sigproc.is_filterbank(filename):<EOL><INDENT>return FilReader(filename, f_start=f_start, f_stop=f_stop, t_start=t_start, t_stop=t_stop, load_data=load_data, max_load=max_load)<EOL><DEDENT>else:<EOL><INDENT>raise NotImplementedError('<STR_LIT>')<EOL><DEDENT>


def _setup_selection_range(self, f_start=None, f_stop=None, t_start=None, t_stop=None, init=False):

<EOL>if init is True:<EOL><INDENT>if t_start is None:<EOL><INDENT>t_start = self.t_begin<EOL><DEDENT>if t_stop is None:<EOL><INDENT>t_stop = self.t_end<EOL><DEDENT>if f_start is None:<EOL><INDENT>f_start = self.f_begin<EOL><DEDENT>if f_stop is None:<EOL><INDENT>f_stop = self.f_end<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if f_start is None:<EOL><INDENT>f_start = self.f_start<EOL><DEDENT>if f_stop is None:<EOL><INDENT>f_stop = self.f_stop<EOL><DEDENT>if t_start is None:<EOL><INDENT>t_start = self.t_start<EOL><DEDENT>if t_stop is None:<EOL><INDENT>t_stop = self.t_stop<EOL><DEDENT><DEDENT>if t_stop >= <NUM_LIT:0> and t_start >= <NUM_LIT:0> and t_stop < t_start:<EOL><INDENT>t_stop, t_start = t_start,t_stop<EOL>logger.warning('<STR_LIT>')<EOL><DEDENT>if f_stop and f_start and f_stop < f_start:<EOL><INDENT>f_stop, f_start = f_start,f_stop<EOL>logger.warning('<STR_LIT>')<EOL><DEDENT>if t_start >= self.t_begin and t_start < self.t_end:<EOL><INDENT>self.t_start = int(t_start)<EOL><DEDENT>else:<EOL><INDENT>if init is False or t_start != None:<EOL><INDENT>logger.warning('<STR_LIT>'%self.t_begin)<EOL><DEDENT>self.t_start = self.t_begin<EOL><DEDENT>if t_stop <= self.t_end  and t_stop > self.t_begin:<EOL><INDENT>self.t_stop = int(t_stop)<EOL><DEDENT>else:<EOL><INDENT>if init is False or t_stop:<EOL><INDENT>logger.warning('<STR_LIT>'%self.t_end)<EOL><DEDENT>self.t_stop = self.t_end<EOL><DEDENT>if f_start >= self.f_begin and f_start < self.f_end:<EOL><INDENT>self.f_start = f_start<EOL><DEDENT>else:<EOL><INDENT>if init is False or f_start:<EOL><INDENT>logger.warning('<STR_LIT>'%self.f_begin)<EOL><DEDENT>self.f_start = self.f_begin<EOL><DEDENT>if f_stop <= self.f_end and f_stop > self.f_begin:<EOL><INDENT>self.f_stop = f_stop<EOL><DEDENT>else:<EOL><INDENT>if init is False or f_stop:<EOL><INDENT>logger.warning('<STR_LIT>'%self.f_end)<EOL><DEDENT>self.f_stop = self.f_end<EOL><DEDENT>self.selection_shape = self._calc_selection_shape()<EOL>

Making sure the selection if time and frequency are within the file limits.

        Args:
            init (bool): If call during __init__


<EOL>if self._n_bytes  == <NUM_LIT:4>:<EOL><INDENT>return b'<STR_LIT>'<EOL><DEDENT>elif self._n_bytes  == <NUM_LIT:2>:<EOL><INDENT>return b'<STR_LIT>'<EOL><DEDENT>elif self._n_bytes  == <NUM_LIT:1>:<EOL><INDENT>return b'<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>logger.warning('<STR_LIT>')<EOL>return b'<STR_LIT>'<EOL><DEDENT>


<EOL>n_ints = self.t_stop - self.t_start<EOL>n_chan = (self.f_stop - self.f_start) / abs(self.header[b'<STR_LIT>'])<EOL>n_bytes  = self._n_bytes<EOL>selection_size = int(n_ints*n_chan*n_bytes)<EOL>return selection_size<EOL>


<EOL>n_ints = int(self.t_stop - self.t_start)<EOL>n_chan = int(np.round((self.f_stop - self.f_start) / abs(self.header[b'<STR_LIT>'])))<EOL>selection_shape = (n_ints,int(self.header[b'<STR_LIT>']),n_chan)<EOL>return selection_shape<EOL>


if self.header[b'<STR_LIT>'] < <NUM_LIT:0>:<EOL><INDENT>f0 = self.f_end<EOL><DEDENT>else:<EOL><INDENT>f0 = self.f_begin<EOL><DEDENT>i_start, i_stop = <NUM_LIT:0>, self.n_channels_in_file<EOL>if self.f_start:<EOL><INDENT>i_start = np.round((self.f_start - f0) / self.header[b'<STR_LIT>'])<EOL><DEDENT>if self.f_stop:<EOL><INDENT>i_stop  = np.round((self.f_stop - f0)  / self.header[b'<STR_LIT>'])<EOL><DEDENT>chan_start_idx = np.int(i_start)<EOL>chan_stop_idx  = np.int(i_stop)<EOL>if chan_stop_idx < chan_start_idx:<EOL><INDENT>chan_stop_idx, chan_start_idx = chan_start_idx,chan_stop_idx<EOL><DEDENT>self.chan_start_idx =  chan_start_idx<EOL>self.chan_stop_idx = chan_stop_idx<EOL>


if self.header[b'<STR_LIT>'] > <NUM_LIT:0>:<EOL><INDENT>self.f_start = self.f_begin + self.chan_start_idx*abs(self.header[b'<STR_LIT>'])<EOL>self.f_stop = self.f_begin + self.chan_stop_idx*abs(self.header[b'<STR_LIT>'])<EOL><DEDENT>else:<EOL><INDENT>self.f_start = self.f_end - self.chan_stop_idx*abs(self.header[b'<STR_LIT>'])<EOL>self.f_stop = self.f_end - self.chan_start_idx*abs(self.header[b'<STR_LIT>'])<EOL><DEDENT>

Updating frequency borders from channel values


<EOL>ii_start, ii_stop = <NUM_LIT:0>, self.n_ints_in_file<EOL>if self.t_start:<EOL><INDENT>ii_start = self.t_start<EOL><DEDENT>if self.t_stop:<EOL><INDENT>ii_stop = self.t_stop<EOL><DEDENT>t0 = self.header[b'<STR_LIT>']<EOL>t_delt = self.header[b'<STR_LIT>']<EOL>if update_header:<EOL><INDENT>timestamps = ii_start * t_delt / <NUM_LIT>/<NUM_LIT>/<NUM_LIT> + t0<EOL><DEDENT>else:<EOL><INDENT>timestamps = np.arange(ii_start, ii_stop) * t_delt / <NUM_LIT>/<NUM_LIT>/<NUM_LIT> + t0<EOL><DEDENT>return timestamps<EOL>

Populate time axis.
            IF update_header then only return tstart


if self.header[b'<STR_LIT>'] < <NUM_LIT:0>:<EOL><INDENT>f0 = self.f_end<EOL><DEDENT>else:<EOL><INDENT>f0 = self.f_begin<EOL><DEDENT>self._setup_chans()<EOL>i_vals = np.arange(self.chan_start_idx, self.chan_stop_idx)<EOL>freqs = self.header[b'<STR_LIT>'] * i_vals + f0<EOL>return freqs<EOL>


nchans = int(self.header[b'<STR_LIT>'])<EOL>if chan_bw is not None:<EOL><INDENT>bandwidth = abs(self.f_stop - self.f_start)<EOL>n_coarse_chan = int(bandwidth / chan_bw)<EOL>return n_coarse_chan<EOL><DEDENT>elif nchans >= <NUM_LIT:2>**<NUM_LIT:20>:<EOL><INDENT>if nchans % <NUM_LIT:2>**<NUM_LIT:20> == <NUM_LIT:0>:<EOL><INDENT>n_coarse_chan = nchans // <NUM_LIT:2>**<NUM_LIT:20><EOL>return n_coarse_chan<EOL><DEDENT>elif self.header[b'<STR_LIT>'] == <NUM_LIT:6>:<EOL><INDENT>coarse_chan_bw = <NUM_LIT><EOL>bandwidth = abs(self.f_stop - self.f_start)<EOL>n_coarse_chan = int(bandwidth / coarse_chan_bw)<EOL>return n_coarse_chan<EOL><DEDENT>else:<EOL><INDENT>logger.warning("<STR_LIT>")<EOL><DEDENT><DEDENT>elif self.header[b'<STR_LIT>'] == <NUM_LIT:6> and nchans < <NUM_LIT:2>**<NUM_LIT:20>:<EOL><INDENT>coarse_chan_bw = <NUM_LIT><EOL>bandwidth = abs(self.f_stop - self.f_start)<EOL>n_coarse_chan = int(bandwidth / coarse_chan_bw)<EOL>return n_coarse_chan<EOL><DEDENT>else:<EOL><INDENT>logger.warning("<STR_LIT>")<EOL><DEDENT>

This makes an attempt to calculate the number of coarse channels in a given file.

            Note:
                This is unlikely to work on non-Breakthrough Listen data, as a-priori knowledge of
                the digitizer system is required.


n_blobs = int(np.ceil(<NUM_LIT:1.0> * np.prod(self.selection_shape) / np.prod(blob_dim)))<EOL>return n_blobs<EOL>

Given the blob dimensions, calculate how many fit in the data selection.


selection_size_bytes = self._calc_selection_size()<EOL>if selection_size_bytes > self.MAX_DATA_ARRAY_SIZE:<EOL><INDENT>return True<EOL><DEDENT>else:<EOL><INDENT>return False<EOL><DEDENT>

Check if the current selection is too large.


def __init__(self, filename, f_start=None, f_stop=None, t_start=None, t_stop=None, load_data=True, max_load=<NUM_LIT:1.>):

super(H5Reader, self).__init__()<EOL>if filename and os.path.isfile(filename) and h5py.is_hdf5(filename):<EOL><INDENT>self.freq_axis = <NUM_LIT:2><EOL>self.time_axis = <NUM_LIT:0><EOL>self.beam_axis = <NUM_LIT:1>  <EOL>self.stokes_axis = <NUM_LIT:4>  <EOL>self.filename = filename<EOL>self.filestat = os.stat(filename)<EOL>self.filesize = self.filestat.st_size/(<NUM_LIT>**<NUM_LIT:2>)<EOL>self.load_data = load_data<EOL>self.h5 = h5py.File(self.filename)<EOL>self.read_header()<EOL>self.file_size_bytes = os.path.getsize(self.filename)  <EOL>self.n_ints_in_file = self.h5["<STR_LIT:data>"].shape[self.time_axis] <EOL>self.n_channels_in_file = self.h5["<STR_LIT:data>"].shape[self.freq_axis] <EOL>self.n_beams_in_file = self.header[b'<STR_LIT>'] <EOL>self.n_pols_in_file = <NUM_LIT:1> <EOL>self._n_bytes = int(self.header[b'<STR_LIT>'] / <NUM_LIT:8>)  <EOL>self._d_type = self._setup_dtype()<EOL>self.file_shape = (self.n_ints_in_file,self.n_beams_in_file,self.n_channels_in_file)<EOL>if self.header[b'<STR_LIT>'] < <NUM_LIT:0>:<EOL><INDENT>self.f_end = self.header[b'<STR_LIT>']<EOL>self.f_begin = self.f_end + self.n_channels_in_file*self.header[b'<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>self.f_begin = self.header[b'<STR_LIT>']<EOL>self.f_end = self.f_begin + self.n_channels_in_file*self.header[b'<STR_LIT>']<EOL><DEDENT>self.t_begin = <NUM_LIT:0><EOL>self.t_end = self.n_ints_in_file<EOL>self._setup_selection_range(f_start=f_start, f_stop=f_stop, t_start=t_start, t_stop=t_stop, init=True)<EOL>self._setup_chans()<EOL>self._setup_freqs()<EOL>if max_load is not None:<EOL><INDENT>if max_load > <NUM_LIT:1.0>:<EOL><INDENT>logger.warning('<STR_LIT>')<EOL><DEDENT>self.MAX_DATA_ARRAY_SIZE = max_load * MAX_DATA_ARRAY_SIZE_UNIT<EOL><DEDENT>else:<EOL><INDENT>self.MAX_DATA_ARRAY_SIZE = MAX_DATA_ARRAY_SIZE_UNIT<EOL><DEDENT>if self.file_size_bytes > self.MAX_DATA_ARRAY_SIZE:<EOL><INDENT>self.large_file = True<EOL><DEDENT>else:<EOL><INDENT>self.large_file = False<EOL><DEDENT>if self.load_data:<EOL><INDENT>if self.large_file:<EOL><INDENT>if self.f_start or self.f_stop or self.t_start or self.t_stop:<EOL><INDENT>if self.isheavy():<EOL><INDENT>logger.warning("<STR_LIT>" % (self._calc_selection_size() / (<NUM_LIT> ** <NUM_LIT:3>), self.MAX_DATA_ARRAY_SIZE / (<NUM_LIT> ** <NUM_LIT:3>)))<EOL>self._init_empty_selection()<EOL><DEDENT>else:<EOL><INDENT>self.read_data()<EOL><DEDENT><DEDENT>else:<EOL><INDENT>logger.warning("<STR_LIT>"%(self.file_size_bytes/(<NUM_LIT>**<NUM_LIT:3>), self.MAX_DATA_ARRAY_SIZE/(<NUM_LIT>**<NUM_LIT:3>)))<EOL>self._init_empty_selection()<EOL><DEDENT><DEDENT>else:<EOL><INDENT>self.read_data()<EOL><DEDENT><DEDENT>else:<EOL><INDENT>logger.info("<STR_LIT>")<EOL>self._init_empty_selection()<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise IOError("<STR_LIT>")<EOL><DEDENT>

Constructor.

        Args:
            filename (str): filename of blimpy file.
            f_start (float): start frequency, in MHz
            f_stop (float): stop frequency, in MHz
            t_start (int): start time bin
            t_stop (int): stop time bin


self.header = {}<EOL>for key, val in self.h5['<STR_LIT:data>'].attrs.items():<EOL><INDENT>if six.PY3:<EOL><INDENT>key = bytes(key, '<STR_LIT:ascii>')<EOL><DEDENT>if key == b'<STR_LIT>':<EOL><INDENT>self.header[key] = Angle(val, unit='<STR_LIT>')<EOL><DEDENT>elif key == b'<STR_LIT>':<EOL><INDENT>self.header[key] = Angle(val, unit='<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>self.header[key] = val<EOL><DEDENT><DEDENT>return self.header<EOL>

Read header and return a Python dictionary of key:value pairs


def _find_blob_start(self, blob_dim, n_blob):

<EOL>self._setup_chans()<EOL>blob_time_start = self.t_start + blob_dim[self.time_axis]*n_blob<EOL>blob_freq_start = self.chan_start_idx + (blob_dim[self.freq_axis]*n_blob)%self.selection_shape[self.freq_axis]<EOL>blob_start = np.array([blob_time_start, <NUM_LIT:0>, blob_freq_start])<EOL>return blob_start<EOL>


self._setup_selection_range(f_start=f_start, f_stop=f_stop, t_start=t_start, t_stop=t_stop)<EOL>if self.isheavy():<EOL><INDENT>logger.warning("<STR_LIT>" % (self._calc_selection_size() / (<NUM_LIT> ** <NUM_LIT:3>), self.MAX_DATA_ARRAY_SIZE / (<NUM_LIT> ** <NUM_LIT:3>)))<EOL>self.data = np.array([<NUM_LIT:0>],dtype=self._d_type)<EOL>return None<EOL><DEDENT>self._setup_chans()<EOL>self._setup_freqs()<EOL>self.data = self.h5["<STR_LIT:data>"][self.t_start:self.t_stop,:,self.chan_start_idx:self.chan_stop_idx]<EOL>


n_blobs = self.calc_n_blobs(blob_dim)<EOL>if n_blob > n_blobs or n_blob < <NUM_LIT:0>:<EOL><INDENT>raise ValueError('<STR_LIT>'%(n_blob,n_blobs))<EOL><DEDENT>if blob_dim[self.time_axis]*(n_blob+<NUM_LIT:1>) > self.selection_shape[self.time_axis]:<EOL><INDENT>updated_blob_dim = (self.selection_shape[self.time_axis] - blob_dim[self.time_axis]*n_blob, <NUM_LIT:1>, blob_dim[self.freq_axis])<EOL><DEDENT>else:<EOL><INDENT>updated_blob_dim = [int(i) for i in blob_dim]<EOL><DEDENT>blob_start = self._find_blob_start(blob_dim, n_blob)<EOL>blob_end = blob_start + np.array(updated_blob_dim)<EOL>blob = self.h5["<STR_LIT:data>"][int(blob_start[self.time_axis]):int(blob_end[self.time_axis]),<EOL>:,<EOL>int(blob_start[self.freq_axis]):int(blob_end[self.freq_axis])<EOL>]<EOL><INDENT>if self.header[b'<STR_LIT>'] < <NUM_LIT:0>:<EOL><INDENT>blob = blob[:,:,::-<NUM_LIT:1>]<EOL><DEDENT><DEDENT>return blob<EOL>


def __init__(self, filename,f_start=None, f_stop=None,t_start=None, t_stop=None, load_data=True, max_load=<NUM_LIT:1.>):

super(FilReader, self).__init__()<EOL>self.header_keywords_types = sigproc.header_keyword_types<EOL>if filename and os.path.isfile(filename):<EOL><INDENT>self.filename = filename<EOL>self.load_data = load_data<EOL>self.header = self.read_header()<EOL>self.file_size_bytes = os.path.getsize(self.filename)<EOL>self.idx_data = sigproc.len_header(self.filename)<EOL>self.n_channels_in_file  = self.header[b'<STR_LIT>']<EOL>self.n_beams_in_file = self.header[b'<STR_LIT>'] <EOL>self.n_pols_in_file = <NUM_LIT:1> <EOL>self._n_bytes = int(self.header[b'<STR_LIT>'] / <NUM_LIT:8>)  <EOL>self._d_type = self._setup_dtype()<EOL>self._setup_n_ints_in_file()<EOL>self.file_shape = (self.n_ints_in_file,self.n_beams_in_file,self.n_channels_in_file)<EOL>if self.header[b'<STR_LIT>'] < <NUM_LIT:0>:<EOL><INDENT>self.f_end  = self.header[b'<STR_LIT>']<EOL>self.f_begin  = self.f_end + self.n_channels_in_file*self.header[b'<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>self.f_begin  = self.header[b'<STR_LIT>']<EOL>self.f_end  = self.f_begin + self.n_channels_in_file*self.header[b'<STR_LIT>']<EOL><DEDENT>self.t_begin = <NUM_LIT:0><EOL>self.t_end = self.n_ints_in_file<EOL>self._setup_selection_range(f_start=f_start, f_stop=f_stop, t_start=t_start, t_stop=t_stop, init=True)<EOL>self._setup_chans()<EOL>self._setup_freqs()<EOL>self.freq_axis = <NUM_LIT:2><EOL>self.time_axis = <NUM_LIT:0><EOL>self.beam_axis = <NUM_LIT:1>  <EOL>spec = np.squeeze(fil_file.data)<EOL><INDENT>self.datastart=self.hdrraw.find('<STR_LIT>')+len('<STR_LIT>')+self.startsample*self.channels<EOL><DEDENT>if max_load is not None:<EOL><INDENT>if max_load > <NUM_LIT:1.0>:<EOL><INDENT>logger.warning('<STR_LIT>')<EOL><DEDENT>self.MAX_DATA_ARRAY_SIZE = max_load * MAX_DATA_ARRAY_SIZE_UNIT<EOL><DEDENT>else:<EOL><INDENT>self.MAX_DATA_ARRAY_SIZE = MAX_DATA_ARRAY_SIZE_UNIT<EOL><DEDENT>if self.file_size_bytes > self.MAX_DATA_ARRAY_SIZE:<EOL><INDENT>self.large_file = True<EOL><DEDENT>else:<EOL><INDENT>self.large_file = False<EOL><DEDENT>if self.load_data:<EOL><INDENT>if self.large_file:<EOL><INDENT>if self.f_start or self.f_stop or self.t_start or self.t_stop:<EOL><INDENT>if self.isheavy():<EOL><INDENT>logger.warning("<STR_LIT>" % (self._calc_selection_size() / (<NUM_LIT> ** <NUM_LIT:3>), self.MAX_DATA_ARRAY_SIZE / (<NUM_LIT> ** <NUM_LIT:3>)))<EOL>self._init_empty_selection()<EOL><DEDENT>else:<EOL><INDENT>self.read_data()<EOL><DEDENT><DEDENT>else:<EOL><INDENT>logger.warning("<STR_LIT>"%(self.file_size_bytes/(<NUM_LIT>**<NUM_LIT:3>), self.MAX_DATA_ARRAY_SIZE/(<NUM_LIT>**<NUM_LIT:3>)))<EOL>self._init_empty_selection()<EOL><DEDENT><DEDENT>else:<EOL><INDENT>self.read_data()<EOL><DEDENT><DEDENT>else:<EOL><INDENT>logger.info("<STR_LIT>")<EOL>self._init_empty_selection()<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise IOError("<STR_LIT>")<EOL><DEDENT>


self.n_ints_in_file = sigproc.calc_n_ints_in_file(self.filename)<EOL>

Calculate the number of integrations in the file.


self.header = sigproc.read_header(self.filename, return_idxs=return_idxs)<EOL>return self.header<EOL>

Read blimpy header and return a Python dictionary of key:value pairs

        Args:
            filename (str): name of file to open

        Optional args:
            return_idxs (bool): Default False. If true, returns the file offset indexes
                                for values

        Returns:
            Python dict of key:value pairs, OR returns file offset indexes for values.


self._setup_selection_range(f_start=f_start, f_stop=f_stop, t_start=t_start, t_stop=t_stop)<EOL>if self.isheavy():<EOL><INDENT>logger.warning("<STR_LIT>"<EOL>"<STR_LIT>" % (self._calc_selection_size() / (<NUM_LIT> ** <NUM_LIT:3>), self.MAX_DATA_ARRAY_SIZE / (<NUM_LIT> ** <NUM_LIT:3>)))<EOL>self.data = np.array([<NUM_LIT:0>],dtype=self._d_type)<EOL>return None<EOL><DEDENT>self._setup_chans()<EOL>self._setup_freqs()<EOL>n_chans = self.header[b'<STR_LIT>']<EOL>n_chans_selected = self.selection_shape[self.freq_axis]<EOL>n_ifs   = self.header[b'<STR_LIT>']<EOL>f = open(self.filename, '<STR_LIT:rb>')<EOL>f.seek(int(self.idx_data))<EOL>n_ints = self.t_stop - self.t_start<EOL>f.seek(int(self.t_start * self._n_bytes  * n_ifs * n_chans), <NUM_LIT:1>)<EOL>self.data = np.zeros((n_ints, n_ifs, n_chans_selected), dtype=self._d_type)<EOL>for ii in range(n_ints):<EOL><INDENT>for jj in range(n_ifs):<EOL><INDENT>f.seek(int(self._n_bytes  * self.chan_start_idx), <NUM_LIT:1>) <EOL>dd = np.fromfile(f, count=n_chans_selected, dtype=self._d_type)<EOL><INDENT>if self.header[b'<STR_LIT>'] < <NUM_LIT:0>:<EOL><INDENT>dd = dd[::-<NUM_LIT:1>]<EOL><DEDENT><DEDENT>self.data[ii, jj] = dd<EOL>f.seek(int(self._n_bytes  * (n_chans - self.chan_stop_idx)), <NUM_LIT:1>)<EOL><DEDENT><DEDENT>


<EOL>self._setup_chans()<EOL>blob_time_start = self.t_start<EOL>blob_freq_start = self.chan_start_idx<EOL>blob_start = blob_time_start * self.n_channels_in_file + blob_freq_start<EOL>return blob_start<EOL>