def get_channels(framefile): """Return a list of all channels written into the given GWF-format framefile @param framefile `string` path to input frame file @returns a list of all channels present in the table of contents Example: \code >>> get_channels('H-H1_LDAS_C02_L2-9668/H-H1_LDAS_C02_L2-966802176-128.gwf') ['H1:LSC-DATA_QUALITY_VECTOR', 'H1:IFO-SV_STATE_VECTOR', 'H1:LDAS-STRAIN'] \endcode """ frfile = lalframe.FrameUFrFileOpen(framefile, "r") frtoc = lalframe.FrameUFrTOCRead(frfile) nadc = lalframe.FrameUFrTOCQueryAdcN(frtoc) nproc = lalframe.FrameUFrTOCQueryProcN(frtoc) nsim = lalframe.FrameUFrTOCQuerySimN(frtoc) adcchannels = [ lalframe.FrameUFrTOCQueryAdcName(frtoc, i) for i in range(nadc) ] procchannels = [ lalframe.FrameUFrTOCQuerySimName(frtoc, i) for i in range(nsim) ] simchannels = [ lalframe.FrameUFrTOCQueryProcName(frtoc, i) for i in range(nproc) ] return sorted(adcchannels + procchannels + simchannels)
def iter_channel_names(framefile): """Iterate over the names of channels found in a GWF file Parameters ---------- framefile : `str` path of frame file to read Returns ------- channels : `generator` an iterator that will loop over the names of channels as read from the table of contents of the given GWF file """ try: out = shell.call(['FrChannels', framefile])[0] except (OSError, shell.CalledProcessError): import lalframe # read frame and table of contents frfile = lalframe.FrameUFrFileOpen(framefile, "r") frtoc = lalframe.FrameUFrTOCRead(frfile) for ctype in ['Sim', 'Proc', 'Adc']: query = getattr(lalframe, 'FrameUFrTOCQuery%sName' % ctype) i = 0 while True: try: yield query(frtoc, i) except RuntimeError: break i += 1 else: for line in iter(out.splitlines()): yield line.split(' ', 1)[0]
def iter_channels(framefile): """Yield channels from the table-of-contents of the given GWF file @param framefile `str` path to input frame file @return An iterator of channel names """ frfile = lalframe.FrameUFrFileOpen(str(framefile), "r") frtoc = lalframe.FrameUFrTOCRead(frfile) nsim = lalframe.FrameUFrTOCQuerySimN(frtoc) for i in range(lalframe.FrameUFrTOCQueryAdcN(frtoc)): yield lalframe.FrameUFrTOCQueryAdcName(frtoc, i) for i in range(lalframe.FrameUFrTOCQueryProcN(frtoc)): yield lalframe.FrameUFrTOCQueryProcName(frtoc, i) for i in range(lalframe.FrameUFrTOCQuerySimN(frtoc)): yield lalframe.FrameUFrTOCQuerySimName(frtoc, i)
def get_channel_type(channel, framefile): """Find the channel type in a given frame file Parameters ---------- channel : `str`, `~gwpy.detector.Channel` name of data channel to find framefile : `str` path of GWF file in which to search Returns ------- ctype : `str` the type of the channel ('adc', 'sim', or 'proc') Raises ------ ValueError if the channel is not found in the table-of-contents """ import lalframe name = str(channel) # read frame and table of contents frfile = lalframe.FrameUFrFileOpen(framefile, "r") frtoc = lalframe.FrameUFrTOCRead(frfile) for type_ in ['Sim', 'Proc', 'Adc']: query = getattr(lalframe, 'FrameUFrTOCQuery%sName' % type_) i = 0 while True: try: chan = query(frtoc, i) except RuntimeError: break else: if chan == name: return type_.lower() i += 1 raise ValueError("%s not found in table-of-contents for %s" % (name, framefile))