Ejemplo n.º 1
0
    def test_on_file_select(self):

        sepal_ui = self._get_sepal_parent()
        file_input = sw.FileInput(folder=sepal_ui)

        # move into sepal_ui folders
        readme = sepal_ui / 'README.rst'

        file_input._on_file_select({'new': sepal_ui})

        # get all the names
        list_names = []
        for list_item in file_input.file_list.children[0].children:
            list_item_content = list_item.children[1]
            list_item_title = list_item_content.children[0]
            list_names.append(list_item_title.children[0])

        self.assertEqual(file_input.v_model, '')
        self.assertIn('README.rst', list_names)

        # select readme
        file_input._on_file_select({'new': readme})
        self.assertEqual(file_input.v_model, str(readme))

        return
Ejemplo n.º 2
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')
Ejemplo n.º 3
0
    def test_on_reload(self):

        home = Path('~').expanduser()
        file_input = sw.FileInput(folder=home)

        # create a fake file
        test_name = 'test.txt'
        tmp_file = home / test_name
        with tmp_file.open('w') as f:
            f.write('a test \n')

        # reload the folder
        file_input._on_reload(None, None, None)

        # check that the new file is in the list
        list_names = []
        for list_item in file_input.file_list.children[0].children:
            list_item_content = list_item.children[1]
            list_item_title = list_item_content.children[0]
            list_names.append(list_item_title.children[0])

        self.assertIn(test_name, list_names)

        # remove the test file
        tmp_file.unlink()

        return
Ejemplo n.º 4
0
    def __init__(self, statebar=None, **kwargs):

        super().__init__(**kwargs)

        self.gdf = None

        # Parameters
        self.out_path = Path('')
        self.json_path = None

        # Widgets
        self.shape_input = sw.FileInput(['.shp'], os.getcwd())

        self.w_state_bar = sw.StateBar(
            loading=True) if not statebar else statebar

        # Link behaviours

        link((self.shape_input, 'file'), (self, 'shapefile'))

        # View

        self.children = [v.Layout(row=True, children=[
            self.shape_input,
        ])]

        # Add a statebar if there is not provided an external one
        if not statebar: self.children = self.children + [self.w_state_bar]
Ejemplo n.º 5
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)
Ejemplo n.º 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)
Ejemplo n.º 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")
     )
Ejemplo n.º 8
0
    def test_select_file(self):

        sepal_ui = self._get_sepal_parent()
        file_input = sw.FileInput()

        # move into sepal_ui folders
        readme = sepal_ui / 'README.rst'

        file_input.select_file(readme)

        # assert that the file has been selected
        self.assertEqual(file_input.v_model, str(readme))

        return
Ejemplo n.º 9
0
    def test_init(self):

        # default init
        file_input = sw.FileInput(folder=self._get_sepal_parent())

        # init with a string
        file_input = sw.FileInput(folder=str(self._get_sepal_parent()))

        self.assertIsInstance(file_input, sw.FileInput)
        self.assertEqual(file_input.v_model, '')

        # get all the names
        list_names = []
        for list_item in file_input.file_list.children[0].children:
            list_item_content = list_item.children[1]
            list_item_title = list_item_content.children[0]
            list_names.append(list_item_title.children[0])

        self.assertIn('sepal_ui', list_names)

        # default init
        file_input = sw.FileInput(['.shp'], folder=self._get_sepal_parent())

        return
Ejemplo n.º 10
0
    def test_reset(self):

        sepal_ui = self._get_sepal_parent()
        file_input = sw.FileInput(folder=sepal_ui)

        # move into sepal_ui folders
        readme = sepal_ui / 'README.rst'

        file_input.reset()

        # assert that the folder has bee reset
        self.assertEqual(file_input.v_model, '')
        self.assertNotEqual(file_input.folder, str(sepal_ui))

        return
Ejemplo n.º 11
0
    def test_bind(self):

        file_input = sw.FileInput()

        class Test_io:
            def __init__(self):
                self.out = None

        test_io = Test_io()

        output = sw.Alert()
        output.bind(file_input, test_io, 'out')

        path = 'toto.ici.shp'
        file_input.v_model = path

        self.assertEqual(test_io.out, path)
        self.assertTrue(output.viz)

        return
Ejemplo n.º 12
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)
Ejemplo n.º 13
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
Ejemplo n.º 14
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")
Ejemplo n.º 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')