extract data from wrf-ems for weather forecast

All issues/questions about EMS v3.4 package, please ask here.
Post Reply
dominic
Posts: 312
Joined: Thu Jun 14, 2012 7:19 am

extract data from wrf-ems for weather forecast

Post by dominic » Fri Jul 12, 2013 9:28 am

Hi guys, I need to extract the weather data from the run of my domain, so you can work through weather in asp or php script.

How can I do? I heard about the file tlist, can someone give me some instruction

Thanks in advance

meteoadriatic
Posts: 1510
Joined: Wed Aug 19, 2009 10:05 am

Re: extract data from wrf-ems for weather forecast

Post by meteoadriatic » Fri Jul 12, 2013 10:05 pm

In my opinion tslist is most primitive way to do that. You have much better options. I guess the easiest way is to use GrADS for that.

dominic
Posts: 312
Joined: Thu Jun 14, 2012 7:19 am

Re: extract data from wrf-ems for weather forecast

Post by dominic » Sat Jul 13, 2013 9:19 am

Meteoadriatic Hello, have you ever used this for grads?

What I should do is to extract as the temperature for a given point in the plot, and save it to a txt file.

You have an idea how to do it with grads?


Ben Lankamp
Posts: 9
Joined: Thu Jun 17, 2010 1:18 pm

Re: extract data from wrf-ems for weather forecast

Post by Ben Lankamp » Sun Jul 14, 2013 6:01 pm

This is the script I made for saving time series for given locations (by lat lon and an arbitrary locationid). It will save the basic meteorological variables in use for general weather forecasting, such as temperature and dewpoint 2 metres, surface wind speed and gust, downdwelling radiation, cloud cover and precipitation, along with some upper level variables.

Code: Select all

* open WRF output, change according to your set-up
'open /WRFV3/wrfems/lastrun/wrf.ctl'

* initialize variables, this creates a new time series file
* with the first line containing a header
outfile = 'wrf_timeseries.txt'
code=write(''outfile,'sourcerundt;locationid;tau;t2m;dpt2m;rh2m;u10m;v10m;mslp;t850;rh850;t700;hgt700;hgt1000;dswrf;apcp;tcdc;vissfc;gustsfc')

* append a time series to a file, one line for each location
rc=savedata(52.15,4.42,1)

'quit'

* Savedata: function to save data for a specific location (lat lon)
* locationid is a custom integer number for identifying the location, which you can use with a database
function savedata(locationlat,locationlon,locationid)
'set t 1'
'q time'
_inittime = subwrd(result, 3)
day = substr(_inittime, 4, 9)
tm = substr(_inittime, 1, 2)

* Set time
'set lat ' locationlat
'set lon ' locationlon

outfile = 'wrf_timeseries.txt'

'q dims'

* start tau
* we start at t=2 (t+1) because of the precipitation fields
p = 2

'set gxout stat'

'set z 1'

* loop through taus to t+72 (t=73)
while ( p <= 73)
   'set t 'p'' 
  
   'd tmp2m-273.15' 
   regel = sublin(result,9)
   res_t2m=subwrd(regel,4)

   'd dpt2m-273.15' 
   regel = sublin(result,9)
   res_dpt2m=subwrd(regel,4)

   'd rh2m' 
   regel = sublin(result,9)
   res_rh2m=subwrd(regel,4)

   'd ugrd10m' 
   regel = sublin(result,9)
   res_windu=subwrd(regel,4)

   'd vgrd10m' 
   regel = sublin(result,9)
   res_windv=subwrd(regel,4)

   'd prmslmsl/100' 
   regel = sublin(result,9)
   res_slp=subwrd(regel,4)

   'd tmpprs(lev=850)-273.15' 
   regel = sublin(result,9)
   res_t850=subwrd(regel,4)

   'd rhprs(lev=850)' 
   regel = sublin(result,9)
   res_rh850=subwrd(regel,4)

   'd tmpprs(lev=750)-273.15'
   regel = sublin(result,9)
   res_t700=subwrd(regel,4)

   'd hgtprs(lev=700)' 
   regel = sublin(result,9)
   res_hgt700=subwrd(regel,4)

   'd hgtprs(lev=1000)' 
   regel = sublin(result,9)
   res_hgt1000=subwrd(regel,4)

   'd DSWRFsfc' 
   regel = sublin(result,9)
   res_dswrf=subwrd(regel,4)

   'd apcpsfc' 
   regel = sublin(result,9)
   res_apcp=subwrd(regel,4)

   'd VISsfc' 
   regel = sublin(result,9)
   res_vissfc=subwrd(regel,4)

   'd GUST10m' 
   regel = sublin(result,9)
   res_gustsfc=subwrd(regel,4)

   'd TCDCclm' 
   regel = sublin(result,9)
   res_tcdc=subwrd(regel,4)
   code=write(''outfile,day''tm';'locationid';'p';'res_t2m';'res_dpt2m';'res_rh2m';'res_windu';'res_windv';'res_slp';'res_t850';'res_rh850';'res_t700';'res_hgt700';'res_hgt1000';'res_dswrf';'res_apcp';'res_tcdc';'res_vissfc';'res_gustsfc'',append)
   
   p = p + 1
