-
Notifications
You must be signed in to change notification settings - Fork 0
fsm python Tute 2 Build Paddock
In this tutorial, we will focus on building our paddock. The Paddock object is a core part of using the farm soil mapping tools as it will contain all the information to perform the various types of analysis. As shown below, the paddock is made up of 3 components. A boundary, grids and point data.
Before creating your paddocks, you will need to prepare your datasets using the GridInput object. This can be done with any type of measurements such as elevation or gamma radiometric readings. When using the GridInput object the fsm-tools will align the gird to a pre-defined specification (lat/lon spacings and point of origin). This ensures that all the paddock layers are aligned and for processing.
To start, let's get the directory that has all of our sample data:
input_dir = "/path/to/your/fsm_sample_data"Now we can prepare the GridInput for the elevation layer. This is the dem.tif file.
import os
from fsm.models.paddock import GridInput, Paddock, inputFileTypes
ELEVATION = "Elevation"
ele_tif = "dem.tif"
ele_file = os.path.join(input_dir, ele_tif)
ele_gird_input = GridInput(uid=ELEVATION, measurementType="elevation", inputFile=ele_file)Note that we have also supplied:
-
uida unique identifier -
measurementTypea helpful note about the type of measurement -
inputFilethe location of the tif file -
inputFileTypeonlyinputFileTypes.TIFFis supported at this point
Lets add a few more paddock layers using GridInput:
NIR = "nir"
nir_tif = "nir.tif"
nir_file = os.path.join(input_dir, nir_tif)
nir_gird_input = GridInput(uid=NIR, measurementType="ndvi", inputFile=nir_file)
RED = "red"
red_tif = "red.tif"
red_file = os.path.join(input_dir, red_tif)
red_gird_input = GridInput(uid=RED, measurementType="ndvi", inputFile=red_file)Next we need to create a boundary. We can do this directly by using the Boundary object:
from fsm.models.boundary import Boundary
# Boundary([[lon,lat],[lon,lat],[lon,lat],[lon,lat],[lon,lat]], bbox)Or we can use a helper.
from fsm.helpers.shp_converter import shpToBoundaries
shpFileName = "paddock_b.shp"
sFile = os.path.join(input_dir, shpFileName)
boundaries = shpToBoundaries(sFile)For .geojson files:
from fsm.helpers.geojson_converter import geojsonToBoundaries
fileName = "paddocks.json"
gFile = os.path.join(input_dir, fileName)
boundaries = geojsonToBoundaries(file = gFile)Finally, we can create our paddock:
paddock = Paddock(inputData=[ele_gird_input, nir_gird_input, red_gird_input], id="myPaddock", bounds=boundary, persistDir=persist_dir)Note: persistDir will persist the processed data for faster access in future tasks.
If you run into memory problems, set lightning=False.
If you have paddock information in your geojson file, you may want to consider:
from fsm.helpers.geojson_converter import geojsonToPaddocks
paddocks = geojsonToPaddocks(file = gFile, inputData=[nir_gird_input, red_gird_input, ele_gird_input])The id input will help with identifying the output files.
Be sure to check that the boundaries have been loaded properly with the helpers.
Often, we may want to mix the data from the layers that we have to create new layers. This is the case for creating ndvi from red and nir. In the python version, we can achieve this using the mixProcessor, one of the fsm processors.
NDVI = "ndvi"
mix_config = MixConfig(
primary_layer=NIR,
secondary_layer=RED,
new_layer=NDVI,
func= lambda a, b: (a-b)/(a+b))
mixProcessor([paddock], mix_config)Note the lambda function. That's how you calculate the ndvi from red and nir. See here
By calling the paddockLayersDict, we can see all out added paddock layers, including the ndvi.
print(paddock.paddockLayersDict)Note: this will be used in a later lesson
The first step in adding point data to your paddock is creating PointAttribute for each PointDataset. A point attribute represents a measured attribute from a soil sample.
attribute: str - The attribute name. eg "clay" value: Union[float, str] - the numerical value. eg 21 units: Optional[str] - measurement unite. eg % notes: Optional[str] - any notes. eg "indirectly measured"
Usage:
pa = PointAttribute("clay", 20, "%")Once you have put all of your attributes into a list, you may create your PointDataset. This represents a soil sample that was taken at a date, depthRange (in cm), and location (lat, lon).
Usage:
from datetime import datetime
pd = PointDataset(id=3, attributes=[pa1, pa2, pa3, pa4, pa5], location=(-23.6757, 133.8915), depthRange=(0, 10), date=datetime(2021,01,12))from fsm.models.paddock import Paddock, PointAttribute, PointDataset
from datetime import datetime
attributes5 = [PointAttribute("clay",20), PointAttribute("sand",40), PointAttribute("silt",40)]
pd5 = PointDataset(id=3, attributes=attributes5, location=location, depthRange=depths, date=date)
persist_dir = "/path/to/persist_dir"
Paddock(
inputData=PaddockInputList,
id=paddock_id,
soilPointDataArray=[pd1,pd2,pd3,pd4,pd5],
persistDir=persist_dir
)Note: the persistDir input will allow you to persist grid aligned data. This can be helpful for future processing as aligning data to the grid can take a long time or use a lot of memory.
For this tute, you can easily import your samples to PointDatasets like
from fsm.sampleLocation import SampleLocationRecommender
sample_file = "samples.json"
sample_path = os.path.join(input_dir, sample_file)
point_datasets = geojsonToPointDatasets(sample_path)Paper: A conditioned Latin hypercube method for sampling in the presence of ancillary information
Minasny, Budiman, and Alex B. McBratney. 2006. “A Conditioned Latin Hypercube Method for Sampling in the Presence of Ancillary Information.” Computers & Geosciences 32 (9): 1378–88.
Paper: Predicting and Mapping the Soil Available Water Capacity of Australian Wheatbelt.
Padarian, J., B. Minasny, A. B. McBratney, and N. Dalgliesh. 2014. “Predicting and Mapping the Soil Available Water Capacity of Australian Wheatbelt.” Geoderma Regional 2-3 (November): 110–18.
Paper (non-journaled thesis): Provision of soil water retention information for biophysical modelling: an example for Australia
Padarian, J. 2014. "Provision of soil water retention information for biophysical modelling: an example for Australia". Provision of soil information for biophysical modelling: 19-50. Faculty of Agriculture and Environment. The University of Sydney
Paper: Inverse meta-modelling to estimate soil available water capacity at high spatial resolution across a farm
Florin, M. J., A. B. McBratney, B. M. Whelan, and B. Minasny. 2011. “Inverse Meta-Modelling to Estimate Soil Available Water Capacity at High Spatial Resolution across a Farm.” Precision Agriculture 12 (3): 421–38.
Paper: Modelling soil attribute depth functions with equal-area quadratic smoothing splines
Bishop, T. F. A., A. B. McBratney, and G. M. Laslett. 1999. “Modelling Soil Attribute Depth Functions with Equal-Area Quadratic Smoothing Splines.” Geoderma 91 (1): 27–45.
Paper: Validation of digital soil maps at different spatial supports
Bishop, T. F. A., A. Horta, and S. B. Karunaratne. 2015. “Validation of Digital Soil Maps at Different Spatial Supports.” Geoderma 241-242 (March): 238–49.
Paper: Boundaryline analysis of fieldscale yield response to soil properties
Shatar, T. M., and A. B. McBratney. 2004. “Boundary-Line Analysis of Field-Scale Yield Response to Soil Properties.” The Journal of Agricultural Science 142: 553.
Paper: A segmentation algorithm for the delineation of agricultural management zones
Pedroso, Moacir, James Taylor, Bruno Tisseyre, Brigitte Charnomordic, and Serge Guillaume. 2010. “A Segmentation Algorithm for the Delineation of Agricultural Management Zones.” Computers and Electronics in Agriculture 70 (1): 199–208.
Paper: Spatially explicit seasonal forecasting using fuzzy spatiotemporal clustering of long-term daily rainfall and temperature data
Plain, M. B., B. Minasny, A. B. McBratney, and R. W. Vervoort. 2008. “Spatially Explicit Seasonal Forecasting Using Fuzzy Spatiotemporal Clustering of Long-Term Daily Rainfall and Temperature Data.” https://hal.archives-ouvertes.fr/hal-00298949/.
Paper: Spatiotemporal monthly rainfall forecasts for south-eastern and eastern Australia using climatic indices
Montazerolghaem, Maryam, Willem Vervoort, Budiman Minasny, and Alex McBratney. 2016. “Spatiotemporal Monthly Rainfall Forecasts for South-Eastern and Eastern Australia Using Climatic Indices.” Theoretical and Applied Climatology 124 (3): 1045–63.