def __init__(self, aoi_model, model, **kwargs): # gather the model self.aoi_model = aoi_model self.model = model # widgets self.visSelect = v.RadioGroup( v_model=pm.layer_select[0]["value"], children=[ v.Radio( # key=e['key'], label=e["label"], value=e["value"], ) for e in pm.layer_select ], ) # add the widgets self.m = sm.SepalMap() # bindings self.model.bind(self.visSelect, "viz") # construct the Tile with the widget we have initialized super().__init__( id_= "visualization_widget", # the id will be used to make the Tile appear and disapear title=ms.visualization. title, # the Title will be displayed on the top of the tile inputs=[self.visSelect, self.m], # self.asset, alert=sw.Alert(), ) self.visSelect.observe(self._on_change, "v_model")
def __init__(self, model, aoi_model, viz_tile, export_tile, **kwargs): # Define the model and the aoi_model as class attribute so that they can be manipulated in its custom methods self.model = model self.aoi_model = aoi_model # LINK to the result tile self.viz_tile = viz_tile self.export_tile = export_tile # WIDGETS self.year_beg = v.Select( label=cm.process.slider_b, v_model=None, items=[i for i in range(pm.max_year, pm.min_year - 1, -1)], ) self.year_end = v.Select( label=cm.process.slider_e, v_model=None, items=[i for i in range(pm.max_year, pm.min_year - 1, -1)], ) self.type_tmf = v.RadioGroup( row=True, v_model=pm.layer_select[0]["value"], children=[ v.Radio(key=e["key"], label=e["label"], value=e["value"]) for e in pm.layer_select ], ) # self.type_tmf.observe(self._on_change, 'v_model') # Create the alert alert self.model.bind(self.year_beg, "year_beg").bind( self.year_end, "year_end").bind(self.type_tmf, "type_tmf") # construct the Tile with the widget we have initialized super().__init__( id_= "process_widget", # the id will be used to make the Tile appear and disapear title=cm.process. title, # the Title will be displayed on the top of the tile inputs=[self.year_beg, self.year_end, self.type_tmf], btn=sw.Btn(cm.process.validate, "mdi-check", disabled=False, class_="ma-5"), alert=sw.Alert(), ) # now that the Tile is created we can link it to a specific function self.btn.on_event("click", self._on_run)
def __init__(self, statement, choices): # get number of choices self.num_choices = len(choices) self.choices = choices # Shuffle answers self.indices = [i for i in range(self.num_choices)] random.shuffle(self.indices) self.correct = self.indices.index(0) # Define CSS properties to make text larger display(HTML("<style>.large_font { font-size: 100% }</style>")) display(HTML("<style>.xlarge_font { font-size: 120% }</style>")) # store the statement in a widget self.statement = w.HTMLMath(value=statement) # enlarge text self.statement.add_class("xlarge_font") # Create labels for each answer choice answers = [ w.Label(value=self.choices[self.indices[i]]) for i in range(self.num_choices) ] # Enlarge text for labels for a in answers: a.add_class("large_font") # Create radio buttons with answers as labels (slots) self.choice_buttons = v.RadioGroup(v_model=None, children=[ v.Radio(v_slots=[{ 'name': 'label', 'children': [a] }]) for a in answers ]) # Create a submit button self.check_button = v.Btn(color='primary', children=['Check Answer']) # If button is clicked, check the currently selected answer self.check_button.on_event("click", self.on_click_submit) # Create a feedback area self.feedback = w.Output()
def __init__(self): # init the downloadable informations self.geometry = None self.dataset = None self.name = None self.aoi_name = None # create the useful widgets self.w_scale = v.Slider( v_model=30, # align on the landsat images min=10, max=300, thumb_label=True, step=10, ) self.w_method = v.RadioGroup( v_model="gee", row=True, children=[ v.Radio(label=cm.export.radio.sepal, value="sepal"), v.Radio(label=cm.export.radio.gee, value="gee"), ], ) self.alert = sw.Alert() self.btn = sw.Btn(cm.export.apply, small=True) export_data = v.Card(children=[ v.CardTitle( children=[v.Html(tag="h4", children=[cm.export.title])]), v.CardText(children=[ v.Html(tag="h4", children=[cm.export.scale]), self.w_scale, v.Html(tag="h4", children=[cm.export.radio.label]), self.w_method, self.alert, ]), v.CardActions(children=[self.btn]), ]) # the clickable icon self.download_btn = v.Btn( v_on="menu.on", color="primary", icon=True, children=[v.Icon(children=["mdi-cloud-download"])], ) super().__init__( value=False, close_on_content_click=False, nudge_width=200, offset_x=True, children=[export_data], v_slots=[{ "name": "activator", "variable": "menu", "children": self.download_btn }], ) # add js behaviour self.btn.on_event("click", self._apply)
def __init__(self): # init the downloadable informations self.geometry = None self.names = [] self.datasets = {} # create the useful widgets self.w_scale = v.Slider( class_="mt-5", v_model=30, # align on the landsat images, ticks="always", tick_labels=[ str(i) if i in self.TICKS_TO_SHOW else "" for i in range(10, 301, 10) ], min=10, max=300, thumb_label=True, step=10, ) self.w_prefix = v.TextField( label=cm.export.name, small=True, dense=True, v_model=None, ) self.w_datasets = v.Select( dense=True, small=True, label=cm.export.datasets, v_model=None, items=[*self.datasets], multiple=True, chips=True, ) self.w_method = v.RadioGroup( v_model="gee", row=True, children=[ v.Radio(label=cm.export.radio.sepal, value="sepal"), v.Radio(label=cm.export.radio.gee, value="gee"), ], ) self.alert = sw.Alert() self.btn = sw.Btn(cm.export.apply, small=True) export_data = v.Card(children=[ v.CardTitle( children=[v.Html(tag="h4", children=[cm.export.title])]), v.CardText(children=[ self.w_prefix, self.w_datasets, v.Html(tag="h4", children=[cm.export.scale]), self.w_scale, v.Html(tag="h4", children=[cm.export.radio.label]), self.w_method, self.alert, ]), v.CardActions(children=[self.btn]), ]) # the clickable icon self.w_down = v.Btn( v_on="menu.on", color="primary", icon=True, children=[v.Icon(children=["mdi-cloud-download"])], ) super().__init__( value=False, close_on_content_click=False, nudge_width=200, offset_x=True, children=[export_data], v_slots=[{ "name": "activator", "variable": "menu", "children": self.w_down }], ) # add js behaviour self.btn.on_event("click", self._apply)
def __init__(self, viz_model, tb_model): # gather model self.viz_model = viz_model self.tb_model = tb_model # Create alert self.alert = sw.Alert() # create the widgets self.driver = v.RadioGroup( label = cm.viz.driver, row= True, v_model = self.viz_model.driver, children = [ v.Radio(key=i, label=n, value=n) for i, n in enumerate(cp.drivers) ] ) self.sources = v.Select( items=cp.sources, label=cm.viz.sources, v_model=self.viz_model.sources, multiple=True, chips=True ) self.planet_key = sw.PasswordField( label = cm.planet.key_label ).hide() self.semester = v.RadioGroup( label = cm.viz.semester, row= True, v_model = None, children = [ v.Radio(label=cp.planet_semesters[n], value=n) for n in [*cp.planet_date_ranges[cp.planet_min_start_year]] ] ) su.hide_component(self.semester) self.bands = v.Select( items=[*cp.getAvailableBands()], label=cm.viz.bands, v_model=self.viz_model.bands ) self.start = v.Select( class_='mr-5 ml-5', items=[ y for y in range(cp.gee_min_start_year, cp.gee_max_end_year+1) ], label=cm.viz.start_year, v_model=self.viz_model.start_year ) self.end = v.Select( class_='ml-5 mr-5', items=[y for y in range(cp.gee_min_start_year, cp.gee_max_end_year+1) ], label=cm.viz.end_year, v_model=self.viz_model.end_year ) years = v.Layout( xs=12, row=True, children=[self.start, self.end] ) image_size = v.Slider( step=500, min=cp.min_image, max=cp.max_image, label=cm.viz.image_size, v_model=self.viz_model.image_size, thumb_label='always', class_='mt-5' ) square_size = v.Slider( step=10, min=cp.min_square, max=cp.max_square, label=cm.viz.square_size, v_model=self.viz_model.square_size, thumb_label='always', class_='mt-5' ) # bind the inputs self.viz_model.bind(self.sources, 'sources') \ .bind(self.planet_key, 'planet_key') \ .bind(self.bands, 'bands') \ .bind(self.start, 'start_year') \ .bind(self.end, 'end_year') \ .bind(self.driver, 'driver') \ .bind(image_size, 'image_size') \ .bind(square_size, 'square_size') \ .bind(self.semester, 'semester') # create the tile super().__init__( id_ = "viz_widget", title = cm.viz.title, btn = sw.Btn(cm.viz.btn), inputs = [ self.driver, self.sources, self.planet_key, self.bands, years, self.semester, image_size, square_size ], alert = self.alert ) # js behaviour self.btn.on_event('click', self._display_data) self.driver.observe(self._on_driver_change, 'v_model')
def radio_buttons(choices, row=False, v_model=None, label=None, hint=None, persistent_hint=False, class_='px-2 my-0 py-2', style_=None, **kwargs): """ Radio Button input field Function to generate an ipyvuetify Radio Buttons input widget. The value of the widget can be accessed or modified by the `v_model` property of the return value. See the vuetify documention for other arguments that can be passed as keyword arguments: https://vuetifyjs.com/en/components/selection-controls/ Parameters: choices : list or dict Choices to appear in radio button v_model : str (optional, default None) Value of the time input, must be an element of choices row : bool If True choices will be displayed in a row, otherwise in a column label : str (optional, default None) Description of the input hint : str or callable (optional, default None) Hint text or function generating int based on input value for validating input persistent_hint : bool (optional, default False) Set to True to display the hint when widget is not focused class_ : str (optional, default None) ipyvuetify HTML class string style_ : str (optional, default None) ipyvuetify HTML CSS string **kwargs Other arguments supported by ipyvuetify.TextField Returns: ipyvuetify.TextInput An ipyvuetify time input widget """ ret = ipyvuetify.RadioGroup( class_=class_, style_=style_, v_model=v_model, label=label, hint=hint, persistent_hint=persistent_hint, row=row, children=[]) # Set other keyword arguments for arg in kwargs: setattr(ret, arg, kwargs[arg]) if isinstance(choices,list): ret.children = [ipyvuetify.Radio(label=i, value=i) for i in choices] elif isinstance(choices,dict): ret.children = [ipyvuetify.Radio(label=i, value=choices[i]) for i in choices] else: raise Exception("choices must be a dict or a list") # If no default is given, set it to the first if v_model is None: ret.v_model = choices[0] # Return widget return ret
def doe_driver_change(): """ Adapt widgets & vbox widgets to only display widgets you need in this driver """ self.vboxdriver.children[0].children = [] self.vboxdriver.children[1].children = [] drive = driver.doe_driver.DOEDriver() def onchangegenerator(widget, event, data): """ A function which start the function you need for your generator """ if data == "DOEGenerator": doe_generator() elif data == "ListGenerator": list_generator() elif data == "CSVGenerator": csv_generator() elif data == "UniformGenerator": uniform_generator() elif data == "_pyDOE_Generator": pydoe_generator() elif data == "FullFactorialGenerator": full_factorial_generator() elif data == "GeneralizedSubsetGenerator": generalized_subset_generator() elif data == "PlackettBurmanGenerator": plackett_burman_generator() elif data == "BoxBehnkenGenerator": box_behnken_generator() elif data == "LatinHypercubeGenerator": latin_hypercube_generator() self.generator = v.Select( items=[ "DOEGenerator", "ListGenerator", "CSVGenerator", "UniformGenerator", "_pyDOE_Generator", "FullFactorialGenerator", "GeneralizedSubsetGenerator", "PlackettBurmanGenerator", "BoxBehnkenGenerator", "LatinHypercubeGenerator", ], v_model="DOEGenerator", label="Generator :", outlined=True, style_="width:500px;margin-top:5px", ) self.vboxgenerator.children[0].children = [self.generator] self.generator.on_event("change", onchangegenerator) procspermodeldoe = v.TextField( v_model=drive.options.__dict__["_dict"]["procs_per_model"].get("value"), min=drive.options.__dict__["_dict"]["procs_per_model"].get("lower"), max=100, label="Processors per model :", outlined=True, type='number', style_='width:500px;margin-top:5px' ) runparalleldoe = v.Checkbox( v_model=drive.options.__dict__["_dict"]["run_parallel"].get("value"), label="Run parallel", outlined=True, type='number', style_='width:500px;margin-left:50px' ) drive = driver.doe_generators.DOEGenerator() def doe_generator(): """ Adapt widgets & vbox widgets to only display widgets you need in this generator """ self.vboxdoedriver.children[0].children = [procspermodeldoe] self.vboxdoedriver.children[1].children = [runparalleldoe] drive = driver.doe_generators.ListGenerator() _data = v.TextField( v_model="[]", label="List of collections of name :", outlined=True, style_='width:500px;margin-top:5px' ) def list_generator(): """ Adapt widgets & vbox widgets to only display widgets you need in this generator """ self.vboxdoedriver.children[0].children = [_data, runparalleldoe] self.vboxdoedriver.children[1].children = [procspermodeldoe] _filename = v.TextField( label="File name :", outlined=True, style_='width:500px;margin-top:5px' ) def csv_generator(): """ Adapt widgets & vbox widgets to only display widgets you need in this generator """ self.vboxdoedriver.children[0].children = [_filename, runparalleldoe] self.vboxdoedriver.children[1].children = [procspermodeldoe] drive = driver.doe_generators.UniformGenerator() _num_samples = v.TextField( v_model=drive.__dict__["_num_samples"], min=0, max=100, label="Number of samples :", outlined=True, type='number', style_='width:500px;margin-top:5px' ) _seeduniform = v.TextField( v_model=drive.__dict__["_seed"], min=0, max=100, label="Seed :", outlined=True, type='number', style_='width:500px;margin-left:50px;margin-top:5px', ) def uniform_generator(): """ Adapt widgets & vbox widgets to only display widgets you need in this generator """ self.vboxdoedriver.children[0].children = [_num_samples, procspermodeldoe] self.vboxdoedriver.children[1].children = [_seeduniform, runparalleldoe] drive = driver.doe_generators._pyDOE_Generator() def onchangelevels(widget, event, data): """ A function which change the type of the levels widget ( Int or Dict ) """ if self.generator.v_model == '_pyDOE_Generator': drive = drive = driver.doe_generators._pyDOE_Generator() if data == "Int": _levelspydoe = v.TextField( v_model=drive.__dict__["_levels"], label="Levels :", min=0, max=1000, outlined=True, type='number', style_='width:500px;margin-top:27px' ) elif data == "Dict": _levelspydoe = v.TextField( v_model="[]", label="Levels :", outlined=True, style_='width:500px;margin-top:27px' ) self.vboxdoedriver.children[1].children = [_levelspydoe, procspermodeldoe] elif self.generator.v_model == 'FullFactorialGenerator': drive = driver.doe_generators.FullFactorialGenerator() if data == "Int": _levelsfull = v.TextField( v_model=drive.__dict__["_levels"], label="Levels :", min=0, max=1000, outlined=True, type='number', style_='width:500px;margin-top:27px' ) elif data == "Dict": _levelsfull = v.TextField( v_model="[]", label="Levels :", outlined=True, style_='width:500px;margin-top:27px' ) self.vboxdoedriver.children[1].children = [_levelsfull, procspermodeldoe] elif self.generator.v_model == 'PlackettBurmanGenerator': drive = driver.doe_generators.PlackettBurmanGenerator() if data == "Int": _levelsplackett = v.TextField( v_model=drive.__dict__["_levels"], label="Levels :", min=0, max=1000, outlined=True, type='number', style_='width:500px;margin-top:27px' ) elif data == "Dict": _levelsplackett = v.TextField( v_model="[]", label="Levels :", outlined=True, style_='width:500px;margin-top:27px' ) self.vboxdoedriver.children[1].children = [_levelsplackett, procspermodeldoe] elif self.generator.v_model == 'BoxBehnkenGenerator': drive = driver.doe_generators.BoxBehnkenGenerator() if data == "Int": _levelsbox = v.TextField( v_model=drive.__dict__["_levels"], label="Levels :", min=0, max=1000, outlined=True, type='number', style_='width:500px;margin-top:27px' ) elif data == "Dict": _levelsbox = v.TextField( v_model="[]", label="Levels :", outlined=True, style_='width:500px;margin-top:27px' ) self.vboxdoedriver.children[1].children = [_levelsbox, procspermodeldoe] selectlevels = v.RadioGroup( children=[ v.Radio(label='Int', value='Int'), v.Radio(label='Dict', value='Dict'), ], v_model="Int", label="Levels type :", ) selectlevels.on_event('change', onchangelevels) _levelspydoe = v.TextField( v_model=drive.__dict__["_levels"], label="Levels :", min=0, max=1000, outlined=True, type='number', style_='width:500px;margin-top:27px' ) _sizespy = v.TextField( v_model=drive.__dict__["_sizes"], min=0, max=100, label="Sizes :", outlined=True, type='number', style_='width:500px' ) def pydoe_generator(): """ Adapt widgets & vbox widgets to only display widgets you need in this generator """ self.vboxdoedriver.children[0].children = [selectlevels, _sizespy, runparalleldoe] self.vboxdoedriver.children[1].children = [_levelspydoe, procspermodeldoe] drive = driver.doe_generators.FullFactorialGenerator() _levelsfull = v.TextField( v_model=drive.__dict__["_levels"], label="Levels :", min=0, max=1000, outlined=True, type='number', style_='width:500px;margin-top:27px' ) _sizesfull = v.TextField( v_model=drive.__dict__["_sizes"], min=0, max=100, label="Sizes :", outlined=True, type='number', style_='width:500px' ) def full_factorial_generator(): """ Adapt widgets & vbox widgets to only display widgets you need in this generator """ self.vboxdoedriver.children[0].children = [selectlevels, _sizesfull, runparalleldoe] self.vboxdoedriver.children[1].children = [_levelsfull, procspermodeldoe] def generalized_subset_generator(): """ Adapt widgets & vbox widgets to only display widgets you need in this generator """ self.vboxdoedriver.children[0].children = [procspermodeldoe] self.vboxdoedriver.children[1].children = [runparalleldoe] drive = driver.doe_generators.PlackettBurmanGenerator() _levelsplackett = v.TextField( v_model=drive.__dict__["_levels"], label="Levels :", min=0, max=1000, outlined=True, type='number', style_='width:500px;margin-top:27px' ) _sizesplackett = v.TextField( v_model=drive.__dict__["_sizes"], min=0, max=100, label="Sizes :", outlined=True, type='number', style_='width:500px' ) def plackett_burman_generator(): """ Adapt widgets & vbox widgets to only display widgets you need in this generator """ self.vboxdoedriver.children[0].children = [selectlevels, _sizesplackett, runparalleldoe] self.vboxdoedriver.children[1].children = [_levelsplackett, procspermodeldoe] drive = driver.doe_generators.BoxBehnkenGenerator() _levelsbox = v.TextField( v_model=drive.__dict__["_levels"], label="Levels :", min=0, max=1000, outlined=True, type='number', style_='width:500px;margin-top:27px;margin-left:50px' ) _sizesbox = v.TextField( v_model=drive.__dict__["_sizes"], min=0, max=100, label="Sizes :", outlined=True, type='number', style_='width:500px' ) _center = v.TextField( v_model=drive.__dict__["_center"], min=0, max=100, label="Center :", type='number', outlined=True, style_='width:500px;margin-top:5px;margin-left:50px' ) def box_behnken_generator(): """ Adapt widgets & vbox widgets to only display widgets you need in this generator """ self.vboxdoedriver.children[0].children = [selectlevels, _sizesbox, procspermodeldoe] self.vboxdoedriver.children[1].children = [_levelsbox, _center, runparalleldoe] drive = driver.doe_generators.LatinHypercubeGenerator() _samples = v.TextField( v_model=drive.__dict__["_samples"], min=0, max=100, label="Number of samples to generate :", type='number', outlined=True, style_="width:500px;margin-top:5px", ) _criterion = v.Select( items=["None", "center", "maximin", "centermaximin", "correlation"], v_model=drive.__dict__["_criterion"], label="Criterion :", outlined=True, style_="width:500px;margin-top:5px;margin-left:50px", ) _iterations = v.TextField( v_model=drive.__dict__["_iterations"], min=0, max=100, label="Iterations :", outlined=True, type='number', style_="width:500px;margin-top:5px", ) _seedlatin = v.TextField( v_model=drive.__dict__["_seed"], min=0, max=100, label="Seed :", outlined=True, type='number', style_="width:500px;margin-top:5px;margin-left:50px", ) def latin_hypercube_generator(): """ Adapt widgets & vbox widgets to only display widgets you need in this generator """ self.vboxdoedriver.children[0].children = [_samples, _iterations, procspermodeldoe] self.vboxdoedriver.children[1].children = [_criterion, _seedlatin, runparalleldoe] doe_generator()