Basic geoprocessing tools to handle geotiff and shapefile data
Contains some additional tools for basic glacier calculations and plotting
Activate the desired python or conda environment, then enter pip install raster_basics
To import the modules, type import raster_basics or import specific functions with from raster_basics.RasterBasics import function
If you've already downloaded the module, enter sudo pip install raster_basics --upgrade while in the conda environment to upgrade to the newest version
All of the functions can be imported with:
from raster_basics.RasterBasics import rOpen, show_fig, show_fig_subplot, rasterLike, rasterMathfrom raster_basics.RasterBasics import shpReprojection, shpClip, tifReprojectionResample, reproject_velocity, fillHole, mosaic_filesfrom raster_basics.RasterBasics import extract_along_line,points_along_lines, end_points
Dependencies are automatically installed when raster_basics is downloaded via PyPI. Dependencies can otherwise be installed via the requirements.txt file. Download the file, navigate to it's directory in the terminal, and install dependencies by typing pip install -r requirements.txt or conda install --file requirements.txt. If creating a new conda environment for raster_basics, you may also need to conda install pip initially. This should install all the dependencies needed to run the raster_basics module.
The raster_basics module can be used in Jupyter Notebooks or any IDE. Simply import the desired functions to use them. An example of use can be found in the rasterio_basics-package.ipynb, velocity_reprojection.ipynb, wolverine_index_site_method.ipynb, and gulkana_flux_gate_method.ipynb notebooks.
rOpen: open a geotiff file as an array, and/or get the geotiff resolution and coordinate systemshow_fig: show geotiff as a matplotlib figureshow_fig_subplot: shows multiple geotiff or array-like figuresrasterLike: save array as a rastershpReprojection: reproject shapefileshpBuffer: add a buffer to shapefileshpClip: clip geotiff by a shapefiletifReprojectionResample: reproject, resample, and/or clip geotiffreproject_velocity: reproject velocity datarasterMath: perform basic arithmetic on two raster files (even if they have difference crs, res, and/or extents)fillHole: fill missing data in geotifffillArrayHole: helper function forfillHole, but works directly with arraysmosaic_files: mosaic two or more geotiffs togetherextract_along_line: sample for points on a line (this uses geocoordinate points as line)points_along_lines: sample for points on a line (this uses a shapefile line)end_points: obtain raster values at point locationsdistance_to_shp: gets the distance from every pixel to a shapefile
After installing raster_basics into a virtual environment, create a Jupyter Notebook kernel to use the example notebooks. In the terminal, enter python -m ipykernel install --user --name raster_basics_kernel (the last entry can be any desired kernel name). Then, launch the Jupyter with jupyter notebook. In the browser tab, navigate to examples and open the desired notebook.
Follow the Jupyter Notebooks in the examples folder to see how functions can be used. Access to the sample data used in the tutorial can be found by following the links in the notebooks. Run the notebook code in the same folder as the data.
There are a few more functions to help produce specific plots and glacier calculations. These can be imported with:
from raster_basics.GlacierFunctions import FUNCTION_NAMEfrom raster_basics.BaseFunctions import FUNCTION_NAMEfrom raster_basics.DataPlots import FUNCTION_NAMEfrom raster_basics.SmoothingFunctions import FUNCTION_NAMEfrom raster_basics.NoiseFunctions import FUNCTION_NAME
where FUNCTION_NAME is the name of the desired function.
glacierArea: get the area of a glaciertotalMassBalance: get the total mass change on a glacier (pixel by pixel)totalMassBalanceValue: get the total mass change on a glacier (area-sum of pixels)divQ: get the flux divergenceglacierSlope: alternate function to obtain the riserun or degree slope from an arraydemHillshade: create a hillshade from a DEMvelocityAspect: returns the aspect of velocity based on vx and vyvelAspectAngle: get the angle between two arrays of velocity aspectvelFlowlineAspect: return the aspect of every pixel based on a shapely geometry flowlinevelFlowlineOutlineAspect: return the aspect of every pixel based on a shapely geometry flowline and outlineparticle_flow: track the position of a particle based on velocity arraysdistance_from_line: get an array representing the distance of every pixel from any True value in an array
glacierOutline: uses a shapefile and raster array of ones to create a binary array of glacier terrain (1 is glacier, 0 is off-glacier)altitudeAggregation: returns statistics for a desired statistic in an elevation bin, bin boundaries, count, number, standar deviation, min, and maxbinPercentile: returns binned statistics value at a desired percentile of a bin (e.g. 25th percentile MB value per elevation bin)latlonTiffIndex: obtain raster array index values from a lat/lon coordinate pair
Note that all of these plotting functions only save the image if savefig=True (by default, it is set to False).
plotData: another method to plot an array. Can handle quiver inputs for arrows on velocity plots (quiver input fromvelPlotfunction)plotData3: same asplotDatabut places 3 plots side-by-sideplotMany: an arbitrary number of plots side-by-side in a gridelevationBinPlot: plots two sets of data: line plot for MB and horizontal bar graph for elevation bin sizeelevationBinPlot3Subfigs: plotselevationBinPlotalong with 3 more subplots from desired input arraysplotDataPoints: plots labeled data points on top of an array basemap. This is used to plot stake locations, for exampleplotDataPoints2: identical toplotDataPoints, but plots two maps side-by-sidevelPlot: this does no actually plot anything. Rather, it returns the quiver input needed to plot velocity arrows in other functions such asplotDataplotClassify: plot array with discrete valuesplotContinuous: plot array with continuous valuesplot_binned_data: returns a data array with values corresponding to alitudinally-aggregated elevation bins
sgolay2d: Savitzky-Golay smoothing filter to eliminate high frequency noise via moving average; a low-pass filtergaussianFilter: Gaussian (normal) smoothing filterdynamicSmoothing: Gaussian filter, dynamic smoothing with changing pixel window sizedynamicSmoothingExponential: Exponential filter, dynamic smoothing with changing pixel window sizeadd_array_border: Helper function to add a border around an array indynamicSmoothinganddynamicSmoothingExponentialsmoothingCorrection: Apply a correction to smoothed data products, such that smoothing does not decrease the mean values Correction is based on glacier centerline valuesdistance_scaling_correction: corrects a smoothed data products based on a scaling from relative distance from centerline
add_grf_noise: Introduce spatially-correlated noise via Gaussian random fieldsadd_ice_thickness_bias: Add ice thickness bias based on parabolic vs V-shape bed cross-section assumption