-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwrf_post.html
115 lines (104 loc) · 6.96 KB
/
wrf_post.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<!DOCTYPE html>
<html>
<head>
<title>Brian Blaylock, UofU</title>
<link rel="stylesheet" href="./css/brian_style.css" />
<script src="./js/site/siteopen.js"></script>
</head>
<body>
<a name="TOP"></a>
<script src="./js/site/sitemenu.js"></script>
<div id="content">
<h1 align="center">WRF Data Post Processing</h1>
<p>My language of choice is Python :)
<!-- Tabs -->
<ul class="nav nav-tabs">
<li class="active"><a data-toggle="tab" href="#tab1">NetCDF with Python</a></li>
<li><a data-toggle="tab" href="#tab2">Multiprocessing Plots</a></li>
<li><a data-toggle="tab" href="#tab3">Staggered Grid to Mass Points</a></li>
<li><a data-toggle="tab" href="#tab4">Other Tools</a></li>
</ul>
<div class="tab-content">
<div id="tab1" class="tab-pane fade in active">
<h3>Basics of opening and looking at NetCDF data in Python</h3>
<script src="https://gist.github.com/blaylockbk/37dfcba1a6b31a4d6ccd350a5283c976.js"></script>
</div>
<div id="tab2" class="tab-pane fade">
<h3>Python Multiprocessing: Lots of plots fast</h3>
<p>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.
<p>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...
<iframe width="560" height="315" src="https://www.youtube.com/embed/X2mO1O5Nuwg?rel=0" frameborder="0" allowfullscreen></iframe>
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).
<p style="text-align:center"><a class='btn btn-default btn-lg' href="https://github.com/blaylockbk/Ute_other/blob/master/plot_TDWR_multiprocessor.py"><i class="fab fa-github"></i> plot_TDWR_multiprocessor.py</a>
</div>
<div id="tab3" class="tab-pane fade">
<h3>Converting Staggered Grid Variables to Mass Points (by averaging)</h3>
WRF uses the <a href="http://www.openwfm.org/wiki/How_to_interpret_WRF_variables#Grid" target="_blank">Arakawa C Grid</a>.
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.
<p style="text-align:center"><a class='btn btn-default btn-lg' href="https://github.com/blaylockbk/Ute_WRF/blob/master/functions/stagger_to_mass.py"><i class="fab fa-github"></i> stagger_to_mass.py</a>
<p> 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.
<p> <img align=right width='35%' src="./images/arakawa-C-grid.png">
<p> To the left is a 3x3 Arakawa C-Grid.
<ul>
<li> Red Dots: mass point (3x3)
<li> Blue Line: U staggered (3x4)
<li> Green Line: V staggered (4x3)
</ul>
<p>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...
<h4>stagger_to_mass.py</h4>
<p>
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.
<hr>
<h4>Vstagger_to_mass(V)</h4>
<p> Average the top and bottom column values for each box. Perform the following calculation on the array and loop through all rows.
<img width="90%" src="./images/avg_columns.png">
<br><br>
<h4>Ustagger_to_mass(U)</h4>
<p> Average the left and right row values for each box. Perform the following calculation on the array and loop through all columns.
<img width="90%" src="./images/avg_rows.png">
<p>Each U and V variable has a coorespoinding XLAT_U, XLONG_U, XLAT_V, and XLONG_V variable as well.
<p>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.
</div>
<div id="tab4" class="tab-pane fade">
<h3>Other WRF Tools</h3>
<h4>My Python Blog</h4>
I share my latest tips and tricks on my Python blog:
<a href="http://kbkb-wx-python.blogspot.com/"> Blogger</a>.
<hr>
<h4>Luke Madaus's Python Code</h4>
This is a good place for more python WRF examples
<a href="https://github.com/lmadaus/old_wrf_plotting_scripts"> GitHub</a>.
<hr>
<h4>WRF Browser</h4>
<p>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.
<p>Download the latest version <a href="http://www.enviroware.com/WRF_Browser/">here</a> 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.
</div>
</div>
</div>
<script src="./js/site/siteclose.js"></script>
</div>
</body>
</html>