Development_Distance_Time_Analysis#

Classes:

Development_Distance_Time_Analysis(input_file)

Relating development distance to time using historical data.

Functions:

exponential_decline(p, x)

Exponential decay function for fitting.

fit_generic(x, y, function[, p_guess, kwargs])

Generic least squares fitting function.

linear(p, x)

Linear function for fitting.

residual_generic(p, x, y, function, **kwargs)

Generic residual function for least squares fitting.

class pyH2A.Analysis.Development_Distance_Time_Analysis.Development_Distance_Time_Analysis(input_file)[source]#

Relating development distance to time using historical data.

Parameters
Development_Distance_Time_Analysis > Input File > Valuestr

Path to textfile containing historical data for parameters specified in Monte Carlo analysis (see Notes).

Development_Distance_Time_Analysis > Log Normalization > Valuebool

Boolean flag to control if logarithmic normalization is used for distance calculation or not. If False, linear normalization is used. When analyzing historical data, it is advised to use logaritthmic normalization to avoid outsized impacts of parameters which have changed on the order of magnitudes.

Development_Distance_Time_Analysis > Base Year > Valueint

Year which corresponds to the Base values specified in Monte Carlo analysis.

Development_Distance_Time_Analysis > Extrapolation Limit > Yearint

Year until which the distance/time models should be extrapolated.

Notes

The loaded textfile has to contain datapoints with historical parameter values for the specified technology. The first column contains the year of the respective datapoint and the other columns contain the corresponding parameter values. The textfile needs to be tab separated. The header of textfile has to start with # and needs to contain the tab separated column names (first being Year and the other being the same parameter names specified in the Parameters - Monte_Carlo_Analysis table.) If the textfile does not contain values for all parameters from the Monte Carlo analysis, missing parameter values are set to the base/reference value are are assumed to be constant across all years included in the textfile.

Methods:

determine_distance_time_correspondence(...)

Mapping development distance to time for plotting.

fit_historical_development_distance()

Linear and asymptotic models are fitted to historical distances and are used to extrapolate into the future.

generate_time_axis(ax, position, distances, ...)

Generating additional x axis for plot which maps development distance to time.

harmonize_monte_carlo_parameters()

Checking if all Monte Carlo parameters are included in historical dataset.

historical_development_distance()

Calculating development distance for historical and Monte Carlo analysis data.

import_data(file_name)

Importing historical data from textfile.

map_parameters()

Mapping parameters from historical data input file to Monte Carlo parameters.

plot_distance_cost_relationship([ax, ...])

Plot distance/cost relationship with additional axis mapping development distance to time.

plot_distance_histogram([ax, figure_lean, ...])

Plot distance histogram with additional axis mapping development distance to time.

plot_distance_time_relationship([ax, ...])

Ploting relationship between time and development distance based on historical data.

determine_distance_time_correspondence(years, model, spacing=1, minimum_tick_distance=0.1, spacing_distances=array([1, 2, 3, 5, 10, 15, 20]))[source]#

Mapping development distance to time for plotting.

Parameters
yearsndarray

1D array of years, for which development distances have been computed using the specified model.

modelndarray

1D array of modelled, time-dependent development distance values.

spacingint, optional

Spacing of year ticks for visualization. Unit is years.

minimum_tick_distancefloat, optional

Minimum allowable distance between year ticks in axis coordinates (0 to 1).

spacing_distancesndarray, optional

Possible spacings which are to be used if specified spacing violates minimum_tick_distance.

Returns
labelsndarray

Array of year tick labels.

distancesndarray

Array of distances, to which year tick labels correspond.

Notes

If specified spacing leads to tick separation which is smaller than minimum_tick_distance, the spacing is increased by iterating through spacing_distances until the minimum_tick_distance criterion is fullfilled.

fit_historical_development_distance()[source]#

Linear and asymptotic models are fitted to historical distances and are used to extrapolate into the future.

Notes

To simply fitting of the exponential/asymptotic model, year values and distances are transformed to start at 0 and converge to 0, respectively. Both the linear and the asymptotic model are then fitted to the transformed data. The results are transformed back for visualization.

generate_time_axis(ax, position, distances, labels, axis_label, color)[source]#

Generating additional x axis for plot which maps development distance to time.

harmonize_monte_carlo_parameters()[source]#

Checking if all Monte Carlo parameters are included in historical dataset.

Notes

If Monte Carlo parameters are missing, they are added with their historical value being set to the present reference/base value.

historical_development_distance()[source]#

Calculating development distance for historical and Monte Carlo analysis data.

Notes

To ensure that historical development distances are consistent with the Monte Carlo derived development, Monte Carlo distances are recalculated using the same hyperparameters. If log_normalize is set to True, all distances are calculated using logarithmic normalization.

import_data(file_name)[source]#

Importing historical data from textfile.

map_parameters()[source]#

Mapping parameters from historical data input file to Monte Carlo parameters.

plot_distance_cost_relationship(ax=None, figure_lean=True, linear_axis_y_pos=-0.25, expo_axis_y_pos=-0.5, linear_axis_label='Year (linear model)', expo_axis_label='Year (asymptotic model)', label_kwargs={}, dist_kwargs={}, table_kwargs={}, image_kwargs={}, plot_kwargs={}, **kwargs)[source]#