endwhile

return rc
The time series will be saved as wrf_timeseries.txt. You can extend the list of locations by adding calls to savedata.

dominic
Posts: 312
Joined: Thu Jun 14, 2012 7:19 am

Re: extract data from wrf-ems for weather forecast

Post by dominic » Mon Jul 15, 2013 9:38 am

Ben Lankamp wrote:This is the script I made for saving time series for given locations (by lat lon and an arbitrary locationid). It will save the basic meteorological variables in use for general weather forecasting, such as temperature and dewpoint 2 metres, surface wind speed and gust, downdwelling radiation, cloud cover and precipitation, along with some upper level variables.

Code: Select all

* open WRF output, change according to your set-up
'open /WRFV3/wrfems/lastrun/wrf.ctl'

* initialize variables, this creates a new time series file
* with the first line containing a header
outfile = 'wrf_timeseries.txt'
code=write(''outfile,'sourcerundt;locationid;tau;t2m;dpt2m;rh2m;u10m;v10m;mslp;t850;rh850;t700;hgt700;hgt1000;dswrf;apcp;tcdc;vissfc;gustsfc')

* append a time series to a file, one line for each location
rc=savedata(52.15,4.42,1)

'quit'

* Savedata: function to save data for a specific location (lat lon)
* locationid is a custom integer number for identifying the location, which you can use with a database
function savedata(locationlat,locationlon,locationid)
'set t 1'
'q time'
_inittime = subwrd(result, 3)
day = substr(_inittime, 4, 9)
tm = substr(_inittime, 1, 2)

* Set time
'set lat ' locationlat
'set lon ' locationlon

outfile = 'wrf_timeseries.txt'

'q dims'

* start tau
* we start at t=2 (t+1) because of the precipitation fields
p = 2

'set gxout stat'

'set z 1'

* loop through taus to t+72 (t=73)
while ( p <= 73)
   'set t 'p'' 
  
   'd tmp2m-273.15' 
   regel = sublin(result,9)
   res_t2m=subwrd(regel,4)

   'd dpt2m-273.15' 
   regel = sublin(result,9)
   res_dpt2m=subwrd(regel,4)

   'd rh2m' 
   regel = sublin(result,9)
   res_rh2m=subwrd(regel,4)

   'd ugrd10m' 
   regel = sublin(result,9)
   res_windu=subwrd(regel,4)

   'd vgrd10m' 
   regel = sublin(result,9)
   res_windv=subwrd(regel,4)

   'd prmslmsl/100' 
   regel = sublin(result,9)
   res_slp=subwrd(regel,4)

   'd tmpprs(lev=850)-273.15' 
   regel = sublin(result,9)
   res_t850=subwrd(regel,4)

   'd rhprs(lev=850)' 
   regel = sublin(result,9)
   res_rh850=subwrd(regel,4)

   'd tmpprs(lev=750)-273.15'
   regel = sublin(result,9)
   res_t700=subwrd(regel,4)

   'd hgtprs(lev=700)' 
   regel = sublin(result,9)
   res_hgt700=subwrd(regel,4)

   'd hgtprs(lev=1000)' 
   regel = sublin(result,9)
   res_hgt1000=subwrd(regel,4)

   'd DSWRFsfc' 
   regel = sublin(result,9)
   res_dswrf=subwrd(regel,4)

   'd apcpsfc' 
   regel = sublin(result,9)
   res_apcp=subwrd(regel,4)

   'd VISsfc' 
   regel = sublin(result,9)
   res_vissfc=subwrd(regel,4)

   'd GUST10m' 
   regel = sublin(result,9)
   res_gustsfc=subwrd(regel,4)

   'd TCDCclm' 
   regel = sublin(result,9)
   res_tcdc=subwrd(regel,4)
   code=write(''outfile,day''tm';'locationid';'p';'res_t2m';'res_dpt2m';'res_rh2m';'res_windu';'res_windv';'res_slp';'res_t850';'res_rh850';'res_t700';'res_hgt700';'res_hgt1000';'res_dswrf';'res_apcp';'res_tcdc';'res_vissfc';'res_gustsfc'',append)
   
   p = p + 1
