This repo contains scripts to generate (rough!) visualizations of daily U.S. snow depth. I used these scripts to generate timelapse visualizations of the snow depth map throughout the contiguous US from 1950 through 2015. A slow version and fast version are available.
The following guide explains how to download the underlying dataset, format it, import it into QGIS, and ultimately combine the resulting map frames into a timelapse video. I completed this project on a Windows machine, so this guide is highly Windows-specific.
I. Download the raw data
- This step requires wget, available here for Windows
- The data we want to use is provided by the National Climate Data Center's Global Historical Climatological Network, and is available via FTP server here.
- To download some or all of the yearly GHCND files (CAUTION: over 13 GB total!):
1. Edit
download_by_year.bat
to specify the year range to download 2. Editdownload_by_year.bat
to specify the save directory - Extract the csv files within these
.gz
files using a utility like 7-zip
II. Format the raw data
- This step requires a Unix shell. If you are on Windows, consider Cygwin:
- These
.csv
files contain all weather data for every station in the Global Historical Climate Network (GHCN). We only need the snow depth data from U.S. stations. - From the terminal (on Windows, open Cygwin), navigate to the location of the csv files.
- Run
format_raw_data.sh
from the Cygwin terminal. This will create a new directory containing daily csv files for snow depth data at continental U.S. stations. The files are named in the following way:YYYYMMDD.csv
III. Create spatially-interpolated snow depth maps
- This step requires QGIS, and specifically, QGIS 2.10 Pisa.
-
The script is not working with more recent QGIS versions (such as 2.14 Essen) due to a backwards compatibility issue in some of the processing algorithms.
-
Links to the older QGIS 2.10 Windows installation binaries
- QGIS-OSGeo4W-2.10.1-1-Setup-x86.exe (32-bit version)
- QGIS-OSGeo4W-2.10.1-1-Setup-x86_64.exe (64-bit version)
-
- Open QGIS 2.10
- Uncheck the box next to "Render" in the QGIS window. This will speeds up the script because it prevents QGIS from displaying the intermediate canvases during processing.
- Click the Python logo to open the Python Console within QGIS.
- Click "Show Editor"
- Click "Open file" and load the
QGIS_Snow_Depth_Renderer.py
script. - IMPORTANT : You will need to edit line 6 of
QGIS_Snow_Depth_Renderer.py
to specify the correct path to your local GitHub repository housing the Daily-Snow-Depth files. - Please take note of the warnings and suggestions below BEFORE running
QGIS_Snow_Depth_Renderer.py
. * This is a very time-consuming and processor-intensive task; rendering takes approximately 30-45 seconds per map, depending on your hardware. * I recommend only running the script for a few years' worth of daily files (up to a decade) at a time, since the temporary files generated by QGIS take up a lot of space and are not removed until the QGIS session is terminated. If you know/find a way to delete temp files while the script is running, please share it! * You may need to go in and manually delete the temp files if QGIS fails to remove them. On Windows, the default temp directory is something like C:\Users\[your-name-here]\AppData\Local\Temp\processing * If you are using an SSD for your OS and installed programs and a larger HDD for bulk storage, consider changing the environment variable of the QGIS temp directory to a location on your HDD, as explained here: http://gis.stackexchange.com/a/156156 * The warning message about incompatible CRS layers can be ignored. - Run
QGIS_Snow_Depth_Renderer.py
, which will save the individual map files to the[Your GitHub path]/Daily-Snow-Depth/QGIS_Python/Rendered_Frames/
directory inYYYYMMDD.png
format.
IV. Create timelapse video from daily map images
-
**This step requires the following:
-
Crop maps to remove headers (will be added in separately in later steps.)
Run
crop_maps.sh
in the command line. -
Generate timelapse for all map images (after cd'ing to wherever the individual map files are) using:
ffmpeg -framerate 2 -i %05d.png -c:v libx264 -preset veryslow -r 2 -pix_fmt yuv420p {maps_out.mkv}
-
Generate date headers for all map images. These are handled separately by isolating them off the previously rendered map frames so that the header dates appear plainly and sequentially instead of blending one into another (which is hard to read) in the final timelapse.
Run
crop_headers.sh
in the command line. -
Generate timelapse for all header images (after cd'ing to wherever the individual header files are):
ffmpeg -framerate 2 -i %05d.png -c:v libx264 -preset veryslow -r 30 {headers_out.mkv}
-
Stack the non-blended header and blended map video files:
ffmpeg -i {headers_out.mkv} -i {maps_out.mkv} -filter_complex vstack {stacked.mkv}
-
Upload to desired video hosting platform (e.g., Youtube or Vimeo).