Example #1
0
    def __init__(self, aoi_tile, model, questionnaire_model, **kwargs):

        # link the ios to the tile
        self.model = model
        self.questionnaire_model = questionnaire_model
        self.aoi_tile = aoi_tile

        self.table = cw.LayerTable(aoi_tile)

        # create the txt
        self.txt = sw.Markdown(cm.custom.desc)

        self.reset_to_recipe = sw.Btn(
            text=cm.custom.recipe.apply,
            icon="mdi-download",
            class_="ml-2",
            color="success",
        )

        # build the tile
        super().__init__("manual_widget",
                         cm.custom.title,
                         inputs=[self.txt, self.table],
                         **kwargs)

        # js behaviours
        self.table.observe(self._on_item_change, "change_model")
Example #2
0
    def __init__(self, aoi_tile, model, result_tile):

        # gather the model objects
        self.aoi_model = aoi_tile.view.model
        self.model = model

        # add the result_tile map to attributes
        self.m = result_tile.m
        self.tile = result_tile

        # create the widgets
        mkd = sw.Markdown(cm.process_txt)

        # create the tile
        super().__init__(
            "compute_widget",
            cm.tile.launch,
            inputs=[mkd],
            btn=sw.Btn(cm.launch_btn, class_="mt-5"),
            alert=sw.Alert(),
        )

        # link the js behaviours
        self.btn.on_event("click", self._launch_fcdm)
        aoi_tile.view.observe(self._update_geometry, "updated")
Example #3
0
    def __init__(self, io, nb_class):

        # gather the io
        self.io = io

        # create the widgets
        self.file = sw.FileInput(['.tif', '.tiff'])
        self.classes = [
            v.Select(label=cp.convert[nb_class]['label'][i],
                     items=None,
                     v_model=None,
                     chips=True,
                     multiple=True) for i in range(nb_class)
        ]
        requirements = sw.Markdown(cm.requirement[nb_class])

        # bind it to the io
        self.output = sw.Alert().bind(self.file, self.io, 'file')
        for i in range(nb_class):
            self.output.bind(self.classes[i], self.io,
                             cp.convert[nb_class]['io'][i])

        # create the btn
        btn = sw.Btn("Convert the imag classes")

        super().__init__(self.io.tile_id,
                         "Select map classes",
                         inputs=[requirements, self.file] + self.classes,
                         output=self.output,
                         btn=btn)

        # bind js event
        btn.on_event('click', self._on_click)
        self.file.observe(self._on_change, 'v_model')
Example #4
0
    def __init__(self, aoi_tile, questionnaire_tile):

        # gather the io
        self.layer_model = questionnaire_tile.layer_model
        self.aoi_model = aoi_tile.view.model
        self.question_model = questionnaire_tile.question_model

        # gather the tiles that need to be filled
        self.aoi_tile = aoi_tile
        self.questionnaire_tile = questionnaire_tile

        # add the naming textField
        self.w_name = v.TextField(label=cm.custom.recipe.name, v_model=None)

        # link the widget to the model
        self.question_model.bind(self.w_name, "recipe_name")

        # create the layer list widget
        self.layers_recipe = cw.layerRecipe().hide()
        mkd = sw.Markdown("  \n".join(cm.valid.txt))

        # add the recipe loader
        self.reset_to_recipe = sw.Btn(text=cm.custom.recipe.apply,
                                      icon="mdi-download",
                                      class_="ml-2")
        self.file_select = sw.FileInput([".json"], cp.result_dir,
                                        cm.custom.recipe.file)
        ep = v.ExpansionPanels(
            class_="mt-5",
            children=[
                v.ExpansionPanel(children=[
                    v.ExpansionPanelHeader(disable_icon_rotate=True,
                                           children=[cm.custom.recipe.title]),
                    v.ExpansionPanelContent(
                        children=[self.file_select, self.reset_to_recipe]),
                ])
            ],
        )

        # create the tile
        super().__init__(
            id_="compute_widget",
            inputs=[ep, mkd, self.w_name, self.layers_recipe],
            title=cm.valid.title,
            btn=sw.Btn(cm.valid.display, class_="ma-1"),
            alert=sw.Alert(),
        )

        # decorate the custom recipe btn
        self.load_recipe = su.loading_button(self.alert,
                                             self.reset_to_recipe,
                                             debug=True)(self.load_recipe)

        # js behaviours
        aoi_tile.view.observe(self._recipe_placeholder, "updated")
        self.btn.on_event("click", self._validate_data)
        self.reset_to_recipe.on_event("click", self.load_recipe)
        self.w_name.on_event("blur", self._normalize_name)
    def __init__(self):

        txt = sw.Markdown(cm.dashboard.theme.txt)

        # create the tile
        super().__init__(
            id_="dashboard_widget",
            title=cm.dashboard.theme.title,
        )
