env_canada

Environment Canada Weather Data

https://github.com/michaeldavie/env_canada

Science Score: 36.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
    2 of 18 committers (11.1%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (10.7%) to scientific vocabulary
Last synced: 10 months ago · JSON representation

Repository

Environment Canada Weather Data

Basic Info
  • Host: GitHub
  • Owner: michaeldavie
  • License: mit
  • Language: Python
  • Default Branch: master
  • Homepage:
  • Size: 719 KB
Statistics
  • Stars: 97
  • Watchers: 9
  • Forks: 23
  • Open Issues: 1
  • Releases: 73
Created almost 8 years ago · Last pushed about 1 year ago
Metadata Files
Readme Changelog License

README.md

Environment Canada (env_canada)

PyPI version Snyk rating Python Lint and Test

This package provides access to various data sources published by Environment and Climate Change Canada.

[!IMPORTANT] If you're using the library in a Jupyter notebook, replace asyncio.run(...) with await ... in the examples below. For example:

python asyncio.run(ec_en.update())

becomes

python await ec_en.update()

Weather Observations and Forecasts

ECWeather provides current conditions and forecasts. It automatically determines which weather station to use based on latitude/longitude provided. It is also possible to specify a station code in multiple flexible formats:

  • Full format: "AB/s0000123" (province code and full station ID)
  • Station ID only: "s0000123" (station ID without province - province is resolved automatically)
  • Numeric only: "123" (just the station number - province is resolved automatically)

Station codes are based on those listed in this CSV file. For example:

```python import asyncio

from env_canada import ECWeather

Using coordinates (automatic station selection)

ec_coords = ECWeather(coordinates=(50, -100))

Using station ID - multiple formats supported:

ecfull = ECWeather(stationid="ON/s0000430", language="french") # Full format ecstation = ECWeather(stationid="s0000430") # Station ID only ecnumeric = ECWeather(stationid="430") # Numeric only

asyncio.run(ec_coords.update())

current conditions

ec_coords.conditions

daily forecasts

eccoords.dailyforecasts

hourly forecasts

eccoords.hourlyforecasts

alerts

ec_coords.alerts ```

[!NOTE] As of version 0.11.0, ECWeather automatically handles Environment Canada's new timestamped weather file URL structure (effective June 2025). The library dynamically discovers the most recent weather files, ensuring continued functionality during Environment Canada's infrastructure changes.

Weather Radar

ECRadar provides Environment Canada meteorological radar imagery.

```python import asyncio

from env_canada import ECRadar

radar_coords = ECRadar(coordinates=(50, -100))

Conditions Available

animatedgif = asyncio.run(radarcoords.getloop()) latestpng = asyncio.run(radarcoords.getlatest_frame()) ```

Weather Maps

ECMap provides Environment Canada WMS weather map imagery with support for various meteorological layers.

```python import asyncio

from env_canada import ECMap

Create a map with rain radar layer

map_coords = ECMap(coordinates=(50, -100), layer="rain")

Get the latest image with the specified layer

latestpng = asyncio.run(mapcoords.getlatestframe())

Get an animated GIF with the specified layer

animatedgif = asyncio.run(mapcoords.get_loop())

Customize the map appearance

custommap = ECMap( coordinates=(50, -100), layer="snow", width=1200, height=800, radius=300, layeropacity=80, legend=True, timestamp=True, language="french", ) ```

Available layers include:

  • rain: Precipitation rain radar
  • snow: Precipitation snow radar
  • precip_type: Surface precipitation type

Additional configuration options:

  • width/height: Image dimensions (default: 800x800)
  • radius: Map radius in km around coordinates (default: 200km)
  • layer_opacity: Layer transparency 0-100% (default: 65%)
  • legend: Show legend (default: True)
  • timestamp: Show timestamp (default: True)
  • language: "english" or "french" (default: "english")

Note: ECMap automatically discovers available legend styles from Environment Canada's WMS capabilities, ensuring compatibility with any future style changes.

Air Quality Health Index (AQHI)

ECAirQuality provides Environment Canada air quality data.

```python import asyncio

from env_canada import ECAirQuality

aqhi_coords = ECAirQuality(coordinates=(50, -100))

asyncio.run(aqhi_coords.update())

Data available

aqhicoords.current aqhicoords.forecasts ```

Water Level and Flow

ECHydro provides Environment Canada hydrometric data.

```python import asyncio

from env_canada import ECHydro

hydro_coords = ECHydro(coordinates=(50, -100))

asyncio.run(hydro_coords.update())

Data available

hydro_coords.measurements ```

Historical Weather Data

ECHistorical provides historical daily weather data. The ECHistorical object is instantiated with a station ID, year, language, format (one of xml or csv) and granularity (hourly, daily data). Once updated asynchronously, historical weather data is contained with the station_data property. If xml is requested, station_data will appear in a dictionary form. If csv is requested, station_data will contain a CSV-readable buffer. For example:

```python import asyncio

from envcanada import ECHistorical from envcanada.echistorical import gethistorical_stations

search for stations, response contains station_ids

coordinates = [53.916944, -122.749444] # [lat, long]

coordinates: [lat, long]

radius: km

limit: response limit, value one of [10, 25, 50, 100]

The result contains station names and ID values.

stations = asyncio.run(gethistoricalstations(coordinates, radius=200, limit=100))

ecenxml = ECHistorical(stationid=31688, year=2020, language="english", format="xml") ecfrxml = ECHistorical(stationid=31688, year=2020, language="french", format="xml") ecencsv = ECHistorical(stationid=31688, year=2020, language="english", format="csv") ecfrcsv = ECHistorical(stationid=31688, year=2020, language="french", format="csv")

timeframe argument can be passed to change the granularity

timeframe=1 hourly (need to create of for every month in that case, use ECHistoricalRange to handle it automatically)

timeframe=2 daily (default)

ecenxml = ECHistorical( stationid=31688, year=2020, month=1, language="english", format="xml", timeframe=1 ) ecencsv = ECHistorical( stationid=31688, year=2020, month=1, language="english", format="csv", timeframe=1 )

asyncio.run(ecenxml.update()) asyncio.run(ecencsv.update())

metadata describing the station

ecenxml.metadata

historical weather data, in dictionary form

ecenxml.station_data

csv-generated responses return csv-like station data

import pandas as pd

df = pd.readcsv(ecencsv.stationdata) ```

ECHistoricalRange provides historical weather data within a specific range and handles the update by itself.

The ECHistoricalRange object is instantiated with at least a station ID and a daterange. One could add language, and granularity (hourly, daily (default)).

The data can then be used as pandas DataFrame, XML (requires pandas >=1.3.0) and csv

For example :

```python import pandas as pd import asyncio from envcanada import ECHistoricalRange from envcanada.echistorical import gethistorical_stations from datetime import datetime

coordinates = ["48.508333", "-68.467667"]

stations = pd.DataFrame( asyncio.run( gethistoricalstations( coordinates, startyear=2022, endyear=2022, radius=200, limit=100 ) ) ).T

ec = ECHistoricalRange( station_id=int(stations.iloc[0, 2]), timeframe="daily", daterange=(datetime(2022, 7, 1, 12, 12), datetime(2022, 8, 1, 12, 12)), )

ec.get_data()

yield an XML formated str.

For more options, use ec.to_xml(arg, *kwargs) with pandas options

ec.xml

yield an CSV formated str.

For more options, use ec.to_csv(arg, *kwargs) with pandas options

ec.csv ```

In this example ec.df will be:

| Date/Time | Longitude (x) | Latitude (y) | Station Name | Climate ID | Year | Month | Day | Data Quality | Max Temp (°C) | Max Temp Flag | Min Temp (°C) | Min Temp Flag | Mean Temp (°C) | Mean Temp Flag | Heat Deg Days (°C) | Heat Deg Days Flag | Cool Deg Days (°C) | Cool Deg Days Flag | Total Rain (mm) | Total Rain Flag | Total Snow (cm) | Total Snow Flag | Total Precip (mm) | Total Precip Flag | Snow on Grnd (cm) | Snow on Grnd Flag | Dir of Max Gust (10s deg) | Dir of Max Gust Flag | Spd of Max Gust (km/h) | Spd of Max Gust Flag | | | ---------- | ------------- | ------------ | --------------------- | ---------- | ---- | ----- | --- | ------------ | -------------- | ------------- | -------------- | ------------- | --------------- | -------------- | ------------------- | ------------------ | ------------------- | ------------------ | --------------- | --------------- | --------------- | --------------- | ----------------- | ----------------- | ----------------- | ----------------- | ------------------------- | -------------------- | ---------------------- | -------------------- | --- | | 2022-07-02 | -68,47 | 48,51 | POINTE-AU-PERE (INRS) | 7056068 | 2022 | 7 | 2 | | 22,8 | | 12,5 | | 17,7 | | 0,3 | | 0 | | | | | | 0 | | | | 26 | | 37 | | | | 2022-07-03 | -68,47 | 48,51 | POINTE-AU-PERE (INRS) | 7056068 | 2022 | 7 | 3 | | 21,7 | | 10,1 | | 15,9 | | 2,1 | | 0 | | | | | | 0,4 | | | | 28 | | 50 | | | | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | | 2022-07-31 | -68,47 | 48,51 | POINTE-AU-PERE (INRS) | 7056068 | 2022 | 7 | 31 | | 23,5 | | 14,1 | | 18,8 | | 0 | | 0,8 | | | | | | 0 | | | | 23 | | 31 | | | | 2022-08-01 | -68,47 | 48,51 | POINTE-AU-PERE (INRS) | 7056068 | 2022 | 8 | 1 | | 23 | | 15 | | 19 | | 0 | | 1 | | | | | | 0 | | | | 21 | | 35 | | |

One should note that july 1st is excluded as the time provided contains specific hours, so it yields only data after or at exactly the time provided.

To have all the july 1st data in that case, one can provide a datarange without time: datetime(2022, 7, 7) instead of datetime(2022, 7, 1, 12, 12)

License

The code is available under terms of MIT License

Owner

  • Name: Michael Davie
  • Login: michaeldavie
  • Kind: user

GitHub Events

Total
  • Create event: 14
  • Issues event: 8
  • Release event: 10
  • Watch event: 13
  • Delete event: 3
  • Member event: 1
  • Issue comment event: 20
  • Push event: 27
  • Pull request review event: 5
  • Pull request review comment event: 3
  • Pull request event: 26
  • Fork event: 5
Last Year
  • Create event: 14
  • Issues event: 8
  • Release event: 10
  • Watch event: 13
  • Delete event: 3
  • Member event: 1
  • Issue comment event: 20
  • Push event: 27
  • Pull request review event: 5
  • Pull request review comment event: 3
  • Pull request event: 26
  • Fork event: 5

Committers

Last synced: 10 months ago

All Time
  • Total Commits: 323
  • Total Committers: 18
  • Avg Commits per committer: 17.944
  • Development Distribution Score (DDS): 0.297
Past Year
  • Commits: 41
  • Committers: 4
  • Avg Commits per committer: 10.25
  • Development Distribution Score (DDS): 0.659
Top Committers
Name Email Commits
michaeldavie m****e@g****m 227
Glenn Waters g****n@w****a 43
Brian Fitzgerald f****b@u****m 14
Glenn Waters g****s@g****m 10
lletac l****c@3****a 8
JM Lopez j****z@u****a 4
MrDizzystick M****k@u****m 3
snyk-bot s****t@s****o 3
Marc-Antoine Ruel m****l@g****m 2
Andreas Billmeier b@e****t 1
Darren Wiens d****s@g****m 1
Fabian Affolter f****n@a****h 1
Marc Mueller 3****p@u****m 1
Rob Leveille r****e@g****m 1
Shixian Sheng s****2@f****u 1
everett e****r@g****m 1
marawan31 m****1@g****m 1
stevendinardo 1****o@u****m 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 10 months ago

All Time
  • Total issues: 63
  • Total pull requests: 68
  • Average time to close issues: 3 months
  • Average time to close pull requests: 7 days
  • Total issue authors: 42
  • Total pull request authors: 18
  • Average comments per issue: 2.87
  • Average comments per pull request: 0.79
  • Merged pull requests: 61
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 5
  • Pull requests: 32
  • Average time to close issues: about 1 hour
  • Average time to close pull requests: 4 days
  • Issue authors: 5
  • Pull request authors: 5
  • Average comments per issue: 1.6
  • Average comments per pull request: 0.38
  • Merged pull requests: 28
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • gwww (8)
  • fitzb (3)
  • glassbase (3)
  • alexandery (3)
  • ikifar2012 (2)
  • michaeldavie (2)
  • jm66 (2)
  • cpw (2)
  • deftdawg (2)
  • PhilBaobab (2)
  • A-c0rN (2)
  • maruel (2)
  • rcblackwell (1)
  • pgsylvestre (1)
  • AR1985 (1)
Pull Request Authors
  • gwww (32)
  • michaeldavie (14)
  • fitzb (6)
  • jm66 (4)
  • maruel (3)
  • cdce8p (2)
  • everettsp (2)
  • KPCOFGS (2)
  • Biorix (2)
  • darrenwiens (1)
  • infectedroot (1)
  • MrDizzystick (1)
  • onkelbeh (1)
  • marawan31 (1)
  • stevendinardo (1)
Top Labels
Issue Labels
enhancement (4) bug (2)
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 46,784 last-month
  • Total docker downloads: 757,189,253
  • Total dependent packages: 2
  • Total dependent repositories: 19
  • Total versions: 107
  • Total maintainers: 1
pypi.org: env-canada

A package to access meteorological data from Environment Canada

  • Versions: 107
  • Dependent Packages: 2
  • Dependent Repositories: 19
  • Downloads: 46,784 Last month
  • Docker Downloads: 757,189,253
Rankings
Docker downloads count: 0.2%
Dependent packages count: 3.2%
Dependent repos count: 3.4%
Downloads: 3.7%
Average: 4.7%
Stargazers count: 8.3%
Forks count: 9.6%
Maintainers (1)
Last synced: 10 months ago

Dependencies

.github/workflows/codeql-analysis.yml actions
  • actions/checkout v3 composite
  • github/codeql-action/analyze v2 composite
  • github/codeql-action/autobuild v2 composite
  • github/codeql-action/init v2 composite
.github/workflows/python-app.yml actions
  • actions/checkout v2 composite
  • actions/setup-python v2 composite
.github/workflows/python-publish.yml actions
  • actions/checkout v2 composite
  • actions/setup-python v2 composite
requirements.txt pypi
  • Pillow *
  • aiohttp *
  • defusedxml *
  • geopy *
  • imageio *
  • lxml *
  • pandas >=1.3.0
  • python-dateutil *
  • voluptuous *
setup.py pypi
  • Pillow *
  • aiohttp *
  • defusedxml *
  • geopy *
  • imageio *
  • lxml *
  • pandas >=1.3.0
  • python-dateutil *
  • voluptuous *