Skip to content

GLM_JSON

JSONReader

Supports the reading of GLM configuration blocks in a JSON format or working with GLM configuration blocks in dictionary format.

Reads and parses a JSON file into a dictionary object which can be used to set the attributes of the corresponding NML class. Useful for converting a JSON file of GLM parameters from a web application.

Attributes:

Name Type Description
json_file str | PathLike | dict

The path to the json file to be read or dict representation of the nml file in memory.

nml_file str

The path to the nml file to be written.

Examples:

>>> from glmpy import glm_json
>>> json_to_nml = glm_json.JSONReader("sparkling_lake.json")

get_nml_blocks()

Reads a JSON file or dictionary of GLM configuration blocks and returns a list of the block names.

Examples:

>>> from glmpy import glm_json
>>> json_to_nml = glm_json.JSONReader("config.json")
>>> json_to_nml.get_nml_blocks()

get_nml_parameters(nml_block)

Get the model parameters for a GLM configuration block.

Returns a dictionary of model parameters for a specified GLM configuration block. Used for setting the attributes of the corresponding nml.NML* classes.

Parameters:

Name Type Description Default
nml_block str

The name of the GLM configuration block

required

Returns:

Type Description
dict

A dictionary of the model parameters for a specified GLM configuration block.

Examples:

>>> from glmpy import glm_json, nml
>>> json = glm_json.JSONReader("sparkling_lake.json")
>>> setup_dict = json.get_nml_parameters("&glm_setup")
>>> setup = nml.NMLSetup()
>>> setup.set_attributes(setup_dict)

read_json()

Read a JSON file of .nml parameters.

Reads a JSON file of GLM configuration blocks and returns a dictionary.

Examples:

>>> from glmpy import glm_json
>>> json_to_nml = glm_json.JSONReader("sparkling_lake.json")
>>> json_to_nml.read_json()