Example #6
0
    def __init__(self, io, nb_class):

        # gather the io
        self.io = io

        # create the download layout
        self.down_test = sw.Btn(cm.bin.default.btn,
                                icon="mdi-cloud-download-outline",
                                small=True,
                                outlined=True,
                                class_="ma-5")
        tooltip = sw.Tooltip(widget=self.down_test,
                             tooltip=cm.bin.default.tooltip)

        # create the widgets

        self.file = sw.FileInput(['.tif', '.tiff'])
        self.classes = [
            v.Select(label=cp.convert[nb_class]['label'][i],
                     items=None,
                     v_model=None,
                     chips=True,
                     small_chips=True,
                     multiple=True,
                     dense=True,
                     deletable_chips=True)
            for i in range(len(cp.convert[nb_class]['label']))
        ]
        requirements = sw.Markdown(cm.requirement[nb_class])

        # bind it to the io
        self.output = sw.Alert().bind(self.file, self.io, 'file')
        for i in range(len(cp.convert[nb_class]['label'])):
            self.output.bind(self.classes[i], self.io,
                             cp.convert[nb_class]['io'][i])

        # create the btn
        btn = sw.Btn(cm.bin.btn)

        super().__init__(
            self.io.tile_id,
            cm.bin.title,
            inputs=[tooltip, v.Divider(), requirements, self.file] +
            self.classes,
            output=self.output,
            btn=btn)

        # bind js event
        btn.on_event('click', self._on_click)
        self.file.observe(self._on_change, 'v_model')
        self.down_test.on_event('click', self._on_download)
Example #7
0
 def __init__(self):
     
     # create the widget 
     file_input = sw.FileInput(extentions=[''])
     txt = sw.Markdown("here I will add a lot of explanations")
     
     # create the actual tile
     super().__init__(
         'folder_tile',
         "Select folder",
         inputs = [txt, file_input],
         output = sw.Alert(),
         btn = sw.Btn("validate this folder")
     )
Example #8
0
 def __init__(self):
     
     # create the widgets 
     txt = sw.Markdown(cm.table.test.txt) 
     self.alert = sw.Alert()
     
     # create the tile
     super().__init__(
         id_ = 'file_widget',
         title = cm.table.test.title,
         alert = self.alert,
         btn = sw.Btn(cm.table.test.btn, outlined=True, small=True),
         inputs = [txt]
     )
     
     # js behaviour 
     self.btn.on_event('click', self._import_test_file)
    def __init__(self, model, aoi_model):

        # gather models
        self.model = model
        self.aoi_model = aoi_model

        # create a result tile
        self.result_tile = sw.Tile('gfc_export_tile', "Results", inputs=[''])

        super().__init__("gfc_export_tile",
                         "Export the data",
                         btn=sw.Btn('Export data'),
                         alert=sw.Alert(),
                         inputs=[sw.Markdown(cm.gfc.txt)])

        # add js behaviour
        self.btn.on_event('click', self._on_click)
Example #10
0
    def __init__(self):

        with cp.eula_md.open() as f:
            licence = f.read()
        mkd = sw.Markdown(licence)
        text = v.CardText(children=[mkd])

        btn = v.CardActions(children=[sw.Btn(cm.app.licence.btn)])

        self.card = v.Card(children=[btn, v.Divider(), text, v.Divider(), btn])

        super().__init__(value=not self._is_gwb(),
                         max_width='1000px',
                         children=[self.card],
                         persistent=True)

        # link the btn behaviour
        btn.on_event('click', self._set_gwb)
