scenario_tool_interface package

This module provides access to the Scenario-Tool’s REST API to create and run scenarios and manage models

Submodules

class scenario_tool_interface.dynamind2json.DynaMindXML2Json[source]

Bases: object

dump(file_name, output)[source]
class scenario_tool_interface.json2dynamind.Json2DynaMindXML[source]

Bases: object

dump(input_file, output_file)[source]
class scenario_tool_interface.sti.AccessLevel[source]

Bases: enum.Enum

An enumeration.

ADMIN = 4
CONSULTANT = 3
DEMO = 1
PARTICIPANT = 2
SUPERADMIN = 5
class scenario_tool_interface.sti.ScenarioToolInterface(api_url='https://stable-api.harc-dev.com.au/api', results_url='https://stable-sql.harc-dev.com.au/resultsdb/')[source]

Bases: object

add_model(name, src)[source]
add_node(node_data)[source]
archive_project(project)[source]

Share a project

Parameters
  • project – project id

  • username – share user name

check_status(scenario: int)[source]

Return status of current simulation.

returns:

{
   status: status code (int),
   status_text: status description
}

// CREATED = 1
// BASE_IN_QUEUE = 2
// BASE_RUNNING = 3
// BASE_COMPLETE = 4
// PA_IN_QUEUE = 5
// PA_RUNNING = 6
// PA_COMPLETE = 7
// COMPLETE = 8
Parameters

scenario (int) – scenario id

Returns

scenario status

Return type

dict

create_assessment_model(filename, model_id=None)[source]

Creates a new assessment model and a default version tagged as 0.0.1 the data must be of the shape:

Parameters
  • filename (str) – filename of json file (see below)

  • model_id (int) – dynamind model id

{
   name: "some name",
   description: "some desc",

   //optionally add assessment model stage of development
   //1 = ALPHA
   //2 = BETA
   //3 = UNDER DEVELOPMENT
   //default is 3
   stage: 2
   //must specify one of:
   model_id: <model_id> //by default will use the active version of this model
   model_version_id: <model_version_id> //if present will use this model version id
}

returns:

{
  assessment_model_id: <the id of the new assessment model>,
  assessment_model_version_id: <id of the new default version>
}
create_dash_tile_template(json)[source]

Define tile template (see doc)

Parameters

json

Returns

dash_tile_template_id

Return type

int

create_datasource(project_id, name, source_type='file', upload_id=None)[source]

Upload a geojson file and return id

Parameters
  • geojson (str) – geojson file

  • project_id (int) – project the node will be assigned to

  • name (str) – added option to set name of geojson file default is set to casestudyarea

Returns

geojson id

Return type

int

create_node(filename, model_id=None, access_level=5)[source]

Create a new node

Parameters
  • filename – point to json file containing the node description

  • model_id – model id in json file will be replaced by this. If not set model_id from json file

  • access_level – access level of node

:type str :type int :type int :return: node_id :rtype: int

create_project()[source]

Creates a new project

Returns

project id

Return type

int

create_query_template(json, access_level)[source]

Define tile template (see doc)

Parameters

json

:param access_level :type geojson: str :type access_level: int :return: query_template_id :rtype: int

create_scenario(project, parent, name='Baseline')[source]

Creates a new scenario. The provides the shell for the new scenarios. Scenario are derived from the base line or any other scenario in the project. To modify the environment workflow may be defined and executed.

Parameters
  • project – project id

  • parent – parent scenario id

  • name – name of scenario

:type int :type int :type str :return: scenario id :rtype: int

db_name(simulation_id)[source]
deactivate_assessment_model(node_id)[source]

Deactivate assessment model

Parameters

node_id (int) – node id

deactivate_node(node_id)[source]

Deactivate node

Parameters

node_id (int) – node id

download_geojson(scenario_id, layer_name)[source]

Download layer as geojson file

Parameters
  • scenario_id – scenario id

  • layern_name

:type int :type string :return: geojson string

edit_dash_tile_template(template_id, json=None, active=True)[source]

