10.1. ramascene package¶
10.1.1. Submodules¶
10.1.2. ramascene.analyze module¶
-
class
ramascene.analyze.
Analyze
(product_calc_indices, country_calc_indices, indicator_calc_indices, querySelection, idx_units, job_name, job_id, s_country_idx, Y_data, B_data, L_data)¶ Bases:
object
This class contains the method for calculations
-
route_four
()¶ Perform calculations according to route four.
Returns: json result data Return type: json
-
route_one
()¶ Perform calculations according to route one.
Returns: json result data Return type: json
-
route_three
()¶ Perform calculations according to route three.
Returns: json result data Return type: json
-
route_two
()¶ Perform calculations according to route two.
Returns: json result data Return type: json
-
10.1.3. ramascene.consumers module¶
-
class
ramascene.consumers.
RamasceneConsumer
(scope)¶ Bases:
channels.generic.websocket.JsonWebsocketConsumer
This class represents the Django Channels web socket interface functionality.
-
celery_message
(event)¶ Sends Celery task status.
-
save_job
(job_name)¶ Update and save the job status to started
-
websocket_connect
(event)¶ websocket first connection, accept immediately
-
websocket_disconnect
(message)¶ Websocket disconnect function.
-
websocket_receive
(event)¶ Receives message from front-end.
Tries to parse the message, if successful it will perform pre-processing steps and invokes Celery tasks.
Parameters: event (dict) – message from front-end
-
ws_response
(job)¶ Sends web socket response that the job is started
-
10.1.4. ramascene.modelling module¶
-
class
ramascene.modelling.
Modelling
(ready_model_details, Y_data, load_A, year, model_details)¶ Bases:
object
This class contains the methods for modeling
-
apply_model
()¶
-
model_final_demand
(Y, rows, columns, tech_change)¶ It allows for modification of values within final demand for scenario building
-
model_intermediates
(A, rows, columns, tech_change)¶ It allows for modification of values within intermediates for scenario building
-
unpack
(structure, name)¶ Unpack deep structure of modelling details (these are arrays of local ids per intervention)
-
10.1.5. ramascene.models module¶
-
class
ramascene.models.
Country
(*args, **kwargs)¶ Bases:
django.db.models.base.Model
Country model to store identifiers for the countries and aggregations
-
exception
DoesNotExist
¶ Bases:
django.core.exceptions.ObjectDoesNotExist
-
exception
MultipleObjectsReturned
¶ Bases:
django.core.exceptions.MultipleObjectsReturned
-
code
¶ The country code
-
global_id
¶ The global id representing the application coordinates as primary id
-
id
¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
identifier
¶ an identifier determining if it is a leaf node or aggregate
-
leaf_children_global
¶ the global id’s of the leafs for this continent (if available)
-
leaf_children_local
¶ the local id’s of the leafs of this country (if available)
-
level
¶ The level of hierarchy this country is in
-
local_id
¶ The local id, only used if the hierarchy level is the lowest
-
name
¶ The name of the country
-
objects
= <django.db.models.manager.Manager object>¶
-
parent_id
¶ The id representing what parent this country belongs to (by parent global_id)
-
exception
-
class
ramascene.models.
Indicator
(*args, **kwargs)¶ Bases:
django.db.models.base.Model
Indicator model to store identifiers for indicators
-
exception
DoesNotExist
¶ Bases:
django.core.exceptions.ObjectDoesNotExist
-
exception
MultipleObjectsReturned
¶ Bases:
django.core.exceptions.MultipleObjectsReturned
-
global_id
¶ The global id representing the application coordinates as primary id
-
id
¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
level
¶ The level of hierarchy this indicator is in
-
local_id
¶ The local id (unusedas there are no direct summing steps performed for the extensions)
-
name
¶ The name of the indicator
-
objects
= <django.db.models.manager.Manager object>¶
-
parent_id
¶ The id representing what parent this indicator belongs to (unused as there are no direct summing steps performed for the extensions)
-
unit
¶ The unit used for the indicator
-
exception
-
class
ramascene.models.
Job
(*args, **kwargs)¶ Bases:
django.db.models.base.Model
Job model to store Celery jobs
-
exception
DoesNotExist
¶ Bases:
django.core.exceptions.ObjectDoesNotExist
-
exception
MultipleObjectsReturned
¶ Bases:
django.core.exceptions.MultipleObjectsReturned
-
celery_id
¶ The unique identifier for retrieving the results of the job from Celery
-
completed
¶ The date the Celery job was completed
-
created
¶ The date the Celery job was created
-
get_next_by_created
(*, field=<django.db.models.fields.DateTimeField: created>, is_next=True, **kwargs)¶
-
get_previous_by_created
(*, field=<django.db.models.fields.DateTimeField: created>, is_next=False, **kwargs)¶
-
id
¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
name
¶ The name of the Celery job
-
objects
= <django.db.models.manager.Manager object>¶
-
status
¶ The status of the Celery job
-
exception
-
class
ramascene.models.
ModellingProduct
(*args, **kwargs)¶ Bases:
django.db.models.base.Model
Modelling data-model to store identifiers for the products and aggregations (slight modified version of Product)
-
exception
DoesNotExist
¶ Bases:
django.core.exceptions.ObjectDoesNotExist
-
exception
MultipleObjectsReturned
¶ Bases:
django.core.exceptions.MultipleObjectsReturned
-
code
¶ The product category code
-
global_id
¶ The global id representing the application coordinates as primary id
-
id
¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
identifier
¶ an identifier determining if it is a leaf node or aggregate
-
leaf_children_global
¶ the global id’s of the leafs for this product group (if available)
-
leaf_children_local
¶ the local id’s of the leafs of this product group (if available)
-
level
¶ The level of hierarchy this product is in
-
local_id
¶ The local id, only used if the hierarchy level is the lowest
-
name
¶ The name of the product category
-
objects
= <django.db.models.manager.Manager object>¶
-
parent_id
¶ The id representing what parent this product belongs to (by parent global_id)
-
exception
-
class
ramascene.models.
Product
(*args, **kwargs)¶ Bases:
django.db.models.base.Model
Product model to store identifiers for the products and aggregations
-
exception
DoesNotExist
¶ Bases:
django.core.exceptions.ObjectDoesNotExist
-
exception
MultipleObjectsReturned
¶ Bases:
django.core.exceptions.MultipleObjectsReturned
-
code
¶ The product category code
-
global_id
¶ The global id representing the application coordinates as primary id
-
id
¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
identifier
¶ an identifier determining if it is a leaf node or aggregate
-
leaf_children_global
¶ the global id’s of the leafs for this product group (if available)
-
leaf_children_local
¶ the local id’s of the leafs of this product group (if available)
-
level
¶ The level of hierarchy this product is in
-
local_id
¶ The local id, only used if the hierarchy level is the lowest
-
name
¶ The name of the product category
-
objects
= <django.db.models.manager.Manager object>¶
-
parent_id
¶ The id representing what parent this product belongs to (by parent global_id)
-
exception
10.1.6. ramascene.productindexmanger module¶
-
class
ramascene.productindexmanger.
ProductIndexManager
(c_prd_ids, s_cntr_ids, p_prd_ids, p_cntr_ids)¶ Bases:
object
The ProductIndexManager provides functions to translate ids of selected countries and products into ids of the combination of selected countries and products and returns ids that cab be used directly to select columns and/or rows from final demand matrices, extension matrices and leontief inverse matrix.
The selected countries and products have to be supplied when initializing the ProductIndexManager. After initialisation no changes to the supplied ids are allowed.
Parameters: - c_prd_ids – ndarray 1D array containing integers indicating the ids of selected consumed products
- s_cntr_ids – ndarray 1D array containing integers indicating the ids of the selected countries selling final products
- p_prd_ids – ndarray 1D array containing integers indicating the ids of the selected produced products
- p_cntr_ids – 1D array containing integers indicating the ids of the selected producing countries
-
get_consumed_product_ids
()¶ Get the ids of the selected consumed products
Based on the ids of the selected consumed products and the ids of the selected countries selling final products the ids of all selected products in the final demand vector are generated. It allows to make a full selection of the selected consumed products from a final demand vector. A full selection means that if the id of the product bread was selected, now the ids of bread from Italy, bread from Belgium etc are generated as long as Italy, Belgium etc are within the ids of countries selling final products. The ids are zero based.
Returns: one dimensional numpy array with ids of type int
-
get_country_count
()¶ Get the number of countries and regions in EXIOBASE
Returns: integer object with the number of countries/regions.
-
get_full_selected_c_product_count
()¶ Get the full number of consuming products selected.
Products in different countries are counted as unique items, i.e. bread from Belgium and bread from Italy consumed in a particular country are considered two items.
Returns: integer object with the full count of consumed products selected.
-
get_full_selected_p_product_count
()¶ Get the full number of produced products selected.
Products in different countries are counted as unique items, i.e. cars produced in France and cars produced in Germany are considered two items.
Returns: integer object with the full count of produced products selected.
-
get_produced_product_ids
()¶ Get the ids of the selected produced products
Based on the ids of the selected produced products and the ids of the selected producing countries the ids of all selected produced products are generated. It allows to make a full selection of the selected produced products from the output vector. A full selection means that if the id of the product car was selected, now the ids of car from Germany, car from France etc are generated as long as Germany, France etc are within the ids of selected producing countries. The ids are zero based.Returns: one dimensional numpy array with ids of type int
-
get_product_count
()¶ Get the number of products per country in EXIOBASE
Returns: integer object with the number of products.
-
get_selected_c_product_count
()¶ Get the number of consumed products selected.
Returns: integer object with the number of consumed products selected.
-
get_selected_p_country_count
()¶ Get the number of selected producing countries.
Returns: integer object with the number of producing countries selected.
-
get_selected_p_product_count
()¶ Get the number of selected produced products.
Returns: integer object with the number of produced products selected.
-
get_selected_s_country_count
()¶ Get the number of selected countries selling final products.
Returns: integer object with the number of contries selling final products selected.
10.1.7. ramascene.querymanagement module¶
-
ramascene.querymanagement.
clean_indicators
(idx_lst)¶ Clean data as preprocessing step for calculation.
Clean the selected indicator by converting to integers and applying offset of -1.
Parameters: idx_lst (list) – indicators Returns: indicators(processed) Return type: list
-
ramascene.querymanagement.
clean_local_leafs
(a_list)¶ Clean data as preprocessing step for calculation.
Clean the country or product data for calculations by splitting and converting to integers.
Parameters: a_list (str) – country or product string of coordinates separated by # Returns: country or product list of coordinates as integers Return type: list
-
ramascene.querymanagement.
clean_single_leafs
(leaf, OFFSET)¶ Clean data as preprocessing step for calculation.
Clean the country or product data for calculations by splitting, applying offset (-1) and converting to integers.
Parameters: leaf (str) – single country or product coordinate (non-processed) Returns: country or product list of coordinates (single element, processed) Return type: list
-
ramascene.querymanagement.
convert_to_numpy
(list_obj)¶ Clean data as preprocessing step for calculation.
Convert processed country,product, indicator lists to numpy array.
Parameters: product,country,indicator (list) – pre-processed list Returns: numpy arrays of products or countries or indicator coordinates Return type: list
-
ramascene.querymanagement.
get_aggregations_countries
(querySelection, result_data)¶ Sum to construct aggregates results for countries.
Invoked at Celery tasks to sum values that belong to a certain aggregate.
Parameters: Returns: dicitonary of result_data, but with aggregations if there are any
Return type:
-
ramascene.querymanagement.
get_aggregations_products
(querySelection, result_data)¶ Sum to construct aggregates results for products.
Invoked at Celery tasks to sum values that belong to a certain aggregate.
Parameters: Returns: dicitonary of result_data, but with aggregations if there are any
Return type:
-
ramascene.querymanagement.
get_calc_names_country
(country_result_data)¶ Get name of countries.
Uses the database/model to fetch names, used inside calculation as conversion step
Parameters: country_result_data (dict) – key/value pair product with key as global_id Returns: key/value pair country with key as name corresponding to querySelection global_id Return type: dict
-
ramascene.querymanagement.
get_calc_names_product
(prod_result_data)¶ Get name of products.
Uses the database/model to fetch names, used inside calculation as conversion step
Parameters: prod_result_data (dict) – key/value pair product with key as global_id Returns: key/value pair product with key as name corresponding to querySelection global_id Return type: dict
-
ramascene.querymanagement.
get_indicator_units
(idx_lst)¶ Get units of passed-in indicators.
Can be multiple or single units depending on the API implementation version
Parameters: idx_lst (list) – indicators Returns: key/value pair name of indicator and corresponding unit Return type: dict
-
ramascene.querymanagement.
get_leafs_country
(country_global_ids)¶ Returns the leaf nodes of a given global id
Uses the database/model to fetch leaf nodes.
Parameters: country_global_ids (list) – A list of user selected country global ids Returns: complete list of leaf ids (minus a offset of -1 for calculation purposes) Return type: list
-
ramascene.querymanagement.
get_leafs_modelled_product
(product_global_ids)¶ Returns the leaf nodes of a given global id
Uses the database/model to fetch leaf nodes.
Parameters: product_global_ids (list) – A list of user selected product global ids Returns: complete list of leaf ids (minus a offset of -1 for calculation purposes) Return type: list
-
ramascene.querymanagement.
get_leafs_product
(product_global_ids)¶ Returns the leaf nodes of a given global id
Uses the database/model to fetch leaf nodes.
Parameters: product_global_ids (list) – A list of user selected product global ids Returns: complete list of leaf ids (minus a offset of -1 for calculation purposes) Return type: list
-
ramascene.querymanagement.
get_modelled_names_product
(prod_ids)¶ Get name of products consumed by in modelling
Uses the database/model to fetch names, used for sending selection information to front-end
Parameters: prod_ids (list) – list of products by global id Returns: lists of products Return type: list
-
ramascene.querymanagement.
get_names_country
(country_ids)¶ Get name of countries
Uses the database/model to fetch names, used for sending selection information to front-end
Parameters: country_ids (list) – list of countries by global id Returns: lists of countries Return type: list
-
ramascene.querymanagement.
get_names_indicator
(indicator_ids)¶ Get name of indicators
Uses the database/model to fetch names, used for sending selection information to front-end
Parameters: indicator_ids (list) – list of indicators by global id Returns: lists of indicators as names Return type: list
-
ramascene.querymanagement.
get_names_product
(prod_ids)¶ Get name of products
Uses the database/model to fetch names, used for sending selection information to front-end
Parameters: prod_ids (list) – list of products by global id Returns: lists of products Return type: list
-
ramascene.querymanagement.
get_numpy_objects
(year, object_name)¶ - Retrieve numpy objects per year.
- Args: year (int): selected year object_name (str): L, A, B, or Y
- Returns:
- numpy object: numpy object of the given object_name
-
ramascene.querymanagement.
identify_country
(country_id)¶ Helper function.
Does database check on countries if the global_id the user selected is an aggregate or not
Parameters: country_id (int) – global id Returns: identifier e.g. LEAF or AGG or TOTAL Return type: str
10.1.8. ramascene.tasks module¶
-
ramascene.tasks.
async_send
(channel_name, job)¶ Send job message to front-end.
uses the channel_name and Job object. Send success or failure status.
Parameters:
-
ramascene.tasks.
default_handler
(job_name, job_id, channel_name, ready_query_selection, query_selection)¶ invokes Celery function.
Handler for invoking Celery method.
Parameters: - job_name (str) – the name of the job
- job_id (int) – the id of the job
- channel_name (object) – the websocket channel name
- ready_query_selection (dict) – the query_selection preprocessed (only needs convertion to numpy array)
- query_selection (dict) – the original query_selection used for aggregations at later stage
-
ramascene.tasks.
handle_complete
(job_id, channel_name, celery_id)¶ Handle a successful Celery Task.
-
ramascene.tasks.
job_update
(job_id)¶ Update job status to completion.
Update the job status by reference job id. :param job_id: job id :type job_id: int
10.1.9. ramascene.views module¶
-
ramascene.views.
ajaxHandling
(request)¶ AJAX handler.
Checks if the request is a post. Uses from the request the task/job id to fetch the Celery unique identifier. In turn it retrieves by using the Celery unique identifier the actual results
Parameters: object – request Returns: JSON response of result calculation
-
ramascene.views.
home
(request)¶ Home page.