예제 #1
0
 def __init__(self, dggs=rHEALPix(N_side=3, north_square=0,
                                  south_square=0)):
     """
     :param dggs: Discrete Global Grid System, rHEALPix by default
     """
     self.dggs = dggs
     self.db = MongoClient(mongodb_config.MONGODB_CONFIG['host']).bds
예제 #2
0
    def __init__(self,
                 boundary_ID=None,
                 cells=None,
                 dggs=rHEALPix(N_side=3, north_square=0, south_square=0)):
        """
        :param boundary_ID: boundary identifier, as defined in the AGILE19 paper, of type AUID
        :param cells: list of identifiers of the cells that make up the boundary, [ CellID, CellID ... ]
        :param dggs: Discrete Global Grid System, rHEALPix by default
        """
        self.boundary_ID = boundary_ID
        self.cells = cells
        self.optimal = True
        self.dggs = dggs

        assert boundary_ID is not None or cells is not None

        if cells is None:
            cells = bp_auid_to_cuids(boundary_ID.value,
                                     pars="()",
                                     with_opening_par=False)
            self.cells = []
            for cell in cells:
                self.cells.append(CellID(cell))
        if boundary_ID is None:
            cuids = [cell.value for cell in self.cells]
            auid_bp, _, _, _, _ = cuids_to_bp_auid(cuids,
                                                   pars="()",
                                                   with_opening_par=False)
            self.boundary_ID = AUID(auid_bp)
예제 #3
0
    def __init__(self,
                 boundary_ID=None,
                 cells=None,
                 dggs=rHEALPix(N_side=3, north_square=0, south_square=0)):
        """
        :param boundary_ID: boundary identifier, of type BoundaryID
        :param cells: list of identifiers of the cells that make up the boundary, [ CellID, CellID ... ]
        :param dggs: Discrete Global Grid System, rHEALPix by default
        """
        self.boundary_ID = boundary_ID
        self.cells = cells
        self.dggs = dggs

        assert boundary_ID is not None or cells is not None

        if cells is None:
            cells = []
            cell_ID = ''
            first = True
            for char in boundary_ID.value:
                if char in self.dggs.cells_R0:
                    if not first:
                        cells.append(CellID(cell_ID))
                    else:
                        first = False
                    cell_ID = char
                else:
                    cell_ID = cell_ID + char
            cells.append(CellID(cell_ID))
            cell_ids = sorted([cell.value for cell in cells])
            self.cells = [CellID(id) for id in cell_ids]

        if boundary_ID is None:
            cell_ids = sorted([cell.value for cell in cells])
            self.cells = [CellID(id) for id in cell_ids]
            boundary_ID = ''
            for cell_ID in self.cells:
                boundary_ID = boundary_ID + cell_ID.value
            self.boundary_ID = BoundaryID(boundary_ID)

        refinement_set = {}
        for cell in cells:
            if cell.get_refinement() in refinement_set:
                cell_list = refinement_set[cell.get_refinement()]
                cell_list.append(cell)
            else:
                refinement_set[cell.get_refinement()] = [cell]

        grids_list = []
        for refinement, cell_list in refinement_set.items():
            grids_list.append(Grid(refinement, cells=cell_list))

        def sort_by_refinement_level(grid):
            return grid.refinement_level

        grids_list.sort(key=sort_by_refinement_level)
        self.grids = grids_list
예제 #4
0
    def __init__(self,
                 refinement_level,
                 boundary_ID=None,
                 cells=None,
                 dggs=rHEALPix(N_side=3, north_square=0, south_square=0)):
        """
        :param refinement_level
        :param boundary_ID: boundary identifier, of type BoundaryID
        :param cells: list of identifiers of the cells that make up the boundary, [ CellID, CellID ... ]
        :param dggs: Discrete Global Grid System, rHEALPix by default
        """
        self.boundary_ID = boundary_ID
        self.cells = cells
        self.dggs = dggs
        self.refinement_level = refinement_level

        assert boundary_ID is not None or cells is not None

        if cells is None:
            cells = []
            cell_ID = ''
            first = True
            for char in boundary_ID.value:
                if char in self.dggs.cells_R0:
                    if not first:
                        cells.append(CellID(cell_ID))
                    else:
                        first = False
                    cell_ID = char
                else:
                    cell_ID = cell_ID + char
            cells.append(CellID(cell_ID))
            cell_ids = sorted([cell.value for cell in cells])
            self.cells = [CellID(id) for id in cell_ids]

        if boundary_ID is None:
            cell_ids = sorted([cell.value for cell in cells])
            self.cells = [CellID(id) for id in cell_ids]
            boundary_ID = ''
            for cell_ID in self.cells:
                boundary_ID = boundary_ID + cell_ID.value
            self.boundary_ID = BoundaryID(boundary_ID)
