Skip to content

Commit

Permalink
issue 428 resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonMolinsky committed Jun 28, 2024
1 parent fd8c757 commit fec0e41
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
6 changes: 6 additions & 0 deletions changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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**
Expand Down
2 changes: 1 addition & 1 deletion pyinterpolate/processing/transform/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,'
Expand Down
27 changes: 24 additions & 3 deletions tests/test_pipelines/test_smooth_areas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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)

Expand All @@ -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)
1 change: 1 addition & 0 deletions tests/test_processing/test_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit fec0e41

Please sign in to comment.