Coder Social home page Coder Social logo

woeminator's Introduction

WoEminator

A few scripts to apply Weights of Evidence (and Frequency Ratio) to spatial data (landslides).

Comes with basic functions to ready your .shp and .tif files for calculation.

If you are looking for a more complete solution with a GUI you might like LSAT.

Recipes

A small collection of snippets to get you started (and for me to reuse).

Convert to Array

From Raster to Array

Default band = 1. If you want to use another band specify it as a second parameter of raster2Array. The array will have the type of the raster.

from toArray import raster2Array

raster_path = "path_to_raster"
array_raster = raster2Array(raster_path)

From Shapefile to Array

Default no data = -9999. If you want to use another value specify it as the last parameter of vector2Array. For good compability the value to write into the array should be an unique integer and >= 1. The array type is always int16.

from toArray import vector2Array

vector_path = "path_to_vector"
mask_raster_path = "path_to_mask_raster"
burn_field = "attribute_from_FAT_to_write_into_array"
array_vector = vector2Array(vector_path, mask_raster_path, burn_field)

Convert to Raster

Default no data = -9999. If you want to use another value specify it as the second to last parameter of array2Raster. Default raster type = gdal.GDT_Float32. If you want to use another type specify it as the last parameter of array2Raster.

from toRaster import array2Raster

array = numpy_array
mask_raster_path = "path_to_mask_raster"
out_raster_path = "path_to_output_raster"
out_raster = array2Raster(array, mask_raster_path, out_raster_path)

Full WoE Workflow - From gis files to averaged Weights raster

Uses all default values to create an averaged weights raster out of 50 subsamples of the training array and an input raster file.

from arrayWork import readyArray4calc, replaceValuesInArray
import numpy as np
from randomize import getRandomArrays
from toArray import raster2Array, vector2Array
from toRaster import array2Raster
from woe import WoE

landslides_file = "path_to_vector"
attribute_to_burn_in = "attribute"
raster_file = "path_to_raster"
output_file = "path_to_output_raster"

raster_array = raster2Array(raster_file)
ls_array = vector2Array(landslides_file, raster_file, attribute_to_burn_in)

ls_train_arrays, _ = getRandomArrays(ls_array, 50)
ls_train_arrays = [readyArray4calc(ls_train_array) for ls_train_array in ls_train_arrays]

weights = []
for ls_train_array in ls_train_arrays:
    tmp = WoE(raster_array, ls_train_array)
    weights.append(tmp.resultsTable["classWeight"])
weights_average = np.array(weights).mean(axis=0)

weights_array = replaceValuesInArray(raster_array, tmp.resultsTable["classValue"], weights_average)

array2Raster(weights_array, raster_file, output_file)

woeminator's People

Contributors

nck00 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.