예제 #5
0
    def __init__(self,
                 id,
                 boundary_data_set=None,
                 dggs=rHEALPix(N_side=3, north_square=0, south_square=0)):
        """
        :param id: boundary dataset identifier
        :param boundary_data_set: dictionary with optimal boundary identifier as key
        and OptimalBoundary and associated Data pairs as value:
        {
            BoundaryID.value: (OptimalBoundary,Data)
        }
        :param dggs: Discrete Global Grid System, rHEALPix by default
        """
        assert id is not None
        self.id = id

        if boundary_data_set is None:
            boundary_data_set = {}
        self.boundary_data_set = boundary_data_set
        self.dggs = dggs
예제 #6
0
    def __init__(self,
                 id,
                 dggs=rHEALPix(N_side=3, north_square=0, south_square=0),
                 cell_data_set=None):
        """
        :param boundary_ID: boundary identifier, of type BoundaryID
        :param cells: list of identifiers of the cells that make up the boundary, [ CellID, CellID ... ]
        :param dggs: Discrete Global Grid System, rHEALPix by default
        :param cell_data_set: dictionary with CellID.value as key and  (CellID, Data) as value:
        {
            CellID.value: (CellID, Data)
        }
        """
        assert id is not None
        self.id = id
        self.boundary_ID = ''
        self.cells = []
        self.dggs = dggs

        if cell_data_set is None:
            cell_data_set = {}
        else:
            cells = []
            for id, (cell_id, data) in cell_data_set.items():
                if cell_id not in self.cells:
                    cells.append(cell_id)
                else:
                    print('Cell already exists in this dataset')
            cell_ids = sorted([cell.value for cell in cells])
            self.cells = [CellID(id) for id in cell_ids]

            boundary_ID = ''
            for cell_ID in self.cells:
                boundary_ID = boundary_ID + cell_ID.value
            self.boundary_ID = BoundaryID(boundary_ID)
        self.cell_data_set = cell_data_set
예제 #7
0
 def __init__(self, dggs=None):
     if dggs is None:
         dggs = rHEALPix(N_side=3, north_square=0, south_square=0)
     self.dggs = dggs
예제 #8
0
import unittest
from numpy import pi

from dggs.cell_ID import CellID
from dggs.rHealPix import rHEALPix

r = rHEALPix(N_side=3, north_square=0, south_square=0)


class TestBoundaryDataSet(unittest.TestCase):

    def test_cell_width(self):
        self.assertEqual(r.cell_width(0), 0.998882147091 * (pi / 2) * 3 ** (-0))
        self.assertEqual(r.cell_width(10), 0.998882147091 * (pi / 2) * 3 ** (-10))

    def test_rowcol(self):
        self.assertEqual(r.rowcol(CellID('N00')), (['N', 0, 0], ['N', 0, 0]))
        self.assertEqual(r.rowcol(CellID('O4')), (['O', 1], ['O', 1]))
        self.assertEqual(r.rowcol(CellID('S800')), (['S', 2, 0, 0], ['S', 2, 0, 0]))

    def test_up_down(self):
        self.assertEqual(r.up(CellID('N00'), CellID('O00')), True)
        self.assertEqual(r.down(CellID('S80'), CellID('P3')), True)
        self.assertEqual(r.up(CellID('O00'), CellID('N00')), False)
        self.assertEqual(r.down(CellID('P3'), CellID('S80')), False)

    def test_right_left(self):
        self.assertEqual(r.left(CellID('N00'), CellID('O80')), True)
        self.assertEqual(r.right(CellID('R3'), CellID('P5')), True)
        self.assertEqual(r.left(CellID('O80'), CellID('N00')), False)
        self.assertEqual(r.right(CellID('P3'), CellID('R5')), False)