File: xmp_wnd_msk.nco

package info (click to toggle)
nco 4.0.9-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 15,600 kB
  • sloc: ansic: 32,932; cpp: 21,766; sh: 11,973; xml: 7,149; perl: 3,457; makefile: 1,801; lex: 1,139; yacc: 605; python: 116
file content (128 lines) | stat: -rw-r--r-- 5,244 bytes parent folder | download | duplicates (3)
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
116
117
118
119
120
121
122
123
124
125
126
127
128
// $Header: /cvsroot/nco/nco/data/xmp_wnd_msk.nco,v 1.3 2008/08/07 17:25:20 scapps Exp $ -*-C++-*-
/* USAGE: ncap2 -O -S xmp_wnd_msk.nco in.nc out.nc */

// PARAMETERS------------------------------------------------------
*rho80m=1.215f; //  Air Density at 80m;  Assumed to be a function 
                //of height only (using the U.S. standard atmosphere).
                // rho=1.225-(1.194e10-4)80.
//------------------------------------------------------
// Instantiate arrays and fill with missing values
*wnd_dns[time,lat,lon]=wnd_spd_80m@_FillValue;
*wnd_dns_tot[lat,lon]=wnd_spd_80m@_FillValue;
*cnt_3_45[lat,lon]=wnd_spd_80m@_FillValue;
*cnt_0_60[lat,lon]=wnd_spd_80m@_FillValue;
*wnd_msk_3_45[time,lat,lon]=wnd_spd_80m@_FillValue;
*wnd_msk_0_60[time,lat,lon]=wnd_spd_80m@_FillValue;
*wnd_msk_3_45_pct[lat,lon]=wnd_spd_80m@_FillValue;
*wnd_msk_0_60_pct[lat,lon]=wnd_spd_80m@_FillValue;
*wnd_spd_avg[lat,lon]=wnd_spd_80m@_FillValue;
*wnd_spd_sdn[lat,lon]=wnd_spd_80m@_FillValue;
*wnd_spd_shp[lat,lon]=wnd_spd_80m@_FillValue;
*wnd_pwr_dns[lat,lon]=wnd_spd_80m@_FillValue;
*wnd_spd_80m_0_60[time,lat,lon]=wnd_spd_80m@_FillValue;
*wnd_spd_80m_3_45[time,lat,lon]=wnd_spd_80m@_FillValue;
*time_cnt[lat,lon]=wnd_spd_80m@_FillValue;
//------------------------------------------------------
// Set missing value attributes
set_miss(wnd_dns,wnd_spd_80m@_FillValue);
set_miss(wnd_dns_tot,wnd_spd_80m@_FillValue);
set_miss(cnt_3_45,wnd_spd_80m@_FillValue);
set_miss(cnt_0_60,wnd_spd_80m@_FillValue);
set_miss(wnd_msk_3_45,wnd_spd_80m@_FillValue);
set_miss(wnd_msk_0_60,wnd_spd_80m@_FillValue);
set_miss(wnd_msk_3_45_pct,wnd_spd_80m@_FillValue);
set_miss(wnd_msk_0_60_pct,wnd_spd_80m@_FillValue);
set_miss(wnd_spd_avg,wnd_spd_80m@_FillValue);
set_miss(wnd_spd_sdn,wnd_spd_80m@_FillValue);
set_miss(wnd_spd_shp,wnd_spd_80m@_FillValue);
set_miss(wnd_pwr_dns,wnd_spd_80m@_FillValue);
set_miss(wnd_spd_80m_0_60,wnd_spd_80m@_FillValue);
set_miss(wnd_spd_80m_3_45,wnd_spd_80m@_FillValue);
set_miss(time_cnt,wnd_spd_80m@_FillValue);
//------------------------------------------------------------
//------------------------------------------------------------

