powersimdata.utility package

Subpackages

Submodules

powersimdata.utility.config module

class powersimdata.utility.config.Config[source]

Bases: object

Base class for configuration data. It should contain all expected keys, defaulting to None when not universally applicable.

BACKUP_DATA_ROOT_DIR = None
DATA_ROOT_DIR = '/mnt/bes/pcm'
ENGINE_DIR = None
EXECUTE_DIR = 'tmp'
INPUT_DIR = ('data', 'input')
LOCAL_DIR = '/root/ScenarioData/'
MODEL_DIR = None
OUTPUT_DIR = ('data', 'output')
SERVER_ADDRESS = None
SERVER_SSH_PORT = None
class powersimdata.utility.config.ContainerConfig[source]

Bases: Config

Values specific to containerized environment

SERVER_ADDRESS = 'reisejl'
class powersimdata.utility.config.DeploymentMode[source]

Bases: object

Constants representing the type of installation being used

CONFIG_MAP = {'CONTAINER': <class 'powersimdata.utility.config.ContainerConfig'>, 'LOCAL': <class 'powersimdata.utility.config.LocalConfig'>, 'SERVER': <class 'powersimdata.utility.config.ServerConfig'>}
Container = 'CONTAINER'
Local = 'LOCAL'
Server = 'SERVER'
class powersimdata.utility.config.LocalConfig[source]

Bases: Config

Values specific to native installation

DATA_ROOT_DIR = '/root/ScenarioData/'
ENGINE_DIR = None
initialize()[source]

Create data directory with blank templates

class powersimdata.utility.config.ServerConfig[source]

Bases: Config

Values specific to internal client/server usage

MODEL_DIR = '/home/bes/pcm'
SERVER_ADDRESS = 'becompute01.gatesventures.com'
SERVER_SSH_PORT = 22
powersimdata.utility.config.get_config()[source]

Get a config instance based on the DEPLOYMENT_MODE environment variable

Returns:

(powersimdata.utility.config.Config) – a config instance

powersimdata.utility.config.get_deployment_mode()[source]

Get the deployment mode used to determine various configuration values

Returns:

(str) – the deployment mode

powersimdata.utility.distance module

powersimdata.utility.distance.angular_distance(uv1, uv2)[source]

Calculate the angular distance between two vectors.

Parameters:
  • uv1 (list) – 3-components vector as returned by ll2uv().

  • uv2 (list) – 3-components vector as returned by ll2uv().

Returns:

(float) – angle (in degrees).

powersimdata.utility.distance.find_closest_neighbor(point, neighbors)[source]

Locates the closest neighbor.

Parameters:
  • point (tuple) – (lon, lat) in degrees.

  • neighbors (list) – each element of the list are the (lon, lat) of potential neighbor.

Returns:

(int) – id of the closest neighbor

powersimdata.utility.distance.great_circle_distance(x)[source]

Calculates distance between two sites.

Parameters:

x (pandas.dataFrame) – start and end point coordinates of branches.

Returns:

(float) – length of branch (in km.).

powersimdata.utility.distance.haversine(point1, point2)[source]

Given two lat/long pairs, return distance in miles.

Parameters:
  • point1 (tuple) – first point, (lat, long) in degrees.

  • point2 (tuple) – second point, (lat, long) in degrees.

Returns:

(float) – distance in miles.

powersimdata.utility.distance.ll2uv(lon, lat)[source]

Convert (longitude, latitude) to unit vector.

Parameters:
  • lon (float) – longitude of the site (in deg.) measured eastward from Greenwich, UK.

  • lat (float) – latitude of the site (in deg.). Equator is the zero point.

Returns:

(list) – 3-components (x,y,z) unit vector.

powersimdata.utility.helpers module

class powersimdata.utility.helpers.CacheKeyBuilder(*args, **kwargs)[source]

Bases: object

Helper class to generate cache keys

Parameters:

args – variable length arguments from which to build a key

build()[source]

Combine args into a tuple, preserving the structure of each element.

Returns:

(tuple) – container which can be used as a cache key

class powersimdata.utility.helpers.MemoryCache[source]

Bases: object

Wrapper around a dict object that exposes a cache interface. Users should create a separate instance for each distinct use case.

get(key)[source]

Retrieve the value associated with key if it exists.

Parameters:

key (tuple) – the cache key

Returns:

(Any or NoneType) – the cached value if found, or None

list_keys()[source]

Return and print the current cache keys.

Returns:

(list) – the list of cache keys

put(key, obj)[source]

Add or set the value for the given key.

Parameters:
  • key (tuple) – a tuple used to lookup the cached value

  • obj (Any) – the object to cache

class powersimdata.utility.helpers.PrintManager[source]

Bases: object

Manages print messages.

static block_print()[source]

Suppresses print

enable_print()[source]

Enables print

powersimdata.utility.helpers.cache_key(*args, **kwargs)[source]

Creates a cache key from the given args. The user should ensure that the range of inputs will not result in key collisions.

Parameters:

args – variable length argument list

Returns:

(tuple) – a tuple containing the input in heirarchical structure

powersimdata.utility.server_setup module

powersimdata.utility.server_setup.get_blob_credential()[source]
powersimdata.utility.server_setup.get_server_user()[source]

Returns the first username found using the following sources:

  • BE_SERVER_USER environment variable

  • powersimdata/utility/.server_user

  • username of the active login.

Returns:

(str) – user name to be used to log into server.

Module contents