richardutils package#
Submodules#
richardutils.cli module#
richardutils.richardutils module#
- richardutils.richardutils.cetrainbow()#
Make a CET perceptually uniform rainbow colormap newcmp = cetrainbow() cm.register_cmap(name=’cetrainbow’, cmap=newcmp)
- To reverse: cet_r = ListedColormap(newcmp.colors[::-1])
cm.register_cmap(name=’cetrainbow_r’, cmap=cet_r)
- richardutils.richardutils.clip_da(da, gdfpath)#
Clips a rioxarray by geodataframe polygons
- Parameters:
da – rioxarray Data Array
gdfpath – Path to vector polygon dataset
- Returns:
Clipped rioxarray
Examples
schaus = clip_da(‘dapath’, ‘gdfpath’)
- richardutils.richardutils.clip_dabox(dapath, bb)#
Clips a rioxarray by bounding box
- Parameters:
dapath – Path to raster
bb – boundingbox coordinates iterable xmin, ymin, xmax, ymax
- Returns:
Clipped rioxarray
Examples
schaus = clip_dabox(‘dapath’, bb)
- richardutils.richardutils.clip_raster(dapath, gdfpath)#
Clips a rioxarray by geodataframe polygons
- Parameters:
dapath – Path to raster
gdfpath – Path to vector polygon dataset
- Returns:
Clipped rioxarray
Examples
schaus = clip_da(‘dapath’, ‘gdfpath’)
- richardutils.richardutils.create_vrt_for_geotiffs(directory)#
- Parameters:
directory – Path to raster tifs
- richardutils.richardutils.df_bb(df, bb, xcol='longitude', ycol='latitude')#
Clips a dataframe of points by a bounding box
- Parameters:
df – a dataframe from csv
xcol – x coordinate [longitude, easting etc.]
ycol – y coordinate
bb – a bounding box
- Returns:
df trimmed to bounding box
Examples
dfbb = df_bb(df,bb, ‘longitude’,’latitude’)
- richardutils.richardutils.ers_dict(strpath, masked=True, chunks=None, dsmatch=None)#
Walks a directory of ers grids and returns a dictionary of rioxarray DataArrays :param strpath: directory name :param chunks: tuple of integers :param dsmatch: data array to match the directory of raster to :param masked: whether to mask by nodata, default is yes, pass masked=False if not desired
- Returns:
a dictionary of rioxarrays
Examples
ers_dict(r’D:BananaSplits’) ers_dict(r’D:BananaSplits’, chunk=s(1,1024,1024))
- richardutils.richardutils.extract_band(tifpath, findstr)#
Extract a named band from a geotiff via rioxarray
- Parameters:
tifpath – Path to raster
- Returns:
geotiff band
Examples
darock = extract_band(usepath, ‘ROCK’)
- richardutils.richardutils.gdb_dict(gdbpath)#
Returns a dictionary of geodataframes
- Parameters:
gdbpath – path to a FileGDB
- richardutils.richardutils.gdf_bb(gdf, bb)#
Returns a bounding box filtered gdf
- Parameters:
gdf – geodataframe
bb – bounding box
- richardutils.richardutils.gdf_parquet_dict(strpath)#
Walks a directory of parquet geodataframes :param strpath: directory name
- Returns:
a dictionary of geodataframes
Examples
gdf_parquet_dict(r’D:BananaSplits’)
- richardutils.richardutils.gdf_parquet_list(strpath)#
Walks a directory of parquet geodataframes :param strpath: directory name
- Returns:
a list of geodataframes
Examples
gdf_parquet_list(r’D:BananaSplits’)
- richardutils.richardutils.gdf_shape_dict(strpath)#
Walks a directory of shapefiles :param strpath: directory name
- Returns:
a dictionary of geodataframes
Examples
gdf_shape_dict(r’D:BananaSplits’)
- richardutils.richardutils.global_low_res()#
- Returns:
built in global low res world polygons for cheap clipping
- richardutils.richardutils.location_sample(gdf, da, name_col)#
Returns a dataframe of points sample from a DataArray by location at once
- Parameters:
gdf – geodataframe of points
da – DataArray to sample:
name_col – String to identify the location names
- Returns:
Onshore location sample dataframe
- richardutils.richardutils.makegdf(df, xcol='longitude', ycol='latitude', crs='EPSG:4326')#
Turn a dataframe of a csv of points into a geodataframe
- Parameters:
df – a dataframe from csv
xcol – x coordinate [longitude, easting etc.]
ycol – y coordinate
- Returns:
gdf geodataframe
Examples
gdf = makegdf(df,’longitude’,’latitude’,’EPSG:4326’)
- richardutils.richardutils.mmnorm(da)#
Minmax norm xarray DataArray
- Parameters:
da – A DataArray
- Returns:
normalised DataArray
Examples
mnorm(geoscience_raster)
- richardutils.richardutils.norm_diff_comparison(da1, da2)#
Normalised difference and ratio of two xarray
- Parameters:
da1 – DataArrays
da2 – DataArrays
- Returns:
Difference and ratio of reprojected match DataArrays
Examples
norm_diff_comparison(daarea1, daarea2):
- richardutils.richardutils.plotgdf(gdf, column, title, alpha=0.5, savefig=True, cmap='cetrainbow', slide_dict=None, size=7, legend=False)#
Plot a gepdataframe with a title. Allow saving to a png Allow adding to a dictionary e.g. for presentation use
- Parameters:
gdf – A gepdataframe
column – string column to plot
title – title of plot
alpha – transparently
savefig – write a png to the directory
cmap – a matplotlib colormap
slide_dict – dictionary to store reference to plots in
Examples:
- richardutils.richardutils.plotgdf_da(gdf, da, column, title, alpha=0.5, savefig=True, cmap='cetrainbow', cmap_da='cetrainbow', slide_dict=None, size=7, legend=False, robust=False)#
Plot a geopdataframe with a title. Allow saving to a png Allow adding to a dictionary e.g. for presentation use
- Parameters:
gdf – A gepdataframe
column – string column to plot
title – title of plot
alpha – transparently
savefig – write a png to the directory
cmap – a matplotlib colormap or a string with color_colorwanted e.g. plotgdf(da,cmap=”color_white”) to get a flat color gdf plot
slide_dict – dictionary to store reference to plots in
Examples:
- richardutils.richardutils.plothist(da, title, color='Orange', savefig=True, slide_dict=None)#
- richardutils.richardutils.plothist_combo(da, da2, title, color1='Orange', color2='Gold', savefig=True, slide_dict=None)#
Plot a geodataframe with a title. Allow saving to a png Allow adding to a dictionary e.g. for presentation use
- Parameters:
da – A DataArray
da2 – A DataArray to compare
color1 – string color for first histogram
color2 – string color for secondt histogram
title – title of plot
alpha – transparently
savefig – write a png to the directory
slide_dict – dictionary to store reference to plots in
- richardutils.richardutils.plotmap(da, robust=False, cmap='cetrainbow', size=6, title='Title Here', clip=None, savefig=True, slide_dict=None, background=False)#
Plot a dataarray with a title. Allow saving to a png Allow adding to a dictionary e.g. for presentation use
- Parameters:
da – A DataArray
robust – clip to 2/98 or not
cmap – a matplotlib colormap
size – integer size of plot
title – string title of plot
clip – quantile number to clip to
savefig – save png to directory
slide_dict – add png path to a dictionary
background – plot a background shape layer
- Returns:
The squarest root.
Examples:
- richardutils.richardutils.plotmap3(da, robust=False, cmap='cetrainbow', size=6, title='Title Here', clip=None, savefig=True, slide_dict=None, background=False)#
Plot a dataarray with a title. Allow saving to a png Allow adding to a dictionary e.g. for presentation use
- Parameters:
da – A DataArray with 3 bands
robust – clip to 2/98 or not
cmap – a matplotlib colormap
size – integer size of plot
title – string title of plot
clip – quantile number to clip to
savefig – save png to directory
slide_dict – add png path to a dictionary
background – plot a background shape layer
- Returns:
The squarest root.
Examples:
- richardutils.richardutils.plotmap_background(da, robust=False, cmap='cetrainbow', size=6, title='Title Here', clip=None, savefig=True, slide_dict=None, background=False, alpha=0.999)#
Plot a dataarray with a title. Allow saving to a png Allow adding to a dictionary e.g. for presentation use
- Parameters:
da – A DataArray
robust – clip to 2/98 or not
cmap – a matplotlib colormap
size – integer size of plot
title – string title of plot
clip – quantile number to clip to
savefig – save png to directory
slide_dict – add png path to a dictionary
background – plot a background shape layer if True is passed based on the DataArray, if a da is passed, use that - assumes data > 0
Returns:
Examples:
- richardutils.richardutils.plotmapc(da, robust=False, cmap='cetrainbow', size=6, title='Title Here', clip=None, savefig=True, slide_dict=None, background=False)#
Plots a dataarray and makes the colorbar the same height as the plot
Plot a dataarray with a title. Allow saving to a png Allow adding to a dictionary e.g. for presentation use
- Parameters:
da – A DataArray
robust – clip to 2/98 or not
cmap – a matplotlib colormap
size – integer size of plot
title – string title of plot
clip – quantile number to clip to
savefig – save png to directory
slide_dict – add png path to a dictionary
background – plot a background shape layer
- Returns:
The squarest root.
Examples: plotmapc(da_exploding_stars, cmap=’magma’, title=’Exploding Stars’)
- richardutils.richardutils.plotmapw(da, robust=False, cmap='cetrainbow', size=6, title='Title Here', clip=None, savefig=True, slide_dict=None, vmax=None)#
Plot a dataarray with a title. Remove colorbar in the way Allow saving to a png Allow adding to a dictionary e.g. for presentation use
- Parameters:
da – A DataArray
Examples:
- richardutils.richardutils.rasterize_one(tilow, strpath, da)#
Rasterize a geodataframe to a default one raster
- Parameters:
tilow – gdf
strpath – output geotif path
da – raster for resolution and bounds to match
- Returns:
geotiff to file
Examples
rasterize_one(gdf, outpath, darock)
- richardutils.richardutils.richardfunction(n: float) float #
This is not currently used so pointless to look at currently My function makes square roots.
- Parameters:
n – A number of some kind.
- Returns:
The squarest root.
Examples: >>> richardfunction(9) 3.0 >>> richardfunction(100) 10.0
- richardutils.richardutils.shape_dict(shapepath)#
Returns a dictionary of geodataframes
- Parameters:
shapepath – path to a directory with shapefiles
- richardutils.richardutils.tif_dict(strpath, masked=True, chunks=None, dsmatch=None)#
Walks a directory of geotiffs and returns a dictionary of rioxarray DataArrays :param strpath: directory name :param chunks: tuple of integers :param dsmatch: data array to match the directory of raster to :param masked: whether to mask by nodata, default is yes, pass masked=False if not desired
- Returns:
a dictionary of rioxarrays
Examples
tif_dict(r’D:BananaSplits’) tif_dict(r’D:BananaSplits’, chunk=s(1,1024,1024))
- richardutils.richardutils.tif_to_ers(strpath, masked=True, chunks=None, dsmatch=None)#
Walks a directory of geotiffs and returns each as an ers grid and writes to fiel :param strpath: directory name :param chunks: tuple of integers :param dsmatch: data array to match the directory of rasters to :param masked: whether to mask by nodata, default is yes, pass masked=False if not desired
- Returns:
a dictionary of rioxarrays
Examples
tif_dict(r’D:BananaSplits’) tif_dict(r’D:BananaSplits’, chunk=s(1,1024,1024))
- richardutils.richardutils.tif_to_img(strpath, masked=True, chunks=None, dsmatch=None)#
Walks a directory of geotiffs and returns each as an img rasterl :param strpath: directory name :param chunks: tuple of integers :param dsmatch: data array to reproject match the directory of rasters to :param masked: whether to mask by nodata, default is yes, pass masked=False if not desired
- Returns:
a dictionary of rioxarrays
Examples
tif_dict(r’D:BananaSplits’) tif_dict(r’D:BananaSplits’, chunk=s(1,1024,1024))
- richardutils.richardutils.world_low_res(country)#
- Parameters:
country – string of desired country border e.g. Australia
- Returns:
Built in global low res world polygons for cheap clipping filtered to one country
- richardutils.richardutils.zonal_onshore(country, data)#
Returns geodataframe clipped to a country low res boundary: e.g. for after zonal stats dataframe production
- Parameters:
country – string of desired country border e.g. Australia
data – ataframe with a geometry column
- Returns:
onshore lowres clipped geodataframe
- richardutils.richardutils.zonal_onshore_globe(data)#
Returns geodataframe clipped to global land: e.g. for after zonal stats dataframe production
- Parameters:
data – dataframe with a geometry column
- Returns:
Onshore zonal data
- richardutils.richardutils.zonal_stats(vector_data, measurements, dalike, variable)#
Get a dataframe of zonal statistics from a DataArray
- Parameters:
vector_data – a dataframe with a unique id
measurements – unique column of interest
dalike – DataArray to make grid from
variable – Name to give the out grid variable
- Returns:
zonal stats dataframe
Examples
gdf = zonal_stats(gdf,’USEID’,da,’LASERBLASTRADIUS’)