Values

Internal structure to organise DSSAT file data and variable values.

class tradssat.tmpl.vals.FileValueSet[source]

Represents the set of values in a DSSAT file.

add_row(sect, subsect=None, vals=None)[source]

Adds a row to the file.

Parameters:
  • sect (str) – Name of section.
  • subsect (int) – Subsection number. If None, will add row to all subsections.
  • vals (dict) – Dictionnary of new row variable values.
add_section(name)[source]

Adds a section to the file.

Parameters:name (str) – Name of the new section.
changed()[source]

Detects if any variable values have been changed.

Returns:
Return type:bool
find_var_sect(var)[source]

Finds the section in which a variable appears.

Parameters:var (str) – The name of the variable
Returns:The file section name.
Return type:str
to_dict()[source]

Converts the file to a dictionnary.

Returns:
Return type:dict
write(lines)[source]

Writes the file.

Parameters:lines (list[str]) – List to which to write output lines.
Returns:The modified list.
Return type:list
class tradssat.tmpl.vals.HeaderValues[source]

Represents DSSAT file header variables and their values.

changed()[source]

Checks if the header variables values have been changed.

Returns:
Return type:bool
get_value(var)[source]

Obtain the value of a header variable.

Parameters:var (str) – The variable of interest.
Returns:The value of the variable.
Return type:np.ndarray
set_vars(subsect)[source]

Sets the variables of the header.

Parameters:subsect (ValueSubSection) – The subsection with variables and their values already specified.
to_dict()[source]

Convert to dictionnary (json) format.

Returns:The (mostly) jsonified version of the header’s variables.
Return type:list
write()[source]

Writes the header values to a string.

Returns:
Return type:str
class tradssat.tmpl.vals.ValueSection(name)[source]

Represents the structure and variable values in a DSSAT file section.

add_subsection(subsect)[source]

Add a subsection to the section.

Parameters:subsect (ValueSubSection) – The new subsection.
changed()[source]

Checks whether any value has changed in the section.

Returns:
Return type:bool
get_header_var(var)[source]

Obtain the value of a header variable.

Parameters:var (str) – The name of the variable
Returns:The value of the header variable.
Return type:np.ndarray
set_header_vars(h_vars)[source]

Sets the section’s header variables.

Parameters:h_vars (ValueSubSection) – The subsection representing the header variables.
to_dict()[source]

Converts the section to a dictionnary.

Returns:
Return type:dict
write(lines)[source]

Writes the section to a list of lines.

Parameters:lines (list[str]) – The list of lines to which to append this section.
class tradssat.tmpl.vals.ValueSubSection(l_vars, l_vals)[source]

Represents the variables and values in a DSSAT file subsection.

add_row(vals=None)[source]

Adds a row to the subsection.

Parameters:vals (dict) – The values for the new row. Any missing value will be assigned the corresponding missing code for that variable (usually -99).
changed()[source]

Checks whether any variable in the subsection has been changed.

Returns:
Return type:bool
check_dims()[source]

Checks that all variables in the subsection have the same size. (If not, the subsection cannot write to disk.)

Raises:ValueError – If not all variables have the same size.
n_data()[source]

Obtain the size of variables. Will fail if not all variables have the same size.

Returns:The size of all variables in the subsection.
Return type:int
Raises:ValueError – If not all variables have the same size.
to_dict()[source]

Converts the subsection to a dictionnary.

Returns:
Return type:dict
write(lines)[source]

Writes the subsection.

Parameters:lines (list[str]) – The list of lines to which to append this subsection.
class tradssat.tmpl.vals.VariableValue(var, val)[source]

Represents a DSSAT file variable.

add_value(val)[source]

Adds a value to the variable’s matrix.

Parameters:val (int | float) – The new value.
remove_value(i)[source]

Removes a value from the variable’s matrix.

Parameters:i (np.ndarray) – The indices of the value(s) to remove. May be a list of indices, or else a boolean mask of the same size as the variable.
set_value(val, i=None)[source]

Changes the value of the variable.

Parameters:
  • val (float | int | np.ndarray) – The new value.
  • i (int | np.ndarray) – Índices at which to change the value. If None, all values of the variable will be changed.
size()[source]

Returns the size of the variable.

Returns:
Return type:int
write(i=None)[source]

Converts the variable to a string.

Parameters:i (int) – The index of the value to write. If None, the name of the variable will be written instead.
Returns:The properly written and formatted variable.
Return type:str