Skip to main content

Python Client for the CAMS NCP API.

Project description

CAMS NCP Client

Description

CAMS NCP Client is a Python package for interfacing with the CAMS NCP API. With the CAMS NCP Client, you can manage measurements, forecasts, models, and file uploads/downloads related to CAMS (Copernicus Atmosphere Monitoring Service) data.

Installation with pip

To install the package, you can use the following command:

pip install cams-ncp-client 

Building from Source

Clone the repository:

git clone https://git.vito.be/scm/marvin-atmosys/cams_ncp_client.git
cd cams-ncp-client

Create the Python environment:

conda env create --prefix ./.venv --file conda_env.yml
conda activate ./.venv

Install the package:

poetry install
poetry install -E "full"

Usage

The CamsNcpApiClient requires a base API URL to function. You can instantiate it as follows:

from cams_ncp_client import CamsNcpApiClient

client = CamsNcpApiClient(base_url="https://193.190.137.75/api")

Data retrieval

The CAMS NCP Client provides a consistent interface across different entity types (e.g., forecasts, observations, models, quantities, etc.) using a dual-method pattern for data retrieval:

find_xxx() Methods

These methods are API query functions that return results in paged Pydantic-typed objects (wrapped in a TableData[...] structure). They typically support:

Pagination (limit, offset) Sorting (order_by) Filtering using optional query parameters, such as:

  • station_name

  • quantity_name

  • start_time/end_time

  • model_name

  • aggregation, etc.

Example find_forecasts():

from datetime import datetime
from cams_ncp_client import CamsNcpApiClient

client = CamsNcpApiClient(base_url="https://193.190.137.75/api") 
result = client.forecast.find_forecasts(
    quantity_name="NO2",
    station_name="42N016",
    model_name="CAMS",
    base_time_start=datetime(2024, 1, 1),
    limit=100,
    offset=0
)

This returns a TableData[ForecastHourly] object containing structured hourly forecast results.

Pagination gives fine control for handling large datasets.

find_xxx_df() Methods

These are wrapper methods that call the corresponding find_xxx() method repeatedly across pages, aggregate the results, and return the data as a Pandas DataFrame.

They are ideal for:

  • Data analysis
  • Visualization
  • Exporting to CSV/Excel
  • Integration with scientific workflows

Example find_observations_df():

from datetime import datetime
from cams_ncp_client import CamsNcpApiClient

client = CamsNcpApiClient(base_url="https://193.190.137.75/api") 

df = client.observation.find_observations_df(
    station_name="42N016",
    quantity_name="PM10",
    start_time=datetime(2023, 1, 1),
    end_time=datetime(2023, 6, 1)
)

Internally calls find_observations() over multiple pages and returns a flat pandas.DataFrame.

Feature find_xxx() find_xxx_df()
Returns TableData[PydanticModel] pandas.DataFrame
Paged API Access Yes (manual limit + offset) Yes (auto-pagination via max_pages)
Type Safety Strongly typed via Pydantic Standard DataFrame schema
Use Case Low-level control, validation Analysis, plotting, quick insights

Data Upload

The CAMS NCP Client also supports data submission to the API via various create_xxx() methods. These methods are used to upload new data entries such as forecasts, observations, models, stations, ...

Uploading Forecasts example:

To upload a list of hourly forecast records, use the ForecastClient.create_forecasts() method. The method expects a list of ForecastHourly objects that match the API schema.

from cams_ncp_client.client import CamsNcpApiClient
from cams_ncp_client.schemas.common import ForecastHourly
from datetime import datetime

client = CamsNcpApiClient(base_url="https://193.190.137.75/api")

forecast_data = [
    ForecastHourly(
        station_name="42N016",
        quantity_name="PM10",
        model_name="CAMS",
        base_time=datetime(2024, 5, 10, 0, 0),
        forecast_time=datetime(2024, 5, 11, 12, 0),
        value=15.3
    ),
    ForecastHourly(
        station_name="42N016",
        quantity_name="PM10",
        model_name="CAMS",
        base_time=datetime(2024, 5, 10, 0, 0),
        forecast_time=datetime(2024, 5, 11, 13, 0),
        value=16.7
    )
]

created_forecasts = client.forecast.create_forecasts(forecast_data)
print(f"Uploaded: {created_forecasts}.")

Full API

The full API documentation is available at http://docs.marvin.vito.local/map/cams-ncp-client/.

Contributing

If you want to contribute to this project, please follow the standard contributing guidelines and push your changes to a new branch in https://git.vito.be/projects/MARVIN-ATMOSYS/repos/cams_ncp_client/browse

Testing

This client code is automatically tested in the CAMS NCP API repository. cfr: https://git.vito.be/projects/MARVIN-ATMOSYS/repos/ncp_be_cams_api/browse/test

CI/CD

The CI/CD pipeline is fully automated using Jenkins. Pipeline details are defined in the Jenkinsfile located in the repository root.

Updating the Package Version

To update the package version:

  1. Tag the code with the new version number in the format major.minor.fix.
  2. Push the tagged code to the appropriate branch.

Pipeline Automation

The Jenkins pipeline is set up to automatically build and publish the Master branche to the PyPI server.

The Development and Master branches are automatically build and published to the Vito Artifactory (https://repo.vito.be/artifactory/api/pypi/marvin-projects-pypi-local).

Contact

For questions or issues, please reach out to the project maintainers:

License

This project is licensed under the MIT License. See the LICENSE.md file for details.

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

cams_ncp_client-0.1.0.tar.gz (17.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cams_ncp_client-0.1.0-py3-none-any.whl (22.1 kB view details)

Uploaded Python 3

File details

Details for the file cams_ncp_client-0.1.0.tar.gz.

File metadata

  • Download URL: cams_ncp_client-0.1.0.tar.gz
  • Upload date:
  • Size: 17.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.0 CPython/3.10.16 Linux/6.8.0-40-generic

File hashes

Hashes for cams_ncp_client-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a91f48512a45e79cb5f391f1b5e68310b15873aa09bec38fa21c07ae6cb3ae51
MD5 a60e7de2a93dc393e4c33f0b0612a16a
BLAKE2b-256 e0540c765341cced6be15293cbc2bba00681d500c823eb44c502a8d9bdf77b45

See more details on using hashes here.

File details

Details for the file cams_ncp_client-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: cams_ncp_client-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 22.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.0 CPython/3.10.16 Linux/6.8.0-40-generic

File hashes

Hashes for cams_ncp_client-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b89d8d8b0bcf43775ac6aca54afb7cf3d476b3541d604d51e81b1bb09dca47a4
MD5 abaa7db9017c9c2aaf25402864ea2295
BLAKE2b-256 e10ef2b22eafc56370d90f5ba5c3e36cd37d110a001a873abff4aaeef244ed65

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page