Example #11
0
    def __init__(self, ex_model, viz_model, tb_model, result_tile):

        # gather model
        self.ex_model = ex_model,
        self.viz_model = viz_model
        self.tb_model = tb_model

        # gather the result tile
        self.result_tile = result_tile

        # create widgets
        txt = sw.Markdown('  \n'.join(cm.export.txt))

        super().__init__(id_='export_widget',
                         title=cm.export.title,
                         btn=sw.Btn(cm.export.btn),
                         alert=cw.CustomAlert(),
                         inputs=[txt])

        # js behaviour
        self.btn.on_event('click', self._export_data)
    def dev_set_summary(self, json_themes_values, aoi_names, colors):
        benefits_layer = []
        constraints_layer = []
        costs_layer = []

        for k, val in json_themes_values.items():
            for layer in json_themes_values[k]:
                if k == "name":
                    # have name column as it will be good to add this while displaying at some point
                    continue
                name = layer
                try:
                    values = json_themes_values[k][layer]["values"]
                    if k == "benefits":
                        benefits_layer.append(
                            cw.LayerFull(name, values, aoi_names[::-1], colors)
                        )
                    elif k == "costs":
                        costs_layer.append(
                            cw.LayerFull(name, values, aoi_names[::-1], colors)
                        )
                    elif k == "constraints":
                        constraints_layer.append(
                            cw.LayerPercentage(name, values, colors)
                        )

                except Exception as e:
                    print(name, "not found", e)
                    continue

        benefits = v.Html(tag="h2", children=["Benefits"])
        benefits_txt = sw.Markdown("  \n".join(cm.dashboard.theme.benefit))

        costs = v.Html(tag="h2", children=["Costs"])
        costs_txt = sw.Markdown("  \n".join(cm.dashboard.theme.cost))

        constraints = v.Html(tag="h2", children=["Constraints"])
        constraints_txt = sw.Markdown("  \n".join(cm.dashboard.theme.constraint))

        # create an expansion panel to store everything
        ep = v.ExpansionPanels(
            children=[
                v.ExpansionPanel(
                    children=[
                        v.ExpansionPanelHeader(children=[benefits]),
                        v.ExpansionPanelContent(
                            children=[benefits_txt] + benefits_layer
                        ),
                    ]
                ),
                v.ExpansionPanel(
                    children=[
                        v.ExpansionPanelHeader(children=[costs]),
                        v.ExpansionPanelContent(children=[costs_txt] + costs_layer),
                    ]
                ),
                v.ExpansionPanel(
                    children=[
                        v.ExpansionPanelHeader(children=[constraints]),
                        v.ExpansionPanelContent(
                            children=[constraints_txt] + constraints_layer
                        ),
                    ]
                ),
            ]
        )

        self.set_content([ep])

        return self
    def __init__(self, questionnaire_tile, aoi_model, area_tile, theme_tile):

        # add the explanation
        mkd = sw.Markdown("  \n".join(cm.map.txt))

        # create a save widget
        self.save = cw.ExportMap()

        # create the map
        self.m = sm.SepalMap(dc=True).hide_dc()
        self.m.add_control(WidgetControl(widget=self.save, position="topleft"))
        self.m.add_colorbar(colors=cp.red_to_green, vmin=1, vmax=5)

        # create a window to display AOI information
        self.html = HTML()
        self.html.layout.margin = "0em 2em 0em 20em"
        control = WidgetControl(widget=self.html, position="bottomright")
        self.m.add_control(control)

        # drawing managment
        self.draw_features = deepcopy(self.EMPTY_FEATURES)
        self.colors = []
        self.name_dialog = cw.CustomAoiDialog()

        # create a layout with 2 btn
        self.map_btn = sw.Btn(cm.compute.btn, class_="ma-2")
        self.compute_dashboard = sw.Btn(cm.map.compute_dashboard,
                                        class_="ma-2",
                                        disabled=True)

        # models
        self.layer_model = questionnaire_tile.layer_model
        self.question_model = questionnaire_tile.question_model
        self.aoi_model = aoi_model

        # create the shape loader
        self.load_shape = cw.LoadShapes()

        # get the dashboard tile
        self.area_tile = area_tile
        self.theme_tile = theme_tile

        # init the final layers
        self.wlc_outputs = None
        self.area_dashboard = None
        self.theme_dashboard = None

        # create the tile
        super().__init__(
            id_="map_widget",
            title=cm.map.title,
            inputs=[mkd, self.load_shape, self.m, self.name_dialog],
            alert=sw.Alert(),
            btn=v.Layout(children=[self.map_btn, self.compute_dashboard]),
        )

        # decorate the function
        self._compute = su.loading_button(self.alert, self.map_btn,
                                          debug=True)(self._compute)
        self._dashboard = su.loading_button(self.alert,
                                            self.compute_dashboard,
                                            debug=True)(self._dashboard)

        # add js behaviour
        self.compute_dashboard.on_event("click", self._dashboard)
        self.m.dc.on_draw(self._handle_draw)
        self.map_btn.on_event("click", self._compute)
        self.load_shape.btn.on_event("click", self._load_shapes)
        self.name_dialog.observe(self.save_draw, "value")
