Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Bokeh filter Keyword in NRS TA Monitors #1620

Merged
merged 6 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1304,7 +1304,7 @@ def plt_mags_time(self):
""",
)
self.date_range.js_on_change("value", callback)
mini_view = CDSView(filters=[self.date_filter])
mini_view = CDSView(filter=self.date_filter)

# create the bokeh plot
plot = figure(
Expand Down Expand Up @@ -1408,14 +1408,18 @@ def setup_date_range(self):
return indices;
""",
)
self.date_view = CDSView(filters=[self.date_filter])
self.date_view = CDSView(filter=self.date_filter)

def mk_plt_layout(self):
"""Create the bokeh plot layout"""
self.query_results = pd.DataFrame(
list(NIRSpecMsataStats.objects.all().values())
)
self.source = ColumnDataSource(data=self.query_results)
def mk_plt_layout(self, plot_data):
"""Create the bokeh plot layout

Parameters
----------
plot_data : pandas.DateFrame
Pandas data frame of data to plot.
"""

self.source = ColumnDataSource(data=plot_data)

# add a time array to the data source
self.add_time_column()
Expand Down Expand Up @@ -1815,8 +1819,14 @@ def run(self):
# Add MSATA data to stats table.
self.add_msata_data()

# Generate plot -- the database is queried in mk_plt_layout().
self.mk_plt_layout()
# Query results and convert into pandas df.
self.query_results = pd.DataFrame(
list(NIRSpecMsataStats.objects.all().values())
)

# Generate plot
self.mk_plt_layout(self.query_results)

logging.info(
"\tNew output plot file will be written as: {}".format(
self.output_file_name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -797,13 +797,18 @@ def setup_date_range(self):
return indices;
""",
)
self.date_view = CDSView(filters=[filt])
self.date_view = CDSView(filter=filt)

def mk_plt_layout(self):
"""Create the bokeh plot layout"""
self.query_results = pd.DataFrame(list(NIRSpecWataStats.objects.all().values()))
def mk_plt_layout(self, plot_data):
"""Create the bokeh plot layout

self.source = ColumnDataSource(data=self.query_results)
Parameters
----------
plot_data : pandas.DataFrame
Dataframe of data to plot in bokeh
"""

self.source = ColumnDataSource(data=plot_data)

# add a time array to the data source
self.add_time_column()
Expand Down Expand Up @@ -1144,8 +1149,10 @@ def run(self):
# Add WATA data to stats table.
self.add_wata_data()

# Generate plot -- the database is queried in mk_plt_layout().
self.mk_plt_layout()
# Get Results from database table
self.query_results = pd.DataFrame(list(NIRSpecWataStats.objects.all().values()))
# Generate plot.
self.mk_plt_layout(self.query_results)
logging.info(
"\tNew output plot file will be written as: {}".format(
self.output_file_name
Expand Down
167 changes: 167 additions & 0 deletions jwql/tests/test_nrs_ta_plotting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
"""Test NRS TA (WATA & MSATA) plotting bokeh routines.

Author
______
- Mees Fix
"""

import datetime
import pandas as pd


from jwql.instrument_monitors.nirspec_monitors.ta_monitors.msata_monitor import MSATA
from jwql.instrument_monitors.nirspec_monitors.ta_monitors.wata_monitor import WATA


def test_nrs_msata_bokeh():
test_row = {
"id": 1,
"filename": "filename",
"date_obs": datetime.datetime(
1990, 11, 15, 20, 28, 59, 8000, tzinfo=datetime.timezone.utc
),
"visit_id": "visit_id",
"tafilter": "tafilter",
"detector": "detector",
"readout": "readout",
"subarray": "subarray",
"num_refstars": 1,
"ta_status": "ta_status",
"v2halffacet": 1.0,
"v3halffacet": 1.0,
"v2msactr": 1.0,
"v3msactr": 1.0,
"lsv2offset": 1.0,
"lsv3offset": 1.0,
"lsoffsetmag": 1.0,
"lsrolloffset": 1.0,
"lsv2sigma": 1.0,
"lsv3sigma": 1.0,
"lsiterations": 1,
"guidestarid": 1,
"guidestarx": 1.0,
"guidestary": 1.0,
"guidestarroll": 1.0,
"samx": 1.0,
"samy": 1.0,
"samroll": 1.0,
"box_peak_value": [
1.0,
1.0,
],
"reference_star_mag": [
1.0,
1.0,
],
"convergence_status": [
"convergence_status",
"convergence_status",
],
"reference_star_number": [
1,
1,
],
"lsf_removed_status": [
"lsf_removed_status",
"lsf_removed_status",
],
"lsf_removed_reason": [
"lsf_removed_reason",
"lsf_removed_reason",
],
"lsf_removed_x": [
1.0,
1.0,
],
"lsf_removed_y": [
1.0,
1.0,
],
"planned_v2": [
1.0,
1.0,
],
"planned_v3": [
1.0,
1.0,
],
"stars_in_fit": 1,
"entry_date": datetime.datetime(
1990, 11, 15, 20, 28, 59, 8000, tzinfo=datetime.timezone.utc
),
}

df = pd.DataFrame([test_row])
monitor = MSATA()
monitor.output_file_name = "msata_output.html"
monitor.mk_plt_layout(df)


def test_nrs_wata_bokeh():
test_row = {
"id": 1,
"filename": "filename",
"date_obs": datetime.datetime(
1990, 11, 15, 20, 28, 59, 8000, tzinfo=datetime.timezone.utc
),
"visit_id": "visit_id",
"tafilter": "tafilter",
"readout": "readout",
"ta_status": "ta_status",
"star_name": 1,
"star_ra": 1.0,
"star_dec": 1.0,
"star_mag": 1.0,
"star_catalog": 1,
"planned_v2": 1.0,
"planned_v3": 1.0,
"stamp_start_col": 1,
"stamp_start_row": 1,
"star_detector": "star_detector",
"max_val_box": 1.0,
"max_val_box_col": 1,
"max_val_box_row": 1,
"iterations": 1,
"corr_col": 1,
"corr_row": 1,
"stamp_final_col": 1.0,
"stamp_final_row": 1.0,
"detector_final_col": 1.0,
"detector_final_row": 1.0,
"final_sci_x": 1.0,
"final_sci_y": 1.0,
"measured_v2": 1.0,
"measured_v3": 1.0,
"ref_v2": 1.0,
"ref_v3": 1.0,
"v2_offset": 1.0,
"v3_offset": 1.0,
"sam_x": 1.0,
"sam_y": 1.0,
"entry_date": datetime.datetime(
1990, 11, 15, 20, 28, 59, 8000, tzinfo=datetime.timezone.utc
),
"nrsrapid_f140x": [
1.0
], # Not in DB but added to column source data in algorithm, adding here
"nrsrapid_f110w": [
1.0
], # Not in DB but added to column source data in algorithm, adding here
"nrsrapid_clear": [
1.0
], # Not in DB but added to column source data in algorithm, adding here
"nrsrapidd6_f140x": [
1.0
], # Not in DB but added to column source data in algorithm, adding here
"nrsrapidd6_f110w": [
1.0
], # Not in DB but added to column source data in algorithm, adding here
"nrsrapidd6_clear": [
1.0
], # Not in DB but added to column source data in algorithm, adding here
}

df = pd.DataFrame([test_row])
monitor = WATA()
monitor.output_file_name = "wata_output.html"
monitor.mk_plt_layout(df)
Loading