From 9be8007fe636c40d29057c0573efab59a11dbcaa Mon Sep 17 00:00:00 2001
From: Jameson Graef Rollins <jrollins@finestructure.net>
Date: Wed, 12 Feb 2020 15:34:35 -0800
Subject: [PATCH] script to generate comparison plot of all IFOs

implement as __main__ for `gwinc.ifo`

also add to CI.  closes #48
---
 .gitlab-ci.yml        |  3 ++
 IFO.md                | 44 +++++++++++++++++++++++++++++
 gwinc/ifo/__main__.py | 64 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 111 insertions(+)
 create mode 100644 IFO.md
 create mode 100644 gwinc/ifo/__main__.py

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 1e0a190b..8913d916 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -17,6 +17,7 @@ test:
   - for ifo in aLIGO Aplus Voyager CE1 CE2; do
   -     python3 -m gwinc $ifo -s $ifo.png
   - done
+  - python3 -m gwinc.ifo -s all_compare.png
   - python3 -m gwinc.test -r gwinc_test_report.pdf
   after_script:
   - rm gitID.txt
@@ -32,6 +33,7 @@ test:
     - Voyager.png
     - CE1.png
     - CE2.png
+    - all_compare.png
     - gwinc_test_report.pdf
 
 pages:
@@ -43,6 +45,7 @@ pages:
   - for ifo in aLIGO Aplus Voyager CE1 CE2; do
   -     mv $ifo.png public/
   - done
+  - mv all_compare.png public/ || true
   - mv gwinc_test_report.pdf public/ || true
   - apt-get install -y -qq python3-pip python3-dev make
   - pip3 install sphinx sphinx-rtd-theme
diff --git a/IFO.md b/IFO.md
new file mode 100644
index 00000000..b2774d51
--- /dev/null
+++ b/IFO.md
@@ -0,0 +1,44 @@
+# Canonical IFOs
+
+CI-generated plots and data for all IFOs included in pygwinc.
+
+![IFO compare](https://gwinc.docs.ligo.org/pygwinc/all_compare.png)
+
+## aLIGO
+
+* [ifo.yaml](gwinc/ifo/aLIGO/ifo.yaml)
+* [aLIGO.h5](https://gwinc.docs.ligo.org/pygwinc/aLIGO.h5)
+
+![aLIGO](https://gwinc.docs.ligo.org/pygwinc/aLIGO.png)
+
+
+## A+
+
+* [ifo.yaml](gwinc/ifo/Aplus/ifo.yaml)
+* [Aplus.h5](https://gwinc.docs.ligo.org/pygwinc/Aplus.h5)
+
+![Aplus](https://gwinc.docs.ligo.org/pygwinc/Aplus.png)
+
+
+## Voyager
+
+* [ifo.yaml](gwinc/ifo/Voyager/ifo.yaml)
+* [Voyager.h5](https://gwinc.docs.ligo.org/pygwinc/Voyager.h5)
+
+![Voyager](https://gwinc.docs.ligo.org/pygwinc/Voyager.png)
+
+
+## Cosmic Explorer 1
+
+* [ifo.yaml](gwinc/ifo/CE1/ifo.yaml)
+* [CE1.h5](https://gwinc.docs.ligo.org/pygwinc/CE1.h5)
+
+![CE1](https://gwinc.docs.ligo.org/pygwinc/CE1.png)
+
+
+## Cosmic Explorer 2
+
+* [ifo.yaml](gwinc/ifo/CE2/ifo.yaml)
+* [CE2.h5](https://gwinc.docs.ligo.org/pygwinc/CE2.h5)
+
+![CE2](https://gwinc.docs.ligo.org/pygwinc/CE2.png)
diff --git a/gwinc/ifo/__main__.py b/gwinc/ifo/__main__.py
new file mode 100644
index 00000000..9e5b3cba
--- /dev/null
+++ b/gwinc/ifo/__main__.py
@@ -0,0 +1,64 @@
+import argparse
+import numpy as np
+import matplotlib.pyplot as plt
+
+from . import IFOS, PLOT_STYLE
+from .. import load_budget
+
+
+FLO = 3
+FHI = 10000
+NPOINTS = 3000
+YLIM = (1e-25, 1e-20)
+
+
+def main():
+    parser = argparse.ArgumentParser(
+        description="Reference IFO comparison plot",
+    )
+    parser.add_argument(
+        '--save', '-s',
+        help="save plot to file (.pdf/.png/.svg)")
+    args = parser.parse_args()
+
+    fig = plt.figure()
+    ax = fig.add_subplot(1, 1, 1)
+
+    freq = np.logspace(np.log10(FLO), np.log10(FHI), NPOINTS)
+
+    for ifo in IFOS:
+        Budget = load_budget(ifo)
+        data = Budget(freq).calc()
+        label = Budget.name
+
+        ax.loglog(freq, np.sqrt(data), label=label)
+
+    ax.grid(
+        True,
+        which='both',
+        lw=0.5,
+        ls='-',
+        alpha=0.5,
+    )
+
+    ax.legend(
+        # ncol=2,
+        fontsize='small',
+    )
+
+    ax.autoscale(enable=True, axis='y', tight=True)
+    ax.set_ylim(*YLIM)
+    ax.set_xlim(freq[0], freq[-1])
+
+    ax.set_xlabel('Frequency [Hz]')
+    ax.set_ylabel(PLOT_STYLE['ylabel'])
+    ax.set_title("PyGWINC reference IFO strain comparison")
+
+    if args.save:
+        fig.savefig(args.save)
+    else:
+        plt.show()
+
+
+if __name__ == '__main__':
+    main()
-- 
GitLab