dsgrid package

Submodules

dsgrid.helpers module

dsgrid.helpers.multi_index(df, cols)[source]
dsgrid.helpers.ensure_enum(cls, val)[source]

Returns the instance of cls that corresponds to val. cls is expected to be an enum-type class.

Parameters
  • cls (an Enum class) --

  • val (str or cls object) --

Returns

Return type

cls object

dsgrid.helpers.lighten_color(hex_color, fraction_to_white)[source]
dsgrid.helpers.palette(hex_color, n, max_fraction=0.75)[source]
class dsgrid.helpers.h5Reader(filepath)[source]

Bases: object

property is_hsds
property is_s3

dsgrid.layerstack module

class dsgrid.layerstack.DSGridDatafileLayer[source]

Bases: layerstack.layer.ModelLayerBase

classmethod new_filepath(model, suffix, out_filepath=None)[source]

dsgrid.model module

A dsgrid LoadModel consists of a number of different LoadModelComponents. Each LoadModelComponent is a BOTTOMUP, GAP, DG, TOPDOWN, or DERIVED ComponentType. Load is represented by the BOTTOMUP (detailed) and GAP (coarser) models. The other components allow for computation of variants other than total site load (e.g. net site load, system load), as well as validation/calibration/ reconciliation with historical data.

class dsgrid.model.LoadModelStatus(value)[source]

Bases: enum.Enum

An enumeration.

RAW = 1
class dsgrid.model.ComponentType(value)[source]

Bases: enum.Enum

An enumeration.

BOTTOMUP = 1
GAP = 2
DG = 3
TOPDOWN = 4
DERIVED = 5
UNKNOWN = 9999
class dsgrid.model.LoadModelComponent(name, component_type=ComponentType.UNKNOWN, color=None)[source]

Bases: object

A LoadModelComponent is generally associated with a dsgrid.dataformat.Datafile, and is therefore data of a particular type, represented at a certain geographic, temporal, sectoral, and end-use resolution. A LoadModelComponent is also commonly part of a LoadModel. Based on the dimension-mapping capabilities of dsgrid, the LoadModel likely has uniform geographical and temporal extents and resolution.

name

The name of the LoadModelComponent

Type

str

component_type

The type of the LoadModelComponent, defaults to ComponentType.UNKNOWN

Type

ComponentType

color

Color to use when plotting this LoadModelComponent, in Hexadecimal. Otherwise None.

Type

str

property key

The (hash) key used by LoadModel to identify this LoadModelComponent.

Returns

(self.component_type,self.name)

Return type

tuple

property datafile

returns: Returns a Datafile if self.load_datafile has been called successfully. :rtype: None or dsgrid.dataformat.Datafile

load_datafile(filepath)[source]
Parameters

filepath (str) -- Path to dsgrid.dataformat.Datafile corresponding to this component

classmethod clone(original, filepath=None)[source]

Creates a new instance of a LoadModelComponent, perhaps pointing to a different dsgrid.dataformat.Datafile.

Parameters
  • original (LoadModelComponent) -- Only the metadata (e.g. name, type, color) are used, and orignial is not modified in any way

  • filepath (str or None) -- If not None, path to the dsgrid.dataformat.Datafile corresponding to the new LoadModelComponent created by this method. In most cases, should not be the same as original.datafile.h5path.

Returns

Clone of original, with the appropriate dsgrid.dataformat.Datafile loaded if filepath was not None.

Return type

LoadModelComponent

get_datatable(sort=True, **kwargs)[source]
save(dirpath)[source]

Saves this component (primarily its datafile) to a new directory.

Parameters

dirpath (str) -- The folder to which to save this component's datafile (using the same filename)

Returns

A new component with the copy of this component's datafile that has been saved to dirpath already loaded

Return type

LoadModelComponent

map_dimension(dirpath, to_enum, mappings, filename_prefix='')[source]

If there is an appropriate mapping, map the dimension specified by to_enum's class to match to_enum. If there is not, simply create a copy of this LoadModelComponent in the new location.

Parameters
  • dirpath (str) -- Directory in which to save the result of mapping this LoadModelComponent

  • to_enum (dsgrid.dataformat.enumeration.Enumeration) -- This enumeration's class (e.g. SectorEnumeration, TimeEnumeration) determines which dimension is being mapped. The enumeration specifies the target resolution and particular naming convention that is desired.

  • mappings (dsgrid.dataformat.dimmap.Mappings) -- Container of dsgrid.dataformat.dimmap.DimensionMaps. If for the dimension in question this component's enumeration (the from_enum), there is either a TautologyMapping to to_enum, or there is an explicit mapping to to_enum, then we say that we are able to map this component, and proceed to do that by either simply saving this component to the new location or by calling dsgrid.dataformat.Datafile.map_dimension.

  • filename_prefix (str) -- Default is the empty string, ''. If not empty, the new dsgrid.dataformat.Datafile created by this method is saved using the filename created by placing this string before the current datafile's filename.

Returns

New component with either a copy of this component's datafile loaded, or a new, mapped datafile loaded. In either case the new datafile is located at os.path.join(dirpath,filename_prefix + os.path.basename(self.datafile.h5path)).

Return type

LoadModelComponent

scale_data(dirpath, factor=0.001)[source]

Scale all the data in self.datafile by factor, creating a new HDF5 file and corresponding LoadModelComponent.

Parameters
  • dirpath (str) -- Folder the new version of the data should be placed in. This LoadModelComponent's filename will be retained.

  • factor (float) -- Factor by which all the data in the file is to be multiplied. The default value of 0.001 corresponds to converting the bottom-up data from kWh to MWh.

class dsgrid.model.LoadModel[source]

Bases: collections.abc.MutableMapping

classmethod create(components)[source]
save(dirpath, clean=False)[source]
map_dimension(dirpath, to_enum, mappings)[source]

Map the appropriate dimension to_enum for all possible components. Will only map those components for which the given dimension (determined by to_enum's class) is resolved by a from_enum for which a map between from_enum and to_enum is in mappings.

Parameters
  • dirpath (str) -- Folder for new model created by doing this mapping

  • to_enum (dsgrid.dataformat.Enumeration) -- Enumeration to which to map the appropriate dimension

  • mappings (dsgrid.dimmap.Mappings) -- collection of dsgrid.dimmap.DimensionMap objects. Only maps registered in this object will be applied.

move_sectors(dirpath, from_component_key, to_component_key, sectors_to_move)[source]

Moves sectors_to_move from_component_key to_component_key. If to_component_key is None, simply drops those sectors.

Module contents

exception dsgrid.DSGridError[source]

Bases: Exception

exception dsgrid.DSGridNotImplemented[source]

Bases: dsgrid.DSGridError

exception dsgrid.DSGridRuntimeError[source]

Bases: dsgrid.DSGridError

exception dsgrid.DSGridValueError[source]

Bases: dsgrid.DSGridError