Convert far contour plot script from py2
We're wanting to plot far contours on events in O4. This MR converts the far contour plotting script (gstlal_cohfar_plot_stats) from py2 and the main spiir repo.
There were some weird issues to fix:
- We save some params with uppercase letters, though the regex for the attribute
elem.Name
of params seems to assume lowercase. Rather than change the pipeline, for now we go through and rename params to lowercase if reading xml withlegacy_postcoh_compat
enabled. - Related issue for Tables,
ligo.lw.table.Table.get_table
assumes the document contains exactly one table with the given name. We have 3 in Marginalized stats. So I've madeget_exact_table_from_xmldoc
, which matches onelem.getAttribute("Name")
instead. e.g.background_feature:rank_rate:table
rather thanrank_rate
(elem.Name
) - The marker
x
didn't work. I don't understand why, maybe it's some kind of weird font thing. So I just used a star instead. - The old script depended on
pipe_macro.py
, which has a mix of redundant data from marginalized stats, bins sizes/min/max/steps, and table names. I've done a mix of command line args, parsing marginalized stats, and hard coding.- 5 command line args have to match what was used in the pipeline run.
far_factor
,snr_min
,snr_max
,chisq_min
,chisq_max
. Otherwise, the contours will be translated & scaled weirdly. Onlyfar_factor
changes run to run though.
- 5 command line args have to match what was used in the pipeline run.
Also, @daniel.tang suggested trying Typer. I wound up with a mix of typer & click due to using @click_logger_options
, dunno if that's an issue. Also, Typer doesn't support Union types, which we use in some other scripts. I've got no strong opinions on it, though I do like the reduced boilerplate.
If we go with typer, do I need to update some dependency list somewhere?
Tests
I've tried running it locally, passing in marginalized stats and zerolags from a test run:
python share/scripts/analysis/plot_far_contours.py /fred/oz016/tdavies/projects/testing/inj/8000_test/spiir-O4-review-v5_3/run1/013/013_marginalized_stats_2w.xml.gz H1L1 2 20 1 test.png --log-file test.log --zerolags-paths /fred/oz016/tdavies/projects/testing/inj/8000_test/spiir-O4-review-v5_3/run1/013/013_zerolag_1186642720_7982.xml.gz
Followups
We'll be wanting a igwn consumer to plot & upload these automatically, pulling the directory from the command line args in the coinc, finding the marginalized stats and recent zerolag files, and upload the plot (I think). This will probably be the next MR. There's a related script gstlal_inspiral_postcohspiir_lvalert_plotter
that could also be updated, though I think it takes a gracedb ID and runs the process above rather than using igwn alerts.