eviz.lib package

Subpackages

Submodules

eviz.lib.const module

Class that defines all eViz constants used throughout the code.

exception eviz.lib.const.ConstError

Bases: TypeError

eviz.lib.autoviz_base module

class eviz.lib.autoviz_base.Autoviz(source_names: list, args: ~argparse.Namespace | None = None, model_info: dict = <factory>, model_name: str | None = None, _config: ~eviz.lib.autoviz.config.Config | None = None)

Bases: object

This is the Autoviz class definition. It takes in a list of (source) names and

creates data-reading-classes (factories) associated with each of those names.

Parameters:
  • source_names (list) – source models to process

  • factory_models (list) – source models to process

  • args (Namespace) – source models to process

args: Namespace = None
property config
property logger: Logger
model_info: dict
model_name: str = None
run()

Create plots

set_data(input_files)

Assign model input files as specified in model config file

Parameters:

input_files (list) – Names of input files

set_output(output_dir)

Assign model output directory as specified in model config file

Parameters:

output_dir (str) – Name output directory

source_names: list
eviz.lib.autoviz_base.create_config(args)
eviz.lib.autoviz_base.get_config_path_from_env()
eviz.lib.autoviz_base.get_factory_from_user_input(inputs)

Return subclass associated with user input sources

Note: An entry here associates the specified data source with a unique named configuration existing within EVIZ_CONFIG_PATH.

eviz.lib.iviz_base module

class eviz.lib.iviz_base.Iviz(*args: Any, **kwargs: Any)

Bases: Parameterized

The Iviz class processes inputs to the tool and initializes necessary classes.

Parameters:

session_file (str) – Name of session file (default is None)

static check_input_model(inp, model)

Helper function to check if model and input exist.

comparison_name = None
config_dir = None
custom_config = False
dataInput = None
exp_name = None
file_list = None
get_dash()

Determine the corresponding dashboard to use based on determined model type.

Parameters:

self.model (str) – model type

Returns:

corresponding model dashboard, generic if none

Return type:

dash (cls)

static get_list(d)
static get_params_class(dtype)
handle_directory_input(inp)

Helper function to handle input directory containing files.

handle_input(inp)

Helper function to handle input (file, directory, or URL).

static input_not_found()
is_url = False
static load(yaml_path, specs_path=None)

Load the corresponding yaml configuration and model specs file.

Returns:

tool configuration info specs (dict): field specs

Return type:

cfg (dict)

load_model_config(model)

Helper function to load model configurations.

static load_options(plot_options_file=None)

If plot settings are provided by the user at startup, load plot options file.

Parameters:

plot_options_file (yaml) – a yaml dict file with plot settings.

Returns:

dictionary with plot settings

Return type:

plot_options (dict)

static load_session(session_file=None)

If a session file is provided by the user at startup, load the yaml file.

Parameters:
  • session_file (yaml) – a yaml dict file with parameter settings

  • session. (and widget values from an iViz)

Returns:

dictionary with tool param names and values

Return type:

session (dict)

make_app(inp=None, source=None, dtype=None, session_file=None, plot_options=None)

Initializes all classes and sets them to class variables, includes self.params, and self.dash.

Runs all needed functions to create app template and serve the app. Auto runs pn.serve to launch app in web browser tab.

Parameters:
  • dtype (str) – data type

  • source (str) – data source name

  • inp (str) – tool input, source config or file, or dir path

  • session_file (str) – optional iViz session file to restore

  • plot_options (str) – optional plot options file to apply.

Returns:

final app

Return type:

template (pn.template.BootstrapTemplate)

make_notebook(inp=None, source=None, dtype=None, session_file=None, plot_options=None)

Initializes all classes and sets them to class variables, includes self.params, and self.dash.

Runs all needed functions to create the app without the panel web template. For use in the JupyterNotebook.

Parameters:
  • dtype (str) – data type

  • source (str) – data source name

  • inp (str) – tool input, source config or file, or dir path

  • session_file (str) – optional iViz session file to restore

  • plot_options (str) – optional plot options file to apply.

Returns:

returns final tool as pn.Row instead of template.

Return type:

app (pn.Row)

make_panel(inp=None, source=None, dtype=None, session_file=None, plot_options=None)

Initializes all classes and sets them to class variables, includes self.params, and self.dash. Runs all needed functions to create app template and returns the .servable app. Returns template without starting panel server automatically. Best for use with ‘Render with Panel’ button in notebook. Run function, add .servable, press green ‘Render with Panel’ button from JupyterLab/Hub toolbar.

Parameters:
  • dtype (str) – data type

  • inp (str) – tool input, source config or file, or dir path

  • source (str) – data source name

  • session_file (str) – optional iViz session file to restore

  • plot_options (str) – optional plot options file to apply.

