def test_fieldSim(): """Tests the ``fieldSim`` function in the ``field_simulator`` module""" ra = '04 25 29.0162' dec = '-30 36 01.603' instrument = 'NIRISS' sim_cube = field_simulator.fieldSim(ra, dec, instrument) assert isinstance(sim_cube, np.ndarray) and len(sim_cube) > 0
def main(): """ Wrapper to the field simulator and contamination figure generator.""" # User inputs ra = input( 'Please input the Right Ascension of your target in decimal degrees (The more decimal places the better) : \n' ) # Making sure RA input is correct before we continue if (float(ra) < 0) or (float(ra) > 360): print( 'RA should be between 0 and 360 decimal degrees. Got {}. Starting over...' .format(ra)) main() dec = input( 'Please input the Declination of your target in decimal degrees (The more decimal places the better) : \n' ) # Making sure DEC input is correct if (float(dec) < -90) or (float(dec) > 90): print( 'DEC should be between -90 and +90 in decimal degrees. Got {}. Starting over...' .format(dec)) main() companion = input( 'Any companion not in IRSA`s 2MASS Point-Source Catalog that should be considered for contamination? If no, just press Enter. If yes, please enter the following (comma-separated, no spaces): \n RA offset ("), DEC offset ("), 2MASS J (mag), H (mag) and Ks (mag) \n ' ).split(',') print(len(companion)) if len(companion) == 5: binComp = [int(param) for param in companion] elif len(companion) == 1: binComp = '' elif (len(companion) < 5) & (len(companion) > 1): print('Companion information is incomplete. Starting over...') main() instrument = input( 'Please input the instrument your target will be observed with (Case-sensitive. Can be: NIRISS, MIRI, NIRCam F322W2, or NIRCam F444W) : \n' ) # Making sure the instrument input is correct before we continue possible_instruments = ['NIRISS', 'MIRI', 'NIRCam F322W2', 'NIRCam F444W'] if instrument not in possible_instruments: print( 'It looks like your last input (instrument) had a typo. The instrument input is case-sensitive and can only be NIRISS, MIRI, NIRCam F322W2, or NIRCam F444W. Starting over...' ) main() # Getting the bad PAs from visibility calculator for shading purposes instrument_vpa = instrument.split(' ')[0] paMin, paMax, gd, fig, table, grouped_badPAs = vpa.using_gtvt( ra, dec, instrument_vpa) # Converting RA, DEC from decimal degrees (ExoMAST) to HMSDMS sc = SkyCoord(ra, dec, unit='deg') ra_dec = sc.to_string('hmsdms') ra_hms, dec_dms = ra_dec.split(' ')[0], ra_dec.split(' ')[1] # Generating cube with a field for every Aperture Position Angle (APA) cube = fs.fieldSim(ra_hms, dec_dms, instrument, binComp) title_ra, title_dec = str(np.round(float(ra), 3)), str(np.round(float(dec), 3)) # Generating Bokeh figure `fig` that plots contamination levels at every APA plot = cf.contam(cube, instrument, targetName=' {}, {} (RA, DEC)'.format( title_ra, title_dec), badPAs=grouped_badPAs) show(plot)
def contam_visibility(): """The contamination and visibility form page Returns ------- ``flask.render_template`` obj The rendered template for the contamination and visibility 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 ('NIRCam' in form.inst.data) or (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 log_exoctk.log_form_input(request.form, 'contam_visibility', DB) # 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 = io.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)