Server Code API

model2050

class server_code.model2050.Model2050(module)

A wrapper class for compiled 2050 Calculator models produced by excel_to_code and wrapped with SWIG. Provides a simple interface for running the model.

__init__(module)

module should be Python module produced by SWIG to be wrapped.

calculate(ambition_values, start_values=None, end_values=None)

Run the model and return a dictionary containing all model outputs. ambition_values should be a sequence returing valid values for each input lever of the model i.e. 1 to 4. start_values and end_values should provide a sequence of integer values representing years up to 2100 for each input lever. If no keyword arguments are provided model defaults are used instead.

input_values_default()

Return a valid input for self.calculate with all levers set to 1.

Model2050Server

server_code.Model2050Server.arc_length_to_angle(length, radius)

Return the change in angle (in degrees) associated with a known arc length and radius.

server_code.Model2050Server.area_to_side_length(area, radius)

Return the side length for a square of known area on a spherical surface.

server_code.Model2050Server.calculate(inputs, start_year, end_year, expert_mode=False)

Run the model in expert (2100) mode, or standard (2050) mode.

Callable from the client side of the web app.

Parameters
  • inputs (list) – A list of all the ambition lever values.

  • start_year (list) – A list of the start year for each ambition lever.

  • end_year (list) – A list of the end year for each ambition lever.

  • expert_mode (bool, optional) – Flag to run in expert mode. Defaults to False.

Returns

A dictionary with lists for each output of the model and the years on the

x axis (dictionary key is “x”). In 2050 mode the x axis will be from 2015 to 2050 (inclusive) in steps of 5 years. 2100 mode will extend it to 2100.

Return type

dict

server_code.Model2050Server.default_end_years()

Return the default end year values of the model.

server_code.Model2050Server.default_inputs()

Return the default lever values of the model.

server_code.Model2050Server.default_start_years()

Return the default start year values of the model.

server_code.Model2050Server.example_pathways()

Return the lever values for the example pathways in the model.

server_code.Model2050Server.initial_values()

Return the initial values for when loading the web app.

Callable from the client side of the web app.

server_code.Model2050Server.layout()

Return the details of the layout - ie the Web Outputs Summary Table.

server_code.Model2050Server.lever_groups()

Return the groups names and tooltips of the ambition levers.

server_code.Model2050Server.map(data)

Generate the figure for the map plot. Currently centred over the UK.

Callable from the client side of the web app.

Parameters

data (dict) – Contains the filled areas and distances to plot on the map.

Returns

The plotly figure with the map and the filled areas.

Return type

go.Figure

server_code.Model2050Server.model()

The interface for running the model.

Returns

An initialised model.

Return type

Model2050

server_code.Model2050Server.translate(locale, text)

Stub for translating text to different languages. Requires a translation file. requires a dictionary/translation file to be added to the server_code/translations directory. The file will be named <locale>.yml and is a simple 1:1 translation. So every phrase to be translated must be included exactly as written, in full.

Callable from the client side of the web app.

Parameters
  • locale (str) – The name of the language to translate to.

  • text (str) – The word/phrase to translate

Returns

The translated text

Return type

str

interface2050

Automatically generated by using the Calc2050 Spreadsheet Converter as described in the Web App Setup Process. Used by server_code.model2050.Model2050 which abstracts away the complexities of this module.