Returns:

final app

Return type:

template (pn.template.BootstrapTemplate)

make_params(session_file=None, plot_options_file=None)

Run necessary functions and initialize Params class values.

Parameters:
  • session_file (str) – optional iViz session file to restore

  • plot_options (str) – optional plot options file to apply.

Returns:

initialized Params class

Return type:

self.Params (cls)

make_template()

After initializing all needed classes and arranging plots and widgets in one panel Row, create the Panel template for content to be embedded in. Serve the tool on a randomly generated localhost address, automatically opens, using pn.serve().

model = None
output_dir = None
set_config_info(config)

Use a configuration file to set all needed class variables.

Parameters:

config (list) – the loaded config and specs dictionaries.

Returns:

all config info needed

Return type:

self.file_config (dict)

set_input(inp, model, dtype)

Determine what kind of input has been provided either from the CLI or notebook.

Parameters:
  • inp (str) – input file or directory

  • model (str) – a model type

  • dtype (str) – data type

Returns:

either a param.Selector with files provided or a single Xarray file.

Return type:

self.dataInput

set_iviz(inp=None, source=None, dtype=None, session_file=None, plot_options=None)

Initializes all classes and sets them to class variables, includes self.params, and self.dash.

Runs all needed functions to create app template and serve the app. Auto runs pn.serve to launch app in web browser tab.

Parameters:
  • dtype (str) – data type

  • source (str) – data source name

  • inp (str) – tool input, source config or file, or dir path

  • session_file (str) – optional iViz session file to restore

  • plot_options (str) – optional plot options file to apply.

Returns:

final app

Return type:

template (pn.template.BootstrapTemplate)

set_model_and_dtype(model, dtype)

Helper function to set model and its corresponding dtype.

set_panel_session_widgets(vals)

If a session file or plot options file is input by user, this function sets all the panel based widgets manually.

Parameters:

vals (dict) – all the session and plot options values.

set_plotopts_widgets(vals)
set_yaml_dataInput(input_file)

Set the class variable self.dataInput if yaml being used.

Note

Can be dir, filepath, list of files, or dict of files.

Parameters:

() (input_file) – dir, filepath, list, or dict

Returns:

either a param.Selector with files provided or str of single file.

Return type:

self.dataInput ()

view()

Arrange all the final objects from dashboard and parameters classes to create final plot and widget layout.

Returns:

final panel Row object with plot and widgets for dashboard.

Return type:

row (pn.Row)

eviz.lib.utils module

eviz.lib.utils.get_default_yaml_path(model_name) str

Retrieve the default YAML path associated with a model.

Parameters:

model_name (str) – Model name.

Returns:

YAML file path relative to EViz top level directory.

Return type:

yaml_config (str)

eviz.lib.utils.get_nested_key_value(dictionary, keys)

Get the value of a nested key in a dictionary.

Parameters: - dictionary: The input dictionary. - keys: A list of keys specifying the path to the nested key.

Returns: - The value of the nested key, or None if the key doesn’t exist.

eviz.lib.utils.get_project_root(anchor='.git')

Get the top-level project directory by searching for an anchor name

Parameters:

anchor – A filename or directory that is unique to the project root (e.g., ‘README.md’, ‘.git’).

Returns:

Path to the project root directory.

eviz.lib.utils.get_reader_from_name(name)

Get reader name (as defined in RootFactory) from a given source name

eviz.lib.utils.get_repo_root_dir(repo_path: str) str

Given a path to a file or dir in a repo, find the root directory of the repo.

Parameters:

repo_path (str) – Any path into the repo.

Returns:

The repo’s root directory.

eviz.lib.utils.get_season_from_file(file_name)
eviz.lib.utils.load_yaml(yaml_filename)

Given a YAML file, create the corresponding YAML data structure .

Parameters:

yaml_filename (str) – Path to the YAML file.

Returns:

A YAML data structure.

Return type:

yaml_config (yaml)

eviz.lib.utils.logger_setup(logger_name, log=1, verbose=1)

Set up the application logger.

Parameters:
  • logger_name (str) – Name of the logger.

  • verbose (int) – verbosity level.

eviz.lib.utils.mkdir_p(path)
eviz.lib.utils.read_meta_attrs() dict

Read meta attributes YAML file and load into data structure

eviz.lib.utils.read_meta_coords() dict

Read meta coordinates YAML file and load into data structure

eviz.lib.utils.read_species_db() dict

Read species database YAML file and load into data structure

eviz.lib.utils.squeeze_fig_aspect(fig, preserve='h')
eviz.lib.utils.timer(start_time, end_time)

Simple timer.

