def _build_inst_form(self): imager_config = read_json(os.path.join(os.environ['pandeia_refdata'], 'wfirst', 'wfirstimager', 'config.json')) ifu_config = read_json(os.path.join(os.environ['pandeia_refdata'], 'wfirst', 'wfirstifu', 'config.json')) self.inst_select = widgets.Dropdown( description="Instrument:", options=['Imager'], value='Imager' ) im_filters = imager_config['filters'] im_readmodes = imager_config['readmodes'] im_subarrays = imager_config['subarrays'] self.filt = widgets.Dropdown( description="Filter:", options=im_filters ) self.readmode = widgets.Dropdown( description="Readmode:", options=im_readmodes ) self.subarray = widgets.Dropdown( description="Sub-array:", options=im_subarrays, ) return widgets.VBox([ self.inst_select, self.filt, self.readmode, self.subarray, ])
def _get_config(self): """ Read default configuration from JSON Returns ------- config: dict All desired class attributes should have defaults defined in the config file """ # use this trick to key the configuration file name off the name of the instantiated subclass ref_dir = os.path.join(default_refdata_directory, "sed") config = read_json(os.path.join(ref_dir, "config.json"), raise_except=True) defaults = config.pop("defaults") config.update(defaults) # nuke some unused things that are there for UI use for k in ["sed_families"]: del config[k] return config
def __init__(self, webapp=False, config={}, **kwargs): """ How an SED is configured depends on the defaults and any input configuration. Parameters ---------- webapp: bool Determines whether strict API checks should be performed config: dict Extra configuration information in engine input API dict format **kwargs: keyword/value pairs Extra configuration information in kwargs format """ SED.__init__(self, webapp=webapp, config=config, **kwargs) spectra_file = os.path.join(default_refdata_directory, "sed", self.spectra["config_all"]) self.spectra = read_json(spectra_file) self.wave, self.flux = self.get_spectrum() self.wmin = self.wave.min() self.wmax = self.wave.max()
def get_config(filename): """ read configuration data from a JSON file and create a dict using display_strings as the keys. these dicts will be used to populate pull-downs with descriptive names, but provide lookup to the values that need to be passed back to the engine. Parameters ---------- filename: string filename of JSON config file to Load Returns ------- conf: dict JSON configuration data with keys swapped out for display_strings where available. """ conf_data = read_json(filename) conf = {} for k in conf_data: if "display_string" in conf_data[k]: conf[conf_data[k]["display_string"]] = k else: conf[k] = k return conf
def __init__(self): self.r = {} self.form = widgets.VBox(width="100%", background_color="#EEE") self.src_form = widgets.HBox(padding='10px', width="100%", visible=False) self.src_select = widgets.Dropdown(description="Source type: ", options=['point', 'extended'], value='point') self.l1 = widgets.HTML(value="Scale length (arcsec): ", margin="5px") self.l2 = widgets.HTML(value="Position angle (deg): ", margin="5px") self.l3 = widgets.HTML(value="Ellipticity: ", margin="5px") self.sersic = widgets.Dropdown(description="Profile: ", options=["Gaussian", "Exponential", "de Vaucouleurs"]) self.sersic_idx = { "Gaussian": 0.5, "Exponential": 1.0, "de Vaucouleurs": 4.0 } self.ext_scale = widgets.BoundedFloatText(value=0.2, min=0.0, max=999999.0, width=70) self.ellip = widgets.BoundedFloatText(value=0.0, min=0.0, max=1.0, width=70) self.posang = widgets.BoundedFloatText(min=0.0, max=360.0, value=0.0, width=70) self.src_form.children = [self.sersic, self.l1, self.ext_scale, self.l3, self.ellip, self.l2, self.posang] self.src_select.on_trait_change(self.on_src_select, 'value') norm_form = widgets.HBox(padding='10px', width="100%") self.flux = widgets.BoundedFloatText(description="Source flux: ", min=0.0, max=1.0e30, value=1.0) self.units = widgets.Dropdown(value='ujy', options=['abmag', 'njy', 'ujy', 'mjy', 'jy']) atwave = widgets.HTML(value=" at ", margin='5px') self.wave = widgets.BoundedFloatText(min=0.1, max=99999.0, value=1.5) waveunits = widgets.HTML(value="microns", margin='5px') norm_form.children = [self.flux, self.units, atwave, self.wave, waveunits] self.units.on_trait_change(self.on_units_select, 'value') sed_form = widgets.HBox(padding='10px', width="100%") self.sed_select = widgets.Dropdown( description="SED type: ", options=['power-law', 'blackbody', 'star', 'extragalactic'], value='power-law' ) self.pl_index = widgets.FloatText(description="Index: ", value=1.0, visible=True, width=50) self.bb_temp = widgets.BoundedFloatText(description="Temp (K): ", min=0.0, max=99999.0, value=6500.0, visible=False, width=75) star_config_file = os.path.join(os.environ['pandeia_refdata'], 'sed', 'phoenix', 'spectra.json') self.star_config = get_config(star_config_file) self.stars = widgets.Dropdown(options=sorted(self.star_config.keys()), visible=False) gal_config_file = os.path.join(os.environ['pandeia_refdata'], 'sed', 'brown', 'spectra.json') self.gal_config = get_config(gal_config_file) self.galaxies = widgets.Dropdown(options=sorted(self.gal_config.keys()), visible=False) self.redshift = widgets.BoundedFloatText(description="Redshift:", min=0.0, max=99999.0, value=0.0, width=70) self.sed_select.on_trait_change(self.on_sed_select, 'value') sed_form.children = [self.sed_select, self.pl_index, self.bb_temp, self.stars, self.galaxies, self.redshift] imager_config = read_json(os.path.join(os.environ['pandeia_refdata'], 'wfirst', 'wfirstimager', 'config.json')) ifu_config = read_json(os.path.join(os.environ['pandeia_refdata'], 'wfirst', 'wfirstifu', 'config.json')) inst_form = widgets.HBox(padding='10px', width="100%") self.inst_select = widgets.Dropdown(description="Instrument: ", options=['Imager'], value='Imager') im_filters = imager_config['filters'] im_readmodes = imager_config['readmodes'] im_subarrays = imager_config['subarrays'] self.filt = widgets.Dropdown(description="Filter:", options=im_filters) self.readmode = widgets.Dropdown(description="Readmode:", options=im_readmodes) self.subarray = widgets.Dropdown(description="Sub-array:", options=im_subarrays) inst_form.children = [self.inst_select, self.filt, self.readmode, self.subarray] det_form = widgets.HBox(padding='10px', width="100%") self.ngroups = widgets.BoundedIntText(description="Groups: ", min=2, max=999, value=10, width=50) self.nints = widgets.BoundedIntText(description="Integrations: ", min=1, max=999, value=1, width=50) self.nexps = widgets.BoundedIntText(description="Exposures: ", min=1, max=999, value=1, width=50) det_form.children = [self.ngroups, self.nints, self.nexps] strat_form = widgets.VBox(padding='10px') ap_lab = widgets.HTML(value="Aperture radius (arcsec): ", margin='5px') self.ap_size = widgets.BoundedFloatText(min=0.0, max=999.0, value=0.1, width=60) self.ap_size.on_trait_change(self.check_ann, 'value') self.overplot = widgets.Checkbox(description="Overlay", value=True) self.overplot.on_trait_change(self.update_plots) hb1 = widgets.HBox(padding='10px', width="100%", children=[ap_lab, self.ap_size, self.overplot]) bg_lab = widgets.HTML(value="Background annulus radii (arcsec): ", margin='5px') self.ann_inner = widgets.BoundedFloatText(description="inner", min=0.0, max=999.0, value=0.2, width="100%") self.ann_inner.on_trait_change(self.check_ann_inner, 'value') self.ann_outer = widgets.BoundedFloatText(description="outer", min=0.0, max=999.0, value=0.3, width="100%") self.ann_outer.on_trait_change(self.check_ann_outer, 'value') hb2 = widgets.HBox(padding='10px', width="100%", children=[bg_lab, self.ann_inner, self.ann_outer]) strat_form.children = [hb1, hb2] self.calc_button = widgets.Button(description='Calculate', width="100%", background_color="#bee2c4") self.calc_button.on_click(self.run_calc) self.plot_form = widgets.HBox(padding='10px', width="100%", pack='center') self.oned_plots = { "Input Source Flux (mJy)": "target", "Input Background (MJy/sr)": "bg", "Focal Plane Rate (e-/sec/pixel)": "fp" } self.oned_units = { "target": "mJy", "bg": "MJy/sr", "fp": "e-/sec/pixel" } self.twod_plots = { "Detector (e-/sec)": "detector", "S/N": "snr", "Saturation": "saturation" } self.twod_units = { "detector": "e-/sec", "snr": "S/N", "saturation": "" } self.oned_pulldown = widgets.Dropdown( description="1D Plot", options=sorted(self.oned_plots.keys()), value="Input Source Flux (mJy)" ) self.twod_pulldown = widgets.Dropdown( description="2D Image", options=sorted(self.twod_plots.keys()), value="S/N" ) self.plot_form.children = [self.oned_pulldown, self.twod_pulldown] self.plot_form.visible = False self.oned_pulldown.on_trait_change(self.update_plots) self.twod_pulldown.on_trait_change(self.update_plots) tlab1 = widgets.HTML(value="<b>Extracted S/N: <b>", margin='5px') self.esn = widgets.HTML(value="0.0", margin='5px') tlab2 = widgets.HTML(value=" <b>Extracted Flux (e-/sec): </b>", margin='5px') self.eflux = widgets.HTML(value="0.0", margin='5px') tlab3 = widgets.HTML(value=" <b>Exposure Time (sec): <b>", margin='5px') self.etime = widgets.HTML(value="0.0", margin='5px') self.tab_form = widgets.HBox(padding='10px', width="100%", pack='center') self.tab_form.children = [tlab1, self.esn, tlab2, self.eflux, tlab3, self.etime] self.tab_form.visible = False self.form.children = [ self.src_select, self.src_form, norm_form, sed_form, inst_form, det_form, strat_form, self.calc_button, self.tab_form, self.plot_form ]