From 96468bf2e553a4f93a27d505690cf66700588fc8 Mon Sep 17 00:00:00 2001 From: Bradley Sappington Date: Tue, 13 Feb 2024 12:43:43 -0500 Subject: [PATCH] Revert "filter provided opd table by month" This reverts commit 2eb1fe333cf5b5d738b048bbbde0656fc7d852d2. --- webbpsf/trending.py | 116 ++++++++++++++------------------------------ 1 file changed, 37 insertions(+), 79 deletions(-) diff --git a/webbpsf/trending.py b/webbpsf/trending.py index 4ccd777b..e4700d65 100644 --- a/webbpsf/trending.py +++ b/webbpsf/trending.py @@ -339,12 +339,9 @@ def wfe_histogram_plot( pre_or_post = [] for row in opdtable1: if download_opds: - full_file_path = os.path.join( - webbpsf.utils.get_webbpsf_data_path(), - "MAST_JWST_WSS_OPDs", - row["fileName"], - ) - if "rms_wfe" not in opdtable1.colnames: + full_file_path = os.path.join(webbpsf.utils.get_webbpsf_data_path(), 'MAST_JWST_WSS_OPDs', row['fileName']) + if 'rms_wfe' not in opdtable1.colnames: + if ote_only == False: rmses.append(fits.getheader(full_file_path, ext=1)["RMS_WFE"]) elif ote_only == True: @@ -367,10 +364,10 @@ def wfe_histogram_plot( mjds = opdtable1["date_obs_mjd"] pre_or_post.append(webbpsf.mast_wss.infer_pre_or_post_correction(row)) - where_pre = ["pre" in a for a in pre_or_post] - where_post = ["post" in a for a in pre_or_post] + where_pre = ['pre' in a for a in pre_or_post] + where_post = ['post' in a for a in pre_or_post] - dates = astropy.time.Time(opdtable1["date"], format="isot") + dates = astropy.time.Time(opdtable1['date'], format='isot') # Interpolate those RMSes into an even grid over time interp_fn = scipy.interpolate.interp1d(mjds, rmses, kind="linear") @@ -385,21 +382,14 @@ def wfe_histogram_plot( figsize=(16, 10), nrows=nrows, gridspec_kw={"hspace": hspace} ) - ms = 14 # markersize + ms = 14 #markersize - axes[0].plot_date( - dates.plot_date, - np.asarray(rmses) * 1e3, - ".", - ms=ms, - ls="-", - label="Sensing visit", - ) + axes[0].plot_date(dates.plot_date, np.asarray(rmses)*1e3, '.', ms=ms, ls='-', label='Sensing visit') axes[0].xaxis.set_major_locator(matplotlib.dates.DayLocator(bymonthday=[1])) axes[0].xaxis.set_minor_locator(matplotlib.dates.DayLocator(interval=1)) - axes[0].tick_params("x", length=10, rotation=30) + axes[0].tick_params('x', length=10, rotation=30) - if mark_corrections == "lines": + if mark_corrections=='lines': # Add vertical lines for corrections icorr = 0 for i, idate in enumerate(where_post): @@ -414,18 +404,12 @@ def wfe_histogram_plot( if icorr == 0: plot.set_label("Corrections") icorr += 1 - elif mark_corrections == "triangles": - yval = (np.asarray(rmses) * 1e3).max() * 1.01 - axes[0].scatter( - dates[where_post].plot_date, - np.ones(np.sum(where_post)) * yval, - marker="v", - s=100, - color="limegreen", - label="Corrections", - ) - elif mark_corrections == "arrows": - rms_nm = np.asarray(rmses) * 1e3 + elif mark_corrections=='triangles': + yval = (np.asarray(rmses)*1e3).max() *1.01 + axes[0].scatter(dates[where_post].plot_date, np.ones(np.sum(where_post))*yval, + marker='v', s=100, color='limegreen', label='Corrections') + elif mark_corrections=='arrows': + rms_nm = np.asarray(rmses)*1e3 sub_height = fig.get_figheight() / (nrows + hspace) plot_size_points = np.asarray([fig.get_figwidth(), sub_height]) * fig.dpi @@ -434,16 +418,9 @@ def wfe_histogram_plot( np.diff(axes[0].get_ylim())[0], ] - yoffset = (1.2 * ms) * plot_size_data[1] / plot_size_points[1] - axes[0].scatter( - dates[where_post].plot_date, - rms_nm[where_post] + yoffset, - marker="v", - s=100, - color="limegreen", - label="Corrections", - zorder=99, - ) + yoffset = (1.2*ms) * plot_size_data[1] / plot_size_points[1] + axes[0].scatter(dates[where_post].plot_date, rms_nm[where_post] + yoffset, + marker='v', s=100, color='limegreen', label='Corrections', zorder=99) yoffsets = [ 0.6 * ms * plot_size_data[0] / plot_size_points[0], @@ -480,14 +457,11 @@ def wfe_histogram_plot( nbins = 100 binwidth = 1 - minbin = np.round(np.min(interp_rmses * 1e3) - binwidth) - maxbin = np.round(np.max(interp_rmses * 1e3) + binwidth) + minbin = np.round( np.min(interp_rmses*1e3) - binwidth) + maxbin = np.round( np.max(interp_rmses*1e3) + binwidth) - axes[1].set_title( - f"{fig_title} WFE Histogram from {start_date.isot[0:10]} to {end_date.isot[0:10]}", - fontsize=14, - fontweight="bold", - ) + axes[1].set_title(f"{fig_title} WFE Histogram from {start_date.isot[0:10]} to {end_date.isot[0:10]}", + fontsize=14, fontweight='bold') hist_values = axes[1].hist( interp_rmses * 1e3, @@ -530,16 +504,12 @@ def wfe_histogram_plot( if thresh: for i in [1]: if thresh <= xmax: - axes[i].axvline(thresh, color="C2", linestyle="dashed") - fractime = (interp_rmses * 1e3 < thresh).sum() / len(interp_rmses) - axes[i].text( - xmin + 0.68 * (xmax - xmin), - 0.65 * ymax, - f"{fractime*100:.1f}% of the time has \nmeasured {ylabel} WFE < {thresh}", - color="C2", - fontweight="bold", - fontsize=14, - ) + axes[i].axvline(thresh, color='C2', linestyle='dashed') + fractime = (interp_rmses*1e3 < thresh).sum()/len(interp_rmses) + axes[i].text(xmin+0.68*(xmax-xmin), 0.65*ymax, + f"{fractime*100:.1f}% of the time has \nmeasured {ylabel} WFE < {thresh}", color='C2', + fontweight='bold', fontsize=14) + # Add vertical lines for dates of PID observations if pid: @@ -1357,6 +1327,7 @@ def filter_opdtable_for_month(year, mon, opdtable): to the first one """ start_date, end_date = get_month_start_end(year, mon) + # Start a little early, such that we are going to have at least 1 WFS before the start date pre_start_date = astropy.time.Time(start_date) - astropy.time.TimeDelta(4 * u.day) opdtable = webbpsf.mast_wss.filter_opd_table( @@ -1447,16 +1418,9 @@ def get_dates_for_pid(pid, project="jwst"): return -def monthly_trending_plot( - year, - month, - verbose=True, - instrument="NIRCam", - filter="F200W", - vmax=200, - pid=None, - opdtable=None, -): + + +def monthly_trending_plot(year, month, verbose=True, instrument='NIRCam', filter='F200W', vmax=200, pid=None, opdtable=None): """Make monthly trending plot showing OPDs, mirror moves, RMS WFE, and the resulting PSF EEs year, month : integers @@ -1626,16 +1590,10 @@ def basic_show_image(image, ax, vmax=0.3, nanmask=1): #### Plot 1: Wavefront Error - axes[0].plot_date( - dates_array.plot_date, - rms_obs * 1e9, - color="C1", - ls="-", - label="Observatory WFE at NIRCam NRCA3", - ) - axes[0].plot_date( - dates_array.plot_date, rms_ote * 1e9, color="C0", ls="-", label="Telescope WFE" - ) + axes[0].plot_date(dates_array.plot_date, rms_obs * 1e9, + color='C1', ls='-', label='Observatory WFE at NIRCam NRCA3') + axes[0].plot_date(dates_array.plot_date, rms_ote * 1e9, + color='C0', ls='-', label='Telescope WFE') for ax in axes: for corr_date in correction_times: