Package: uavgeo
uavgeo ⛰️A UAV-specific Python image processing library built uponxarrayandgeopandas.Explore the wiki »Report Bug.Request FeatureTable Of ContentsSummaryFeaturesIndex calculationDataset chippingDEM creationDataset shadowsInstallationSummaryUAV image analysis is a powerful tool to gain valuable insights into the rural, urban and natural environment. Especially in conjunction with Deep Learning, large strides can be made. The problem however is that there is little standardization and a lot of boilerplate code to be written for image analysis. This package serves to bridge the gap in image processing and machine learning in UAV applications. It builds upon the efforts fromxarray,rasterio/rioxarrayandgeopandas.
Importing should be done through rioxarray functions. The currently implemented functions inuavgeoexamples cover index calculation (see below) and data/rastser chipping and reconstruction.FeaturesTheuavgeopackage can be installed throughpip. Additionally, a docker container with jupyterlab can be used. See the Installation section for more information.Dataset chippingChipping is a prerequisite for geographic raster data to be processed for ML/DL models.
This library implements it as follows:creating a chips-geodataframe based on wanted dimensions, overlap and raster shapechipping the input raster into a list of chipsreset the coordinates from crs to image pixels (numpy assumed dimensions)export the list of images to file (or do whatever)(optional): perform the ML modelling on the chips(optional): reconstruct the images back to the original raster and crsThis whole pipeline and functions are presented in anexample notebookCreating a dem with thecalc_dem_from_dsmfunctionThecalc_dem_from_dsmfunction is a utility to create a Digital Elevation Model (DEM) from a Digital Surface Model (DSM) using specified sampling parameters. It operates on data represented as xarray DataArray and relies on the rasterio library for Geographic Information System (GIS) operations. The resulting DEM is created by sampling and extracting the minimum elevation values from the DSM at a user-defined grid, built upon the chipping presented above.An example can be found in anexample notebookInputs:dsm (xr.DataArray): The input Digital Surface Model as an xarray DataArray.pixel_size (float): The pixel size in the same unit as the DSM data.sampling_meters (float): The distance in meters that defines the sampling grid for DEM creation.importuavgeoasugimportrioxarraryasrxrdsm_data=rxr.open_rasterio(('dsm.tif')# Load DSM data from a GeoTIFF filepixel_size=1.0# Specify the pixel size in meterssampling_distance=10.0# Define the sampling distance in metersdem=ug.compute.calc_dem_from_dsm(dsm_data,pixel_size,sampling_distance)# Calculate the DEMchm=dem-dsm_data# subtract the two, and you have a Canopy Height Model tooIndex calculationsYou can use it to calculate a variety of indices from your imagery:# assuming you already loaded your data as ortho:importuavgeoasugsavi=ug.compute.calc_savi(bandstack=ortho,red_id=1,nir_id=4,l=0.51)savi.plot.imshow(cmap="greens")Implemented indices:Based on the list fromFieldImageR. With some additional indices added.
They can be accesses through theuavgeo.computemodule. All functions expect abandstack, which is anxarray.DataArraywityh multiple bands asbandsdata. And the required bands ids, eg.:red_id=1. By default the functions rescale the output floats back to uint8 (0-255). This behaviour can be turned of with therescale = Falseparameter.Indexcalc_indexnameDescriptionFormulaRelated TraitsReferencesBIcalc_biBrightness Indexsqrt((RA^2+GA^2+B^2)/3)Vegetation coverage, water contentRichardson and Wiegand (1977)SCIcalc_sciSoil Color Index(R-G)/(R+G)Soil colorMathieu et al. (1998)GLIcalc_gliGreen Leaf Index(2 * G-R-B)/(2 * G+R+B)ChlorophyllLouhaichi et al. (2001)HIcalc_hiHue Index(2*R-G-B)/(G-B)Soil colorEscadafal et al. (1994)NGRDIcalc_ngrdiNormalized Green Red Difference Index(G-R)/(G+R)Chlorophyll, biomass, water contentTucker (1979)SIcalc_siSaturation Index(R-B)/(R+B)Soil colorEscadafal et al. (1994)VARIcalc_variVisible Atmospherically Resistant Index(G-R)/(G+R-B)Canopy, biomass, chlorophyllGitelson et al. (2002)HUEcalc_hueOverall Hue Index#atan(2*(B-G-R)/30.5*(G-R))Soil colorEscadafal et al. (1994)BGIcalc_bgiBlue Green Pigment IndexB/GChlorophyllZarco-Tejada et al. (2005)PSRIcalc_psriPlant Senescence Reflectance Index(R-G)/(RE)Chlorophyll, LAIMerzlyak et al. (1999)NDVIcalc_ndviNormalized Difference Vegetation Index(NIR-R)/(NIR+R)Chlorophyll, nitrogen, maturityRouse et al. (1974)GNDVIcalc_gndviGreen Normalized Difference Vegetation Index(NIR-G)/(NIR+G)Chlorophyll, LAI, biomass, yieldGitelson et al. (1996)RVIcalc_rviRatio Vegetation IndexNIR/RChlorophyll, LAI, nitrogen, protein content, water contentPearson and Miller (1972)NDREcalc_ndreNormalized Difference Red Edge Index(NIR-RE)/(NIR+RE)Biomass, water content, nitrogenGitelson and Merzlyak (1994)TVIcalc_tviTriangular Vegetation Index0.5 * (120 * (NIR — G)-200 * (R — G))ChlorophyllBroge and Leblanc (2000)CVIcalc_cviChlorophyll Vegetation Index(NIR * R)/(GA^2)ChlorophyllVincini et al. (2008)EVIcalc_eviEnhanced Vegetation Index2.5  *(NIR — R)/(NIR + 6 * R — 7.5 * B)Nitrogen, chlorophyllHuete et al. (2002)CIGcalc_cigChlorophyll Index — Green(NIR/G) — 1ChlorophyllGitelson et al. (2003)CIREcalc_cireChlorophyll Index — Red Edge(NIR/RE) — 1ChlorophyllGitelson et al. (2003)DVIcalc_dviDifference Vegetation IndexNIR-RENitrogen, chlorophyllJordan (1969)RGBVIcalc_rgbviRGB Vegetation Index((G^2)-(R * B)/(G^2)+(R * B))Nitrogen, chlorophyllBendig et al. (2015)SAVIcalc_saviSoil Adjusted Vegetation Index(NIR-R)/(NIR+R+l)*(1+l)Vegetation coverage, LAIHuete (1988)-------------------------------------------------------------------------NDWIcalc_ndwiNormalized Difference Water Index(G-NIR)/(G+NIR)Water coverage, water contentMcFeeters (1996)MNDWIcalc_mndwiModified Normalized Difference Water Index(G-SWIR)/(GREEN+SWIR)Water coverage, water contentMcFeeters (1996)AWEIshcalc_aweishAutomated water extraction index (sh)B + 2.5 * G - 1.5 * (NIR-SWIR1) - 0.25 * SWIR2Water coverage, water contentFayeisha (2014)AWEInshcalc_aweinshAutomated water extraction index (nsh)4 * (G - SWIR1) - (0.25 * NIR + 2.75* SWIR1)Water coverage, water contentFayeisha (2014)Custom/other spectral index:You could also write your own index calculators, according to the following template:fromuavgeo.computeimportrescale_floatsdefcalc_custom(bandstack:xr.DataArray,band_a=1,band_b=2,rescale=True):ds_b=bandstack.astype(float)a:xr.DataArray=ds_b.sel(band=band_a)b:xr.DataArray=ds_b.sel(band=band_b)custom=a/b+1custom.name="custom index"ifrescale:custom=rescale_floats(custom)returncustomShadow calculations:Calculate vineyard shadows using a method proposed by Velez et al. (2021) for vineyards and UAVs. Based on Kmeans. Velez et al. (2021). "A New Leaf Area Index Methodology Based on Unmanned Aerial Vehicle Imagery for Vineyards."https://oeno-one.eu/article/view/4639fromuavgeo.computeimportcalc_vineyard_shadowsvineyard_data=xr.open_rasterio('path/to/vineyard_image.tif')shadows_mask=calc_vineyard_shadows(vineyard_data)# can also be used with a band_id to base the shadows from (NIR or Red are usally best)shadows_mask=calc_vineyard_shadows(vineyard_data,band_id=4)Installation:It is built upon the work ofrioxarray,geopandas,shapelyand a few more: see requirements.txt.
Additionally, when working with the object detection part, theultralyticsandtorchlibraries (torch,torchvision,torchdata) is also a prerequisite.
You can choose to install everything in a Python virtual environment or directly run a jupyterlab docker:Option A: Setup directly in python:Create a new environment (optional but recommended):condacreate-nuavgeo_envpython=3.10
condaactivateuavgeo_envInstall the required dependencies:Using conda (not recommended):condainstall-cconda-forgerioxarraygeopandasshapelyUsing pip:pipinstall-frioxarraygeopandasshapelyInstall this package (for now: pip only)pipinstalluavgeoOption B: Setup through Docker:This starts a premade jupyter environment with everything preinstalled, based around a nvidia docker image for DL support.Linux/Ubuntu:dockerrun--rm-it--runtime=nvidia-p8888:8888--gpus1--shm-size=5gb--network=host-v/path_to_local/dir:/home/jovyanjurrain/drone-ml:gpu-torch11.8-uavgeoformers--network=hostflag whether you want to run it on a different machine in the same network, and want to access the notebook. (does not run locally)-vflag makes sure that once downloaded, it stays in that folder, accessible from the PC, and when restarting, all the weights etc. remain in that folder.path_to_local/diris thew path to your working dir where you want to access the notebook from. can be.if you alreadycded into it.--runtime=nvidiacan be skipped when working on WSL2Windows requires WSL2 and NVIDIA drivers, WSL2 should also have the nvidia toolkit (for deep learning)