Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix lon_bounds returning range > 360 degrees #859

Merged
merged 2 commits into from
Mar 14, 2024

lon_bounds: refactor

424fba3
Select commit
Loading
Failed to load commit list.
Sign in for the full log view
Merged

Bugfix lon_bounds returning range > 360 degrees #859

lon_bounds: refactor
424fba3
Select commit
Loading
Failed to load commit list.
GitHub Actions / Unit Test Results Python 3.11 failed Mar 14, 2024 in 0s

10 fail, 652 pass in 6m 28s

662 tests  ±0   652 ✅ ±0   6m 28s ⏱️ -12s
  1 suites ±0     0 💤 ±0 
  1 files   ±0    10 ❌ ±0 

Results for commit 424fba3. ± Comparison against earlier commit 1984f1d.

Annotations

Check warning on line 0 in climada.entity.exposures.test.test_base.TestChecker

See this annotation in the file changed.

@github-actions github-actions / Unit Test Results Python 3.11

test_error_geometry_fail (climada.entity.exposures.test.test_base.TestChecker) failed

tests_xml/tests.xml [took 0s]
Raw output
ValueError: assignment destination is read-only
self = <climada.entity.exposures.test.test_base.TestChecker testMethod=test_error_geometry_fail>

    def test_error_geometry_fail(self):
        """Wrong exposures definition"""
        expo = good_exposures()
        expo.set_geometry_points()
>       expo.gdf.latitude.values[0] = 5
E       ValueError: assignment destination is read-only

climada/entity/exposures/test/test_base.py:282: ValueError

Check warning on line 0 in climada.entity.exposures.test.test_litpop.TestLitPop

See this annotation in the file changed.

@github-actions github-actions / Unit Test Results Python 3.11

test_get_total_value_per_country_gdp (climada.entity.exposures.test.test_litpop.TestLitPop) failed

tests_xml/tests.xml [took 0s]
Raw output
UnboundLocalError: cannot access local variable 'close_year' where it is not associated with a value
cntry_iso = 'CHE', ref_year = 2222, shp_file = None

    def income_group(cntry_iso, ref_year, shp_file=None):
        """Get country's income group from World Bank's data at a given year,
        or closest year value. If no data, get the natural earth's approximation.
    
        Parameters
        ----------
        cntry_iso : str
            key = ISO alpha_3 country
        ref_year : int
            reference year
        shp_file : cartopy.io.shapereader.Reader, optional
            shape file with
            INCOME_GRP attribute for every country. Load Natural Earth admin0
            if not provided.
        """
        try:
>           close_year, close_val = world_bank(cntry_iso, ref_year, 'INC_GRP')

