Zambretti Weather Forecasting in Python
This is a Python implementation of the Zambretti Weather Forecaster
The code is heavily based on the Zambretti Algorithm for Weather Forecasting ESP example
Further reading: Short-Range Local Forecasting with a Digital Barograph using an Algorithm based on the Zambretti Forecaster.
Python Package
This repository is available as a package in PyPi: https://pypi.org/project/zambretti-py/
Usage notes
To calculate for forecast, the Zambretti algorithm requires:
- elevation above sea level
- current temperature
- pressure data from the last three hours, or less.
- data points older than three hours will be removed
- the pressure data is expected to be provided as a list of tuples, each tuple consisting of a datetime.datetime object, and the pressure as float
- optional wind direction, denoting the direction from which the wind is flowing. This has a minor effect on the forecast and can be omitted.
The result will be a text description of the forecasted weather.
Pressure data must be provided in millibars or hPa (those are equivalent). Elevation must be provided in meters. Temperature must be provided in degrees Celsius.
Minimum 6 readings of atmospheric pressure are required. Best results are when the pressure readings span the last three hours, but the code will run on any timespan.
Technical notes
This project has no dependencies, uses only functions from the Python Standard Library. It should run both in Python and MicroPython.
Examples
Example usage with provided pressure data:
import datetime
from zambretti_py import PressureData, WindDirection, Zambretti
now = datetime.datetime.now()
pressure_data = PressureData(
[
(now - datetime.timedelta(hours=2, minutes=59), 1050.0),
(now - datetime.timedelta(hours=2, minutes=49), 1040.0),
(now - datetime.timedelta(hours=2, minutes=39), 1030.0),
(now - datetime.timedelta(hours=2, minutes=12), 1020.0),
(now - datetime.timedelta(hours=1, minutes=19), 1010.0),
(now - datetime.timedelta(minutes=20), 1000.0),
]
)
zambretti = Zambretti()
forecast = zambretti.forecast(
elevation=90,
temperature=25,
pressure_data=pressure_data,
wind_direction=WindDirection.NORTH,
)
print(forecast)
Example usage with loading pressure data from a CSV file:
If you have the pressure history in a CSV file such as this one:
| state | last_changed |
|---|---|
| 988.6 | 2024-11-19T11:33:32.706Z |
| 988.5 | 2024-11-19T11:34:06.863Z |
| 988.4 | 2024-11-19T11:37:06.887Z |
That file can be loaded into PressureData by using a PressureData.from_csv_file:
from zambretti_py import PressureData, WindDirection, Zambretti
pressure_data = PressureData.from_csv_file(
fname="history.csv",
timestamp_column_position=1,
pressure_column_position=0,
skip_header_rows=1,
strptime_template="%Y-%m-%dT%H:%M:%S.%fZ",
)
zambretti = Zambretti()
forecast = zambretti.forecast(
elevation=75,
temperature=3,
pressure_data=pressure_data,
wind_direction=WindDirection.SOUTH,
)
print(forecast)
Example usage with a CSV file generated in Home Assistant:
When you have a sensor in Home Assistant, you can export its history from the web interface, the result will be a CSV file with this schema:
| entity_id | state | last_changed |
|---|---|---|
| sensor.pressure | 988.6 | 2024-11-19T11:33:32.706Z |
| sensor.pressure | 988.5 | 2024-11-19T11:34:06.863Z |
| sensor.pressure | 988.4 | 2024-11-19T11:37:06.887Z |
That file can be loaded into PressureData by using PressureData.from_home_assistant_csv:
from zambretti_py import PressureData, WindDirection, Zambretti
pressure_data = PressureData.from_home_assistant_csv("history.csv")
zambretti = Zambretti()
forecast = zambretti.forecast(
elevation=75,
temperature=3,
pressure_data=pressure_data,
wind_direction=WindDirection.SOUTH,
)
print(forecast)
Metadata
Release files for zambretti-py 0.0.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| zambretti_py-0.0.6.tar.gz | 7.2 kB | Without provenance | Details for zambretti_py-0.0.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| zambretti_py-0.0.6-py3-none-any.whl | Python 3 | none | any | Details for zambretti_py-0.0.6-py3-none-any.whl |
Total release size: 13.4 kB
Release files / zambretti_py-0.0.6.tar.gz
| Download URL | zambretti_py-0.0.6.tar.gz |
|---|---|
| Size | 7.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d8fc70803bb8bc9c07edb04988d73124172205d9ca791f32766358894c65d6d3
|
|
BLAKE2b-256 checksum How to use checksums |
285a382fe0be0d44f65987b2d1fbc1c7f1c7c00172ba0438eac3df8a1a8f0b31
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.9.21
|
Release files / zambretti_py-0.0.6-py3-none-any.whl
| Download URL | zambretti_py-0.0.6-py3-none-any.whl |
|---|---|
| Size | 6.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9e85424a8aa2bf3bcc30883c347c7d9157e365564b36971fd32b87781fc6c3b6
|
|
BLAKE2b-256 checksum How to use checksums |
ec409c62cd3f8807ce49b8b70a0999053f67ca741a88788818b1bbc5967f171c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.9.21
|
Security for zambretti-py 0.0.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.