endwhile

return rc
The time series will be saved as wrf_timeseries.txt. You can extend the list of locations by adding calls to savedata.
Hello Ben, thank you very much for your reply and for your script!

but this script you can launch from grads? ie example: run save_data.gs


Why when I go to launch it gives me error at line 1

Ben Lankamp
Posts: 9
Joined: Thu Jun 17, 2010 1:18 pm

Re: extract data from wrf-ems for weather forecast

Post by Ben Lankamp » Mon Jul 15, 2013 5:22 pm

Hello Dominic, did you change the first line of my script to open your WRF output? GrADS strips comment lines, so 'line 1' is actually line 2 in the GrADS script file. The script assumes you have GrADS-ready files from the EMS Post-Processor (.ctl, .idx and GRIB2 files). I run the script from the shell with this command: grads -lbc "run savedata.gs" but you should perfectly be able the run the script from GrADS as well.

dominic
Posts: 312
Joined: Thu Jun 14, 2012 7:19 am

Re: extract data from wrf-ems for weather forecast

Post by dominic » Tue Jul 16, 2013 5:20 pm

Hello well, thank you for your time and your answer

to not display errors have been forced to eliminate explanations preceded by an asterisk *

As for the output files, you've made ​​a run arw, and I created the files as usual 3 including the ctl file. I lynched the exact directory of the ctl but when I go to launch through the shell command gives me error hardcopy


Could you do see an example of output? as would be the variables?

Would it be possible to create multiple txt files, each for a variable? t2m.txt example, 850hpa.txt, 500 txt, etc. etc.

dominic
Posts: 312
Joined: Thu Jun 14, 2012 7:19 am

Re: extract data from wrf-ems for weather forecast

Post by dominic » Tue Jul 16, 2013 5:21 pm

You use the data to create the weather forecast via web script?

Ben Lankamp
Posts: 9
Joined: Thu Jun 17, 2010 1:18 pm

Re: extract data from wrf-ems for weather forecast

Post by Ben Lankamp » Tue Jul 16, 2013 9:51 pm

We have GrADS v2.0.2 on our system, perhaps you have an older/newer version. The asterisks should normally be accepted as comment lines, they should not generate errors in GrADS. That would be my first clue in investigating your problems. Perhaps re-install/rebuild GrADS?

The script we use is intented for generating files for import into a Microsoft SQL Server database, which in turn provides access to the time series in our forecaster workstation. Sample output is included below.

Code: Select all

