Skip to content

mttaherpoor/Interpolation-And-Evaluate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Interpolation and Evaluation

Table of Contents:

Objective

The goal of this code is to find the best interpolation method for quantitative data and predict other areas in GIS. The selected methods will be evaluated using metrics such as RSME, R, MABE, MAPE, etc. For more details, click here.

Installation

Clone the repository:

git clone https://github.com/yourusername/yourproject.git
cd yourproject

Library Installation

Install Pandas

This library is installed by default and is recognized as pd in the code.

Install Arcpy

If ArcMap or ArcGIS Pro software is installed, arcpy is installed by default.

Install Geopandas

  1. Install Anaconda.

  2. Remove all environments cloned from Anaconda through the package manager of Anaconda or ArcGIS Pro.

  3. Open the Conda prompt for ArcGIS from the following address:

    C:\Program Files\ArcGIS\Pro\bin\Python\Scripts\proenv.bat

  4. Clone from arcgispro-py3 using the following command:

    conda create --name gisenv --clone arcgispro-py3

    Note: You can use any name instead of gisenv.

  5. Activate the environment created in step 3 using the following command:

    activate gisenv

  6. Install geopandas and its required packages using the following commands:

pip install geopandas 

pip install folium

pip install matplotlib 

pip install mapclassify

Install Rasterio

  1. Install Anaconda.
  2. Remove all environments cloned from Anaconda through the package manager of Anaconda or ArcGIS Pro.
  3. Open the Conda prompt for ArcGIS from the following address:

C:\Program Files\ArcGIS\Pro\bin\Python\Scripts\proenv.bat

  1. Clone from arcgispro-py3 using the following command:

conda create --name gisenv --clone arcgispro-py3

Note: You can use any name instead of gisenv.

  1. Activate the environment created in step 3 using the following command:

activate gisenv

  1. Install rasterio using the following command:
pip install rasterio

Install Permetrics

  1. Install Anaconda.
  2. Remove all environments cloned from Anaconda through the package manager of Anaconda or ArcGIS Pro.
  3. Open the Conda prompt for ArcGIS from the following address:

C:\Program Files\ArcGIS\Pro\bin\Python\Scripts\proenv.bat

  1. Clone from arcgispro-py3 using the following command:

conda create --name gisenv --clone arcgispro-py3

Note: You can use any name instead of gisenv.

  1. Activate the environment created in step 3 using the following command:

activate gisenv

  1. Install permetrics using the following commands:
git clone https://github.com/thieu1995/permetrics.git
cd permetrics
python setup.py install

Functions Used in Libraries

Pandas Functions

GitHub Pandas

Website Pandas

Function Name Input Parameters Output Type Link
read_excel ExcelFile, Sheet Name DataFrame Link
iterrows None Row in DataFrame Link
drop Labels, Axis DataFrame or None Link
at Row, Column Everything Link
DataFrame Data, Index DataFrame Link
columns Origin, Destination Object Link
rename Dictionary DataFrame Link
merge DataFrame, On, How DataFrame Link
to_excel ExcelFile, Index Excel Link

Arcpy Functions

GitHub Arcpy

Website Arcpy

Function Name Input Parameters Output Type Link
sa.Idw Shapefile or Feature Class, Z_Field, Method, Cell_Size Raster Link
sa.Kriging Shapefile or Feature Class, Z_Field, Method, Cell_Size Raster Link
sa.Spline Shapefile or Feature Class, Z_Field, Method, Cell_Size Raster Link

Geopandas Functions

GitHub Geopandas

Website Geopandas

Function Name Input Parameters Output Type Link
GeoDataFrame Data, Geometry GeoDataFrame Link
points_from_xy Longitude, Latitude Point Link
set_crs EPSG, Inplace Int Link
to_file Filename, Driver, Encoding Everything Link

Rasterio Functions

GitHub Rasterio

Website Rasterio

Function Name Input Parameters Output Type Link
open Raster File Link
index Longitude, Latitude Tuple Link
read 1, Window Array Link

Permetrics Functions

GitHub Permetrics

Website Permetrics

Function Name Input Parameters Output Type Link
RegressionMetric Y_true, Y_pred RegressionMetric Link
mean_bias_error None Double Link
root_mean_squared_error None Double Link
mean_percentage_error None Double Link
pearson_correlation_coefficient None Double Link

Example

Excel Data from YouTube

The table below is based on the YouTube video.

The file is sample.xlsx.

Image 1

This file is model.xlsx.

Image 2

Variables

workspace: The address where the interpolation.gdb file should be created.

address_input: The address of the sample Excel file.

zone: The study zone, which is between 38 and 41 for Iran.

raster_address: By default, it is C:\temp.tif. If it gives an error, change the image address, and it will work correctly.

address_model: The address of the model Excel file.

program: Continue the program or not.

Column 2 should be x, and column 3 should be y.

field: Reads from the model Excel.

final_Excel: Asks for the final Excel address.

start_column: Stores the column number of methods, which is 4 by default.

evaluate_Excel: Asks for the evaluation Excel address.

Output Images

Final Excel:

Image 3

Evaluation Excel:

Image 4

Evaluation Metrics

Evaluation Methods

Image 5

The variables are as follows:

Image 6

Code Development

Interpolation

Other Interpolation Methods

if interpolation_type == "Idw":
 out_raster = arcpy.sa.Idw(temp_address, field, method)       
elif interpolation_type == "Kriging":
 out_raster = arcpy.sa.Kriging(temp_address, method, field)
elif interpolation_type == "Spline":
 out_raster = arcpy.sa.Spline(temp_address, field, spline_type=method)
else:
 return None

Evaluation

Other Evaluation Methods

if method == "MBE":
    res = evaluator.mean_bias_error()
    res_dict[i] = [col, res]  
elif method == "RMSE":
    res = evaluator.root_mean_squared_error()
    res_dict[i] = [col, res]
elif method == "MAPE":
    res = evaluator.mean_percentage_error()
    res_dict[i] = [col, res]
elif method == "R":
    res = evaluator.pearson_correlation_coefficient()
    res_dict[i] = [col, res]
else:
    return None

Contributing

  1. Fork the repository.

  2. Create a new branch:git checkout -b feature-newfeature.

  3. Commit changes: git commit -m 'Add new feature'.

  4. Push to the branch: git push origin feature-newfeature.

  5. Submit a pull request.

Contact

About

cross validation interpolation method and evalute them

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published