WRF Data Post Processing
My language of choice is Python :)
Basics of opening and looking at NetCDF data in Python
Python Multiprocessing: Lots of plots fast
I find myself making lots of the same kinds of plots but for different wrfout times. How do you make 400 images real quick? Use Python's Multiprocessing module.
How does multiprocessing work? Your computer has multiple cores, or brains, that it can do work on. When you run a typical Python script it will send that job to one processor. With multiprocessing it will break up parts of the code and solve each piece on different processors. There is a module called multi threading, but multi threading probably wont speed up making plots too much since for reasons explained in the video below. I like to use multiprocessing and the pool function to split the code up among the working processors. Check out the YouTube video for a bit more description... As an example, check out the below (incomplete) script for an example of the parts and pieces. On 32 processors available on CHPC machines, I was able to make 475 plots in less than a minute rather than the hour it took to run in serial (one processor).
Converting Staggered Grid Variables to Mass Points (by averaging)
WRF uses the Arakawa C Grid. Mass point variables like temperature, humidity, etc. are calculated for the inside of the gird box. Advection variables like U and V winds are calculated on a staggered grid for the box edges to represent flow into and out of the box.If you're dealing with WRF output data on certain model levels rather than surface variables you it's likely you'll need to convert the staggered grid variables to the mass points. One reason you'd want to do this is if you want to make wind barbs.
To the left is a 3x3 Arakawa C-Grid.
- Red Dots: mass point (3x3)
- Blue Line: U staggered (3x4)
- Green Line: V staggered (4x3)
The U and V array size will be one column or row bigger than your mass point array. You could get away with trimming the U and V array to the same size as the mass point array and then plot the U and V winds on the mass point lat/lon coordinates. This introduces a small error half the size of your grid spacing (4 km grid box would cause a 2 km error in wind barb placement). That is sloppy, and we can do better. So we reduce the staggered grid to a mass point grid by averaging the values on the left-right side of the box to get an average U vector at the mass point and then average the top-bottom value to get the V average value. Get it? Here's some more details...
stagger_to_mass.py
Two simple python functions to convert the staggered grid values (U, V, winds, and lat/lons) to the mass point. I average the outside coordinates to approximate the masspoint value in the middle.
Vstagger_to_mass(V)
Average the top and bottom column values for each box. Perform the following calculation on the array and loop through all rows.
Ustagger_to_mass(U)
Average the left and right row values for each box. Perform the following calculation on the array and loop through all columns.
Each U and V variable has a coorespoinding XLAT_U, XLONG_U, XLAT_V, and XLONG_V variable as well.
Note: difference between XLAT_U and XLAT is small, on the order of 10e-5. (same with XLAT_V, XLONG_U, and XLONG_V). This means you only have to calcuate the lat/lon from either the U or V variable to get the approximate masspoint lat/lon. Difference in Umass and Ustagger can bigger, I've seen values between 0-5. We expect some difference here.
Other WRF Tools
My Python Blog
I share my latest tips and tricks on my Python blog: Blogger.Luke Madaus's Python Code
This is a good place for more python WRF examples GitHub.WRF Browser
WRF Browser is a Windows application that lets you browse WRF variables, plot variable field on a map, export variable to KML, and create time series plots for a point.
Download the latest version here and join the email list for new updates. This is still being produced and my experience is that if you report a bug they get it fixed rather quickly.