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 NRS TA Monitor Plotting #1633

Merged
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 @@ -1431,7 +1431,6 @@ def mk_plt_layout(self, plot_data):
self.setup_date_range()

# set the output html file name and create the plot grid
output_file(self.output_file_name)
p1 = self.plt_status()
p2 = self.plt_residual_offsets()
p3 = self.plt_res_offsets_corrected()
Expand All @@ -1452,11 +1451,8 @@ def mk_plt_layout(self, plot_data):
merge_tools=False,
)
box_layout = layout(children=[self.date_range, grid])
save(box_layout)

# return the needed components for embedding the results in the MSATA html template
script, div = components(box_layout)
return script, div
self.script, self.div = components(box_layout)

def identify_tables(self):
"""Determine which database tables to use for a run of the TA monitor."""
Expand Down Expand Up @@ -1720,6 +1716,17 @@ def add_msata_data(self):

logging.info("\tUpdated the MSATA statistics table")

def plots_for_app(self):
"""Utility function to access div and script objects for
embedding bokeh in JWQL application.
"""
# 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)

@log_fail
@log_info
def run(self):
Expand All @@ -1730,20 +1737,8 @@ def run(self):
# Identify which database tables to use
self.identify_tables()

# Get the output directory and setup a directory to store the data
self.output_dir = os.path.join(get_config()["outputs"], "msata_monitor")
ensure_dir_exists(self.output_dir)
# Set up directory to store the data
ensure_dir_exists(os.path.join(self.output_dir, "data"))
self.data_dir = os.path.join(
self.output_dir,
"data/{}_{}".format(self.instrument.lower(), self.aperture.lower()),
)
ensure_dir_exists(self.data_dir)

# Locate the record of most recent time the monitor was run
self.query_start = self.most_recent_search()
self.output_file_name = os.path.join(self.output_dir, "msata_layout.html")

# Use the current time as the end time for MAST query
self.query_end = Time.now().mjd
Expand Down Expand Up @@ -1819,25 +1814,10 @@ def run(self):
# Add MSATA data to stats table.
self.add_msata_data()

# 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
)
)
# Once data is added to database table and plots are made, the
# monitor has run successfully.
monitor_run = True
logging.info(
"\tOutput html plot file created: {}".format(self.output_file_name)
)

msata_files_used4plots = len(self.msata_data["visit_id"])
logging.info(
"\t{} MSATA files were used to make plots.".format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,6 @@ def mk_plt_layout(self, plot_data):
self.setup_date_range()

# set the output html file name and create the plot grid
output_file(self.output_file_name)
p1 = self.plt_status()
p2 = self.plt_residual_offsets()
p3 = self.plt_v2offset_time()
Expand All @@ -831,11 +830,8 @@ def mk_plt_layout(self, plot_data):
# make grid
grid = gridplot([p1, p2, p3, p4, p5, p6], ncols=2, merge_tools=False)
box_layout = layout(children=[self.date_range, grid])
save(box_layout)

# return the needed components for embeding the results in the WATA html template
script, div = components(box_layout)
return script, div
self.script, self.div = components(box_layout)

def file_exists_in_database(self, filename):
"""Checks if an entry for filename exists in the wata stats
Expand Down Expand Up @@ -1052,6 +1048,17 @@ def add_wata_data(self):

logging.info("\tUpdated the WATA statistics table")

def plots_for_app(self):
"""Utility function to access div and script objects for
embedding bokeh in JWQL application.
"""
# Query results and convert into pandas df.
self.query_results = pd.DataFrame(
list(NIRSpecWataStats.objects.all().values())
)
# Generate plot
self.mk_plt_layout(self.query_results)

@log_fail
@log_info
def run(self):
Expand All @@ -1062,20 +1069,8 @@ def run(self):
# Identify which database tables to use
self.identify_tables()

# Get the output directory and setup a directory to store the data
self.output_dir = os.path.join(get_config()["outputs"], "wata_monitor")
ensure_dir_exists(self.output_dir)
# Set up directories for the copied data
ensure_dir_exists(os.path.join(self.output_dir, "data"))
self.data_dir = os.path.join(
self.output_dir,
"data/{}_{}".format(self.instrument.lower(), self.aperture.lower()),
)
ensure_dir_exists(self.data_dir)

# Locate the record of most recent time the monitor was run
self.query_start = self.most_recent_search()
self.output_file_name = os.path.join(self.output_dir, "wata_layout.html")

# Use the current time as the end time for MAST query
self.query_end = Time.now().mjd
Expand Down Expand Up @@ -1149,15 +1144,6 @@ def run(self):
# Add WATA data to stats table.
self.add_wata_data()

# 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
)
)
# Once data is added to database table and plots are made, the
# monitor has run successfully.
monitor_run = True
Expand Down
18 changes: 8 additions & 10 deletions jwql/website/apps/jwql/monitor_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,13 +342,12 @@ def msata_monitoring_ajax(request):
JsonResponse object
Outgoing response sent to the webpage
"""
# retrieve existing monitor html content
# Make plots and extract visualization components
monitor = msata_monitor.MSATA()
div, script1, script2 = monitor.read_existing_html()
monitor.plots_for_app()

context = {'script1': script1,
'script2': script2,
'div': div}
context = {'script': monitor.script,
'div': monitor.div}

return JsonResponse(context, json_dumps_params={'indent': 2})

Expand Down Expand Up @@ -391,12 +390,11 @@ def wata_monitoring_ajax(request):
JsonResponse object
Outgoing response sent to the webpage
"""
# retrieve existing monitor html content
# Make plots and extract visualization components
monitor = wata_monitor.WATA()
div, script1, script2 = monitor.read_existing_html()
monitor.plots_for_app()

context = {'script1': script1,
'script2': script2,
'div': div}
context = {'script': monitor.script,
'div': monitor.div}

return JsonResponse(context, json_dumps_params={'indent': 2})
6 changes: 2 additions & 4 deletions jwql/website/apps/jwql/static/js/jwql.js
Original file line number Diff line number Diff line change
Expand Up @@ -1042,8 +1042,7 @@ function update_msata_page(base_url) {

// Build div content
var content = data["div"];
content += data["script1"];
content += data["script2"];
content += data["script"];

/* Add the content to the div
* Note: <script> elements inserted via innerHTML are intentionally disabled/ignored by the browser. Directly inserting script via jquery.
Expand Down Expand Up @@ -1075,8 +1074,7 @@ function update_wata_page(base_url) {

// Build div content
var content = data["div"];
content += data["script1"];
content += data["script2"];
content += data["script"];

/* Add the content to the div
* Note: <script> elements inserted via innerHTML are intentionally disabled/ignored by the browser. Directly inserting script via jquery.
Expand Down
Loading