def contam_visibility(): """The contamination and visibility form page""" # Load default form form = fv.ContamVisForm() form.calculate_contam_submit.disabled = False if request.method == 'GET': # http://0.0.0.0:5000/contam_visibility?ra=24.354208334287005&dec=-45.677930555343636&target=WASP-18%20b target_name = request.args.get('target') form.targname.data = target_name ra = request.args.get('ra') form.ra.data = ra dec = request.args.get('dec') form.dec.data = dec return render_template('contam_visibility.html', form=form) # Reload page with stellar data from ExoMAST if form.resolve_submit.data: if form.targname.data.strip() != '': # Resolve the target in exoMAST try: form.targname.data = get_canonical_name(form.targname.data) data, url = get_target_data(form.targname.data) # Update the coordinates ra_deg = data.get('RA') dec_deg = data.get('DEC') # Set the form values form.ra.data = ra_deg form.dec.data = dec_deg form.target_url.data = url except: form.target_url.data = '' form.targname.errors = [ "Sorry, could not resolve '{}' in exoMAST.".format( form.targname.data) ] # Send it back to the main page return render_template('contam_visibility.html', form=form) # Reload page with appropriate mode data if form.mode_submit.data: # Update the button if form.inst.data != 'NIRISS': form.calculate_contam_submit.disabled = True else: form.calculate_contam_submit.disabled = False # Send it back to the main page return render_template('contam_visibility.html', form=form) if form.validate_on_submit() and (form.calculate_submit.data or form.calculate_contam_submit.data): try: # Log the form inputs try: log_exoctk.log_form_input(request.form, 'contam_visibility', DB) except: pass # Make plot title = form.targname.data or ', '.join( [form.ra.data, form.dec.data]) pG, pB, dates, vis_plot, table = vpa.using_gtvt( str(form.ra.data), str(form.dec.data), form.inst.data.split(' ')[0]) # Make output table vers = '0.3' today = datetime.datetime.now() fh = StringIO() fh.write('# Hi! This is your Visibility output file for... \n') fh.write('# Target: {} \n'.format(form.targname.data)) fh.write('# Instrument: {} \n'.format(form.inst.data)) fh.write('# \n') fh.write( '# This file was generated using ExoCTK v{} on {} \n'.format( vers, today)) fh.write('# Visit our GitHub: https://github.com/ExoCTK/exoctk \n') fh.write('# \n') table.write(fh, format='csv', delimiter=',') visib_table = fh.getvalue() # Format x axis day0 = datetime.date(2019, 6, 1) dtm = datetime.timedelta(days=367) #vis_plot.x_range = Range1d(day0, day0 + dtm) # TODO: Fix this so bad PAs are included pB = [] # Make plot TOOLS = 'crosshair, reset, hover, save' fig = figure(tools=TOOLS, plot_width=800, plot_height=400, x_axis_type='datetime', title=title) fh = StringIO() table.write(fh, format='ascii') visib_table = fh.getvalue() # Format x axis day0 = datetime.date(2019, 6, 1) dtm = datetime.timedelta(days=367) # Get scripts vis_js = INLINE.render_js() vis_css = INLINE.render_css() vis_script, vis_div = components(vis_plot) # Contamination plot too if form.calculate_contam_submit.data: # First convert ra and dec to HH:MM:SS ra_deg, dec_deg = float(form.ra.data), float(form.dec.data) sc = SkyCoord(ra_deg, dec_deg, unit='deg') ra_dec = sc.to_string('hmsdms') ra_hms, dec_dms = ra_dec.split(' ')[0], ra_dec.split(' ')[1] # Make field simulation contam_cube = fs.sossFieldSim(ra_hms, dec_dms, binComp=form.companion.data) contam_plot = cf.contam( contam_cube, title, paRange=[int(form.pa_min.data), int(form.pa_max.data)], badPA=pB, fig='bokeh') # Get scripts contam_js = INLINE.render_js() contam_css = INLINE.render_css() contam_script, contam_div = components(contam_plot) else: contam_script = contam_div = contam_js = contam_css = '' return render_template('contam_visibility_results.html', form=form, vis_plot=vis_div, vis_table=visib_table, vis_script=vis_script, vis_js=vis_js, vis_css=vis_css, contam_plot=contam_div, contam_script=contam_script, contam_js=contam_js, contam_css=contam_css) except IOError: #Exception as e: err = 'The following error occurred: ' + str(e) return render_template('groups_integrations_error.html', err=err) return render_template('contam_visibility.html', form=form)
def contam_visibility(): """The contamination and visibility form page""" # Load default form form = fv.ContamVisForm() form.calculate_contam_submit.disabled = False if request.method == 'GET': # http://0.0.0.0:5000/contam_visibility?ra=24.354208334287005&dec=-45.677930555343636&target=WASP-18%20b target_name = request.args.get('target') form.targname.data = target_name ra = request.args.get('ra') form.ra.data = ra dec = request.args.get('dec') form.dec.data = dec return render_template('contam_visibility.html', form=form) # Reload page with stellar data from ExoMAST if form.resolve_submit.data: if form.targname.data.strip() != '': # Resolve the target in exoMAST try: form.targname.data = get_canonical_name(form.targname.data) data, url = get_target_data(form.targname.data) # Update the coordinates ra_deg = data.get('RA') dec_deg = data.get('DEC') # Set the form values form.ra.data = ra_deg form.dec.data = dec_deg form.target_url.data = url except Exception: form.target_url.data = '' form.targname.errors = [ "Sorry, could not resolve '{}' in exoMAST.".format( form.targname.data) ] # Send it back to the main page return render_template('contam_visibility.html', form=form) # Reload page with appropriate mode data if form.mode_submit.data: # Update the button if (form.inst.data == 'MIRI') or (form.inst.data == 'NIRSpec'): form.calculate_contam_submit.disabled = True else: form.calculate_contam_submit.disabled = False # Send it back to the main page return render_template('contam_visibility.html', form=form) if form.validate_on_submit() and (form.calculate_submit.data or form.calculate_contam_submit.data): try: # Log the form inputs try: log_exoctk.log_form_input(request.form, 'contam_visibility', DB) except Exception: pass # Make plot title = form.targname.data or ', '.join( [str(form.ra.data), str(form.dec.data)]) pG, pB, dates, vis_plot, table, badPAs = vpa.using_gtvt( str(form.ra.data), str(form.dec.data), form.inst.data.split(' ')[0], targetName=str(title)) # Make output table fh = StringIO() table.write(fh, format='csv', delimiter=',') visib_table = fh.getvalue() # Get scripts vis_js = INLINE.render_js() vis_css = INLINE.render_css() vis_script, vis_div = components(vis_plot) # Contamination plot too if form.calculate_contam_submit.data: # First convert ra and dec to HH:MM:SS ra_deg, dec_deg = float(form.ra.data), float(form.dec.data) sc = SkyCoord(ra_deg, dec_deg, unit='deg') ra_dec = sc.to_string('hmsdms') ra_hms, dec_dms = ra_dec.split(' ')[0], ra_dec.split(' ')[1] # Make field simulation contam_cube = fs.fieldSim(ra_hms, dec_dms, form.inst.data, binComp=form.companion.data) contam_plot = cf.contam( contam_cube, form.inst.data, targetName=str(title), paRange=[int(form.pa_min.data), int(form.pa_max.data)], badPAs=badPAs, fig='bokeh') # Get scripts contam_js = INLINE.render_js() contam_css = INLINE.render_css() contam_script, contam_div = components(contam_plot) else: contam_script = contam_div = contam_js = contam_css = '' return render_template('contam_visibility_results.html', form=form, vis_plot=vis_div, vis_table=visib_table, vis_script=vis_script, vis_js=vis_js, vis_css=vis_css, contam_plot=contam_div, contam_script=contam_script, contam_js=contam_js, contam_css=contam_css) except Exception as e: err = 'The following error occurred: ' + str(e) return render_template('groups_integrations_error.html', err=err) return render_template('contam_visibility.html', form=form)