From 9f773411f7880d4226058d3981ca3be013c8dc32 Mon Sep 17 00:00:00 2001 From: cjoldelo Date: Fri, 30 Jul 2021 16:32:30 -0700 Subject: [PATCH 1/2] merge --- mop/toolbox/obs_control.py | 46 +++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/mop/toolbox/obs_control.py b/mop/toolbox/obs_control.py index dc3e5ddd..244265a1 100644 --- a/mop/toolbox/obs_control.py +++ b/mop/toolbox/obs_control.py @@ -3,7 +3,7 @@ from tom_observations.cadence import CadenceForm from tom_observations.models import ObservationRecord from mop.toolbox.obs_details import all_night_moon_sep, calculate_visibility - +from astropy.time import Time from mop.toolbox import TAP import datetime from django.conf import settings @@ -216,8 +216,7 @@ def build_and_submit_phot(target, obs_type): #Probably gonna need a MUSCAT exception - start = datetime.datetime.utcnow().isoformat() - end = (datetime.datetime.utcnow()+datetime.timedelta(days=obs_duration)).isoformat() + mag_now = TAP.TAP_mag_now(target) mag_exposure = mag_now @@ -230,8 +229,11 @@ def build_and_submit_phot(target, obs_type): if telescope_class == '2m': - visible_at_muscat = calculate_visibility(target.ra, target.dec, start, end, 'OSS', max_airmass=max_airmass) - moon_sep_at_muscat = all_night_moon_sep(target.ra, target.dec, start, end, 'OSS', sample_size=75) + start = Time(datetime.datetime.utcnow()) + end = Time(datetime.datetime.utcnow()+datetime.timedelta(days=obs_duration)) + + visible_at_muscat = calculate_visibility(target.ra, target.dec, start, end, 'OGG', max_airmass=max_airmass) + moon_sep_at_muscat = all_night_moon_sep(target.ra, target.dec, start, end, 'OGG', sample_size=75) if visible_at_muscat and min(moon_sep_at_muscat[0]) >= 15: build_and_submit_muscat(target, obs_type) @@ -252,7 +254,8 @@ def build_and_submit_phot(target, obs_type): # ip alone obs_dic = {} - + start = datetime.datetime.utcnow().isoformat() + end = (datetime.datetime.utcnow()+datetime.timedelta(days=obs_duration)).isoformat() obs_dic['name'] = obs_name obs_dic['target_id'] = target.id obs_dic['start'] = start @@ -363,7 +366,6 @@ def build_and_submit_muscat(target, obs_type): #Defaults observing_type = 'IMAGING' instrument_type = '2M0-SCICAM-MUSCAT' - type = 'REPEAT_EXPOSE' proposal = os.getenv('LCO_PROPOSAL_ID') facility = 'LCO' observation_mode = 'NORMAL' @@ -416,13 +418,16 @@ def build_and_submit_muscat(target, obs_type): exposure_time_z = exposure_time_i exposure_time = max(exposure_time_g, exposure_time_r, exposure_time_i, exposure_time_z) - diffuser_g_position = 'OUT' - diffuser_r_position = 'OUT' - diffuser_i_position = 'OUT' - diffuser_z_position = 'OUT' + diffuser_g_position = 'out' + diffuser_r_position = 'out' + diffuser_i_position = 'out' + diffuser_z_position = 'out' + start = datetime.datetime.utcnow().isoformat() + end = (datetime.datetime.utcnow()+datetime.timedelta(days=obs_duration)).isoformat() obs_dic = {} # ASYNCHRONOUS MODE + obs_dic['name'] = obs_name obs_dic['target_id'] = target.id obs_dic['start'] = start @@ -431,19 +436,18 @@ def build_and_submit_muscat(target, obs_type): obs_dic['ipp_value'] = ipp obs_dic['exposure_count'] = 1 - # obs_dic['repeat_duration'​] = 14400 # 4 hours. Not sure how to make sure this happens each night - obs_dic['exposure_mode'] = 'ASYNCHRONOUS' obs_dic['exposure_time_g'] = exposure_time_g obs_dic['exposure_time_r'] = exposure_time_r obs_dic['exposure_time_i'] = exposure_time_i obs_dic['exposure_time_z'] = exposure_time_z - obs_dic['exposure_time'] = exposure_time - obs_dic['mode'] = 'MUSCAT_FAST' - obs_dic['guiding_config'] = 'ON' - obs_dic['diffuser_g_position'] = diffuser_g_position - obs_dic['diffuser_r_position'] = diffuser_r_position - obs_dic['diffuser_i_position'] = diffuser_i_position - obs_dic['diffuser_z_position'] = diffuser_z_position + + obs_dic ['diffuser_g_position'] = diffuser_g_position + obs_dic ['diffuser_r_position'] = diffuser_r_position + obs_dic ['diffuser_i_position'] = diffuser_i_position + obs_dic ['diffuser_z_position'] = diffuser_z_position + + obs_dic['guider_mode'] = 'ON' + obs_dic['exposure_mode'] = 'ASYNCHRONOUS' obs_dic['period'] = cadence obs_dic['jitter'] = jitter @@ -452,7 +456,7 @@ def build_and_submit_muscat(target, obs_type): obs_dic['proposal'] = proposal obs_dic['instrument_type'] = instrument_type obs_dic['facility'] = facility - obs_dic['type'] = type + request_obs = lco.LCOMuscatImagingObservationForm(obs_dic) From df36b4baadf23fc283eb3736277ea73c12b7df0f Mon Sep 17 00:00:00 2001 From: cjoldelo Date: Fri, 30 Jul 2021 17:16:37 -0700 Subject: [PATCH 2/2] Additions to the nav bar --- mop/urls.py | 2 + mop/views.py | 50 ++++++++++++++++++++++++ productivity/urls.py | 8 ++++ templates/productivity.html | 15 +++++++ templates/time-alloc.html | 12 ++++++ templates/tom_common/navbar_content.html | 27 +++++++++++-- time-alloc/urls.py | 8 ++++ 7 files changed, 119 insertions(+), 3 deletions(-) create mode 100644 productivity/urls.py create mode 100644 templates/productivity.html create mode 100644 templates/time-alloc.html create mode 100644 time-alloc/urls.py diff --git a/mop/urls.py b/mop/urls.py index 253fe72c..1a8cd1d4 100644 --- a/mop/urls.py +++ b/mop/urls.py @@ -20,4 +20,6 @@ urlpatterns = [ path('targets//', MOPTargetDetailView.as_view(), name='detail'), path('', include('tom_common.urls')), + path('productivity/', include(('productivity.urls', 'productivity'), namespace='productivity')), + path('time-alloc/', include(('time-alloc.urls', 'time-alloc'), namespace='time-alloc')) ] diff --git a/mop/views.py b/mop/views.py index 72d5b193..6836d0da 100644 --- a/mop/views.py +++ b/mop/views.py @@ -1,7 +1,13 @@ from django.shortcuts import redirect from django.urls import reverse from django.core.management import call_command +from django.views.generic import TemplateView +from django.shortcuts import render from io import StringIO +from plotly.graph_objs import Scatter +import plotly.offline as opy +import plotly.graph_objs as go +from tom_observations.models import Target from tom_targets.views import TargetDetailView @@ -28,3 +34,47 @@ def get(self, request, *args, **kwargs): call_command('run_TAP', target_name, stdout=out) return redirect(reverse('tom_targets:detail', args=(target_id,))) return super().get(request, *args, **kwargs) + +class ProductivityView(TemplateView): + template_name = 'productivity.html' + + def get_context_data(self, **kwargs): + context = super(ProductivityView, self).get_context_data(**kwargs) + + x = [-2,-1,0,1,2] + y = [1, 1, 1, 1, 1] + y1 = [2, 2, 2, 2, 2] + y2 = [3, 3, 3, 3, 3] + #Easy to make multiple plot lines if they are all in a pandas dataframe + #Make the colors by observatory name, but plot by stage: Not Executed, Executed, and Pending + + layout=go.Layout(title="Reqs vs Obs", xaxis={'title':'Date'}, yaxis={'title':''}, + template='simple_white') + fig = go.Figure(layout=layout) #color='name of the observatory column') + + # Add traces + fig.add_trace(go.Scatter(x=x, y=y, + mode='markers', + marker={'color': 'red', 'symbol': 100, 'size': 10}, + name='Not Executed')) + fig.add_trace(go.Scatter(x=x, y=y1, + mode='markers', + marker={'color': 'green', 'symbol': 0, 'size': 10}, + name='Executed')) + fig.add_trace(go.Scatter(x=x, y=y2, + mode='markers', + marker={'color': 'blue', 'symbol': 117, 'size': 10}, + name='Pending')) + + + div = opy.plot(fig, auto_open=False, output_type='div') + + context['graph'] = div + + return context + +class TimeAllocView(TemplateView): + template_name = 'time-alloc.html' + + def get_context_data(self, **kwargs): + return {'targets': Target.objects.all()} diff --git a/productivity/urls.py b/productivity/urls.py new file mode 100644 index 00000000..9778e3c9 --- /dev/null +++ b/productivity/urls.py @@ -0,0 +1,8 @@ +from django.urls import path, include +from django.views.generic import TemplateView +from mop.views import ProductivityView + +urlpatterns = [ + path('', include('tom_common.urls')), + path('productivity/', ProductivityView.as_view(), name='productivity') +] diff --git a/templates/productivity.html b/templates/productivity.html new file mode 100644 index 00000000..b25e9768 --- /dev/null +++ b/templates/productivity.html @@ -0,0 +1,15 @@ +{% extends 'tom_common/base.html' %} +{% block content %} + + + Test Plot + + + {% if graph %} +
+ {{ graph|safe }} +
+ {% endif %} + + +{% endblock %} diff --git a/templates/time-alloc.html b/templates/time-alloc.html new file mode 100644 index 00000000..ca952075 --- /dev/null +++ b/templates/time-alloc.html @@ -0,0 +1,12 @@ +{% extends 'tom_common/base.html' %} +{% block content %} +

+I would like to replace this with a template tag or a list template, +but it seems to be crashing at the moment :/ +

+
    + {% for target in targets %} +
  • {{ target.name }}
  • + {% endfor %} +
+{% endblock %} diff --git a/templates/tom_common/navbar_content.html b/templates/tom_common/navbar_content.html index 5a256b8c..68a3734b 100644 --- a/templates/tom_common/navbar_content.html +++ b/templates/tom_common/navbar_content.html @@ -7,7 +7,6 @@ -