Skip to main content

High-level Python library for Chilean INIA agrometeorological station data

Project description

INIAMET - Chilean INIA Agrometeorological Data Library

Python Version License: MIT PyPI version Documentation Status

High-level Python library for accessing Chilean INIA (Instituto de Investigaciones Agropecuarias) agrometeorological station data.

Access data from 400+ weather stations across Chile with a simple, intuitive API. Download temperature, precipitation, humidity, wind, radiation data and more.

🌟 Features

  • High-Level API: Simple, intuitive functions to query stations and download data
  • Smart Station Management: Automatically handles different station code formats
  • Regional Filtering: Filter stations by Chilean regions (R01-R16)
  • Data Caching: Built-in caching system for faster repeated queries
  • Type Safety: Full type hints for better IDE support
  • pandas Integration: Returns data as pandas DataFrames
  • Comprehensive Variables: Temperature, precipitation, humidity, wind, radiation, and more

📦 Installation

pip install iniamet

Or install from source:

git clone https://github.com/reneignacio/iniamet-library
cd iniamet-library
pip install -e .

🎨 Optional: Visualization Features

If you want to use the visualization features (interactive maps), install with visualization support:

pip install iniamet[viz]
# or install all optional features:
pip install iniamet[all]

🔑 API Key Configuration

IMPORTANT: You need an API key to use INIAMET. Get yours from https://agromet.inia.cl/api/v2/

Option 1: Configuration File (Recommended - Easy Setup)

# Configure your API key once
python -m iniamet.config set-key YOUR-API-KEY-HERE

# Verify it's saved
python -m iniamet.config show

Option 2: Environment Variable

Linux/Mac:

export INIA_API_KEY='your-api-key-here'
# Add to ~/.bashrc or ~/.zshrc for persistence

Windows CMD:

set INIA_API_KEY=your-api-key-here
# For persistence: setx INIA_API_KEY "your-api-key-here"

Windows PowerShell:

$env:INIA_API_KEY='your-api-key-here'
# For persistence: [Environment]::SetEnvironmentVariable('INIA_API_KEY', 'your-key', 'User')

Option 3: Pass Directly in Code

from iniamet import INIAClient
client = INIAClient(api_key='your-api-key-here')

🚀 Quick Start

from iniamet import INIAClient

# Initialize client
client = INIAClient()

# Get all stations
stations = client.get_stations()
print(f"Total stations: {len(stations)}")

# Filter by region (Ñuble)
nuble_stations = client.get_stations(region="R16")
print(f"Ñuble stations: {len(nuble_stations)}")

# Get available variables for a station
variables = client.get_variables("INIA-47")
print(variables[['variable_id', 'nombre', 'unidad']])

# Download data
from datetime import datetime

data = client.get_data(
    station="INIA-47",
    variable=2002,  # Temperatura del aire
    start_date=datetime(2024, 9, 1),
    end_date=datetime(2024, 9, 30)
)

print(data.head())

📊 Regional Download Example

from iniamet import RegionalDownloader

# Download all temperature and precipitation data for Ñuble region
downloader = RegionalDownloader(region="R16")

result = downloader.download_climate_data(
    start_date="2024-09-01",
    end_date="2024-09-30",
    variables=['temperature', 'precipitation'],
    aggregation='daily'
)

# Save to CSV
result.to_csv("nuble_climate_sept2024.csv")

🗺️ Region Codes

Code Region
R01 Tarapacá
R02 Antofagasta
R03 Atacama
R04 Coquimbo
R05 Valparaíso
R06 O'Higgins
R07 Maule
R08 Biobío
R09 La Araucanía
R10 Los Lagos
R11 Aysén
R12 Magallanes
R13 Metropolitana
R14 Los Ríos
R15 Arica y Parinacota
R16 Ñuble

📚 Documentation

Full documentation available at: https://iniamet.readthedocs.io

Station Types

The library handles 10 different station network types:

  • INIA stations
  • DMC (Dirección Meteorológica de Chile)
  • ARAUCO stations
  • AGRICHILE network
  • And more...

Available Variables

  • Temperature (air, soil, surface)
  • Precipitation
  • Humidity (relative, absolute)
  • Wind (speed, direction)
  • Solar radiation
  • Atmospheric pressure
  • And many more...

🔧 Advanced Usage

Caching

# Enable caching (default)
client = INIAClient(cache=True, cache_dir="./cache")

# Disable caching
client = INIAClient(cache=False)

Batch Downloads

# Download multiple variables from multiple stations
stations = ["INIA-47", "INIA-139", "INIA-211"]
variables = [2002, 2001]  # Temperature, Precipitation

data = client.bulk_download(
    stations=stations,
    variables=variables,
    start_date="2024-09-01",
    end_date="2024-09-30"
)

🧪 Development

# Clone repository
git clone https://github.com/inia/iniamet
cd iniamet-library

# Install in development mode with dev dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Run tests with coverage
pytest --cov=iniamet --cov-report=html

# Format code
black src/

# Type check
mypy src/

📄 License

MIT License - see LICENSE file for details.

📚 Documentation

Full documentation available at: iniamet.readthedocs.io

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

🔗 Links

📧 Contact

For questions and support, please open an issue on GitHub.


Note: This library is not officially affiliated with INIA. It's an independent project to facilitate access to public INIA data.

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

iniamet-0.1.0.tar.gz (46.5 kB view details)

Uploaded Source

Built Distribution

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

iniamet-0.1.0-py3-none-any.whl (30.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: iniamet-0.1.0.tar.gz
  • Upload date:
  • Size: 46.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for iniamet-0.1.0.tar.gz
Algorithm Hash digest
SHA256 450995d43cef537154d7e56dfeef5f5764bf14fc58c17b9f1b756349e2653f84
MD5 cae923feca23d9bbce5bf0947c6310c6
BLAKE2b-256 3a61ab235742abd50a65f894bc202459ee31950b3885eaa8b147f1dc750541ea

See more details on using hashes here.

File details

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

File metadata

  • Download URL: iniamet-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 30.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for iniamet-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 523f37898d3adcf223e20b2f8fe99c384fab70d141743634d93cfca18bda5df6
MD5 04a1d1add7137b9bbac0194960346304
BLAKE2b-256 6d313cf1113e22ea8e7a9c4a54d59640e2801c452c44440e097263bfa8ec073f

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