Export and plotting classes and functions

pydantic model flodym.export.PlotlyArrayPlotter
Config:
  • arbitrary_types_allowed: bool = True

  • extra: str = allow

  • protected_namespaces: tuple = ()

Fields:
  • array (flodym.flodym_arrays.FlodymArray)

  • chart_type (str)

  • color_map (list[str])

  • display_names (dict | None)

  • fig (plotly.graph_objs._figure.Figure)

  • intra_line_dim (str)

  • line_label (str | None)

  • line_type (str)

  • linecolor_dim (str | None)

  • subplot_dim (str | None)

  • suppress_legend (bool)

  • title (str | None)

  • x_array (flodym.flodym_arrays.FlodymArray | None)

  • xlabel (str | None)

  • ylabel (str | None)

Validators:
  • check_chart_type » all fields

  • check_colors » all fields

  • check_dims » all fields

  • check_line_type » all fields

field array: FlodymArray [Required]

Values to plot, usually a Flow or Stock; sliced or summed along excess dimensions.

field chart_type: str = 'line'

Type of chart to plot. Can be ‘line’, ‘scatter’, or ‘area’.

field color_map: list[str] = ['#2E91E5', '#E15F99', '#1CA71C', '#FB0D0D', '#DA16FF', '#222A2A', '#B68100', '#750D86', '#EB663B', '#511CFB', '#00A08B', '#FB00D1', '#FC0080', '#B2828D', '#6C7C32', '#778AAE', '#862A16', '#A777F1', '#620042', '#1616A7', '#DA60CA', '#6C4516', '#0D2A63', '#AF0038']

List of colors to use for the lines. If None, a default color map is used.

field display_names: dict | None = {}

Dictionary for string replacement in figures. Keys are strings to be replaced (like process names, etc.), values are strings to display instead. All strings not in this dictionary will be displayed as is.

field fig: Figure = None

A previously created plotly figure object, for adding lines to an existing figure. If None, a new figure is created.

field intra_line_dim: str [Required]

Name of the dimension along which lines are plotted (if no x_array is given, this is also the x-axis).

field line_label: str | None = None

Custom label for the line. If None, the respective item along linecolor_dim is used as label.

field line_type: str = 'solid'

Type of line to plot. Can be ‘solid’, ‘dashed’, ‘dotted’, or ‘dashdot’.

field linecolor_dim: str | None = None

Name of the dimension along which to split the array into several lines within each subplot. If None, only one line is plotted per subplot.

field subplot_dim: str | None = None

Name of the dimension by which to split the array into subplots. If None, the array is plotted in a single subplot.

field suppress_legend: bool = False

If True, the legend is not shown.

field title: str | None = None

Title of the plot, if desired.

field x_array: FlodymArray | None | None = None

Array with x-values for each line. Must have the same dimensions as array, or a subset of them. If None, the intra_line_dim is used as x-axis.

field xlabel: str | None = None

Custom label for the x-axis. If None, the name of the x_array or intra_line_dim is used.

field ylabel: str | None = None

Custom label for the y-axis. If None, the name of the array is used.

add_line(i_subplot, x, y, prev_y, label, i_line)
validator check_chart_type  »  all fields
validator check_colors  »  all fields
validator check_dims  »  all fields
validator check_line_type  »  all fields
col(i_subplot)
display_name(name)
get_fig()
plot(save_path=None, do_show=False)
Parameters:
  • save_path (str | None)

  • do_show (bool)

plot_legend()
row(i_subplot)
save(save_path=None, **kwargs)
Parameters:

save_path (str | None)

set_subplot_title(index, title)
set_title()
set_xlabel(i_subplot, label)
set_ylabel(i_subplot, label)
show()
pydantic model flodym.export.PyplotArrayPlotter
Config:
  • arbitrary_types_allowed: bool = True

  • extra: str = allow

  • protected_namespaces: tuple = ()

Fields:
  • array (flodym.flodym_arrays.FlodymArray)

  • chart_type (str)

  • color_map (list[str] | None)

  • display_names (dict | None)

  • fig (matplotlib.figure.Figure)

  • intra_line_dim (str)

  • line_label (str | None)

  • line_type (str)

  • linecolor_dim (str | None)

  • subplot_dim (str | None)

  • suppress_legend (bool)

  • title (str | None)

  • x_array (flodym.flodym_arrays.FlodymArray | None)

  • xlabel (str | None)

  • ylabel (str | None)

Validators:
  • check_chart_type » all fields

  • check_colors » all fields

  • check_dims » all fields

  • check_line_type » all fields

field array: FlodymArray [Required]

Values to plot, usually a Flow or Stock; sliced or summed along excess dimensions.

field chart_type: str = 'line'

Type of chart to plot. Can be ‘line’, ‘scatter’, or ‘area’.

field color_map: list[str] | None = None

List of colors to use for the lines. If None, a default color map is used.

field display_names: dict | None = {}

Dictionary for string replacement in figures. Keys are strings to be replaced (like process names, etc.), values are strings to display instead. All strings not in this dictionary will be displayed as is.

field fig: Figure = None

