Esempio n. 1
0
    def test_system_regrid_field_nonoverlapping_extents(self):
        """Test regridding with fields that do not spatially overlap."""

        rd = self.test_data.get_rd('cancm4_tas')
        # nebraska and california
        coll = OcgOperations(dataset=rd, geom='state_boundaries', select_ugid=[16, 25], snippet=True,
                             vector_wrap=False).execute()
        source = coll.get_element(container_ugid=25)
        destination = coll.get_element(container_ugid=16)

        with self.assertRaises(RegriddingError):
            from ocgis.regrid.base import regrid_field
            regrid_field(source, destination)
Esempio n. 2
0
    def test_regrid_field_partial_extents(self):
        """Test regridding with fields that partially overlap."""

        rd = self.test_data.get_rd('cancm4_tas')
        # california and nevada
        coll = OcgOperations(dataset=rd, geom='state_boundaries', select_ugid=[23, 25], snippet=True,
                             vector_wrap=False).execute()

        source = coll.get_element(container_ugid=23)
        destination = coll.get_element(container_ugid=25)

        from ocgis.regrid.base import regrid_field
        res = regrid_field(source, destination)
        self.assertEqual(res['tas'].get_mask().sum(), 11)
Esempio n. 3
0
    def test_system_regrid_field_nonoverlapping_extents(self):
        """Test regridding with fields that do not spatially overlap."""

        rd = self.test_data.get_rd('cancm4_tas')
        # nebraska and california
        coll = OcgOperations(dataset=rd,
                             geom='state_boundaries',
                             select_ugid=[16, 25],
                             snippet=True,
                             vector_wrap=False).execute()
        source = coll.get_element(container_ugid=25)
        destination = coll.get_element(container_ugid=16)

        with self.assertRaises(RegriddingError):
            from ocgis.regrid.base import regrid_field
            regrid_field(source, destination)
Esempio n. 4
0
    def test_regrid_field_partial_extents(self):
        """Test regridding with fields that partially overlap."""

        rd = self.test_data.get_rd('cancm4_tas')
        # california and nevada
        coll = OcgOperations(dataset=rd,
                             geom='state_boundaries',
                             select_ugid=[23, 25],
                             snippet=True,
                             vector_wrap=False).execute()

        source = coll.get_element(container_ugid=23)
        destination = coll.get_element(container_ugid=25)

        from ocgis.regrid.base import regrid_field
        res = regrid_field(source, destination)
        self.assertEqual(res['tas'].get_mask().sum(), 11)
Esempio n. 5
0
 def test_icclim(self):
     rd = RequestDataset(**self.get_dataset())
     calc = [{'func': 'icclim_TG', 'name': 'TG'}]
     calc_grouping = ['month', 'year']
     ret = OcgOperations(dataset=rd, calc=calc,
                         calc_grouping=calc_grouping).execute()
     self.assertEqual(
         ret.get_element(variable_name='TG').get_value().mean(), 2.5)
Esempio n. 6
0
    def test_many_request_datasets(self):
        """Test numerous request datasets."""

        rd_base = self.test_data.get_rd('cancm4_tas')
        geom = [-74.0, 40.0, -72.0, 42.0]
        rds = [deepcopy(rd_base) for ii in range(500)]
        for rd in rds:
            ret = OcgOperations(dataset=rd, geom=geom, snippet=True).execute()
            actual = ret.get_element(variable_name='tas').shape
            self.assertEqual(actual, (1, 2, 1))
Esempio n. 7
0
    def test_multipoint_buffering_and_union(self):
        """Test subset behavior using MultiPoint geometries."""

        pts = [Point(3.8, 28.57), Point(9.37, 33.90), Point(17.04, 27.08)]
        mp = MultiPoint(pts)

        rd = self.test_data.get_rd('cancm4_tas')
        coll = OcgOperations(dataset=rd, output_format=constants.OutputFormatName.OCGIS, snippet=True,
                             geom=mp).execute()
        mu1 = coll.get_element(variable_name='tas').get_masked_value().sum()
        nc_path = OcgOperations(dataset=rd, output_format='nc', snippet=True, geom=mp).execute()
        with self.nc_scope(nc_path) as ds:
            var = ds.variables['tas']
            mu2 = var[:].sum()
        self.assertEqual(mu1, mu2)
Esempio n. 8
0
    def test_multipoint_buffering_and_union(self):
        """Test subset behavior using MultiPoint geometries."""

        pts = [Point(3.8, 28.57), Point(9.37, 33.90), Point(17.04, 27.08)]
        mp = MultiPoint(pts)

        rd = self.test_data.get_rd('cancm4_tas')
        coll = OcgOperations(dataset=rd,
                             output_format=constants.OutputFormatName.OCGIS,
                             snippet=True,
                             geom=mp).execute()
        mu1 = coll.get_element(variable_name='tas').get_masked_value().sum()
        nc_path = OcgOperations(dataset=rd,
                                output_format='nc',
                                snippet=True,
                                geom=mp).execute()
        with self.nc_scope(nc_path) as ds:
            var = ds.variables['tas']
            mu2 = var[:].sum()
        self.assertEqual(mu1, mu2)