def test_update_cell_dataset(self):
        store.dropAll()
        cds = CellDataSet("id")
        cells = ['P0', 'P1', 'P2', 'P3', 'P4', 'P5']

        for cell in cells:
            cds.add(CellID(cell), Data(""))
        store.insert(cds)

        cds2 = CellDataSet("id")
        cells2 = ['O0', 'O1', 'O2', 'O3', 'O4']

        for cell in cells2:
            cds2.add(CellID(cell), Data(""))
        store.update_cell_dataset(cds2)

        stored_cds = store.query_by_cell_dataset_id("id")
        num_cds = 0
        num_cells = 0
        for cds in stored_cds:
            for cell in cds.get_cells():
                assert cells2.__contains__(cell.value)
                num_cells = num_cells + 1
            num_cds = num_cds + 1
        self.assertEqual(num_cds, 1)
        self.assertEqual(num_cells, len(cells2))
        store.dropAll()
Exemple #2
0
 def to_internal_value(self, data):
     cds = CellDataSet(id='')
     for item in data:
         if not re.match(r'^[A-Za-z0-9]+$', item['cellID']):
             raise ValidationError('Incorrect format: ' + item['cellID'])
         cds.add(CellID(item['cellID']), Data(item['data']))
     return cds.cell_data_set
    def test_cell_dataset(self):
        cell_data_set = {
            'N01': (CellID('N01'), Data('test')),
            'N02': (CellID('N02'), Data('test')),
            'N03': (CellID('N03'), Data('test'))
        }

        c_dataset = CellDataSet('id', cell_data_set=cell_data_set)
        self.assertEqual(c_dataset.cell_data_set, cell_data_set)
    def test_get_cells(self):
        cells = [CellID('N01'), CellID('N02'), CellID('N03')]
        data = Data('test')
        cell_data_set = {
            cells[0].value: (cells[0], data),
            cells[1].value: (cells[1], data),
            cells[2].value: (cells[2], data)
        }

        c_dataset = CellDataSet('id', cell_data_set=cell_data_set)
        self.assertEqual(c_dataset.get_cells(), cells)
    def test_get_max_refinement(self):
        cells = [CellID('P0'), CellID('N02'), CellID('N033')]
        data = Data('test')
        cell_data_set = {
            cells[0].value: (cells[0], data),
            cells[1].value: (cells[1], data),
            cells[2].value: (cells[2], data)
        }

        c_dataset = CellDataSet('id', cell_data_set=cell_data_set)
        self.assertEqual(c_dataset.get_max_refinement(), 3)
Exemple #6
0
 def all_cell_datasets(self):
     """
     :return: List of all stored CellDatasets
     """
     cell_data_sets = []
     cell_datasets_founded = self.db.c_data_sets.find()
     for cell_dataset in cell_datasets_founded:
         cds = CellDataSet(id=cell_dataset["_id"])
         cells_in_cds_founded = self.db.cells.find({"cell_dataset_id": cell_dataset["_id"]})
         for cell in cells_in_cds_founded:
             cds.add(CellID(cell['cellID']), Data(cell["data"]))
         cell_data_sets.append(cds)
     return cell_data_sets
Exemple #7
0
 def query_by_cell_dataset_id(self, id):
     """
     :param id: identifier of the CellDataset
     :return: List of tuples with stored cells and data associated stored in the CellDataset with that id.
     """
     cell_datasets_founded = self.db.c_data_sets.find({"_id": id})
     cell_data_sets = []
     for cell_dataset in cell_datasets_founded:
         cds = CellDataSet(id=id)
         cells_in_cds_founded = self.db.cells.find({"cell_dataset_id": cell_dataset["_id"]})
         for cell in cells_in_cds_founded:
             cds.add(CellID(cell['cellID']), Data(cell["data"]))
         cell_data_sets.append(cds)
     return cell_data_sets
    def test_get_cell_data_list(self):
        cells = [CellID('P0'), CellID('N02'), CellID('N033')]
        data = Data('test')
        data2 = Data('test2')
        cell_data_set = {
            cells[0].value: (cells[0], data),
            cells[1].value: (cells[1], data),
            cells[2].value: (cells[2], data2)
        }

        c_dataset = CellDataSet('id', cell_data_set=cell_data_set)

        self.assertEqual(c_dataset.get_cell_data_list([cells[0], cells[2]]),
                         [data, data2])
    def test_delete_cell(self):
        store.dropAll()
        cds = CellDataSet("id")
        cells = ['P0', 'P1', 'P2', 'P3', 'P4', 'P5']

        for cell in cells:
            cds.add(CellID(cell), Data(""))
        store.insert(cds)

        deleted_cells = store.delete_cell(CellID('P0'))
        self.assertEqual(deleted_cells, 1)

        stored_cells = store.query_by_cell(CellID('P0'))
        self.assertEqual(stored_cells.__len__(), 0)
        store.dropAll()
    def get_cell_dataset_from_tif_file(self, file, id):
        cds = CellDataSet(id=id)
        dataset, band, refinement = self.tif_file_treatment(file)
        for j in range(dataset.height):
            print(str(j) + "/" + str((dataset.height)))
            for i in range(dataset.width):
                cell_rHealPix_coords = dataset.xy(j, i)
                cell = self.dggs.get_cell_from_projected_point(
                    refinement, cell_rHealPix_coords)
                data = Data(int(band[j, i]))
                cds.add(cell, data)
            if j == 10:
                break

        return cds
    def test_query_by_cell(self):
        store.dropAll()
        cds = CellDataSet("id")
        cells = ['P0', 'P1', 'P2', 'P3', 'P4', 'P5']

        for cell in cells:
            cds.add(CellID(cell), Data(""))
        store.insert(cds)

        stored_cells = store.query_by_cell(CellID('P0'))
        num_cells = 0
        for cell in stored_cells:
            assert cells.__contains__(cell[0].value)
            num_cells = num_cells + 1
        self.assertEqual(num_cells, 1)
        store.dropAll()
    def test_insert_and_all_cells(self):
        store.dropAll()
        cds = CellDataSet("id")
        cells = ['P0', 'P1', 'P2', 'P3', 'P4', 'P5']

        for cell in cells:
            cds.add(CellID(cell), Data(""))
        store.insert(cds)

        stored_cells = store.all_cells()
        num_cells = 0
        for cell in stored_cells:
            assert cells.__contains__(cell[0].value)
            num_cells = num_cells + 1
        self.assertEqual(num_cells, len(cells))
        store.dropAll()
