Skip to content

Commit

Permalink
Added support for dq tags
Browse files Browse the repository at this point in the history
  • Loading branch information
maxtrevor committed Aug 28, 2023
1 parent baabd2d commit d1f9a77
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 16 deletions.
18 changes: 15 additions & 3 deletions bin/workflows/pycbc_make_offline_search_workflow
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,12 @@ save_fig_with_metadata(time_str, time_file.storage_path, **kwds)

# Get segments and find the data locations
sci_seg_name = 'science'
science_tags = []
if 'science' in workflow.cp.get_subsections('workflow-segments'):
science_tags = ['science']
science_seg_file = wf.get_segments_file(workflow, sci_seg_name, 'segments-science',
rdir['analysis_time/segment_data'])
rdir['analysis_time/segment_data'],
tags=science_tags)

ssegs = {}
for ifo in workflow.ifos:
Expand All @@ -143,15 +147,23 @@ datafind_files, analyzable_file, analyzable_segs, analyzable_name = \
seg_file=science_seg_file, tags=hoft_tags)

final_veto_name = 'vetoes'
veto_tags = []
if 'veto' in workflow.cp.get_subsections('workflow-segments'):
veto_tags = ['veto']
final_veto_file = wf.get_segments_file(workflow, final_veto_name,
'segments-vetoes',
rdir['analysis_time/segment_data'])
rdir['analysis_time/segment_data'],
tags=veto_tags)

# Get dq segments from veto definer and calculate data quality timeseries
dq_flag_name = 'dq_flag'
dq_tags = []
if 'dq' in workflow.cp.get_subsections('workflow-segments'):
dq_tags = ['dq']
dq_segment_file = wf.get_flag_segments_file(workflow, dq_flag_name,
'segments-dq',
rdir['analysis_time/segment_data'])
rdir['analysis_time/segment_data'],
tags=dq_tags)

# Template bank stuff
hdfbank = wf.setup_tmpltbank_workflow(workflow, analyzable_segs,
Expand Down
32 changes: 19 additions & 13 deletions pycbc/workflow/segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def save_veto_definer(cp, out_dir, tags=None):
return veto_def_new_path


def get_segments_file(workflow, name, option_name, out_dir):
def get_segments_file(workflow, name, option_name, out_dir, tags=None):
"""Get cumulative segments from option name syntax for each ifo.
Use syntax of configparser string to define the resulting segment_file
Expand All @@ -76,6 +76,9 @@ def get_segments_file(workflow, name, option_name, out_dir):
Name of the segment list being created
option_name: str
Name of option in the associated config parser to get the flag list
tags : list of strings
Used to retrieve subsections of the ini file for
configuration options.
returns
--------
Expand All @@ -95,18 +98,19 @@ def get_segments_file(workflow, name, option_name, out_dir):

# Check for provided server
server = "https://segments.ligo.org"
if cp.has_option("workflow-segments", "segments-database-url"):
server = cp.get("workflow-segments",
"segments-database-url")
if cp.has_option_tags("workflow-segments", "segments-database-url", tags):
server = cp.get_opt_tags("workflow-segments",
"segments-database-url", tags)

if cp.has_option("workflow-segments", "segments-source"):
source = cp.get("workflow-segments", "segments-source")
if cp.has_option_tags("workflow-segments", "segments-source", tags):
source = cp.get_opt_tags("workflow-segments", "segments-source", tags)
else:
source = "any"

if source == "file":
local_file_path = \
resolve_url(cp.get("workflow-segments", option_name+"-file"))
resolve_url(cp.get_opt_tag("workflow-segments",
option_name+"-file", tags))
pfn = os.path.join(out_dir, os.path.basename(local_file_path))
shutil.move(local_file_path, pfn)
return SegFile.from_segment_xml(pfn)
Expand Down Expand Up @@ -380,7 +384,7 @@ def generate_triggered_segment(workflow, out_dir, sciencesegs):
except UnboundLocalError:
return None, min_seg

def get_flag_segments_file(workflow, name, option_name, out_dir):
def get_flag_segments_file(workflow, name, option_name, out_dir, tags=None):
"""Get segments from option name syntax for each ifo for indivudal flags.
Use syntax of configparser string to define the resulting segment_file
Expand Down Expand Up @@ -415,15 +419,17 @@ def get_flag_segments_file(workflow, name, option_name, out_dir):

# Check for provided server
server = "https://segments.ligo.org"
if cp.has_option("workflow-segments", "segments-database-url"):
server = cp.get("workflow-segments", "segments-database-url")
if cp.has_option_tags("workflow-segments", "segments-database-url", tags):
server = cp.get_opt_tags("workflow-segments",
"segments-database-url", tags)

source = "any"
if cp.has_option("workflow-segments", "segments-source"):
source = cp.get("workflow-segments", "segments-source")
if cp.has_option_tags("workflow-segments", "segments-source", tags):
source = cp.get_opt_tags("workflow-segments", "segments-source", tags)
if source == "file":
local_file_path = \
resolve_url(cp.get("workflow-segments", option_name+"-file"))
resolve_url(cp.get_opt_tags("workflow-segments",
option_name+"-file", tags))
pfn = os.path.join(out_dir, os.path.basename(local_file_path))
shutil.move(local_file_path, pfn)
return SegFile.from_segment_xml(pfn)
Expand Down

0 comments on commit d1f9a77

Please sign in to comment.