Tools for importing GCAM output data
Project description
gcamreader: a Python package for extracting content from GCAM databases
gcamreader provides functions for reading data from the output databases
produced by GCAM.
Purpose
gcamreader was created to:
- Use XML queries to extract data into a pandas DataFrame from a GCAM XML database.
- Integrate GCAM with other Python packages.
Requirements
- Python 3.11 or newer.
- A Java runtime (JRE).
gcamreaderruns queries against local databases using a bundled copy of the GCAM ModelInterface, which requires Java. Remote queries use the BaseX REST API and also rely on a server running ModelInterface.
Installation
Set up a virtual environment
It is recommended to install gcamreader into an isolated virtual environment
to avoid conflicts with other packages on your system.
Using the built-in venv module:
# Create a virtual environment in a directory named ".venv".
python -m venv .venv
# Activate it (macOS / Linux).
source .venv/bin/activate
# Activate it (Windows PowerShell).
.venv\Scripts\Activate.ps1
Alternatively, with conda:
conda create -n gcamreader python=3.11
conda activate gcamreader
Once the environment is activated, install gcamreader using one of the
methods below. To leave the environment when you are finished, run deactivate
(venv) or conda deactivate (conda).
Install the latest release from PyPI:
pip install gcamreader
Install the development version from source:
git clone https://github.com/JGCRI/gcamreader.git
cd gcamreader
pip install -e .
To work on the package, install the development and documentation extras:
pip install -e ".[dev,docs]"
Quickstart
Query a local database
import gcamreader
# Connect to a local GCAM database (the parent directory and database name).
conn = gcamreader.LocalDBConn("path/to/output", "database_basexdb")
# List the scenarios contained in the database.
scenarios = conn.listScenariosInDB()
# Parse a GCAM queries XML file and run the first query.
queries = gcamreader.parse_batch_query("Main_queries.xml")
df = conn.runQuery(queries[0])
Run many queries at once
import gcamreader
results = gcamreader.importdata(
"path/to/output/database_basexdb",
"Main_queries.xml",
)
# results is a dict keyed by query title, with DataFrame values.
for title, frame in results.items():
print(title, None if frame is None else frame.shape)
Query a remote database
import gcamreader
conn = gcamreader.RemoteDBConn(
dbfile="database_basexdb",
username="user",
password="secret",
address="localhost",
port=8984,
)
df = conn.runQuery(gcamreader.parse_batch_query("Main_queries.xml")[0])
Command line interface
gcamreader installs a gcamreader command for running the queries in a
queries file and saving each result to a CSV file.
# Show the version.
gcamreader --version
# Query a local database and write CSV outputs to a directory.
gcamreader local \
--database_path path/to/output/database_basexdb \
--query_path Main_queries.xml \
--output_path results/ \
--force
# Query a remote BaseX server.
gcamreader remote \
--username user \
--database_name database_basexdb \
--query_path Main_queries.xml \
--output_path results/ \
--hostname localhost \
--port 8984
Use gcamreader --help, gcamreader local --help, or
gcamreader remote --help for the full list of options.
Documentation
Full documentation, including the API reference, is available at https://jgcri.github.io/gcamreader/.
Contributing
Contributions are welcome. Please run the test suite and the linters before opening a pull request:
pytest
ruff check .
black --check .
Citation
If you use gcamreader in your work, please cite it using the DOI badge above.
License
gcamreader is released under the BSD 2-Clause License. See the
LICENSE file for details.
Project details
Release history Release notifications | RSS feed
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 gcamreader-1.5.0.tar.gz.
File metadata
- Download URL: gcamreader-1.5.0.tar.gz
- Upload date:
- Size: 13.3 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b91c0e1e98b50a847792092f4d5c72994dd91df93b1e93914ccb2181ccb1f517
|
|
| MD5 |
a857174cd4a301306ea9abf5da409185
|
|
| BLAKE2b-256 |
8f4830e3f4c97536e493a1423ea674e69872fd41da7bf87cd786130bfedffe3e
|
Provenance
The following attestation bundles were made for gcamreader-1.5.0.tar.gz:
Publisher:
release.yml on JGCRI/gcamreader
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gcamreader-1.5.0.tar.gz -
Subject digest:
b91c0e1e98b50a847792092f4d5c72994dd91df93b1e93914ccb2181ccb1f517 - Sigstore transparency entry: 2071693055
- Sigstore integration time:
-
Permalink:
JGCRI/gcamreader@8e17c766c9b25e5c6c114629378d4e28fe0da8de -
Branch / Tag:
refs/heads/main - Owner: https://github.com/JGCRI
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@8e17c766c9b25e5c6c114629378d4e28fe0da8de -
Trigger Event:
push
-
Statement type:
File details
Details for the file gcamreader-1.5.0-py3-none-any.whl.
File metadata
- Download URL: gcamreader-1.5.0-py3-none-any.whl
- Upload date:
- Size: 13.3 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bf407a34950afa33526fe98e44b328682961e418934cdbec1f16822d41546773
|
|
| MD5 |
3633896a42f14de5117dfb90c375fbc5
|
|
| BLAKE2b-256 |
d4986fb7fff3e3ba4ab23a6117e4ad5e33a8664b841d48a8d2d8d3f7beab7722
|
Provenance
The following attestation bundles were made for gcamreader-1.5.0-py3-none-any.whl:
Publisher:
release.yml on JGCRI/gcamreader
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gcamreader-1.5.0-py3-none-any.whl -
Subject digest:
bf407a34950afa33526fe98e44b328682961e418934cdbec1f16822d41546773 - Sigstore transparency entry: 2071693063
- Sigstore integration time:
-
Permalink:
JGCRI/gcamreader@8e17c766c9b25e5c6c114629378d4e28fe0da8de -
Branch / Tag:
refs/heads/main - Owner: https://github.com/JGCRI
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@8e17c766c9b25e5c6c114629378d4e28fe0da8de -
Trigger Event:
push
-
Statement type: