Code Monkey home page Code Monkey logo

meteo_hist's Introduction

social-media-image

MeteoHist - Historical Meteo Graphs

A Streamlit app to create interactive temperature and precipitation graphs for places around the world.

This app allows to create temperature and precipitation (rain, showers, and snowfall) graphs that compare the values of a given location in a given year to the values of a reference period at the same place.

The reference period defaults to 1961-1990 which according to the World Meteorological Organization (WMO) is currently the best "long-term climate change assessment". Other reference periods of 30 years each can be selected, too.

The peaks on the graph show how the displayed year's values deviate from the mean of the reference period. For temperature graphs, this means that the more and the higher the red peaks, the more "hotter days than usual" have been observed. The blue peaks indicate days colder than the historical mean. Precipitation graphs show blue peaks on top which means "more precipitation than normal" and in red "less than normal".

The interactive plot is created using Python's Plotly library. In a first version with static images, Matplotlib came to use.

By default, mean values of the reference period are smoothed using Locally Weighted Scatterplot Smoothing (LOWESS). The value can be adjusted under "advanced settings" in the app.

Interactive version

In the latest version (first published on 17 August 2023), the graphs are displayed interactively on larger screens. That means you can hover over the graph and get the exact values displayed for every day. You can also zoom in to see parts of the plot.

Data

To create the graph, data from the open-source weather API Open-Meteo is used. According to them, "the Historical Weather API is based on reanalysis datasets and uses a combination of weather station, aircraft, buoy, radar, and satellite observations to create a comprehensive record of past weather conditions. These datasets are able to fill in gaps by using mathematical models to estimate the values of various weather variables. As a result, reanalysis datasets are able to provide detailed historical weather information for locations that may not have had weather stations nearby, such as rural areas or the open ocean."

The Reanalysis Models are based on ERA5, ERA5-Land, and CERRA from the European Union's Copernicus Programme.

To get location data (lat/lon) for the input location, Openstreetmap's Nominatim is used.

Metrics

Available metrics are:

  • Mean Temperature: Mean daily air temperature at 2 meters above ground (24 hour aggregation from hourly values)
  • Minimum Temperature: Minimum daily air temperature at 2 meters above ground (24 hour aggregation from hourly values)
  • Maximum Temperature: Maximum daily air temperature at 2 meters above ground (24 hour aggregation from hourly values)
  • Precipitation (Rolling Average): 30-day rolling/moving average of the sum of daily precipitation (including rain, showers and snowfall)
  • Precipitation (Cumulated): Cumulated sum of daily precipitation (including rain, showers, and snowfall)

Settings

  • Location to display: Name of the location you want to display. A search at Openstreetmap's Nominatim will be performed to find the location and get latitude and longitude.
  • Year to show: Year to be compared to reference period.
  • Reference period: The reference period is used to calculate the historical average of the daily values. The average is then used to compare the daily values of the selected year. 1961-1990 (default) is currently considered the best "long-term climate change assessment" by the World Meteorological Organization (WMO).
  • Peaks to be annotated: Number of maximum and minimum peaks to be annotated (default: 1). If peaks are too close together, the next highest/lowest peak is selected to avoid overlapping.
  • Unit system: Whether to use Metric System (°C, mm - default) or Imperial System (°F, In).
  • Smoothing: Degree of smoothing to apply to the historical data. 0 means no smoothing. The higher the value, the more smoothing is applied. Smoothing is done using LOWESS (Locally Weighted Scatterplot Smoothing).
  • Peak method: Method to determine the peaks. Either the difference to the historical mean (default) or the difference to the 05/95 percentiles. The percentile method focuses more on extreme events, while the mean method focuses more on the difference to the historical average.
  • Emphasize peaks: If checked, peaks that leave the gray area between the 5 and 95 percentiles will be highlighted more.

Examples

License

The app and the plots it produces are published under a Creative Commons license (CC by-sa-nc 4.0).

Try it

You can try the app at https://yotka.org/meteo-hist/

To use the app on your machine, there are two simple ways:

1. Set up a Python environment, clone the repository, and run app.py using streamlit:

git clone https://github.com/yotkadata/meteo_hist/
cd meteo_hist/
pip install -r requirements.txt
streamlit run app.py

This should open a page in your default browser at http://localhost:8501 that shows the app.

2. Set up Docker and run it in a container (you can change the name and the tag, of course):

docker build -t meteo_hist:latest github.com/yotkadata/meteo_hist
docker run -d --name meteo_hist -p 8501:8501 meteo_hist:latest

Then open http://localhost:8501 or http://0.0.0.0:8501/ in your browser to see the app.

To save the generated files outside the Docker container, you can add a binding to a folder on your hard drive when you start the container: (replace /home/user/path/output/ with the path to the folder to be used).

docker run -d --name meteo_hist -p 8501:8501 -v /home/user/path/output/:/app/output meteo_hist:latest

Using the class without the web interface

It is also possible to use the Python class directly, without the web app. See the notebooks directory for examples.

Thanks

meteo_hist's People

Contributors

yotkadata avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

meteo_hist's Issues

[Feature request] Add support to query string in URL

Actual behavior

If you set up parameters and create a chart, URL doesn't change and sharing a specific location is not possible.

Expected behavior

On create, URL query string updates with all chosen parameters values. If page is loaded with a valid query string, parameters are initialized with chosen values.

Bonus

Add a "share this" button and/or an embed code for current location.

Not running on local machine

getting the following error when we submit the location
File "C:\Users\Admin\AppData\Roaming\Python\Python311\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 552, in _run_script
exec(code, module.dict)
File "C:\Users\Admin\meteo_hist\app.py", line 68, in
main()
File "C:\Users\Admin\meteo_hist\app.py", line 64, in main
build_content(plot_placeholder, message_box)
File "C:\Users\Admin\meteo_hist\app\build.py", line 118, in build_content
input_processed = process_form(st.session_state["input_values"], message_box)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Admin\meteo_hist\app\forms.py", line 253, in process_form
lat, lon, location = build_location_by_name(
^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Admin\meteo_hist\app\utils.py", line 219, in build_location_by_name
location = MeteoHist.get_lat_lon(location)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Admin\meteo_hist\meteo_hist\base.py", line 506, in get_lat_lon
location = location.json()
^^^^^^^^^^^^^^^
File "C:\Users\Admin\AppData\Roaming\Python\Python311\site-packages\requests\models.py", line 975, in json
raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)

it was working until last week , issue persists from 3 days.

image

Feature request - all available data as reference period

This is not to report an issue, just a feature request

I know WMO sets 30 years period for reference periods but I always find it interesting to compare current year with all available periods. So I was thinking that adding a new option to the Reference Period drop down list to select "all available years/periods" would be interesting if doesn't need too many resources to plot the graphs with 50+ years of data

Great work, I love the app!

btw: how often does data get updated? I'm checking data for Madrid and last available data is 24th August 2023

Where do the confidence interval values come from?

I just found out about your app and really like it. Just one thing I couldn't figure out is how you get the 5% and 95% confidence interval. In the meteo app I couldn't find. Do you calculate them on the fly from historic values from each station for each 30 year avarage period?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.