climada/util/finance.py:121: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
climada/util/finance.py:210: in world_bank
    dfr_wb = dfr_wb.replace(INCOME_GRP_WB_TABLE.keys(),
../../../micromamba/envs/climada_env_3.11/lib/python3.11/site-packages/pandas/core/generic.py:7867: in replace
    new_data = self._mgr.replace_list(
../../../micromamba/envs/climada_env_3.11/lib/python3.11/site-packages/pandas/core/internals/base.py:253: in replace_list
    bm = self.apply_with_block(
../../../micromamba/envs/climada_env_3.11/lib/python3.11/site-packages/pandas/core/internals/managers.py:354: in apply
    applied = getattr(b, f)(**kwargs)
../../../micromamba/envs/climada_env_3.11/lib/python3.11/site-packages/pandas/core/internals/blocks.py:908: in replace_list
    b.refs.referenced_blocks.index(ref)
../../../micromamba/envs/climada_env_3.11/lib/python3.11/site-packages/pandas/core/ops/common.py:76: in new_method
    return method(self, other)
../../../micromamba/envs/climada_env_3.11/lib/python3.11/site-packages/pandas/core/arraylike.py:40: in __eq__
    return self._cmp_method(other, operator.eq)
../../../micromamba/envs/climada_env_3.11/lib/python3.11/site-packages/pandas/core/indexes/base.py:7129: in _cmp_method
    result = ops.comp_method_OBJECT_ARRAY(op, self._values, other)
../../../micromamba/envs/climada_env_3.11/lib/python3.11/site-packages/pandas/core/ops/array_ops.py:131: in comp_method_OBJECT_ARRAY
    result = libops.scalar_compare(x.ravel(), y, op)
ops.pyx:32: in pandas._libs.ops.scalar_compare
    ???
stringsource:660: in View.MemoryView.memoryview_cwrapper
    ???
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

>   ???
E   ValueError: buffer source array is read-only

stringsource:350: ValueError

During handling of the above exception, another exception occurred:

self = <climada.entity.exposures.test.test_litpop.TestLitPop testMethod=test_get_total_value_per_country_gdp>

    def test_get_total_value_per_country_gdp(self):
        "test _get_total_value_per_country get number for gdp"
        gdp_togo = lp._get_total_value_per_country('TGO', 'gdp', 2010)
        gdp_switzerland = lp._get_total_value_per_country('CHE', 'gdp', 2222)
>       value_switzerland = lp._get_total_value_per_country('CHE', 'income_group', 2222)

climada/entity/exposures/test/test_litpop.py:349: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
climada/entity/exposures/litpop/litpop.py:864: in _get_total_value_per_country
    return gdp_value*(u_fin.income_group(cntry_iso3a, reference_year)[1]+1)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

cntry_iso = 'CHE', ref_year = 2222, shp_file = None

    def income_group(cntry_iso, ref_year, shp_file=None):
        """Get country's income group from World Bank's data at a given year,
        or closest year value. If no data, get the natural earth's approximation.
    
        Parameters
        ----------
        cntry_iso : str
            key = ISO alpha_3 country
        ref_year : int
            reference year
        shp_file : cartopy.io.shapereader.Reader, optional
            shape file with
            INCOME_GRP attribute for every country. Load Natural Earth admin0
            if not provided.
        """
        try:
            close_year, close_val = world_bank(cntry_iso, ref_year, 'INC_GRP')
        except (KeyError, IndexError):
            # take value from natural earth repository
            close_year, close_val = nat_earth_adm0(cntry_iso, 'INCOME_GRP',
                                                   shp_file=shp_file)
        finally:
>           LOGGER.info('Income group %s %s: %s.', cntry_iso, close_year, close_val)
E           UnboundLocalError: cannot access local variable 'close_year' where it is not associated with a value

climada/util/finance.py:127: UnboundLocalError

Check warning on line 0 in climada.entity.measures.test.test_base.TestApply

See this annotation in the file changed.

@github-actions github-actions / Unit Test Results Python 3.11

test_change_exposures_impf_pass (climada.entity.measures.test.test_base.TestApply) failed

tests_xml/tests.xml [took 0s]
Raw output
ValueError: assignment destination is read-only
self = <climada.entity.measures.test.test_base.TestApply testMethod=test_change_exposures_impf_pass>

    def test_change_exposures_impf_pass(self):
        """Test _change_exposures_impf"""
        meas = Measure(
            imp_fun_map='1to3',
            haz_type='TC',
        )
    
        imp_set = ImpactFuncSet()
    
        intensity = np.arange(10, 100, 10)
        mdd = np.arange(10, 100, 10)
        paa = np.arange(10, 100, 10)
        imp_tc = ImpactFunc("TC", 1, intensity, mdd, paa)
        imp_set.append(imp_tc)
    
        mdd = np.arange(10, 100, 10) * 2
        paa = np.arange(10, 100, 10) * 2
        imp_tc = ImpactFunc("TC", 3, intensity, mdd, paa)
    
        exp = Exposures.from_hdf5(EXP_DEMO_H5)
>       new_exp = meas._change_exposures_impf(exp)

climada/entity/measures/test/test_base.py:164: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <climada.entity.measures.base.Measure object at 0x78e389151890>
exposures = <climada.entity.exposures.base.Exposures object at 0x78e388d96c50>

    def _change_exposures_impf(self, exposures):
        """Change exposures impact functions ids according to imp_fun_map.
    
        Parameters
        ----------
        exposures : climada.entity.Exposures
            exposures instance
    
        Returns
        -------
        new_exp : climada.entity.Exposure
            Exposure with updated impact functions ids accordgin to
            impf_fun_map
        """
        if self.imp_fun_map == NULL_STR:
            return exposures
    
        LOGGER.debug('Setting new exposures impact functions%s', self.imp_fun_map)
        new_exp = exposures.copy(deep=True)
        from_id = int(self.imp_fun_map[0:self.imp_fun_map.find('to')])
        to_id = int(self.imp_fun_map[self.imp_fun_map.find('to') + 2:])
        try:
            exp_change = np.argwhere(
                new_exp.gdf[INDICATOR_IMPF + self.haz_type].values == from_id
            ).reshape(-1)
>           new_exp.gdf[INDICATOR_IMPF + self.haz_type].values[exp_change] = to_id
E           ValueError: assignment destination is read-only

climada/entity/measures/base.py:351: ValueError

Check warning on line 0 in climada.entity.measures.test.test_base.TestApply

See this annotation in the file changed.

@github-actions github-actions / Unit Test Results Python 3.11

test_cutoff_hazard_region_pass (climada.entity.measures.test.test_base.TestApply) failed

tests_xml/tests.xml [took 0s]
Raw output
ValueError: assignment destination is read-only
self = <climada.entity.measures.test.test_base.TestApply testMethod=test_cutoff_hazard_region_pass>

    def test_cutoff_hazard_region_pass(self):
        """Test _cutoff_hazard_damage in specific region"""
        meas = MeasureSet.from_mat(ENT_TEST_MAT)
        act_1 = meas.get_measure(name='Seawall')[0]
        act_1.exp_region_id = [1]
    
        haz = Hazard.from_mat(HAZ_TEST_MAT)
        exp = Exposures.from_mat(ENT_TEST_MAT)
        exp.gdf['region_id'] = np.zeros(exp.gdf.shape[0])
>       exp.gdf.region_id.values[10:] = 1
E       ValueError: assignment destination is read-only

climada/entity/measures/test/test_base.py:118: ValueError

Check warning on line 0 in climada.entity.measures.test.test_base.TestApply

See this annotation in the file changed.

@github-actions github-actions / Unit Test Results Python 3.11

test_filter_exposures_pass (climada.entity.measures.test.test_base.TestApply) failed

tests_xml/tests.xml [took 0s]
Raw output
ValueError: assignment destination is read-only
self = <climada.entity.measures.test.test_base.TestApply testMethod=test_filter_exposures_pass>

    def test_filter_exposures_pass(self):
        """Test _filter_exposures method with two values"""
        meas = Measure(
            exp_region_id=[3, 4],
            haz_type='TC',
        )
    
        exp = Exposures.from_mat(ENT_TEST_MAT)
        exp.gdf.rename(columns={'impf_': 'impf_TC', 'centr_': 'centr_TC'}, inplace=True)
        exp.gdf['region_id'] = np.ones(exp.gdf.shape[0])
>       exp.gdf.region_id.values[:exp.gdf.shape[0] // 2] = 3
E       ValueError: assignment destination is read-only

climada/entity/measures/test/test_base.py:243: ValueError

Check warning on line 0 in climada.hazard.centroids.test.test_centr.TestCentroidsReader

See this annotation in the file changed.

@github-actions github-actions / Unit Test Results Python 3.11

test_geodataframe (climada.hazard.centroids.test.test_centr.TestCentroidsReader) failed

tests_xml/tests.xml [took 0s]
Raw output
AssertionError: 45 != 44
self = <climada.hazard.centroids.test.test_centr.TestCentroidsReader testMethod=test_geodataframe>

    def test_geodataframe(self):
        """Test that constructing a valid Centroids instance from gdf works."""
        gdf = gpd.GeoDataFrame(pd.read_excel(HAZ_TEMPLATE_XLS))
        gdf.geometry = gpd.points_from_xy(
                gdf['longitude'], gdf['latitude']
        )
        gdf['elevation'] = np.random.rand(gdf.geometry.size)
        gdf['region_id'] = np.zeros(gdf.geometry.size)
        gdf['region_id'][0] = np.NaN
        gdf['geom'] = gdf.geometry  # this should have no effect on centroids
    
        centroids = Centroids.from_geodataframe(gdf)
        centroids.check()
    
        self.assertEqual(centroids.geometry.size, 45)
        self.assertEqual(centroids.lon[0], 32.57)
        self.assertEqual(centroids.lat[0], -25.95)
        self.assertEqual(centroids.elevation.size, 45)
>       self.assertEqual(centroids.on_land.sum(), 44)
E       AssertionError: 45 != 44

climada/hazard/centroids/test/test_centr.py:107: AssertionError

Check warning on line 0 in climada.hazard.test.test_tc_tracks.TestFuncs

See this annotation in the file changed.

@github-actions github-actions / Unit Test Results Python 3.11

test_interp_track_pass (climada.hazard.test.test_tc_tracks.TestFuncs) failed

tests_xml/tests.xml [took 0s]
Raw output
ValueError: output array is read-only
self = <climada.hazard.test.test_tc_tracks.TestFuncs testMethod=test_interp_track_pass>

    def test_interp_track_pass(self):
        """Interpolate track to min_time_step. Compare to MATLAB reference."""
        tc_track = tc.TCTracks.from_processed_ibtracs_csv(TEST_TRACK)
        tc_track.equal_timestep(time_step_h=1)
    
        self.assertEqual(tc_track.data[0].time.size, 223)
        self.assertAlmostEqual(tc_track.data[0].lon.values[11], -27.426151640151684)
        self.assertAlmostEqual(float(tc_track.data[0].lat[23]), 12.300006169591480)
        self.assertEqual(tc_track.data[0].time_step[7], 1)
        self.assertEqual(np.max(tc_track.data[0].radius_max_wind), 0)
        self.assertEqual(np.min(tc_track.data[0].radius_max_wind), 0)
        self.assertEqual(tc_track.data[0].max_sustained_wind[21], 25)
        self.assertTrue(np.isfinite(tc_track.data[0].central_pressure.values).all())
        self.assertAlmostEqual(tc_track.data[0].central_pressure.values[29], 1008, places=0)
        self.assertEqual(np.max(tc_track.data[0].environmental_pressure), 1010)
        self.assertEqual(np.min(tc_track.data[0].environmental_pressure), 1010)
        self.assertEqual(tc_track.data[0]['time.year'][13], 1951)
        self.assertEqual(tc_track.data[0]['time.month'][26], 8)
        self.assertEqual(tc_track.data[0]['time.day'][7], 27)
        self.assertEqual(tc_track.data[0].max_sustained_wind_unit, 'kn')
        self.assertEqual(tc_track.data[0].central_pressure_unit, 'mb')
        self.assertEqual(tc_track.data[0].orig_event_flag, 1)
        self.assertEqual(tc_track.data[0].name, '1951239N12334')
        self.assertEqual(tc_track.data[0].data_provider, 'hurdat_atl')
        np.testing.assert_array_equal(tc_track.data[0].basin, 'NA')
        self.assertEqual(tc_track.data[0].id_no, 1951239012334)
        self.assertEqual(tc_track.data[0].category, 1)
    
        # test some "generic floats"
        for time_step_h in [0.6663545049172093, 2.509374054925788, 8.175754471661111]:
            # artifically create data that doesn't start at full hour
            for loffset in [0, 22, 30]:
                tc_track = tc.TCTracks.from_processed_ibtracs_csv(TEST_TRACK)
>               tc_track.data[0].time.values[:] += np.timedelta64(loffset, "m")
E               ValueError: output array is read-only

climada/hazard/test/test_tc_tracks.py:632: ValueError

Check warning on line 0 in climada.util.test.test_finance.TestWBData

See this annotation in the file changed.

@github-actions github-actions / Unit Test Results Python 3.11

test_income_grp_sxm_1999_pass (climada.util.test.test_finance.TestWBData) failed

tests_xml/tests.xml [took 0s]
Raw output
UnboundLocalError: cannot access local variable 'close_year' where it is not associated with a value
cntry_iso = 'SXM', ref_year = 1999
shp_file = <cartopy.io.shapereader.FionaReader object at 0x78e38acc9650>

    def income_group(cntry_iso, ref_year, shp_file=None):
        """Get country's income group from World Bank's data at a given year,
        or closest year value. If no data, get the natural earth's approximation.
    
        Parameters
        ----------
        cntry_iso : str
            key = ISO alpha_3 country
        ref_year : int
            reference year
        shp_file : cartopy.io.shapereader.Reader, optional
            shape file with
            INCOME_GRP attribute for every country. Load Natural Earth admin0
            if not provided.
        """
        try:
>           close_year, close_val = world_bank(cntry_iso, ref_year, 'INC_GRP')

climada/util/finance.py:121: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
climada/util/finance.py:210: in world_bank
    dfr_wb = dfr_wb.replace(INCOME_GRP_WB_TABLE.keys(),
../../../micromamba/envs/climada_env_3.11/lib/python3.11/site-packages/pandas/core/generic.py:7867: in replace
    new_data = self._mgr.replace_list(
../../../micromamba/envs/climada_env_3.11/lib/python3.11/site-packages/pandas/core/internals/base.py:253: in replace_list
    bm = self.apply_with_block(
../../../micromamba/envs/climada_env_3.11/lib/python3.11/site-packages/pandas/core/internals/managers.py:354: in apply
    applied = getattr(b, f)(**kwargs)
../../../micromamba/envs/climada_env_3.11/lib/python3.11/site-packages/pandas/core/internals/blocks.py:908: in replace_list
    b.refs.referenced_blocks.index(ref)
../../../micromamba/envs/climada_env_3.11/lib/python3.11/site-packages/pandas/core/ops/common.py:76: in new_method
    return method(self, other)
../../../micromamba/envs/climada_env_3.11/lib/python3.11/site-packages/pandas/core/arraylike.py:40: in __eq__
    return self._cmp_method(other, operator.eq)
../../../micromamba/envs/climada_env_3.11/lib/python3.11/site-packages/pandas/core/indexes/base.py:7129: in _cmp_method
    result = ops.comp_method_OBJECT_ARRAY(op, self._values, other)
../../../micromamba/envs/climada_env_3.11/lib/python3.11/site-packages/pandas/core/ops/array_ops.py:131: in comp_method_OBJECT_ARRAY
    result = libops.scalar_compare(x.ravel(), y, op)
ops.pyx:32: in pandas._libs.ops.scalar_compare
    ???
stringsource:660: in View.MemoryView.memoryview_cwrapper
    ???
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

>   ???
E   ValueError: buffer source array is read-only

stringsource:350: ValueError

During handling of the above exception, another exception occurred:

self = <climada.util.test.test_finance.TestWBData testMethod=test_income_grp_sxm_1999_pass>

    def test_income_grp_sxm_1999_pass(self):
        """Test income_group function Sint Maarten."""
        ref_year = 1999
        with self.assertLogs('climada.util.finance', level='INFO') as cm:
>           ig_year, ig_val = income_group('SXM', ref_year, SHP_FILE)

climada/util/test/test_finance.py:70: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

cntry_iso = 'SXM', ref_year = 1999
shp_file = <cartopy.io.shapereader.FionaReader object at 0x78e38acc9650>

    def income_group(cntry_iso, ref_year, shp_file=None):
        """Get country's income group from World Bank's data at a given year,
        or closest year value. If no data, get the natural earth's approximation.
    
        Parameters
        ----------
        cntry_iso : str
            key = ISO alpha_3 country
        ref_year : int
            reference year
        shp_file : cartopy.io.shapereader.Reader, optional
            shape file with
            INCOME_GRP attribute for every country. Load Natural Earth admin0
            if not provided.
        """
        try:
            close_year, close_val = world_bank(cntry_iso, ref_year, 'INC_GRP')
        except (KeyError, IndexError):
            # take value from natural earth repository
            close_year, close_val = nat_earth_adm0(cntry_iso, 'INCOME_GRP',
                                                   shp_file=shp_file)
        finally:
>           LOGGER.info('Income group %s %s: %s.', cntry_iso, close_year, close_val)
E           UnboundLocalError: cannot access local variable 'close_year' where it is not associated with a value

climada/util/finance.py:127: UnboundLocalError

Check warning on line 0 in climada.util.test.test_finance.TestWBData

See this annotation in the file changed.

@github-actions github-actions / Unit Test Results Python 3.11

test_wb_income_grp_sxm_pass (climada.util.test.test_finance.TestWBData) failed

tests_xml/tests.xml [took 0s]
Raw output
ValueError: buffer source array is read-only
self = <climada.util.test.test_finance.TestWBData testMethod=test_wb_income_grp_sxm_pass>

    def test_wb_income_grp_sxm_pass(self):
        """Test world_bank function Sint Maarten."""
        ref_year = 2012
>       wb_year, wb_val = world_bank('SXM', ref_year, 'INC_GRP')

climada/util/test/test_finance.py:59: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
climada/util/finance.py:210: in world_bank
    dfr_wb = dfr_wb.replace(INCOME_GRP_WB_TABLE.keys(),
../../../micromamba/envs/climada_env_3.11/lib/python3.11/site-packages/pandas/core/generic.py:7867: in replace
    new_data = self._mgr.replace_list(
../../../micromamba/envs/climada_env_3.11/lib/python3.11/site-packages/pandas/core/internals/base.py:253: in replace_list
    bm = self.apply_with_block(
../../../micromamba/envs/climada_env_3.11/lib/python3.11/site-packages/pandas/core/internals/managers.py:354: in apply
    applied = getattr(b, f)(**kwargs)
../../../micromamba/envs/climada_env_3.11/lib/python3.11/site-packages/pandas/core/internals/blocks.py:908: in replace_list
    b.refs.referenced_blocks.index(ref)
../../../micromamba/envs/climada_env_3.11/lib/python3.11/site-packages/pandas/core/ops/common.py:76: in new_method
    return method(self, other)
../../../micromamba/envs/climada_env_3.11/lib/python3.11/site-packages/pandas/core/arraylike.py:40: in __eq__
    return self._cmp_method(other, operator.eq)
../../../micromamba/envs/climada_env_3.11/lib/python3.11/site-packages/pandas/core/indexes/base.py:7129: in _cmp_method
    result = ops.comp_method_OBJECT_ARRAY(op, self._values, other)
../../../micromamba/envs/climada_env_3.11/lib/python3.11/site-packages/pandas/core/ops/array_ops.py:131: in comp_method_OBJECT_ARRAY
    result = libops.scalar_compare(x.ravel(), y, op)
ops.pyx:32: in pandas._libs.ops.scalar_compare
    ???
stringsource:660: in View.MemoryView.memoryview_cwrapper
    ???
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

>   ???
E   ValueError: buffer source array is read-only

stringsource:350: ValueError

Check warning on line 0 in climada.util.test.test_lines_polys_handler.TestExposureGeomToPnt

See this annotation in the file changed.

@github-actions github-actions / Unit Test Results Python 3.11

test_point_exposure_from_polygons_on_grid (climada.util.test.test_lines_polys_handler.TestExposureGeomToPnt) failed

tests_xml/tests.xml [took 0s]
Raw output
ValueError: assignment destination is read-only
self = <climada.util.test.test_lines_polys_handler.TestExposureGeomToPnt testMethod=test_point_exposure_from_polygons_on_grid>

    def test_point_exposure_from_polygons_on_grid(self):
        """Test disaggregation of polygons to points on grid"""
        exp_poly = EXP_POLY.copy()
        res = 0.1
        exp_poly.set_gdf(exp_poly.gdf[exp_poly.gdf['population']<400000])
>       height, width, trafo = u_coord.pts_to_raster_meta(
            exp_poly.gdf.geometry.bounds, (res, res)
            )

climada/util/test/test_lines_polys_handler.py:214: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

points_bounds =              minx       miny     maxx       maxy
Zeeland  4.767854  51.941171  5.61974  52.285491
res = array([0.1, 0.1])

    def pts_to_raster_meta(points_bounds, res):
        """Transform vector data coordinates to raster.
    
        If a raster of the given resolution doesn't exactly fit the given bounds, the raster might have
        slightly larger (but never smaller) bounds.
    
        Parameters
        ----------
        points_bounds : tuple
            points total bounds (xmin, ymin, xmax, ymax)
        res : tuple
            resolution of output raster (xres, yres)
    
        Returns
        -------
        nrows : int
            Number of rows.
        ncols : int
            Number of columns.
        ras_trans : affine.Affine
            Affine transformation defining the raster.
        """
        bounds = np.asarray(points_bounds).reshape(2, 2)
        res = np.asarray(res).ravel()
        if res.size == 1:
            res = np.array([res[0], res[0]])
        sizes = bounds[1, :] - bounds[0, :]
        nsteps = np.floor(sizes / np.abs(res)) + 1
        nsteps[np.abs(nsteps * res) < sizes + np.abs(res) / 2] += 1
>       bounds[:, res < 0] = bounds[::-1, res < 0]
E       ValueError: assignment destination is read-only

climada/util/coordinates.py:1748: ValueError