Commit 694dbb38 authored by Roelofsen, Hans's avatar Roelofsen, Hans
Browse files

Merge branch 'LeviFunctions2' into 'master'

Levi functions2

See merge request !10
parents d38ea91c 1831ed36
# Default ignored files
/shelf/
/workspace.xml
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="jdk" jdkName="Python 3.7 (py37) (2)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PyPep8Inspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<option name="ignoredErrors">
<list>
<option value="W605" />
</list>
</option>
</inspection_tool>
<inspection_tool class="PyUnresolvedReferencesInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoredIdentifiers">
<list>
<option value="int.*" />
<option value="tuple.*" />
</list>
</option>
</inspection_tool>
</profile>
</component>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7 (py37) (2)" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/benb_utils.iml" filepath="$PROJECT_DIR$/.idea/benb_utils.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
......@@ -148,7 +148,6 @@ def colrow2xy(colrow, rio_object=None, affine_in=None):
return x, y
def progress_bar(iterable, prefix='', suffix='', decimals=1, length=100, fill='#', printEnd="\r"):
"""
Call in a loop to create terminal progress bar
......@@ -230,4 +229,3 @@ def file_of_type(x, ext):
raise argparse.ArgumentTypeError('{} is not a file'.format(x))
if not ext_match:
raise argparse.ArgumentTypeError('{} is not a correct file'.format(x))
import rasterio as rio
import numpy as np
import os
def buffer_raster(raster_path: str, crs, padding: int = 100):
"""
Parameters
----------
raster_path : str
filepath for raster to buffer
crs
crs specification
padding : int
amount of cells to buffer around raster
Returns
-------
buffered raster : rasterio.io.DatasetReader
"""
raster = rio.open(raster_path)
raster_buffered = raster.read(1)
for i in range(padding):
raster_buffered = np.insert(raster_buffered, [0], -9999, axis=1)
raster_buffered = np.insert(raster_buffered, [0], -9999, axis=0)
raster_buffered = np.insert(raster_buffered, [-1], -9999, axis=1)
raster_buffered = np.insert(raster_buffered, [-1], -9999, axis=0)
raster_buffered = np.where(raster_buffered == -9999, np.nan, raster_buffered)
origin_x, origin_y = raster.xy(-padding, -padding)
outputpath = os.path.splitext(raster_path)[0] + ".tif"
with rio.open(
outputpath,
"w",
driver="GTiff",
height=raster_buffered.shape[0],
width=raster_buffered.shape[1],
count=1,
dtype=raster_buffered.dtype,
crs=crs,
transform=rio.transform.from_origin(origin_x - 12.5, origin_y + 12.5, 25, 25),
) as outputraster:
outputraster.write(raster_buffered, 1)
return rio.open(outputpath)
......@@ -9,7 +9,7 @@ from mpl_toolkits.axes_grid1 import make_axes_locatable
import os
def mnp_hokaggregation(hok_csv, hokken_polygon_path, background_raster_path, outputdir):
def mnp_hokaggregation(hok_csv, hokken_polygon_path, background_raster_path, outputdir, gridcell_count=False):
"""
make aggregationplots for use in manual validation of mnp runs. can both aggregate validation data and species
model gridcells per hok.
......@@ -39,12 +39,12 @@ def mnp_hokaggregation(hok_csv, hokken_polygon_path, background_raster_path, out
counts.columns = colnames
counthokken = pd.merge(hokken, counts, on="ID")
if "COUNT_KEY_VALUE" in colnames:
bounds = np.array([1, 10, 100, 1000, 10000, 40000])
if "MEAN" in colnames:
bounds = np.round(np.arange(1,counts.MEAN.max(),counts.MEAN.max()/6),1)
explabel = "_"
valuecolumn = "COUNT_KEY_VALUE"
extend = "neither"
ylabel_text = "Number of gridcells in Hok"
valuecolumn = "MEAN"
extend = "max"
ylabel_text = "Number of observations in SOVON"
elif "OPS_COUNT" in colnames:
bounds = np.array([1, 10, 50, 100, 500, 1000])
......@@ -53,6 +53,20 @@ def mnp_hokaggregation(hok_csv, hokken_polygon_path, background_raster_path, out
extend = "max"
ylabel_text = "number of observations in NDFF"
elif gridcell_count:
bounds = np.array([1, 10, 100, 1000, 10000, 40000])
explabel = "_"
valuecolumn = "COUNT_KEY_VALUE"
extend = "neither"
ylabel_text = "Number of gridcells in Hok"
elif "MAX_KEY_VALUE" in colnames:
bounds = np.array([0, 0.1, 0.5, 1, 1.5, 2])
explabel = "_"
valuecolumn = "MAX_KEY_VALUE"
extend = "max"
ylabel_text = "Largest key population in cell"
else:
raise Exception("no value column in columns")
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment