Skip to content

Commit

Permalink
Revert "filter provided opd table by month"
Browse files Browse the repository at this point in the history
This reverts commit 2eb1fe3.
  • Loading branch information
BradleySappington committed Feb 13, 2024
1 parent 461df7e commit 96468bf
Showing 1 changed file with 37 additions and 79 deletions.
116 changes: 37 additions & 79 deletions webbpsf/trending.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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")
Expand All @@ -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):
Expand All @@ -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
Expand All @@ -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],
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 96468bf

Please sign in to comment.