Gives functions to help build a mater providing data script.
Project description
MATER data providing
A library to help providing the right json files to feed the mater database.
It can be used to create a local json database to run mater simulations locally.
[TOC]
📋 Requirements
- Python 3.12 or higher
We recommend using one virtual environment per Python project to manage dependencies and maintain isolation. You can use a package manager like uv to help you with library dependencies and virtual environments.
📦 Install the mater-data-providing Package
Install the mater package via uv:
uv add mater-data-providing
Install the mater package via pip:
pip install mater-data-providing
⚙️ API
metadata_definition
import mater-data-providing as mdp
metadata = mdp.metadata_definition("source_link", "my_source", "my_project")
print(metadata)
{"link": "source_link", "source": "my_source", "project": "my_project"}
provider_definition
import mater-data-providing as mdp
provider = mdp.provider_definition("Jon", "Do", "jon.do@mail.com")
print(provider)
{"first_name": "Jon", "last_name": "Do", "email_address": "jon.do@mail.com"}
dump_json
This function is used at the end of your providing script to dump into a serialized json the input dataframe, the provider dictionnary and the metadata dictionnary.
import mater_data_providing as mdp
import pandas as pd
# 1. Build a DataFrame
df = pd.DataFrame([
{"location": "france", "object": "car", "value": 15, "unit": "year", "time": 2015, "scenario": "historical", "variable": "lifetime_mean_value"},
{"location": "france", "object": "car", "value": 17, "unit": "year", "time": 2020, "scenario": "historical", "variable": "lifetime_mean_value"},
])
# 2. Create a provider and metadata dictionnary
provider = mdp.provider_definition("Jon", "Do", "jon.do@mail.com")
metadata = mdp.metadata_definition("source_link", "my_source", "my_project")
# 3. Dump the data into a serialized json
j = mdp.dump_json(input_data, provider, metadata)
print(j)
{
"input_data": [
{
"location": "france",
"object": "car",
"value": 15,
"unit": "year",
"time": 2015,
"scenario": "historical",
"variable": "lifetime_mean_value"
},
{
"location": "france",
"object": "car",
"value": 17,
"unit": "year",
"time": 2020,
"scenario": "historical",
"variable": "lifetime_mean_value"
}
],
"provider": {
"first_name": "Jon",
"last_name": "Do",
"email_address": "jon.do@mail.com"
},
"metadata": {
"link": "source_link",
"source": "my_source",
"project": "my_project"
}
}
replace_equivalence
data\dimension\dimension.json:
[
{
"value": "car",
"equivalence": {
"short": "PLDV",
"long": "personal_vehicle"
}
},
{
"value": "france",
"equivalence": {
"ISO3": "FRA"
}
}
]
Python scrip at the root of the project:
import mater_data_providing as mdp
import pandas as pd
# 1. Build a DataFrame
df = pd.DataFrame([
{"location": "FRA", "object": "personal_vehicle", "value": 15, "unit": "year", "time": 2015, "scenario": "historical", "variable": "lifetime_mean_value"},
{"location": "france", "object": "PLDV", "value": 17, "unit": "year", "time": 2020, "scenario": "historical", "variable": "lifetime_mean_value"},
])
df_uniform = mdp.replace_equivalence(df)
print(df_uniform)
location object value unit time scenario variable
0 france car 15 year 2015 historical lifetime_mean_value
1 france car 17 year 2020 historical lifetime_mean_value
to_json
replace the equivalences into the serialized json returned from mdp.dump_json funciton and write into a specific directory.
data\dimension\dimension.json:
[
{
"value": "car",
"equivalence": {
"short": "PLDV",
"long": "personal_vehicle"
}
},
{
"value": "france",
"equivalence": {
"ISO3": "FRA"
}
}
]
Python scrip at the root of the project:
import mater_data_providing as mdp
import pandas as pd
# 1. Build a DataFrame
df = pd.DataFrame([
{"location": "FRA", "object": "personal_vehicle", "value": 15, "unit": "year", "time": 2015, "scenario": "historical", "variable": "lifetime_mean_value"},
{"location": "france", "object": "PLDV", "value": 17, "unit": "year", "time": 2020, "scenario": "historical", "variable": "lifetime_mean_value"},
])
# 2. Create a provider and metadata dictionnary
provider = mdp.provider_definition("Jon", "Do", "jon.do@mail.com")
metadata = mdp.metadata_definition("source_link", "my_source", "my_project")
# 3. Dump the data into a serialized json
j = mdp.dump_json(input_data, provider, metadata)
# 4. Write out as "input_data/sample.json"
# (creates data/input_data/sample.json)
mdp.to_json(
j,
name="sample", # filename will be sample.json
mode="w" # write (overwrite) – this is the default
)
Creates data/input_data/sample.json:
[
{
"location": "france",
"object": "car",
"value": 15,
"unit": "year",
"time": 2015,
"scenario": "historical",
"variable": "lifetime_mean_value"
},
{
"location": "france",
"object": "car",
"value": 17,
"unit": "year",
"time": 2020,
"scenario": "historical",
"variable": "lifetime_mean_value"
}
]
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mater_data_providing-0.2.0.tar.gz.
File metadata
- Download URL: mater_data_providing-0.2.0.tar.gz
- Upload date:
- Size: 23.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cbbb4c26240731fa2762c4c108e101d83618988c0ae5e96e7e0d7d3dc156beb5
|
|
| MD5 |
4e0967a4fa6ec10c986a57bb01f4c995
|
|
| BLAKE2b-256 |
a10aa217eff017c9936256de7e637aef56183102e39e06cca127aa54aebd6d5d
|
File details
Details for the file mater_data_providing-0.2.0-py3-none-any.whl.
File metadata
- Download URL: mater_data_providing-0.2.0-py3-none-any.whl
- Upload date:
- Size: 10.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
10661dea166994f76a11f4df12951b7bf74ec20605b58b87be3e17d6efac7400
|
|
| MD5 |
1062f1a972981355e58b4ef45195a687
|
|
| BLAKE2b-256 |
050bdff225414d8b0c8681dcb5415c042e58288232c4ee11c29773f8be1806fc
|