wnd_spd_80m_0_60=wnd_spd_80m;
wnd_spd_80m_3_45=wnd_spd_80m;
//------------------------------------------------------------
// Only want non-missing value winds between 3 and 45m/s
//   where more than 10% of timeseries is available
//------------------------------------------------------------
// Wind Power for speeds between 3 and 45 m/s
wnd_msk_3_45=(wnd_spd_80m > 3.0f && wnd_spd_80m < 45.0f);
// Speeds between 0 and 60 m/s
wnd_msk_0_60=(wnd_spd_80m >= 0.0f && wnd_spd_80m <= 60.0f);

// Count number of speeds between 3 and 45m/s
cnt_3_45=(wnd_msk_3_45.total($time));
// Count number of speeds between 0 and 60m/s
cnt_0_60=(wnd_msk_0_60.total($time));

time_cnt(:,:)=$time.size;
wnd_msk_3_45_pct(:,:)=(cnt_3_45(:,:)/time_cnt(:,:) > 0.10f);
wnd_msk_0_60_pct(:,:)=(cnt_0_60(:,:)/time_cnt(:,:) > 0.10f);
//------------------------------------------------------------

//------------------------------------------------------------
// set zeros to missing value
where(cnt_3_45==0)
  cnt_3_45=wnd_spd_80m@_FillValue;
where(wnd_msk_3_45_pct==0 || wnd_msk_3_45==0)
  wnd_spd_80m_3_45=wnd_spd_80m@_FillValue;
// set zeros to missing value
where(cnt_0_60==0)
  cnt_0_60=wnd_spd_80m@_FillValue;
where(wnd_msk_0_60_pct==0 || wnd_msk_0_60==0)
  wnd_spd_80m_0_60=wnd_spd_80m@_FillValue;
//------------------------------------------------------------

//PERFORM CALCULATIONS:
//------------------------------------------------------------
//Wind Speed Average for winds between 0 and 60m/s
wnd_spd_avg=wnd_spd_80m_0_60.avg($time);
//Wind Speed Standard Deviation for winds between 0 and 60m/s
wnd_spd_sdn=(wnd_spd_80m_0_60-wnd_spd_avg).rmssdn($time);
//Wind Speed Weibull Shape for winds between 0 and 60m/s
where(wnd_spd_sdn==0.0f)
  wnd_spd_sdn=0.1f;
wnd_spd_shp=((wnd_spd_avg/wnd_spd_sdn)^1.086f);

//Wind Power Density for winds between 3 and 45m/s
wnd_dns=((wnd_spd_80m_3_45^3.0f)*rho80m);
wnd_dns_tot=(wnd_dns.total($time));
wnd_pwr_dns=(wnd_dns_tot/(2.0f*cnt_3_45));		
//------------------------------------------------------------

//------------------------------------------------------------
//Assign attributes
wnd_spd_avg@long_name="80m mean wind speed";
wnd_spd_sdn@long_name="80m wind speed standard deviation";
wnd_spd_shp@long_name="80m wind speed Weibull Shape Param";
wnd_pwr_dns@long_name="80m wind power density (3 and 45m/s)";
cnt_3_45@long_name="Number of 80m winds between 3 and 45 m/s";
cnt_0_60@long_name="Number of 80m winds between 0 and 60 m/s";

wnd_spd_avg@units="m/s";
wnd_spd_sdn@units="m/s";
wnd_spd_shp@units="dimensionless";
wnd_pwr_dns@units="W/m2";
//------------------------------------------------------------

// Write these to netCDF file
ram_write(wnd_pwr_dns);
ram_write(cnt_3_45);
ram_write(cnt_0_60);
ram_write(wnd_spd_avg);
ram_write(wnd_spd_sdn);
ram_write(wnd_spd_shp);
//Cleanup your mess
ram_delete(rho80m);
ram_delete(wnd_dns);
ram_delete(wnd_dns_tot);
ram_delete(wnd_msk_3_45);
ram_delete(wnd_msk_0_60);
ram_delete(wnd_msk_3_45_pct);
ram_delete(wnd_msk_0_60_pct);
ram_delete(wnd_spd_80m_0_60);
ram_delete(wnd_spd_80m_3_45);
ram_delete(time_cnt);