Exemple #13
0
    def query_by_cell_to_cell_datasets(self, cell_id):
        """
        :param cell_id: CellID
        :return: List of CellDataSets where cell_id is located
        """
        cells_founded = self.db.cells.find({"id": cell_id.value})

        cell_data_sets = []
        for cell in cells_founded:
            cds = CellDataSet()
            cells_in_bds_founded = self.db.cells.find(
                {"cell_dataset_id": cell["cell_dataset_id"]})
            for cell_2 in cells_in_bds_founded:
                cell, data = self.get_Cell_Data(cell_2)
                cds.add(cell, data)
            cell_data_sets.append(cds)
        return cell_data_sets
    def test_cell_dataset_add_list(self):
        cells = [
            CellID('N01'),
            CellID('N02'),
            CellID('N03'),
            CellID('N04'),
            CellID('N05')
        ]
        data = Data('test')
        cell_data_set = {
            cells[0].value: (cells[0], data),
            cells[1].value: (cells[1], data),
            cells[2].value: (cells[2], data)
        }

        c_dataset = CellDataSet('id', cell_data_set=cell_data_set)
        c_dataset.add_list([(cells[3], data), (cells[4], data)])

        self.assertEqual(c_dataset.cells, cells)
    def test_delete_cell_in_cell_datasets(self):
        store.dropAll()
        cds = CellDataSet("id")
        cells = ['P0', 'P1', 'P2', 'P3', 'P4', 'P5']

        for cell in cells:
            cds.add(CellID(cell), Data(""))
        store.insert(cds)

        deleted_cells = store.delete_cell_in_cell_datasets("id", CellID('P0'))
        self.assertEqual(deleted_cells, 1)

        stored_cds = store.query_by_cell_in_cell_datasets("id", CellID('P0'))
        num_cds = 0
        for cds in stored_cds:
            assert cds.get_cells().__len__() == 0
            num_cds = num_cds + 1
        self.assertEqual(num_cds, 1)

        store.dropAll()
    def test_query_by_cell_in_cell_datasets(self):
        store.dropAll()
        cds = CellDataSet("id")
        cells = ['P0', 'P1', 'P2', 'P3', 'P4', 'P5']

        for cell in cells:
            cds.add(CellID(cell), Data(""))
        store.insert(cds)

        stored_cds = store.query_by_cell_in_cell_datasets("id", CellID('P0'))
        num_cds = 0
        num_cells = 0
        for cds in stored_cds:
            for cell in cds.get_cells():
                assert cells.__contains__(cell.value)
                num_cells = num_cells + 1
            num_cds = num_cds + 1
        self.assertEqual(num_cds, 1)
        self.assertEqual(num_cells, 1)
        store.dropAll()
Exemple #17
0
 def tif_file_from_cell_dataset_cli(self, cell_dataset_file, out_tif):
     with open(cell_dataset_file) as json_file:
         cds = CellDataSet("").fromJSON(json_file, file=True)
         self.tif_file_from_cell_dataset(cds, out_tif)
Exemple #18
0
 def save(self, store):
     cds = CellDataSet(id=self.validated_data['id'],
                       cell_data_set=self.validated_data['cell_data_set'])
     store.insert(cds)
Exemple #19
0
 def save(self, store, cds_id):
     cds = CellDataSet(id=cds_id,
                       cell_data_set=self.validated_data['cell_data_set'])
     store.update_cell_dataset(cds)