Example #14
0
    def set_inputs(self):

        root_dir = os.path.expanduser('~')

        # select type
        self.select_type = v.Select(items=available_drivers,
                                    label=ms.SELECT_TYPE,
                                    v_model=None)

        # start/end line
        self.start_picker = sw.DatePicker('Start', xs6=True)
        self.output.bind(self.start_picker, self.io, 'start')

        self.end_picker = sw.DatePicker('End', xs6=True)
        self.output.bind(self.end_picker, self.io, 'end')

        self.picker_line = v.Layout(
            xs=12, row=True, children=[self.start_picker, self.end_picker])

        # local text
        self.local_txt = sw.Markdown(ms.LOCAL_TXT)

        # date file
        self.select_date_file = sw.FileInput(['.tif', '.tiff'],
                                             label=ms.SELECT_DATE_FILE)
        self.output.bind(self.select_date_file, self.io, 'date_file')

        # alert file
        self.select_alerts_file = sw.FileInput(['.tif', '.tiff'],
                                               label=ms.SELECT_ALERTS_FILE)
        self.output.bind(self.select_alerts_file, self.io, 'alert_file')

        def update_asset_bands(widget, event, data, dropdown, obj, variable):

            setattr(obj.io, variable, widget.v_model)
            obj.output.add_msg(f"You selected: {widget.v_model}")

            # read and add the bands to the dropdown
            try:
                ee_image = ee.ImageCollection(widget.v_model).first()
                dropdown.items = [
                    band['id'] for band in ee_image.getInfo()['bands']
                ]
            except Exception as e:
                obj.output.add_msg(str(e), 'error')
            return

        # gee text
        self.gee_txt = sw.Markdown(ms.GEE_TXT)

        # date asset
        self.select_date_asset = v.TextField(
            xs8=True,
            label=ms.SELECT_DATE_ASSET,
            placeholder='users/[username]/[asset_name]',
            v_model=None)
        self.select_date_asset_band = v.Select(xs4=True,
                                               class_='pl-5',
                                               label='band',
                                               items=None,
                                               v_model=None)
        self.output.bind(self.select_date_asset_band, self.io,
                         'asset_date_band')
        self.select_date_asset.on_event(
            'change',
            partial(update_asset_bands,
                    dropdown=self.select_date_asset_band,
                    obj=self,
                    variable='date_asset'))

        self.asset_date_line = v.Layout(
            class_='pa-5',
            xs12=True,
            row=True,
            children=[self.select_date_asset, self.select_date_asset_band])

        # alert asset
        self.select_alerts_asset = v.TextField(
            label=ms.SELECT_ALERTS_ASSET,
            placeholder='users/[username]/[asset_name]',
            v_model=None)
        self.select_alerts_asset_band = v.Select(xs4=True,
                                                 class_='pl-5',
                                                 label='band',
                                                 items=None,
                                                 v_model=None)
        self.output.bind(self.select_alerts_asset_band, self.io,
                         'asset_alerts_band')
        self.select_alerts_asset.on_event(
            'change',
            partial(update_asset_bands,
                    dropdown=self.select_alerts_asset_band,
                    obj=self,
                    variable='alert_asset'))

        self.asset_alerts_line = v.Layout(
            class_='pa-5',
            xs12=True,
            row=True,
            children=[self.select_alerts_asset, self.select_alerts_asset_band])

        return self
