JSON
The JSON mode allows you to use high-level visualization functions to easily and quickly create figures.
What you can do
You can generate the following types of figures by specifying the figure key in your JSON file:
|
Function reference |
JSON example file |
Remark |
|---|---|---|---|
|
Can unite multiple fields (see example below) |
||
|
Compute the difference between two fields |
||
|
|
Unite: hist+scenario |
|
|
|
||
|
|||
|
For a complete list of available arguments, refer to the documentation for each function, and consult the corresponding JSON example file for practical usage.
With "figure": "map_simple", you can unite multiple fields into one and visualize them in a single map. Set "unite": true when you have multiple input files to combine them (e.g., concatenating a historical run with a scenario run, or joining spatial pieces). For example:
{
"figure": "map_simple",
"input_file": ["example_data/hist/anpp.out.gz", "example_data/ssp1A/anpp.out.gz"],
"unite": true,
...
}
With "figure": "time_series", you can unite multiple fields to create a single continuous time series (e.g., historical + scenario). See unite_time_series.json:
{
"figure": "time_series",
"input_file": [
"example_data/hist/cpool.out.gz",
"example_data/ssp1A/cpool.out.gz"
],
"unite": true,
"output_file": "figures/test_json_examples/united_cpool_ts.png",
"grid_type": "lonlat",
"gridop": "sum",
"convert_units": [1e-12, "GtC"],
"layers": ["Total"],
"yaxis_label": "Carbon Pools",
"title": "Total carbon pools (historical + SSP1A united)",
"palette": "Dark2",
"x_fig": 12,
"y_fig": 8
}
Other features
Grid types and source: You can specify which
file_format,grid_type, andsource(to retrieve metadata) to use from theField.from_file()arguments.Slice reduction: You can reduce data along
time,lat, orlondimensions using thetime_slice,lat_slice, orlon_slicekeys.Drop layers: Remove unwanted layers from your data using the
drop_layerskey (accept a list).Transform layers: Apply transformations to layers using the
reduce_layerskey and theField.reduce_layers()function (accept a dictionary, see stacked_time_series.json for an example).Apply operations: Apply arithmetic operations to layers using the
applykey and theField.apply()function. The config acceptsop(e.g."*","+","-","/"),operand(a constant or layer name), optionallayers(default: all layers), and optionalhow("left"or"right"for non-commutative ops). For example, to multiply the Total layer by 100, use"apply": {"op": "*", "operand": 100, "layers": "Total"}. See apply_map.json for an example.Convert units: Convert the units of your data using the
convert_unitskey. This accepts a list with exactly two elements: the conversion factor (a number) and the new units string. For example, to convert from kg to GtC, use"convert_units": [1e-12, "GtC"]. See multiple_time_series.json for an example.Filter data: Filter your data using the
filterkey with a query string. For example, to filter for values where Total > 0.4 and Que_rob < 0.15, use"filter": "Total > 0.4 and Que_rob < 0.15". See time_series.json for an example.Filter region: Filter your data by a named geographical region using the
regionand optionalregion_typekeys. Supportedregion_typevalues arecountry(Natural Earth),giorgi,SREX(IPCC SREX), andAR6(IPCC AR6). See region_filter_map.json for an example.Unite fields: Combine multiple input files into a single field using
unite. Whenuniteistrueand multiple files are listed ininput_file, they are concatenated along the time or spatial axes usingcanopy.unite(). Fields must have compatible grids and at least one overlapping layer. See unite_time_series.json for an example combining historical and scenario carbon pool data.
What you cannot do
No multiple figures function: You cannot use the
multiple_figs()function.No function keyword arguments as JSON keys: You cannot specify function keyword arguments (
kwargs) directly as JSON keys.No FLUXNET data and functions: You cannot use FLUXNET data and corresponding functions.