1. Alexander Konovalov
  2. poissonraytracer

Commits

kazeevn  committed 080d99c

Added plotter for refraction index curves and transmittance.

  • Participants
  • Parent commits 02daa5c
  • Branches default

Comments (0)

Files changed (1)

File utils/plot_spectrum_and_dispersion.py

View file
  • Ignore whitespace
+#!/usr/bin/python
+
+import sys
+import pylab as pl
+import numpy as np
+import argparse
+import itertools
+import matplotlib as mpl
+
+def main():
+    """
+    python utils/plot_spectrum_and_dispersion.py experiments/mc_alister/our_results.dat -l experiments/mc_alister/n-lambda_*.dat -o spectre_curves.pdf -d 7 5
+    """
+    parser = argparse.ArgumentParser(description='Plots a split with'
+                                     'spectrum and dispersion')
+    parser.add_argument('filename', type=str, nargs=1,
+                        help='results.dat to process')
+    parser.add_argument('-l', '--dispersion', type=str, nargs='+',
+                        help='dispersion curves to plot')
+    parser.add_argument('-d', '--dimensions', type=int, nargs='*',
+                    help="figure dimension, inches")
+    parser.add_argument('-o', '--output', type=str, nargs=1,
+                        help='file to save result to')
+    args = parser.parse_args()
+    fig_params = dict()
+    if args.dimensions is not None:
+        if len(args.dimensions) != 2:
+            print("You maust specify both dimensions")
+            sys.exit(1)
+        fig_params['figsize'] = args.dimensions
+    fig, axes = pl.subplots(2, sharex='col', **fig_params)
+
+    spectrum = np.genfromtxt(args.filename[0]).T
+    ax_spectrum = axes[0]
+    ax_spectrum.scatter(spectrum[0], spectrum[1])
+    ax_spectrum.set_ylabel(r"Transmittance, 1")
+    ax_spectrum.grid()
+
+    ax_nlambda = axes[1]
+    legends = {"experiments/mc_alister/n-lambda_glass.dat": "glass",
+               "experiments/mc_alister/n-lambda_liquid.dat": "liquid"}
+    for filename in args.dispersion:
+        dispersion_data = np.genfromtxt(filename).T
+        ax_nlambda.plot(dispersion_data[0], dispersion_data[1],
+                        label=legends[filename])
+    ax_nlambda.set_xlabel(r"Wavelength, $\AA$")
+    ax_nlambda.set_ylabel("n, 1")
+    ax_nlambda.grid()
+    ax_nlambda.legend()
+
+    ax_spectrum.set_xlim(min(spectrum[0]), max(spectrum[0]))
+    ax_spectrum.set_ylim(bottom=-0.1)
+    ax_nlambda.set_ylim(top=1.535)
+    #WARNING ugly hack
+    if args.output:
+        fig.savefig(args.output[0], bbox_inches="tight")
+
+if __name__ == '__main__':
+    main()