A previously created pyplot figure object, for adding lines to an existing figure. If None, a new figure is created.

field intra_line_dim: str [Required]

Name of the dimension along which lines are plotted (if no x_array is given, this is also the x-axis).

field line_label: str | None = None

Custom label for the line. If None, the respective item along linecolor_dim is used as label.

field line_type: str = 'solid'

Type of line to plot. Can be ‘solid’, ‘dashed’, ‘dotted’, or ‘dashdot’.

field linecolor_dim: str | None = None

Name of the dimension along which to split the array into several lines within each subplot. If None, only one line is plotted per subplot.

field subplot_dim: str | None = None

Name of the dimension by which to split the array into subplots. If None, the array is plotted in a single subplot.

field suppress_legend: bool = False

If True, the legend is not shown.

field title: str | None = None

Title of the plot, if desired.

field x_array: FlodymArray | None | None = None

Array with x-values for each line. Must have the same dimensions as array, or a subset of them. If None, the intra_line_dim is used as x-axis.

field xlabel: str | None = None

Custom label for the x-axis. If None, the name of the x_array or intra_line_dim is used.

field ylabel: str | None = None

Custom label for the y-axis. If None, the name of the array is used.

add_line(i_subplot, x, y, prev_y, label, i_line)
validator check_chart_type  »  all fields
validator check_colors  »  all fields
validator check_dims  »  all fields
validator check_line_type  »  all fields
display_name(name)
get_fig()
plot(save_path=None, do_show=False)
Parameters:
  • save_path (str | None)

  • do_show (bool)

plot_legend()
save(save_path=None, **kwargs)
Parameters:

save_path (str | None)

set_subplot_title(i_subplot, title)
set_title()
set_xlabel(i_subplot, label)
set_ylabel(i_subplot, label)
show()
property ax: Axes
pydantic model flodym.export.PlotlySankeyPlotter
Config:
  • arbitrary_types_allowed: bool = True

  • protected_namespaces: tuple = ()

Fields:
  • display_names (dict | None)

  • exclude_flows (list[str] | None)

  • exclude_processes (list[str] | None)

  • flow_color_dict (dict | None)

  • mfa (flodym.mfa_system.MFASystem)

  • node_color_dict (dict | None)

  • slice_dict (dict | None)

Validators:
  • check_dims » all fields

  • check_excluded » all fields

  • check_flow_colors » all fields

  • check_node_colors » all fields

field display_names: dict | None = {}

Dictionary for string replacement in figures. Keys are strings to be replaced (like process names, etc.), values are strings to display instead. All strings not in this dictionary will be displayed as is.

field exclude_flows: list[str] | None = []

flows that won’t show up in the plot

field exclude_processes: list[str] | None = ['sysenv']

processes that won’t show up in the plot; neither will flows to and from them

field flow_color_dict: dict | None = {'default': 'hsl(230,20,70)'}

dictionary of colors for flows. Keys are flow names, values are either a single color or a tuple of the dimension names to split the flow by, and a color scheme as a list of colors. There must be a “default” key to resort to if a flow is not in the dictionary.

field mfa: MFASystem [Required]

MFA system to visualize.

field node_color_dict: dict | None = {'default': 'gray'}

color of the nodes (processes and stocks)

field slice_dict: dict | None = {}

for selection of a subset of the data; all other dimensions are summed over

validator check_dims  »  all fields
validator check_excluded  »  all fields
validator check_flow_colors  »  all fields
validator check_node_colors  »  all fields
display_name(name)
plot()
property excluded_process_ids
property ids_in_sankey
property shown_flows: dict[str, Flow]
property shown_processes
flodym.export.export_mfa_flows_to_csv(mfa, export_directory)

export flows of an MFA system to csv files.

Parameters:
  • mfa (MFASystem) – The MFA system from which the flows should be exported.

  • export_directory (str) – The directory where the csv files should be saved.

flodym.export.export_mfa_stocks_to_csv(mfa, export_directory, with_in_and_out=False)

export stocks of an MFA system to csv files.

Parameters:
  • mfa (MFASystem) – The MFA system from which the stocks should be exported.

  • export_directory (str) – The directory where the csv files should be saved.

  • with_in_and_out (bool, optional) – If True, the inflow and outflow of the stocks are also exported. Defaults to False.

flodym.export.export_mfa_to_pickle(mfa, export_path)

Write an MFA system to a pickle file.

Parameters:
  • mfa (MFASystem) – The MFA system to be exported.

  • export_path (str) – The path to the file where the MFA system should be saved.

flodym.export.convert_to_dict(mfa, type='numpy')

Convert an MFA system to a dictionary which is readable without flodym.

Parameters:
  • mfa (MFASystem) – The MFA system to be converted.

  • type (str, optional) – The type of the values in the flows and stocks. Options are ‘numpy’ and ‘pandas’. Defaults to “numpy”.

Returns:

The MFA system as a dictionary. Contains the items ‘dimension_names’, ‘dimension_items’, ‘processes’, ‘flows’, ‘flow_dimensions’, ‘flow_processes’, ‘stocks’, ‘stock_dimensions’, ‘stock_processes’.

Return type:

dict