Example #15
0
    def __init__(self, *args, **kwargs):

        self.class_ = "pa-4"
        self._metadata = {"mount_id": "reclassify"}

        super().__init__(*args, **kwargs)

        # Class parameters

        self.root_dir = None
        self.class_path = None
        self.workspace()

        #         self.alert_dialog = Dialog(transition=False)
        self.alert_dialog = sw.Alert().hide()

        title = v.CardTitle(children=[cm.reclassify.title])
        description = v.CardText(
            class_="py-0", children=[sw.Markdown(cm.reclassify.description)])

        self.customize_class = CustomizeTile(self.class_path)
        self.w_class_file = v.Select(label="Select a classes file",
                                     v_model="",
                                     dense=True)

        self.get_table_btn = sw.Btn("Get reclassify table", class_="mb-2")
        self.save_raster_btn = sw.Btn("Reclassify", class_="my-2").hide()

        self.get_items()

        self.w_select_raster = sw.FileInput([".tif"], label="Search raster")
        self.w_reclassify_table = ReclassifyTable().show()

        tabs_titles = ["Reclassify", "Customize classification"]
        tab_content = [
            v.Card(children=[
                title,
                description,
                self.w_select_raster,
                self.w_class_file,
                self.get_table_btn,
                self.w_reclassify_table,
                self.save_raster_btn,
                self.alert_dialog,
            ]),
            self.customize_class,
        ]

        self.children = [Tabs(tabs_titles, tab_content)]

        # Decorate functions
        self.reclassify_and_save = loading_button(
            self.save_raster_btn, self.alert_dialog)(self.reclassify_and_save)
        self.get_reclassify_table = loading_button(
            self.get_table_btn, self.alert_dialog)(self.get_reclassify_table)

        # Events
        self.get_table_btn.on_event("click", self.get_reclassify_table)
        self.save_raster_btn.on_event("click", self.reclassify_and_save)

        # Refresh tables
        self.customize_class.observe(self.get_items, "classes_files")
Example #16
0
    def __init__(self, *args, **kwargs):

        self.class_ = 'pa-4'
        self._metadata = {'mount_id': 'reclassify'}

        super().__init__(*args, **kwargs)

        # Class parameters

        self.root_dir = None
        self.class_path = None
        self.workspace()

        #         self.alert_dialog = Dialog(transition=False)
        self.alert_dialog = sw.Alert().hide()

        title = v.CardTitle(children=[cm.reclassify.title])
        description = v.CardText(
            class_='py-0', children=[sw.Markdown(cm.reclassify.description)])

        self.customize_class = CustomizeTile(self.class_path)
        self.w_class_file = v.Select(label='Select a classes file',
                                     v_model='',
                                     dense=True)

        self.get_table_btn = sw.Btn('Get reclassify table', class_='mb-2')
        self.save_raster_btn = sw.Btn('Reclassify', class_='my-2').hide()

        self.get_items()

        self.w_select_raster = sw.FileInput(['.tif'], label='Search raster')
        self.w_reclassify_table = ReclassifyTable().show()

        tabs_titles = ['Reclassify', 'Customize classification']
        tab_content = [
            v.Card(children=[
                title,
                description,
                self.w_select_raster,
                self.w_class_file,
                self.get_table_btn,
                self.w_reclassify_table,
                self.save_raster_btn,
                self.alert_dialog,
            ]), self.customize_class
        ]

        self.children = [Tabs(tabs_titles, tab_content)]

        # Decorate functions
        self.reclassify_and_save = loading_button(
            self.save_raster_btn, self.alert_dialog)(self.reclassify_and_save)
        self.get_reclassify_table = loading_button(
            self.get_table_btn, self.alert_dialog)(self.get_reclassify_table)

        # Events
        self.get_table_btn.on_event('click', self.get_reclassify_table)
        self.save_raster_btn.on_event('click', self.reclassify_and_save)

        # Refresh tables
        self.customize_class.observe(self.get_items, 'classes_files')