Define tile template (see doc)

Parameters

json

Returns

dash_tile_template_id

Return type

int

execute_scenario(scenario: int, queue='default') → requests.models.Response[source]
Parameters
  • scenario – id of scenario to be executed

  • queue – optional parameter to define queue

Return type

int

Return type

str

get_assessment_model(model_name: str, owner_id=None) → dict[source]

Returns assessment model id

Parameters
  • model_name (str) – Model Name. Currently supported are Land Surface Temperature and Target

  • owner_id (int) – If owner_id is set only models owned by the user will be returned

Returns

dict with assessment_model_id and default parameters

Return type

dict

get_assessment_models()[source]
get_baseline(project_id)[source]

Get a projects baseline scenario id

Parameters

project_id (int) – Project ID

Returns

baseline scenario id

Return type

int

get_city_boundray(project_id)[source]

Return a cities geojson boundary id

Parameters

project_id (int) – project ID

Returns

geojson boundary id

Return type

int

get_data_model(data_model_id: int) → dict[source]

Get data model

Parameters

data_model_id (int) – model to be queried for results

Returns

dict of data model

:rtype dict

get_database_id(scenario_id)[source]

Returns database ID to run data analysis

Parameters

scenario_1_id – scenario id

Returns

data base id needed for query

get_database_structure(scenario_id: int) → dict[source]

Get database structure

Parameters

scenario_id (int) – scenario to be queried for results

Returns

dict of tables and their attributes

:rtype dict

get_default_parameter_dict(node_id: int) → dict[source]

Returns default parameter dict for a node

Parameters

node_id (int) –

Returns

Parameter dict

:rtype dict

get_default_region_parameters(region_id: int) → dict[source]

Returns the default region parameters as dictionary

Parameters

region_id – id of the region

Returns

parameter dictionary

:rtype dict

get_geojsons(project: int)[source]
get_models()[source]
get_my_status()[source]

Get user status

Returns

dict with project status

get_node_id(name, owner_id=None)[source]

Return node id to be used in simulation. If multiple nodes with the same id are identified the first node belonging to the user is returned first. If owner_id is set only the node owned by the user is returned

Parameters
  • name (str) – node name

  • owner_id (int) – user_id

Returns

node_id

:rtype int

get_nodes()[source]

Return list of available nodes

Returns

returns a dict of all scenario

Return type

dict

get_project(project)[source]
get_project_databases(project_id, folder='.', scenario_id=None)[source]

Download project databases. Databases will be downloaded into folder/project_id.zip For larger projects it is recommended to defined the scenario_id to be downloaded. Otherwise the download might fail

Parameters
  • project_id (int) – project id

  • folder (str) – folder

  • scenario_id (int) – scenario_id

get_projects()[source]
get_region(region_name: str) → int[source]

Returns region currently supported is Melbourne

Parameters

region_name – region id

Returns

region id

get_regions() → requests.models.Response[source]
get_results(scenario_id: int, results_tables: list) → dict[source]

Get results from scenario tool interface for tables defined in the results tables list.

Parameters
  • scenario_id (int) – scenario to be queried for results

  • results_tables (list) – list of tables that should be queried for typlical tables include building, parcel, …

Returns

dict with dict for each tables with results as a numpy array. We recommend to use the numpy array to create a pandas dataframe.

:rtype dict

get_scenario(scenario: int)[source]
get_scenario_workflow_nodes(scenario_id=None)[source]
get_scenarios(project_id)[source]

Get a list of scenarios in a project

Parameters

project_id – project ID

:type int :return: returns a dict of all scenario :rtype: dict

get_simulations(scenario: int)[source]

Link dash tile with assessment model

Parameters
  • dash_tile_template_id (int) –

  • assessment_model_id (int) –

Returns

None

Link query prototype with assessment model

Parameters
  • dash_tile_template_id (int) –

  • query_prototype_id (int) –

Returns

None

Link query prototype with assessment model

Parameters
  • query_prototype_id (int) –

  • assessment_model_id (int) –

