def get_colors(self): def rd_tables(file_in): out_table = [] # set up blank array to hold the elements elements = 0 infile = open(file_in, "r") # open the input file for reading rows = infile.readlines() # read the whole thing into a list for this_element in rows: element_values = this_element.split() out_table.append(element_values[:3]) elements = len(out_table) return out_table, elements # Read in the colour definitions artemis_col = get_conf("artemis_cols") (col_codes, nr_col) = rd_tables(artemis_col + "colourdef.sig.cfg") translation = dict(col_codes) # import pdb; pdb.set_trace() # Convert to dictionary # col_cod = dict(col_codes) # Read in the observatory colour tags (obs_col, nr_obs) = rd_tables(artemis_col + "colours.sig.cfg") couleurs = np.array(obs_col) couleurs = couleurs[:, [0, 2]] couleurs = couleurs.tolist() # couleurs=dict(couleurs[::1]) cooleurs = [[i[0], translation[i[1]]] for i in couleurs] # import pdb; pdb.set_trace() self.colors = dict(cooleurs)
def plot_it(event): artemis = get_conf('artemis') Plot=MLPlots.MLplots(event) Plot.path_lightcurves(artemis+'data/') Plot.path_models(artemis+'model/') Plot.load_models() Plot.set_data_limits() Plot.load_data() Plot.find_survey() Plot.align_data() Plot.set_plot_limits() Plot.get_colors() script, div = Plot.plot_data() return script, div
import os import sys from local_conf import get_conf robonet_site = get_conf('robonet_site') sys.path.append(robonet_site) os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'robonet_site.settings') from django.core import management from django.conf import settings from django.utils import timezone from django import setup import time from numpy import linspace,arange from datetime import datetime, timedelta from astropy import units as u from astropy.time import Time from astropy.coordinates import SkyCoord, EarthLocation, AltAz, ICRS from astropy.coordinates import get_sun from scipy.interpolate import interp1d setup() from events.models import Operator, Telescope, Instrument, Filter, Event, EventName, SingleModel, BinaryModel from events.models import RobonetReduction, RobonetRequest, RobonetStatus, DataFile, Tap, Image from update_db_2 import * import warnings warnings.filterwarnings('ignore',module='astropy.coordinates') # Estimate the total visibility of the bulge for all three sites (in hours) def blg_visibility(mlsites=['CPT','COJ','LSC']): vis=0. for site in mlsites: lonrobo=float(Telescope.objects.filter(site=site).values('longitude')[0]['longitude'])*u.deg
# -*- coding: utf-8 -*- """ Created on Mon May 8 10:59:08 2017 @author: rstreet """ from os import getcwd, path, remove, environ from sys import path as systempath, argv cwd = getcwd() systempath.append(path.join(cwd, '..')) from local_conf import get_conf app_config = get_conf('mulens_tom') systempath.append(app_config) environ.setdefault('DJANGO_SETTINGS_MODULE', 'mulens_tom.settings') from django.core import management from django.conf import settings from django.utils import timezone from django import setup from datetime import datetime, timedelta import pytz setup() import ingest, observing_strategy from tom.models import Target import lco_interface, observing_strategy, log_utilities, ingest def get_test_obs(simulate=False): """Function to return an example of an ObsRequest with default parameters for testing purposes"""
def show_event(request, event_id): from local_conf import get_conf site_url = get_conf('site_url') """ Will set up a single event page and display the lightcurve. """ time_now = datetime.now() time_now_jd = Time(time_now).jd possible_status = { 'CH':'check', 'AC':'active', 'AN':'anomaly', 'RE':'rejected', 'EX':'expired'} try: ev_ra = Event.objects.get(pk=event_id).ev_ra ev_dec = Event.objects.get(pk=event_id).ev_dec ev_names = EventName.objects.filter(event_id=event_id) flag = 0 ev_ogle, ev_moa, ev_kmt = '', '', '' for name in ev_names: if 'OGLE' in name.name and flag==0: ev_ogle = name.name flag = 1 if 'MOA' in name.name: ev_moa = name.name if 'KMT' in name.name: ev_kmt = name.name # Get the names for this event ID from all surveys # Keep just one so that we can generate the url link to /microlensing.zah.uni-heidelberg.de if 'ev_ogle': ev_name = ev_ogle survey_name = "OGLE" event_number = ev_name.split('-')[-1] elif 'ev_moa': ev_name = ev_moa survey_name = "MOA" event_number = ev_name.split('-')[-1] elif 'ev_kmt': ev_name = ev_kmt survey_name = "KMT" event_number = ev_name.split('-')[-1] #discussion = "https://microlensing.zah.uni-heidelberg.de/index.php#filter=1&%s&all&%s" % (survey_name, event_number) discussion = "https://microlensing.zah.uni-heidelberg.de/index.php?page=1&filterSurvey=%s&filterStatus=all&minMag=all&searchById=%s" % (survey_name, event_number) # Get list of all observations and select the one with the most recent time. try: event = Event.objects.get(id=event_id) single_recent = SingleModel.objects.select_related().filter(event=event).values().latest('last_updated') obs_recent = DataFile.objects.select_related().filter(event=event).values().latest('last_obs') #status_recent = RobonetStatus.objects.select_related().filter(event=event).values().latest('timestamp') status_recent = Event.objects.get(pk=event_id).status last_obs = obs_recent['last_obs'] last_obs_hjd = Time(last_obs).jd tel_id = obs_recent['datafile'].split('/')[-1].split('_') if len(tel_id) == 2: tel_id = tel_id[0]+'_' else: tel_id = obs_recent['datafile'].split('/')[-1][0] last_obs_tel = site_dict[tel_id][-1] Tmax = single_recent['Tmax'] e_Tmax = single_recent['e_Tmax'] tau = single_recent['tau'] e_tau = single_recent['e_tau'] umin = single_recent['umin'] e_umin = single_recent['e_umin'] last_updated = single_recent['last_updated'] last_updated_hjd = Time(last_updated).jd status = status_recent ogle_url = '' if "OGLE" in ev_name: ogle_url = 'http://ogle.astrouw.edu.pl/ogle4/ews/%s/%s.html' % (ev_name.split('-')[1], 'blg-'+ev_name.split('-')[-1]) except: last_obs = "N/A" last_obs_hjd = "N/A" Tmax = "N/A" e_Tmax = "N/A" tau = "N/A" e_tau = "N/A" umin = "N/A" e_umin = "N/A" last_updated = "N/A" last_updated_hjd = "N/A" last_obs_tel = "N/A" status = 'EX' ogle_url = '' # Convert the name to ARTEMiS format for bokeh plotting if 'OGLE' in ev_name: artemis_name = 'OB'+ev_name.split('-')[1][2:]+ev_name.split('-')[-1] elif 'MOA' in ev_name: artemis_name = 'KB'+ev_name.split('-')[1][2:]+ev_name.split('-')[-1] elif 'KMT' in ev_name: artemis_name = 'KM'+ev_name.split('-')[1][2:]+ev_name.split('-')[-1] else: artemis_name = 'UNKNOWN EVENT' try: script, div = plot_it(artemis_name) except: script, div = '', 'Detected empty or corrupt datafile in list of lightcurve files.<br>Plotting disabled.' context = {'event_id':event_id, 'event_name':ev_names, 'site_url':site_url, 'ev_ra':ev_ra, 'ev_dec':ev_dec, 'discussion':discussion, 'last_obs':last_obs, 'Tmax':Tmax, 'e_Tmax':e_Tmax, 'tau':tau, 'e_tau':e_tau, 'umin':umin, 'e_umin':e_umin, 'last_updated':last_updated, 'last_updated_hjd':last_updated_hjd, 'last_obs':last_obs, 'last_obs_hjd':last_obs_hjd, 'status':possible_status[status], 'last_obs_tel':last_obs_tel, 'ogle_url':ogle_url, 'time_now': time_now, 'time_now_jd': time_now_jd, 'the_script': script, 'the_div': div} except Event.DoesNotExist: raise Http404("Event does not exist.") return render(request, 'events/show_event.html', context)
from .models import Operator, Telescope, Instrument, Filter, Event, EventName, SingleModel, BinaryModel, RobonetReduction, RobonetRequest, RobonetStatus, DataFile, Tap, Image from itertools import chain from django.http import HttpResponse, Http404 from astropy.time import Time from datetime import datetime, timedelta from bokeh.plotting import figure from bokeh.resources import CDN from bokeh.embed import components import sys, os #sys.path.append('/home/Tux/ytsapras/robonet_site/scripts/') sys.path.append(os.getcwd()+'/scripts/') from plotter import * # Path to ARTEMiS files artemis_col = get_conf('artemis_cols') # Color & site definitions for plotting colors = artemis_col+"colours.sig.cfg" colordef = artemis_col+"colourdef.sig.cfg" # Path to save offline plotly plots #plotly_path = "/home/Tux/ytsapras/robonet_site/events/static/events/" # Set up and populate dictionaries col_dict = {} site_dict = {} with open(colors) as f: for line in f: elem = line.split() key = elem[0]
import numpy as np import matplotlib.pyplot as plt import glob from bokeh.plotting import figure, show, output_file, gridplot, vplot from bokeh.resources import CDN from bokeh.embed import components from bokeh.models import PrintfTickFormatter, HoverTool, BoxZoomTool, PanTool, WheelZoomTool, PreviewSaveTool, ResetTool from local_conf import get_conf artemis = get_conf("artemis") class MLplots: def __init__(self, name): self.lightcurves_path = "" self.models_path = "" self.telescopes = [] self.lightcurves = [] self.aligned_lightcurves = [] self.models = [] self.plot_limits = [] self.survey = [] self.colors = [] self.name = name self.data_limits = [] def path_lightcurves(self, directory): self.lightcurves_path = directory def path_models(self, directory): self.models_path = directory