Example #17
0
    def __init__(self, model, nb_class):

        # gather the model
        self.model = model

        # create the download layout
        mkd_txt = sw.Markdown(cm.bin.default.tooltip)
        self.down_test = sw.Btn(
            cm.bin.default.btn,
            icon="mdi-cloud-download-outline",
            small=True,
            outlined=True,
            class_="mb-5",
        )

        # create the widgets
        file = v.Html(tag="h3", children=[cm.bin.file])
        self.file = sw.FileInput([".tif", ".tiff", ".vrt"])
        self.band = v.Select(label=cm.bin.band, items=None, v_model=None)
        reclassify = v.Html(tag="h3", children=[cm.bin.classes], class_="mb-3")
        self.classes = [
            v.Select(
                label=cp.convert[nb_class]["label"][i],
                items=None,
                v_model=[],
                chips=True,
                small_chips=True,
                multiple=True,
                dense=True,
                deletable_chips=True,
            ) for i in range(len(cp.convert[nb_class]["label"]))
        ]
        requirements = sw.Markdown(cm.requirement[nb_class])

        # bind it to the model
        self.model.bind(self.file, "file")
        for i in range(len(cp.convert[nb_class]["label"])):
            self.model.bind(self.classes[i], cp.convert[nb_class]["io"][i])

        super().__init__(
            self.model.tile_id,
            cm.bin.title,
            inputs=[
                mkd_txt,
                self.down_test,
                v.Divider(),
                requirements,
                file,
                self.file,
                self.band,
                reclassify,
                *self.classes,
            ],
            alert=sw.Alert(),
            btn=sw.Btn(cm.bin.btn),
        )

        # bind js event
        self.btn.on_event("click", self._on_click)
        self.file.observe(self._on_change, "v_model")
        self.band.observe(self._on_valid_band, "v_model")
        self.down_test.on_event("click", self._on_download)
    def __init__(self, aoi_view, layer_model):

        # get the models
        self.aoi_model = aoi_view.model
        self.layer_model = layer_model

        # name the tile
        title = cm.constraints.title
        id_ = "nested_widget"

        # write a quick explaination
        tile_txt = sw.Markdown(cm.constraints.desc)

        # read the layer list and find the layer information based on the layer name
        layer_list = pd.read_csv(cp.layer_list).fillna("")

        # create the criteria list
        self.criterias = []
        for key, c in cp.criterias.items():

            layer_row = layer_list[layer_list.layer_id == c["layer"]]
            unit = layer_row.unit.values[0]
            header = c["header"]
            value = c["content"]
            id_ = c["layer"]
            hint = cm.constraints.info[c["tooltip"]].format(key)

            if value == "BINARY":  # binary criteria
                crit = cw.Binary(key, header, id_=id_, hint=hint)
            elif isinstance(value, list):  # dropdown values
                crit = cw.Dropdown(key, value, header, id_=id_, hint=hint)
            elif value == "RANGE":  # range values
                crit = cw.Range(key, header, unit, id_=id_, hint=hint)

            self.criterias.append(crit)

        # create each expansion-panel content
        self.panels = v.ExpansionPanels(
            focusable=True,
            v_model=None,
            hover=True,
            accordion=True,
            children=[
                cw.CustomPanel(k, self.criterias)
                for k in cp.criteria_types.keys()
            ],
        )

        # default custom_v_model
        default_v_model = {c.name: c.custom_v_model for c in self.criterias}
        self.custom_v_model = json.dumps(default_v_model)

        # cration of the tile
        super().__init__(id_, title, inputs=[tile_txt, self.panels])

        # hide the tile border
        self.children[0].elevation = 0

        # link the visibility of each criteria to the select widget
        [c.observe(self._on_change, "custom_v_model") for c in self.criterias]
        self.panels.observe(self._on_panel_change, "v_model")
        aoi_view.observe(self._update_constraints, "updated")