Plot distance/cost relationship with additional axis mapping development distance to time.

Parameters
axmatplotlib.axes, optional

Axes object in which plot is drawn. Default is None, creating new plot.

figure_leanbool, optional

If figure_lean is True, matplotlib.fig object is returned.

linear_axis_y_posfloat, optional

y position of linear model time axis in axis coordinates.

expo_axis_y_posfloat, optional

y position of exponential/asymptotic time axis in axis coordinates.

linear_axis_labelstr, optional

String for label of linear model time axis.

expo_axis_labelstr, optional

String for label of exponential/asymptotic model time axis.

label_kwargsdict, optional

Dictionary containing optional keyword arguments for determine_distance_time_correspondence().

dist_kwargs: dict, optional

Dictionary containg optional keyword arguments for plot_distance_cost_relationship()

table_kwargsdict, optional

Dictionary containing optional keyword arguments for render_parameter_table()

image_kwargs: dict, optional

Dictionary containing optional keyword arguments for insert_image()

plot_kwargs: dict, optional

Dictionary containing optional keyword arguments for Figure_Lean(), has priority over **kwargs.

**kwargs:

Additional kwargs passed to Figure_Lean()

Returns
figurematplotlib.fig or None

matplotlib.fig is returned if figure_lean is True.

plot_distance_histogram(ax=None, figure_lean=True, linear_axis_y_pos=-0.4, expo_axis_y_pos=-0.8, linear_axis_label='Year (linear model)', expo_axis_label='Year (asymptotic model)', label_kwargs={}, hist_kwargs={}, table_kwargs={}, image_kwargs={}, plot_kwargs={}, **kwargs)[source]#

Plot distance histogram with additional axis mapping development distance to time.

Parameters
axmatplotlib.axes, optional

Axes object in which plot is drawn. Default is None, creating new plot.

figure_leanbool, optional

If figure_lean is True, matplotlib.fig object is returned.

linear_axis_y_posfloat, optional

y position of linear model time axis in axis coordinates.

expo_axis_y_posfloat, optional

y position of exponential/asymptotic model time axis in axis coordinates.

linear_axis_labelstr, optional

String for label of linear model time axis.

expo_axis_labelstr, optional

String for label of exponential/asymptotic model time axis.

label_kwargsdict, optional

Dictionary containing optional keyword arguments for determine_distance_time_correspondence().

hist_kwargs: dict, optional

Dictionary containg optional keyword arguments for plot_distance_histogram()

table_kwargsdict, optional

Dictionary containing optional keyword arguments for render_parameter_table()

image_kwargs: dict, optional

Dictionary containing optional keyword arguments for insert_image()

plot_kwargs: dict, optional

Dictionary containing optional keyword arguments for Figure_Lean(), has priority over **kwargs.

**kwargs:

Additional kwargs passed to Figure_Lean()

Returns
figurematplotlib.fig or None

matplotlib.fig is returned if figure_lean is True.

plot_distance_time_relationship(ax=None, figure_lean=True, legend_loc='upper left', xlabel_string='Year', ylabel_string='Development distance', expo_label_string='Asymptotic model', linear_label_string='Linear model', datapoint_label_string=' historical distance', markersize=10, color_future=True, parameter_table=True, target_distances=None, table_kwargs={}, image_kwargs={}, plot_kwargs={}, **kwargs)[source]#

Ploting relationship between time and development distance based on historical data.

Parameters
axmatplotlib.axes, optional

Axes object in which plot is drawn. Default is None, creating new plot.

figure_leanbool, optional

If figure_lean is True, matplotlib.fig object is returned.

legend_locstr, optional

Controls location of legend in plot. Defaults to ‘upper left’.

xlabel_stringstr, optional

String for x axis label.

ylabel_stringstr, optional

String for y axis label.

expo_label_stringstr, optional

String for label of exponential/asymptotic model.

linear_label_stringstr, optional

String for label of linear model.

datapoint_label_stringstr, optional

Second part of string for label of historical datapoints. The first part is the display name of the model.

markersizefloat, optional

Size of markers in scatter plot.

color_futurebool, optional

Boolean flag to control if past or future region of plot is colored.

parameter_tablebool, optional

If parameter_table is True, the parameter table is shown in the plot.

target_distancesndarray, optional

Target distance range as an 1D array with two entries ([lower_limit, higher_limit]), which is highlighted in the plot.

image_kwargs: dict, optional

Dictionary containing optional keyword arguments for insert_image()

plot_kwargs: dict, optional

Dictionary containing optional keyword arguments for Figure_Lean(), has priority over **kwargs.

**kwargs:

Additional kwargs passed to Figure_Lean()

Returns
figurematplotlib.fig or None

matplotlib.fig is returned if figure_lean is True.

pyH2A.Analysis.Development_Distance_Time_Analysis.exponential_decline(p, x)[source]#

Exponential decay function for fitting.

pyH2A.Analysis.Development_Distance_Time_Analysis.fit_generic(x, y, function, p_guess=None, kwargs={})[source]#

Generic least squares fitting function.

pyH2A.Analysis.Development_Distance_Time_Analysis.linear(p, x)[source]#

Linear function for fitting.

pyH2A.Analysis.Development_Distance_Time_Analysis.residual_generic(p, x, y, function, **kwargs)[source]#

Generic residual function for least squares fitting.