Skip to content

Uses machine learning to predict the weather automated with airflow

License

Notifications You must be signed in to change notification settings

Reed-Carter/Weather_Forcaster

Repository files navigation

Weather Forecaster

Uses machine learning to predict the weather

By Reed Carter

This project uses weather data and machine learning to create a 10 day weather forecast presented on a looker studio dashboard for 11 cities around the country.

The ETL pipeline is orchestrated using Apache Airflow so the forecast remains current.

Technologies Used

  • Python (BeautifulSoup, Pandas)
  • Airflow (via Docker)
  • Google Cloud Platform (BigQuery, Looker Studio)
  • SQL

Dashboard Presentations

Data Sources

The Process

Current weather conditions including precip, high temps, low temps, humidity, etc. are scraped from the NWS using beautiful soup. That data is then cleaned and transformed to be inputted into the forecasting model to produce a 10 day forecast estimating high temps of 11 cities around the US. The forecasting model uses the Sklearn library in python to perform a multiple linear regression to make the prediction. The data is then uploaded to google BigQuery to be presented in looker studio.

The airflow dag specifying each task can be found below as well as a graph demonstrating the actual and predicted temperatures of the model for the city of Fairbanks, AK in the year 2022.

simple_dag

Model test

Results

The results were displayed on a looker studio dashboard which can be found here

example of visualizations

Setup/Installation Requirements

Clone repo to your local system:

  1. Make a directory on your disk where you would like to clone the repo.

  2. Copy the repo link: https://github.com/Reed-Carter/Weather_Forcaster (available if you click the green "Code" dropdown button on this page).

  3. Open your terminal and change into the directory you made (cd /path/to/new/directory).

  4. Type git clone and paste the URL.

Install required packages:

These installation instructions assume you have pip, virtualenv, and Docker Desktop installed.

# Create and activate virtual environment
virtualenv -p python3.7 venv 
source venv/bin/activate

# Install packages from requirements.txt
pip install -r requirements.txt

# Install Airflow 
AIRFLOW_VERSION=2.3.2 
PYTHON_VERSION=3.7 
CONSTRAINT_URL="https://raw.githubusercontent.com/apache/airflow/constraints-${AIRFLOW_VERSION}/constraints-${PYTHON_VERSION}.txt"
pip install "apache-airflow[async,postgres,google]==${AIRFLOW_VERSION}" --constraint "${CONSTRAINT_URL}"

The structure of this repo is currently organized into three separate subdirectories containing each group member's work. For the time being, you can create your own airflow directory in the root of this repository and copy any of our DAGs into it if you are interested in running them for yourself.

# Make and change to airflow subdirectory
mkdir airflow && cd "_$"
mkdir ./dags ./plugins ./logs # create subdirectories 

# Download docker-compose.yaml and set the .env  
curl -LfO 'https://airflow.apache.org/docs/apache-airflow/stable/docker-compose.yaml'
echo -e "AIRFLOW_UID=$(id -u)\nAIRFLOW_GID=0" > .env

Prior to initializing Airflow in Docker, you will need to create a project and an associated service account in BigQuery. After downloading the account's credential file, you can configure your docker-compose.yaml to connect to BigQuery:

  GOOGLE_APPLICATION_CREDENTIALS: /google_creds/<name-of-your-creds-file>.json
volumes:
  - ${AIRFLOW_PROJ_DIR:-.}/dags:/opt/airflow/dags
  - ${AIRFLOW_PROJ_DIR:-.}/logs:/opt/airflow/logs
  - ${AIRFLOW_PROJ_DIR:-.}/plugins:/opt/airflow/plugins
  - ${AIRFLOW_PROJ_DIR:-.}/data:/opt/airflow/data
  - </path/to/your/creds/directory>:/google_creds

After opening Docker Desktop (or starting docker via CLI):

# Create and start Docker container from airflow-init image
docker compose up airflow-init
docker compose up 

Known Bugs

  • No known bugs

License

MIT License

Copyright (c) 2023 Alejandro Socarras, Drew White, Reed Carter

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

Uses machine learning to predict the weather automated with airflow

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published