sourcerundt;locationid;tau;t2m;dpt2m;rh2m;u10m;v10m;mslp;t850;rh850;t700;hgt700;hgt1000;dswrf;apcp;tcdc;vissfc;gustsfc
16JUL201318;1;2;18.0853;14.421;80.0445;-0.455902;-2.27081;1023.75;12.3196;50.5175;6.65002;3181.8;199.46;38.3127;0;0;7652.03;4.07516
16JUL201318;1;3;17.3916;14.297;82.8477;-1.17809;-2.32126;1023.73;12.455;49.9542;6.70775;3182.18;199.244;0;0;99.808;7437.86;4.55211
16JUL201318;1;4;16.9933;14.2333;84.5684;-1.48084;-2.21117;1023.55;12.4615;50.4261;6.63239;3180.37;197.884;0;0;97.7681;7229.81;4.55677
16JUL201318;1;5;16.4926;14.1575;86.8423;-1.68152;-1.82516;1024.05;12.4162;51.1726;6.54893;3183.98;202.272;0;0;3.47578;7028.07;4.31731
16JUL201318;1;6;15.9545;14.0894;89.536;-1.94576;-1.43638;1024.31;12.2571;52.7153;6.40472;3184.94;204.678;0;0;1.34371;6927.71;4.25763
16JUL201318;1;7;15.6816;13.8764;89.9749;-2.48288;-1.41565;1024.34;12.335;51.8711;6.44036;3185.39;204.95;0;0;0;6724.59;4.4913
16JUL201318;1;8;15.2797;13.7193;91.3519;-2.52826;-0.908888;1024.2;12.0303;54.7096;6.28221;3182.34;203.914;0;0;0;6523.42;4.21466
16JUL201318;1;9;14.9262;13.5684;92.5416;-2.52138;-0.727222;1024.21;11.8692;56.059;6.16834;3181.25;204.11;0;0;0;6325.09;3.99656
16JUL201318;1;10;14.5834;13.4;93.5588;-2.51123;-0.615751;1024.65;11.6633;57.8345;5.93269;3183.36;208.072;0;0;0;6128.32;3.8745
16JUL201318;1;11;14.2751;13.1895;94.1222;-2.56216;-0.567046;1024.46;11.9365;54.0721;5.98597;3182.34;206.248;0;0;1.39247;6031.38;3.85899
16JUL201318;1;12;14.4738;13.4381;94.4385;-2.54774;-0.644001;1024.61;12.3599;49.3306;6.13537;3184.95;207.284;67.9897;0;64.7943;6027.66;3.75804
16JUL201318;1;13;15.1412;13.3041;89.5592;-2.55083;-0.289108;1024.9;12.696;46.3685;6.33507;3188.76;209.848;122.768;0;100;6223.55;2.96884
16JUL201318;1;14;15.989;13.3522;85.0697;-1.6871;0.363224;1025.08;12.4959;47.7946;6.24285;3188.94;211.828;209.711;0;100;6528.47;1.68926
16JUL201318;1;15;17.393;13.4721;78.4303;-0.882319;-0.451707;1025.11;12.49;48.0243;6.28608;3189.65;212.731;396.319;0;99.9825;7040.93;0.888577
16JUL201318;1;16;19.0604;13.7747;72.726;-0.534509;-1.62564;1025.25;12.289;49.5923;6.22359;3190.34;214.723;570.309;0;100;7650.36;1.76384
16JUL201318;1;17;20.2045;13.2812;66.5948;-0.331708;-2.68481;1025.34;12.2205;50.3919;6.24833;3191.63;215.661;649.456;0;100;8071.04;2.83097
16JUL201318;1;18;20.8196;13.1594;64.1571;0.0415286;-3.50108;1025.54;12.2398;50.7811;6.31303;3194.26;217.584;747.03;0;98.4115;8381.77;3.5448
16JUL201318;1;19;21.0919;13.4911;64.6257;0.254953;-4.35156;1025.56;12.3207;50.9482;6.34038;3195.47;218.128;769.656;0;96.9102;8291.2;4.43317
16JUL201318;1;20;21.2159;13.8513;65.5831;0.179406;-4.55644;1025.52;12.5621;50.334;6.24968;3196.75;218.016;720.458;0;79.7834;8190.34;4.66644
16JUL201318;1;21;21.4072;14.2834;66.8198;0.12789;-4.31024;1025.59;12.9368;49.1665;6.14615;3200;219.021;657.144;0;74.0073;8088.55;4.75561
16JUL201318;1;22;21.5128;14.5318;67.4366;0.0153177;-4.71274;1025.23;13.0194;49.0804;6.07076;3197.96;216.146;589.847;0;83.6295;7986.16;5.36626
16JUL201318;1;23;21.3992;14.7011;68.5451;-0.486153;-5.10668;1025.28;13.0029;49.4667;6.14517;3198.97;216.648;441.477;0;99.9302;7975.38;6.19835
16JUL201318;1;24;21.3098;14.7999;69.0978;-1.26434;-4.61577;1025.11;13.062;49.5893;6.27435;3198.64;215.429;308.279;0;99.9128;7970.93;6.23836
You could generate an output file for every single element by using a different 'outfile', but I would not recommend it, if you are going to be using a database. We store our time series in a matrix with time and station (rows) versus elements (columns). Even with tens of millions of records (hundreds of stations, hourly output), as in our case, the operational performance remains very good.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest