Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
params["flagList"] = glue.segments.segmentlist()
gpsStart = segment[0]
gpsEnd = segment[1]
# set the times
duration = np.ceil(gpsEnd-gpsStart)
segmentlist = glue.segments.segmentlist()
if params["doFlagsDatabase"]:
print "Generating flags from database"
#segmentlist, segmentlistValid = pylal.dq.dqSegmentUtils.grab_segments(
# gpsStart,gpsEnd,
# params["flagsFlag"],params["flagsDatabase"],
# segment_summary=True)
dqsegments = gwpy.segments.DataQualityFlag.query(params["flagsFlag"],gpsStart,gpsEnd,url=params["flagsDatabase"])
segmentlist = dqsegments.active
elif params["doFlagsTextFile"]:
lines = [line.strip() for line in open(params["flagsTextFile"])]
for line in lines:
lineSplit = line.split(",")
seg = [float(lineSplit[0]),float(lineSplit[1])]
segmentlist.append(glue.segments.segment(seg[0],seg[1]))
elif params["doFlagsChannel"]:
print "Generating flags from timeseries"
if params["doPlots"]:
plotDirectory = params["path"] + "/flags"
pylal.pylal_seismon_utils.mkdir(plotDirectory)
pngFile = os.path.join(plotDirectory,"timeseries.png")
plot = gwpy.plotter.TimeSeriesPlot(figsize=[14,8])
data[i, :] = (start.gpsSeconds, start.gpsNanoSeconds,
end.gpsSeconds, end.gpsNanoSeconds)
segtable = Table(data, names=['start_time', 'start_time_ns',
'end_time', 'end_time_ns'])
# write table to HDF5
return segtable.write(output, path=path, format='hdf5', **kwargs)
# -- register -----------------------------------------------------------------
register_reader('hdf5', SegmentList, read_hdf5_segmentlist)
register_writer('hdf5', SegmentList, write_hdf5_segmentlist)
register_identifier('hdf5', SegmentList, io_hdf5.identify_hdf5)
register_reader('hdf5', DataQualityFlag, read_hdf5_flag)
register_writer('hdf5', DataQualityFlag, write_hdf5_flag)
register_identifier('hdf5', DataQualityFlag, io_hdf5.identify_hdf5)
register_reader('hdf5', DataQualityDict, read_hdf5_dict)
register_writer('hdf5', DataQualityDict, write_hdf5_dict)
register_identifier('hdf5', DataQualityDict, io_hdf5.identify_hdf5)
data['metadata']['active_indicates_ifo_badness'] = not flag.isgood
data['metadata']['flag_description'] = flag.description
# write
json.dump(data, fobj, **kwargs)
# -- identify -----------------------------------------------------------------
identify_json = identify_factory('json') # pylint: disable=invalid-name
# -- register -----------------------------------------------------------------
registry.register_reader('json', DataQualityFlag, read_json_flag)
registry.register_writer('json', DataQualityFlag, write_json_flag)
registry.register_identifier('json', DataQualityFlag, identify_json)
data['metadata'] = {}
data['metadata']['active_indicates_ifo_badness'] = not flag.isgood
data['metadata']['flag_description'] = flag.description
# write
json.dump(data, fobj, **kwargs)
# -- identify -----------------------------------------------------------------
identify_json = identify_factory('json') # pylint: disable=invalid-name
# -- register -----------------------------------------------------------------
registry.register_reader('json', DataQualityFlag, read_json_flag)
registry.register_writer('json', DataQualityFlag, write_json_flag)
registry.register_identifier('json', DataQualityFlag, identify_json)
`Observing Run 1 (O1) `__
have been released by |GWOSC|_.
This example demonstrates how to download segment information into a
:class:`~gwpy.segments.DataQualityFlag`, and then plot them.
"""
__author__ = 'Duncan Macleod '
__currentmodule__ = 'gwpy.segments'
# All we need to do is import the `DataQualityFlag` object, and then call
# the :meth:`DataQualityFlag.fetch_open_data` method to query for, and download
# the segments for all of O1:
from gwpy.segments import DataQualityFlag
h1segs = DataQualityFlag.fetch_open_data('H1_DATA', 'Sep 12 2015',
'Jan 19 2016')
# We can then generate a plot of the times when LIGO-Hanford was operating:
plot = h1segs.plot(color='gwpy:ligo-hanford')
plot.show()
# That's a lot of segments. We can pare-down the list a little to display
# only the segments from the first month of the run:
h1month1 = DataQualityFlag.fetch_open_data('H1_DATA', 'Sep 12 2015',
'Oct 12 2015')
# We can also download the LIGO-Livingston segments from the same period
# and display them alongside, as well as those segments during which both
# interferometers were operating at the same time
"""Read a `DataQualityFlag` from a segments-web.ligo.org JSON file
"""
# read from filename
if isinstance(fobj, string_types):
with open(fobj, 'r') as fobj2:
return read_json_flag(fobj2)
# read from open file
txt = fobj.read()
if isinstance(txt, bytes):
txt = txt.decode('utf-8')
data = json.loads(txt)
# format flag
name = '{ifo}:{name}:{version}'.format(**data)
out = DataQualityFlag(name, active=data['active'],
known=data['known'])
# parse 'metadata'
try:
out.description = data['metadata'].get('flag_description', None)
except KeyError: # no metadata available, but that's ok
pass
else:
out.isgood = not data['metadata'].get(
'active_indicates_ifo_badness', False)
return out
dataset = _get_flag_group(h5f, path)
# read dataset
active = SegmentList.read(dataset['active'], format='hdf5',
gpstype=gpstype)
try:
known = SegmentList.read(dataset['known'], format='hdf5',
gpstype=gpstype)
except KeyError as first_keyerror:
try:
known = SegmentList.read(dataset['valid'], format='hdf5',
gpstype=gpstype)
except KeyError:
raise first_keyerror
return DataQualityFlag(active=active, known=known, **dict(dataset.attrs))
def segment_struct(params):
"""@create seismon segment structure
@param params
seismon params structure
"""
if params["doSegmentsDatabase"]:
#segmentlist, segmentlistValid = pylal.dq.dqSegmentUtils.grab_segments(
# params["gpsStart"],params["gpsEnd"],
# params["segmentFlag"],params["segmentDatabase"],
# segment_summary=True)
segmentlist, segmentlistValid = gwpy.segments.DataQualityFlag.query(params["segmentFlag"],
params["gpsStart"],params["gpsEnd"],
url=params["segmentDatabase"])
params["segments"] = segmentlist
elif params["doSegmentsTextFile"]:
segmentlist = glue.segments.segmentlist()
segs = np.loadtxt(params["segmentsTextFile"])
for seg in segs:
segmentlist.append(glue.segments.segment(seg[0],seg[1]))
params["segments"] = segmentlist
params["gpsStart"] = np.min(params["segments"])
params["gpsEnd"] = np.max(params["segments"])
else:
segmentlist = [glue.segments.segment(params["gpsStart"],params["gpsEnd"])]
params["segments"] = segmentlist
# the :meth:`DataQualityFlag.fetch_open_data` method to query for, and download
# the segments for all of O1:
from gwpy.segments import DataQualityFlag
h1segs = DataQualityFlag.fetch_open_data('H1_DATA', 'Sep 12 2015',
'Jan 19 2016')
# We can then generate a plot of the times when LIGO-Hanford was operating:
plot = h1segs.plot(color='gwpy:ligo-hanford')
plot.show()
# That's a lot of segments. We can pare-down the list a little to display
# only the segments from the first month of the run:
h1month1 = DataQualityFlag.fetch_open_data('H1_DATA', 'Sep 12 2015',
'Oct 12 2015')
# We can also download the LIGO-Livingston segments from the same period
# and display them alongside, as well as those segments during which both
# interferometers were operating at the same time
# (see :ref:`gwpy-segments-intersection` for more details on this use of the
# ``&`` operator):
l1month1 = DataQualityFlag.fetch_open_data('L1_DATA', 'Sep 12 2015',
'Oct 12 2015')
bothon = h1month1 & l1month1
plot = h1month1.plot()
ax = plot.gca()
ax.plot(l1month1)
ax.plot(bothon, label='Both')
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GWpy. If not, see .
"""Read gravitational-wave data from a cache of files
"""
from astropy.io import registry
from ...io.cache import (identify_cache, identify_cache_file,
read_cache_factory)
from .. import (DataQualityFlag, DataQualityDict, SegmentList, SegmentListDict)
# register cache reading
for class_ in [DataQualityFlag, DataQualityDict, SegmentList,
SegmentListDict]:
registry.register_reader('lcf', class_, read_cache_factory(class_))
registry.register_reader('cache', class_, read_cache_factory(class_))
registry.register_identifier('lcf', class_, identify_cache_file)
registry.register_identifier('cache', class_, identify_cache)