Parameters:
  • start_time (time.time) – Start time

  • end_time (time.time) – end time

Returns:

Time duration

eviz.lib.utils.validate_yaml(file_content)
eviz.lib.utils.yaml_path_constructor(loader, node)

Extract the matched value, expand env variable, and replace the match

eviz.lib.xarray_utils module

eviz.lib.xarray_utils.calc_spatial_integral(xr_da, lon_name='longitude', lat_name='latitude', radius=6371007.2)

Calculate spatial integral of xarray.DataArray with grid cell weighting.

Parameters:
  • xr_da – xarray.DataArray Data to average

  • lon_name – str, optional Name of x-coordinate

  • lat_name – str, optional Name of y-coordinate

  • radius – float Radius of the planet [metres], currently assumed spherical (not important anyway)

Returns:

Spatially averaged xarray.DataArray.

eviz.lib.xarray_utils.calc_spatial_mean(xr_da, lon_name='longitude', lat_name='latitude', radius=6371007.2)

Calculate spatial mean of xarray.DataArray with grid cell weighting.

Parameters:
  • xr_da (xarray.DataArray) – Data to average

  • lon_name (str, optional) – Name of x-coordinate

  • lat_name (str, optional) – Name of y-coordinate

  • radius (float) – Radius of the planet (in meters)

Returns:

Spatially averaged xarray.DataArray.

eviz.lib.xarray_utils.compute_mean_over_dim(xr_dst, mean_dim, field_name=None)
Computer average over a dataArray (or dataset) dimension

mean_dim can be ‘Time’, ‘x’, ‘y’, or a tuple of dimensions etc.

Returns:

the average of a Xarray Dataset or DataArray over a specified dimension

eviz.lib.xarray_utils.compute_means(xr_dst, means)

Computer average over a dataArray (or dataset)

means can be

‘1D’ = daily ‘1M’ = monthly ‘QS-JAN’ = seasonal (JFM, AMJ, JAS and OND) ‘DS-DEC’ = seasonal (DJF, MAM, JJA and SON) ‘1A’ = annual

Returns:

the time average of a Xarray Dataset or DataArray.

eviz.lib.xarray_utils.compute_std_over_dim(xr_dst, std_dim, field_name=None)
Computer standard deviation over a dataArray (or dataset) dimension

std_dim can be ‘Time’, ‘x’, ‘y’, or a tuple of dimensions etc.

Returns:

the standard deviation of a Xarray Dataset or DataArray over a specified dimension

eviz.lib.xarray_utils.get_dst_attribute(xr_dst, attr_name)

Get an attribute value from a Xarray Dataset or DataArray

Parameters:
  • xr_dst – Xarray Dataset or DataArray

  • attr_name – attribute name

Returns:

Attribute value or None if the attribute does not exist.

eviz.lib.xarray_utils.get_file_ptr(data_dir, file_pat=None)

Use xarray.open_mfdataset to read multiple files

eviz.lib.xarray_utils.grid_cell_areas(lon1d, lat1d, radius=6371007.2)

Calculate grid cell areas given 1D arrays of longitudes and latitudes for a planet with the given radius.

Parameters:
  • lon1d (ndarray) – Array of longitude points [degrees] of shape (M,)

  • lat1d (ndarray) – Array of latitude points [degrees] of shape (M,)

  • radius (float, optional) – Radius of the planet [metres] (currently assumed spherical)

Returns:

Array of grid cell areas [metres**2] of shape (M, N).

eviz.lib.xarray_utils.read_multiple_netcdf(file_paths)

Reads multiple NetCDF files using xarray and returns a combined xarray Dataset.

Parameters: file_paths (list of str): A list of paths to the NetCDF files to read.

Returns: xarray.Dataset: The combined dataset contained in the NetCDF files.

eviz.lib.xarray_utils.read_multiple_netcdf_in_directory(directory_path)

Reads all NetCDF files in a specified directory using xarray and returns a combined xarray Dataset.

Parameters: directory_path (str): The path to the directory containing NetCDF files to read.

Returns: xarray.Dataset: The combined dataset contained in the NetCDF files.

eviz.lib.xarray_utils.read_netcdf(file_path)

Reads a NetCDF file using xarray and returns an xarray Dataset.

Parameters: file_path (str): The path to the NetCDF file to read.

Returns: xarray.Dataset: The dataset contained in the NetCDF file.

eviz.lib.xarray_utils.sum_over_lev(data_array)

Sums over all lev layers in the given xarray DataArray to get a 2D lat-lon result.

Parameters: data_array (xarray.DataArray): The input data array defined on lon, lat, and lev dimensions.

Returns: xarray.DataArray: The resulting 2D data array after summing over the lev dimension.

Module contents