Skip to content

fsm python Tute 3 Graphics Renderer

Kipling edited this page May 26, 2021 · 12 revisions

Generating Images and viewing Grid Data

Often, it is important to allow the user to view the grid data in the context of the paddocks. This will allow the user to make decisions about what layers to data in the tools. For instance, if there is not much variation in the elevation, the user may decide not to use that layer as it is unlikely to provide any utility to the analysis.

In this tutorial, we will create images of NDVI and elevation. This tutorial follows on from the previous tutorial where we learnt how to make a paddock.

buildResult

In this lesson, we will learn about the "buildResult" and how to use it to create images. Generally, the tools and processors will produce build results as their outputs and they can cover a range of output information, including sample locations and layer data. The buildResults are used by the GraphicsRenderer tool to produce images.

We can convert a paddock to a PaddockBuildResult using the paddockToPaddockBuildResult function:

from fsm.utils.paddockConverters import paddockToPaddockBuildResult
p_brs = [paddockToPaddockBuildResult(p) for p in paddocks]

GraphicsRenderer

Now we can add these build results to the GraphicsRenderer tool:

from fsm.graphicsRenderer import GraphicsRenderer

gr = GraphicsRenderer(p_brs)

GradientConfig

To run each tool, we use the .build() method which takes a corresponding config object. Here we will learn about the GradientConfig and how to adjust the settings to get the desired result. The gradient config has the following inputs

  • attribute: str - name of the Layer in the paddock
  • gradient: Gradient - the type of color graident to use
  • output_dir: str - where to save the file
  • fit_to_data: bool = field(default=False) - if True the graident will be stretched to fit the range of the values
from fsm.models.gradients import farmSoilMappingGradients

grad = farmSoilMappingGradients.NDVI
graphics_config = GradientConfig(
    attribute=NDVI,
    gradient=grad,
    output_dir="./tests/temp",
    fit_to_data=True)

Finally, we run the GraphicsRenderer using the .build method.

gr.build(graphics_config) 

Additional information

To provide a user with meaningful data, you will need some metadata about the output. This can be found in the stats property of the buildResults. The stats object includes:

# Take one br for instance
br = p_brs[0].buildResults[0]

br.paddock_id
br.uid

br.stats.max #attribute value
br.stats.min #attribute value
br.stats.max_lat
br.stats.min_lat
br.stats.max_lon
br.stats.min_lon

From this metadata, you can create your bounding box and provide the user with range information.

You may also want to get the colors of the value ranges:

RGB

grad.get(br.stats.max)
grad.get(br.stats.min)

HEX

grad.get_hex(br.stats.max)
grad.get_hex(br.stats.min)

Outputs

This will output the following dirs and files:

  • [name]
    • boundary geojson files
    • [method]
      • geojson
      • svg
      • png
      • npy (for numpy)
      • colors json
      • stats json
      • error geojson(s) -if applicable-

Clone this wiki locally