diff --git a/changelog.rst b/changelog.rst index 580734d8..01bd77c1 100644 --- a/changelog.rst +++ b/changelog.rst @@ -6,6 +6,12 @@ Pyinterpolate is the Python library for **geostatistics** and **spatial statisti Changes by date =============== +2024-07- +-------- +**version 0.5.3** + +* (bug) https://github.com/DataverseLabs/pyinterpolate/issues/428 + 2024-06-26 ---------- **version 0.5.2** diff --git a/pyinterpolate/processing/transform/transform.py b/pyinterpolate/processing/transform/transform.py index a27f2d26..4f22a325 100644 --- a/pyinterpolate/processing/transform/transform.py +++ b/pyinterpolate/processing/transform/transform.py @@ -334,7 +334,7 @@ def transform_blocks_to_numpy(blocks: Union[Blocks, gpd.GeoDataFrame, pd.DataFra raise KeyError(f'Given dataframe doesnt have all expected columns {expected_cols}. ' f'It has {blocks.columns} instead.') - bvalues = blocks.data[['index', 'centroid.x', 'centroid.y', 'ds']].values + bvalues = blocks[['index', 'centroid.x', 'centroid.y', 'ds']].values return bvalues else: raise TypeError(f'Blocks data type {type(blocks)} not recognized. You may use Blocks,' diff --git a/tests/test_pipelines/test_smooth_areas.py b/tests/test_pipelines/test_smooth_areas.py index 077462d2..9d58c773 100644 --- a/tests/test_pipelines/test_smooth_areas.py +++ b/tests/test_pipelines/test_smooth_areas.py @@ -3,8 +3,8 @@ from pyinterpolate import smooth_blocks, Blocks, PointSupport, TheoreticalVariogram -DATASET = 'samples/regularization/cancer_data.gpkg' -VARIOGRAM_MODEL_FILE = 'samples/regularization/regularized_variogram.json' +DATASET = '../samples/regularization/cancer_data.gpkg' +VARIOGRAM_MODEL_FILE = '../samples/regularization/regularized_variogram.json' POLYGON_LAYER = 'areas' POPULATION_LAYER = 'points' POP10 = 'POP10' @@ -28,7 +28,7 @@ THEORETICAL_VARIOGRAM = TheoreticalVariogram() THEORETICAL_VARIOGRAM.from_json(VARIOGRAM_MODEL_FILE) -DIRECTIONAL_VARIOGRAM_MODEL_FILE = 'samples/regularization/regularized_directional_variogram.json' +DIRECTIONAL_VARIOGRAM_MODEL_FILE = '../samples/regularization/regularized_directional_variogram.json' DIRECTIONAL_VARIOGRAM = TheoreticalVariogram() DIRECTIONAL_VARIOGRAM.from_json(DIRECTIONAL_VARIOGRAM_MODEL_FILE) @@ -51,3 +51,24 @@ def test_directional(self): number_of_neighbors=NN) self.assertIsInstance(output_results, gpd.GeoDataFrame) + + def test_blocks_as_geodataframe(self): + blocks_gdf = gpd.read_file( + DATASET, layer=POLYGON_LAYER + ) + # ``centroid.x, centroid.y, ds, index`` - must be in geodataframe + blocks_gdf['centroid'] = blocks_gdf.centroid + blocks_gdf['centroid.x'] = blocks_gdf['centroid'].x + blocks_gdf['centroid.y'] = blocks_gdf['centroid'].y + blocks_gdf.rename(columns={ + 'rate': 'ds', + 'FIPS': 'index' + }, inplace=True) + + smoothed = smooth_blocks( + semivariogram_model=THEORETICAL_VARIOGRAM, + blocks=blocks_gdf, + point_support=POINT_SUPPORT_INPUT, + number_of_neighbors=NN + ) + self.assertIsInstance(smoothed, gpd.GeoDataFrame) diff --git a/tests/test_processing/test_blocks.py b/tests/test_processing/test_blocks.py index f9b398b4..2f7c7fae 100644 --- a/tests/test_processing/test_blocks.py +++ b/tests/test_processing/test_blocks.py @@ -62,6 +62,7 @@ def test_keys_and_values(self): self.assertEqual(expected_columns, columns) + class TestPointSupportDataClass(unittest.TestCase): def test_get_from_files_fn(self):