mnp.utils

Module Contents

Classes

List

Child of list to make a weak referencable list. See https://docs.python.org/3/library/weakref.html This is used to make weak references to the species model lists.

CustomFormatter

For coloring cli outputs, thanks to: https://stackoverflow.com/questions/384076/how-can-i-color-python-logging-output

Functions

get_logger

log_start_completed

log_file_to_cover

Copy log file from temporary storing location to cover location Returns ——-

clear_temp

Clear all files temporarly stored Returns ——-

slugify

Taken from https://github.com/django/django/blob/master/django/utils/text.py Convert to ASCII if ‘allow_unicode’ is False. Convert spaces or repeated dashes to single dashes. Remove characters that aren’t alphanumerics, underscores, or hyphens. Convert to lowercase. Also strip leading and trailing whitespace, dashes, and underscores.

config_info_to_temp

Store a section from the configuration to a pkl file in a temporary location

create_directories

create scenario cover based on the cover design

config_section_to_cover

Save a section in the parameters to a csv file with key value pairs.

add_dynamics_to_config

list_sources_destinations

list source and destination paths of input rasters and tables.

copy_input_file

copy input file

geo_profile_from_hsi

Make geospatial profile from one of the HSI input rasters.

Data

LOG_FILE_NAME

TEMP_DIR

API

mnp.utils.LOG_FILE_NAME = 'log_file.txt'
mnp.utils.TEMP_DIR = 'mkdtemp(...)'
class mnp.utils.List

Bases: list

Child of list to make a weak referencable list. See https://docs.python.org/3/library/weakref.html This is used to make weak references to the species model lists.

Initialization

Initialize self. See help(type(self)) for accurate signature.

class mnp.utils.CustomFormatter(fmt=None, datefmt=None, style='%', validate=True, *, defaults=None)

Bases: logging.Formatter

For coloring cli outputs, thanks to: https://stackoverflow.com/questions/384076/how-can-i-color-python-logging-output

Initialization

Initialize the formatter with specified format strings.

Initialize the formatter either with the specified format string, or a default as described above. Allow for specialized date formatting with the optional datefmt argument. If datefmt is omitted, you get an ISO8601-like (or RFC 3339-like) format.

Use a style parameter of ‘%’, ‘{’ or ‘$’ to specify that you want to use one of %-formatting, str.format() ({}) formatting or string.Template formatting in your format string.

Changed in version 3.2: Added the style parameter.

grey = '\x1b[38;20m'
yellow = '\x1b[38;5;214m'
red = '\x1b[31;20m'
bold_red = '\x1b[31;1m'
cyan = '\x1b[38;5;33m'
reset = '\x1b[0m'
time = '%(asctime)s'
levelname = '%(levelname)s'
funcname = '%(funcName)s'
message = '%(message)s'
FORMATS = None
format(record)
mnp.utils.get_logger()
mnp.utils.log_start_completed(func)
mnp.utils.log_file_to_cover(folders: dict)

Copy log file from temporary storing location to cover location Returns ——-

mnp.utils.clear_temp()

Clear all files temporarly stored Returns ——-

mnp.utils.slugify(value, allow_unicode=False)

Taken from https://github.com/django/django/blob/master/django/utils/text.py Convert to ASCII if ‘allow_unicode’ is False. Convert spaces or repeated dashes to single dashes. Remove characters that aren’t alphanumerics, underscores, or hyphens. Convert to lowercase. Also strip leading and trailing whitespace, dashes, and underscores.

mnp.utils.config_info_to_temp(configuration: configparser.ConfigParser, section: str, key: str, dest: str) bool

Store a section from the configuration to a pkl file in a temporary location

configuration: output from read_ini

mnp.utils.create_directories(folders: dict) None

create scenario cover based on the cover design

directory tree in cover root

mnp.utils.config_section_to_cover(configuration: configparser.ConfigParser, section: str, cover_dir: str)

Save a section in the parameters to a csv file with key value pairs.

mnp.utils.add_dynamics_to_config(configuration: configparser.ConfigParser)
mnp.utils.list_sources_destinations(input_pathway, folders: dict, configuration: configparser.ConfigParser) tuple

list source and destination paths of input rasters and tables.

configuration

The configuration for this mnp run as provided by user

folders

Dictionary of folders in cover for this mnp run

input_pathwayInputPathway

Class defining which input steps to take

([src1, src2, .. src_n], [dest1, dest2, .. dest_n])

mnp.utils.copy_input_file(source: str, destination: str)

copy input file

destinationstr

Path of the destination file

sourcestr

Path for the source file

mnp.utils.geo_profile_from_hsi(folders: dict)

Make geospatial profile from one of the HSI input rasters.