Returns

None

login(username: str, password: str)[source]
Parameters
  • username – registered user name (email address)

  • password – top secret password

run_query(scenario_id, query)[source]

Run a query on the scenario spatialite database. The database supports SQLite and Spatialite commands Only read access is supported! To find out which data are stored in the database read the dynamind_table_definitions

Parameters
  • scenario_id (int) – scenario id

  • query – SQL query

:type query str :return: query result :rtype: dict

set_model_access_level(node_id, access_level)[source]

Set the access level of the performance assessment model

Parameters
  • node_id (int) – model id

  • access_level (int) – access level (see enum)

set_node_access_level(node_id, access_level)[source]

Set the access level of the parent node

Parameters
  • node_id (int) – node id

  • access_level (int) – access level (see enum)

set_node_properties(node_id, properties)[source]

Set the access level of the parent node

Parameters
  • node_id (int) – node id

  • properties – dict

returns:

set_project_assessment_models(project, models)[source]
set_project_data_model(project, model)[source]
set_scenario_workflow(scenario_id, node_data)[source]

Set the workflow for a scenario. The workflow is defined by a series of nodes defined by the node_data The node_data have following structure

[{
   name: node_id,
   area: geojson_id,
   parameters: {

    parameter.value = 1,
    paramter2.value = 2,

   }
},
...
]

The nodes in the workflow are executed as defined in the data structure

Parameters
  • scenario_id (int) – scenario id

  • node_data (list) – node data see above

share_project(project, username)[source]

Share a project

Parameters
  • project – project id

  • username – share user name

show_assessment_models() → None[source]

List available assessment models

Returns

None

show_log(scenario_id)[source]

Print scenario log file

Parameters

scenario_id (int) – scenario id

show_node_versions(node_id: int)[source]
show_nodes()[source]

Prints list of available nodes

show_scenarios(project_id)[source]

Prints a list of the scenarios in a project

Parameters

project_id (int) – project id

update_assessment_model(assessment_model_id, filename, model_id)[source]

Creates a new assessment model and a default version tagged as 0.0.1 the data must be of the shape:

Parameters
  • assessment_model_id (int) – assessment model id to be updated

  • filename (str) – filename of json file (see below)

  • model_id (int) – dynamind model id

{
   name: "some name",
   description: "some desc",

   //optionally add assessment model stage of development
   //1 = ALPHA
   //2 = BETA
   //3 = UNDER DEVELOPMENT
   //default is 3
   stage: 2
   //must specify one of:
   model_id: <model_id> //by default will use the active version of this model
   model_version_id: <model_version_id> //if present will use this model version id
}

returns:

{
  assessment_model_id: <the id of the new assessment model>,
  assessment_model_version_id: <id of the new default version>
}
update_data_model(data_model_id: int, data_model: dict)[source]

Update data model

Parameters
  • data_model_id (int) – model to be queried for results

  • data_model (dict) – data model to be updated

update_node(node_id, filename, model_id=None, access_level=5)[source]

Update an existing node

Parameters
  • node_id – id of node

  • filename – point to json file containing the node description

  • model_id – model id in json file will be replaced by this. If not set model_id from json file

  • access_level – access level of node

:type str :type str :type int :type int :return: node_id :rtype: int

update_project(project, data)[source]
update_sm_node(node_id, node_data)[source]
upload_dynamind_model(name: str, filename: str) → int[source]

Uploads a new model to the server

Parameters
  • name – model name

  • filename – dynamind file

:type str :return: model_id :rtype: int

upload_file(project_id, file)[source]

Upload a file and return id

Parameters
  • file (str) – path to file

  • project_id (int) – project the file will be assigned to

Return type

int

upload_geojson(geojson, project_id, name='casestudyarea')[source]

Upload a geojson file and return id

Parameters
  • geojson (str) – geojson file

  • project_id (int) – project the node will be assigned to

  • name (str) – added option to set name of geojson file default is set to casestudyarea

Returns

geojson id

Return type

int