Skip to content

fsm python Tute 4 Sample Location Recommender

Kipling edited this page May 26, 2021 · 9 revisions

Recogmending Soil Sampling Locations

SampleLocationRecommender

Often, paddocks require new soil samples. This tool recommends the optimal locations to take these samples. The soil attribute data from these locations will inform the next tool; the soilMapper.

Following on from the previous lesson, and in a similar manner, we start by importing config objects.

from fsm.configs import CLHCConfig, SampleConfig

The SampleConfig takes at least 1 argument:

    clhcConfig: Optional[CLHCConfig] = None

Recommend sample locations (simple)

The CLHCConfig informs the SampleLocationRecommender tool on how to select sampling locations.

    samples: int  # Number of samples to pick
    metrics: List[str] # The metrics (or paddock layer names) to use in the CLHC algorithm 
    excludeBoundary: Optional[float] = None # How far form the boundary to exclude points (in lat, on degrees)
    backups: Optional[bool] = False # if True, creates a set of backup locations
    iterations: Optional[int] = 5 # How many itterations to run. The more the better but will take longer
    includeLatLon: bool = False # if True, includes lat and lon dimensions
    includeExisting: bool = False # if true, will include existing sample sites in the analysis

Note: that the CLHC (Conditioned Latin HyperCube) algorithm is based on Minasny, Budiman, and Alex B. McBratney. 2006

Run the SampleLocationRecommender.

from fsm.sampleLocation import SampleLocationRecommender

met_list = [ELEVATION, GAMMA_K, GAMMA_TH, GAMMA_U, NDVI]
clhc_cfg = CLHCConfig(
    samples=5,
    metrics=met_list,
    excludeBoundary=0.0002,
    iterations=5,
    backups=False,
    includeLatLon=True,
    includeExisting=True
)

sample_config = SampleConfig(clhcConfig=clhc_cfg, sampleOnZones=False) 

slr = SampleLocationRecommender(paddocks=paddocks)
br_list = slr.build(config=sample_config)

And generate the output csv and geojson

graphics_config = GraphicsConfig(
    attribute="LocationsTest", 
    gradient=grad, 
    output_dir=output_dir, 
    fit_to_data=True
)

gr = GraphicsRenderer(br_list)
gr.build(graphics_config)

Clone this wiki locally