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

A little idea for point sampling #1

Open
osgeokr opened this issue Mar 24, 2022 · 0 comments
Open

A little idea for point sampling #1

osgeokr opened this issue Mar 24, 2022 · 0 comments

Comments

@osgeokr
Copy link

osgeokr commented Mar 24, 2022

Thanks again for developing PySDMs. I want to share a little idea about PySDMs and Python-SDM you wrote earlier (https://github.com/daniel-furman/Python-species-distribution-modeling/blob/main/Python-sdm.ipynb) .

As you know, the point sampling of rasterstats, which pyimute relies on, is quite slow. I've been using QGIS' Point sampling tool plugin as an alternative to this. This is definitely fast in speed, but I wanted to do everything in a Python environment without running QGIS if possible.

In this regard, there is a point sampling function called rasterio.sample module(https://rasterio.readthedocs.io/en/latest/api/rasterio.sample.html) in the rasterio package that is also used by PySDMs. I tested it and the speed is also very fast! I finished a small test today and uploaded the source code to my github. I would like to share the link. Hope this helps in future updates.
https://github.com/osgeokr/SDM/blob/main/SDM_Species_Distribution_Modeling_v.0.4.ipynb

gdf = gpd.GeoDataFrame.from_file("DATA/JTREE.shp")
coord_list = [(x,y) for x,y in zip(gdf['geometry'].x , gdf['geometry'].y)]

raster_features = sorted(glob.glob('DATA/BIOCLIM/bclim*.asc'))

from pathlib import Path
for file in raster_features:
src = rasterio.open(file)
gdf[Path(file).stem] = [x for x in src.sample(coord_list)]
gdf[Path(file).stem] = gdf[Path(file).stem].astype('float64')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant