-
Notifications
You must be signed in to change notification settings - Fork 0
/
plotPRS.py
1276 lines (1185 loc) · 54.2 KB
/
plotPRS.py
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed May 12 13:07:06 2021
@author: semmerson
"""
import os,re, pyart, pickle, lzma
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors as colors
from netCDF4 import Dataset
from scipy import interpolate
from skimage.restoration import unwrap_phase
from scipy.io import loadmat
from pyart.map.grid_mapper import NNLocator
def loadRadars(file):
with lzma.open(file,'rb') as f:
radarStruct = pickle.load(f)
wxStruct = pickle.load(f)
radars = pickle.load(f)
return radarStruct,wxStruct,radars
def localize(aa,ee,tt,rxPos,txPos):
c = 3e8
nRx = rxPos[:,np.newaxis].shape[1]
if np.all(np.isclose(rxPos,txPos)):
theta = (90 - ee)*np.pi/180
phi = aa*np.pi/180
nAngle = len(theta)
npts = np.zeros((nAngle,len(tt),3))
ranges = c*tt/2
RR,PH = np.meshgrid(ranges,phi)
r,TH = np.meshgrid(ranges,theta)
npts[:,:,0] = r*np.sin(TH)*np.cos(PH)+txPos[0]
npts[:,:,1] = r*np.sin(TH)*np.sin(PH)+txPos[1]
npts[:,:,2] = r*np.cos(TH)+txPos[2]
else:
th = (90 - ee)*np.pi/180
ph = aa*np.pi/180
nAngle = len(th)
pointingVector = np.array([np.sin(th)*np.cos(ph),np.sin(th)*np.sin(ph),np.cos(th)])
rxVector = rxPos - np.tile(txPos,nRx)
rxMag = np.sqrt(np.sum(rxVector**2))
pp = np.zeros((nRx,nAngle))
xx = np.zeros((nRx,len(tt),nAngle))
yy = np.zeros((nRx,len(tt),nAngle))
zz = np.zeros((nRx,len(tt),nAngle))
npts = np.zeros((nAngle,len(tt),3))
ca = np.zeros_like(aa).astype(float)
ce = np.zeros_like(ee).astype(float)
rxAz = np.arctan2(rxVector[1],rxVector[0])
rxEl = np.arcsin(rxVector[2]/rxMag)
D = rxMag
crx = rotMat('y',rxEl)@rotMat('z',-rxAz)@rxVector[:,np.newaxis]
for jj in range(nAngle):
cp = rotMat('y',rxEl)@rotMat('z',-rxAz)@pointingVector[:,jj][:,np.newaxis]
ca[jj] = np.arctan2(cp[1],cp[0])*180/np.pi
ce[jj] = np.arcsin(cp[2]/np.sqrt(np.sum(cp**2)))*180/np.pi
pp[:,jj] = np.arccos(np.sum(crx*cp)/(np.sqrt(np.sum(crx**2))*np.sqrt(np.sum(cp**2))))*180/np.pi
PP,TT = np.meshgrid(pp,tt)
AA = np.tile(ca,np.array([len(tt),1]))
EE = np.tile(ce,np.array([len(tt),1]))
xx = ((c*TT)**2 - D**2)/(2*(c*TT - D*np.cos(PP*np.pi/180)))*np.cos(AA*np.pi/180)*np.cos(EE*np.pi/180)
yy = ((c*TT)**2 - D**2)/(2*(c*TT - D*np.cos(PP*np.pi/180)))*np.sin(AA*np.pi/180)*np.cos(EE*np.pi/180)
zz = ((c*TT)**2 - D**2)/(2*(c*TT - D*np.cos(PP*np.pi/180)))*np.sin(EE*np.pi/180)
for jj in range(nAngle):
for kk in range(len(tt)):
npts[jj,kk,:] = rotMat('z',rxAz)@rotMat('y',-rxEl)@np.array([xx[kk,jj], yy[kk,jj],zz[kk,jj]])+txPos
return npts
def freq2vel(df,xx,yy,zz,rxPos,txPos,_lambda):
if np.all(np.isclose(rxPos,txPos)):
vv = df*_lambda/2
else:
txVecs = np.zeros(xx.shape+(3,))
txVecs[:,:,0] = -xx
txVecs[:,:,1] = -yy
txVecs[:,:,2] = -zz
rxVecs = txVecs + np.tile(np.transpose(rxPos),np.array(xx.shape+(1,)))
txNorm = np.sqrt(np.sum(txVecs**2,axis=2))
rxNorm = np.sqrt(np.sum(rxVecs**2,axis=2))
beta = np.arccos(np.sum(rxVecs*txVecs,axis=2)/(rxNorm*txNorm))
vv = _lambda*df/(2*np.cos(beta/2))
return vv
def map_to_grid(x,y,z,data, grid_shape, grid_limits, grid_origin=None,
grid_origin_alt=None, grid_projection=None,
fields=None, gatefilters=False,
map_roi=True, weighting_function='Barnes2', toa=17000.0,
copy_field_data=True, algorithm='kd_tree', leafsize=10.,
roi_func='dist_beam_bistatic', constant_roi=None,
z_factor=0.05, xy_factor=0.02, min_radius=500.0,
h_factor=1.0, nb=1.5, bsp=1.0, rxPos=np.array([0,0,0]), **kwargs):
"""
Map one or more radars to a Cartesian grid.
Generate a Cartesian grid of points for the requested fields from the
collected points from one or more radars. The field value for a grid
point is found by interpolating from the collected points within a given
radius of influence and weighting these nearby points according to their
distance from the grid points. Collected points are filtered
according to a number of criteria so that undesired points are not
included in the interpolation.
Parameters
----------
x : 2D or 3D array
Array of x coordinates
y : 2D or 3D array
Array of y coordinates
z : 2D or 3D array
Array of z coordinates
data : 2D or 3D array
Moment data to be interpolated
grid_shape : 3-tuple of floats
Number of points in the grid (z, y, x).
grid_limits : 3-tuple of 2-tuples
Minimum and maximum grid location (inclusive) in meters for the
z, y, x coordinates.
grid_origin : (float, float) or None
Latitude and longitude of grid origin. None sets the origin
to the native coordinate origin.
grid_origin_alt: float or None
Altitude of grid origin, in meters. None sets the origin
to the native coordinate origin.
grid_projection : dict
Projection parameters defining the map projection used to transform the
locations of the radar gates in geographic coordinate to Cartesian
coodinates. None will use the default dictionary which uses a native
azimutal equidistance projection. See :py:func:`pyart.core.Grid` for
additional details on this parameter. The geographic coordinates of
the radar gates are calculated using the projection defined for each
radar. No transformation is used if a grid_origin and grid_origin_alt
are None and a single radar is specified.
fields : list or None
List of fields within the radar objects which will be mapped to
the cartesian grid. None, the default, will map the fields which are
present in all the radar objects.
gatefilters : GateFilter, tuple of GateFilter objects, optional
Specify what gates from each radar will be included in the
interpolation onto the grid. Only gates specified in each gatefilters
will be included in the mapping to the grid. A single GateFilter can
be used if a single Radar is being mapped. A value of False for a
specific element or the entire parameter will apply no filtering of
gates for a specific radar or all radars (the default).
Similarily a value of None will create a GateFilter from the
radar moments using any additional arguments by passing them to
:py:func:`moment_based_gate_filter`.
roi_func : str or function
Radius of influence function. A functions which takes an
z, y, x grid location, in meters, and returns a radius (in meters)
within which all collected points will be included in the weighting
for that grid points. Examples can be found in the
:py:func:`example_roi_func_constant`,
:py:func:`example_roi_func_dist`, and
:py:func:`example_roi_func_dist_beam`.
Alternatively the following strings can use to specify a built in
radius of influence function:
* constant: constant radius of influence.
* dist: radius grows with the distance from each radar.
* dist_beam: radius grows with the distance from each radar
and parameter are based of virtual beam sizes.
The parameters which control these functions are listed in the
`Other Parameters` section below.
map_roi : bool
True to include a radius of influence field in the returned
dictionary under the 'ROI' key. This is the value of roi_func at all
grid points.
weighting_function : 'Barnes' or 'Barnes2' or 'Cressman' or 'Nearest'
Functions used to weight nearby collected points when interpolating a
grid point.
toa : float
Top of atmosphere in meters. Collected points above this height are
not included in the interpolation.
Other Parameters
----------------
constant_roi : float
Radius of influence parameter for the built in 'constant' function.
This parameter is the constant radius in meter for all grid points.
This parameter is used when `roi_func` is `constant` or constant_roi
is not None. If constant_roi is not None, the constant roi_func is
used automatically.
z_factor, xy_factor, min_radius : float
Radius of influence parameters for the built in 'dist' function.
The parameter correspond to the radius size increase, in meters,
per meter increase in the z-dimension from the nearest radar,
the same foreach meteter in the xy-distance from the nearest radar,
and the minimum radius of influence in meters. These parameters are
only used when `roi_func` is 'dist'.
h_factor, nb, bsp, min_radius : float
Radius of influence parameters for the built in 'dist_beam' function.
The parameter correspond to the height scaling, virtual beam width,
virtual beam spacing, and minimum radius of influence. These
parameters are only used when `roi_func` is 'dist_mean'.
copy_field_data : bool
True to copy the data within the radar fields for faster gridding,
the dtype for all fields in the grid will be float64. False will not
copy the data which preserves the dtype of the fields in the grid,
may use less memory but results in significantly slower gridding
times. When False gates which are masked in a particular field but
are not masked in the `refl_field` field will still be included in
the interpolation. This can be prevented by setting this parameter
to True or by gridding each field individually setting the
`refl_field` parameter and the `fields` parameter to the field in
question. It is recommended to set this parameter to True.
algorithm : 'kd_tree'.
Algorithms to use for finding the nearest neighbors. 'kd_tree' is the
only valid option.
leafsize : int
Leaf size passed to the neighbor lookup tree. This can affect the
speed of the construction and query, as well as the memory required
to store the tree. The optimal value depends on the nature of the
problem. This value should only effect the speed of the gridding,
not the results.
Returns
-------
grids : dict
Dictionary of mapped fields. The keys of the dictionary are given by
parameter fields. Each elements is a `grid_size` float64 array
containing the interpolated grid for that field.
"""
# check the parameters
if weighting_function.upper() not in [
'CRESSMAN', 'BARNES2', 'BARNES', 'NEAREST']:
raise ValueError('unknown weighting_function')
if algorithm not in ['kd_tree']:
raise ValueError('unknown algorithm: %s' % algorithm)
badval = -9999.0
count = 0
# determine the number of gates (collected points)
total_gates = data.size
data = np.ma.masked_invalid(data)
# create arrays to hold the gate locations and indicators if the gate
# should be included in the interpolation.
gate_locations = np.ma.empty((total_gates, 3), dtype=np.float64)
include_gate = np.ones((total_gates), dtype=np.bool)
offsets = [] # offsets from the grid origin, in meters, for each radar
# create a field lookup tables
field_data = np.ma.empty((total_gates), dtype=np.float64)
# calculate cartesian locations of gates
xg_loc = x
yg_loc = y
zg_loc = z
# add gate locations to gate_locations array
gate_locations[:,0] = zg_loc.flatten()
gate_locations[:,1] = yg_loc.flatten()
gate_locations[:,2] = xg_loc.flatten()
del xg_loc, yg_loc
# determine which gates should be included in the interpolation
gflags = zg_loc < toa # include only those below toa
include_gate = gflags.flatten()
del gflags, zg_loc
# copy/store references to field data for lookup
field_data = data.ravel()
# build field data lookup tables
filtered_field_data = field_data[include_gate]
# populate the nearest neighbor locator with the filtered gate locations
nnlocator = NNLocator(gate_locations[include_gate], algorithm=algorithm,
leafsize=leafsize)
# unpack the grid parameters
nz, ny, nx = grid_shape
zr, yr, xr = grid_limits
z_start, z_stop = zr
y_start, y_stop = yr
x_start, x_stop = xr
if nz == 1:
z_step = 0.
else:
z_step = (z_stop - z_start) / (nz - 1.)
if ny == 1:
y_step = 0.
else:
y_step = (y_stop - y_start) / (ny - 1.)
if nx == 1:
x_step = 0.
else:
x_step = (x_stop - x_start) / (nx - 1.)
if not hasattr(roi_func, '__call__'):
if constant_roi is not None:
roi_func = 'constant'
else:
constant_roi = 1000.0
if roi_func == 'constant':
roi_func = _gen_roi_func_constant(constant_roi)
elif roi_func == 'dist':
roi_func = _gen_roi_func_dist(
z_factor, xy_factor, min_radius, (0,0,0))
elif roi_func == 'dist_beam':
roi_func = _gen_roi_func_dist_beam(
h_factor, nb, bsp, min_radius, (0,0,0))
elif roi_func == 'dist_beam_bistatic':
roi_func = _gen_roi_func_dist_beam_bistatic(
h_factor, nb, bsp, min_radius, rxPos, (0,0,0))
else:
raise ValueError('unknown roi_func: %s' % roi_func)
# create array to hold interpolated grid data and roi if requested
grid_data = np.ma.empty((nz, ny, nx), dtype=np.float64)
grid_data.set_fill_value(badval)
if map_roi:
roi = np.empty((nz, ny, nx), dtype=np.float64)
# interpolate field values for each point in the grid
for iz, iy, ix in np.ndindex(nz, ny, nx):
# calculate the grid point
x = x_start + x_step * ix
y = y_start + y_step * iy
z = z_start + z_step * iz
r = roi_func(z, y, x)
if map_roi:
roi[iz, iy, ix] = r
# find neighbors and distances
ind, dist = nnlocator.find_neighbors_and_dists((z, y, x), r)
if len(ind) == 0:
# when there are no neighbors, mark the grid point as bad
grid_data[iz, iy, ix] = np.ma.masked
grid_data.data[iz, iy, ix] = badval
count += 1
continue
# find the field values for all neighbors
nn_field_data = filtered_field_data[ind]
# preforms weighting of neighbors.
dist2 = dist * dist
r2 = r * r
if weighting_function.upper() == 'NEAREST':
value = nn_field_data[np.argmin(dist2)]
else:
if weighting_function.upper() == 'CRESSMAN':
weights = (r2 - dist2) / (r2 + dist2)
weights = np.exp(-dist2 / (2.0 * r2)) + 1e-5
value = np.ma.average(nn_field_data, weights=weights, axis=0)
elif weighting_function.upper() == 'BARNES2':
kappa = 3.4e-1
gamma = 0.1
weights = np.exp(-dist2 / (r2*kappa)) + 1e-5
value = np.ma.average(nn_field_data, weights=weights, axis=0)
weights = np.exp(-dist2 / (r2*kappa*gamma)) + 1e-5
value = value + np.ma.average(nn_field_data-value, weights=weights, axis=0)
grid_data[iz, iy, ix] = value
# create and return the grid dictionary
grids = {}
grids['data'] = grid_data
if map_roi:
grids['ROI'] = roi
return grids
def example_roi_func_constant(zg, yg, xg):
"""
Example RoI function which returns a constant radius.
Parameters
----------
zg, yg, xg : float
Distance from the grid center in meters for the x, y and z axes.
Returns
-------
roi : float
Radius of influence in meters
"""
# RoI function parameters
constant = 500. # constant 500 meter RoI
return constant
def _gen_roi_func_constant(constant_roi):
"""
Return a RoI function which returns a constant radius.
See :py:func:`map_to_grid` for a description of the parameters.
"""
def roi(zg, yg, xg):
""" constant radius of influence function. """
return constant_roi
return roi
def example_roi_func_dist(zg, yg, xg):
"""
Example RoI function which returns a radius which grows with distance.
Parameters
----------
zg, yg, xg : float
Distance from the grid center in meters for the x, y and z axes.
Returns
-------
roi : float
"""
# RoI function parameters
z_factor = 0.05 # increase in radius per meter increase in z dim
xy_factor = 0.02 # increase in radius per meter increase in xy dim
min_radius = 500. # minimum radius
offsets = ((0, 0, 0), ) # z, y, x offset of grid in meters from radar(s)
offsets = np.array(offsets)
zg_off = offsets[:, 0]
yg_off = offsets[:, 1]
xg_off = offsets[:, 2]
r = np.maximum(z_factor * (zg - zg_off) +
xy_factor * np.sqrt((xg - xg_off)**2 + (yg - yg_off)**2),
min_radius)
return min(r)
def _gen_roi_func_dist(z_factor, xy_factor, min_radius, offsets):
"""
Return a RoI function whose radius grows with distance.
See :py:func:`map_to_grid` for a description of the parameters.
"""
def roi(zg, yg, xg):
""" dist radius of influence function. """
r = np.maximum(
z_factor * zg +
xy_factor * np.sqrt(xg**2 + yg**2),
min_radius)
return min(r)
return roi
def example_roi_func_dist_beam(zg, yg, xg):
"""
Example RoI function which returns a radius which grows with distance
and whose parameters are based on virtual beam size.
Parameters
----------
zg, yg, xg : float
Distance from the grid center in meters for the x, y and z axes.
Returns
-------
roi : float
"""
# RoI function parameters
h_factor = 1.0 # height scaling
nb = 1.5 # virtual beam width
bsp = 1.0 # virtual beam spacing
min_radius = 500. # minimum radius in meters
r = np.maximum(
h_factor * (zg / 20.0) +
np.sqrt(yg**2 + xg**2) *
np.tan(nb * bsp * np.pi / 180.0), min_radius)
return min(r)
def _gen_roi_func_dist_beam(h_factor, nb, bsp, min_radius, offsets):
"""
Return a RoI function whose radius which grows with distance
and whose parameters are based on virtual beam size.
See :py:func:`map_to_grid` for a description of the parameters.
"""
def roi(zg, yg, xg):
""" dist_beam radius of influence function. """
r = np.maximum(
h_factor * (zg / 20.0) +
np.sqrt(yg**2 + xg**2) *
np.tan(nb * bsp * np.pi / 180.0), min_radius)
return r
return roi
def _gen_roi_func_dist_beam_bistatic(h_factor, nb, bsp, min_radius, rxPos, offsets):
"""
Return a RoI function whose radius which grows with distance
and whose parameters are based on virtual beam size.
See :py:func:`map_to_grid` for a description of the parameters.
"""
def roi(zg, yg, xg):
""" dist_beam radius of influence function. """
ba = getBa1(xg,yg,zg,rxPos)
r = np.maximum(
h_factor * (zg / 20.0) +
np.sqrt(yg**2 + xg**2) *
np.tan(nb * bsp * np.pi / 180.0)*1/(2*np.cos(np.pi/180*ba/2)), min_radius)
return r
return roi
def rotMat(axis,angle):
R = np.zeros((3,3))
if axis == 'x':
R[0,0] = 1;
R[1,1] = np.cos(angle)
R[1,2] = -np.sin(angle)
R[2,1] = np.sin(angle)
R[2,2] = np.cos(angle)
elif axis == 'y':
R[0,0] = np.cos(angle)
R[0,2] = np.sin(angle)
R[1,1] = 1
R[2,0] = -np.sin(angle)
R[2,2] = np.cos(angle)
elif axis == 'z':
R[0,0] = np.cos(angle)
R[0,1] = -np.sin(angle)
R[1,0] = np.sin(angle)
R[1,1] = np.cos(angle)
R[2,2] = 1
return R
def getBa(xx,yy,zz,rxPos):
txVecs = np.zeros(xx.shape + (3,))
txVecs[:,:,0] = -xx
txVecs[:,:,1] = -yy
txVecs[:,:,2] = -zz
rxVecs = txVecs + np.tile(rxPos[np.newaxis,:],xx.shape+(1,))
txDist = np.sqrt(np.sum(txVecs**2,axis=2))
rxDist = np.sqrt(np.sum(rxVecs**2,axis=2))
beta = np.arccos(np.sum(rxVecs*txVecs,axis=2)/(rxDist*txDist))*180/np.pi
return beta
def getBa1(xx,yy,zz,rxPos):
txVec = np.array([-xx,-yy,zz])
rxVec = txVec + rxPos
txDist = np.sqrt(np.sum(txVec**2))
rxDist = np.sqrt(np.sum(rxVec**2))
beta = np.arccos(np.sum(rxVec*txVec)/(rxDist*txDist))*180/np.pi
return beta
def gridMoments(xx,yy,zz,vpp,vels,roiLimsX,roiLimsY,roiLimsZ,nx,ny,nz):
nRx = len(vpp)
refgrids = np.ma.ones((nRx,nz,ny,nx))
velgrids = np.ma.ones((nRx,nz,ny,nx))
for i in range(nRx):
# hpp[i][snr[i] < snrThresh] = np.nan
# vpp[i][snr[i] < snrThresh] = np.nan
# for j in range(vpp[0].shape[1]):
# ba = getBa(xx[i][:,j,:],yy[i][:,j,:],zz[i][:,j,:],rxPos2[:,i])
# msk = np.logical_or(ba < betaThresh[0], ba > betaThresh[1])
# vpp[i][:,j,:][msk] = np.nan
# vels[i][:,j,:][msk] = np.nan
print('Gridding Power')
if i == nRx - 1:
grid = map_to_grid(xx[i],yy[i],zz[i],vpp[i],(nz,ny,nx),(roiLimsZ,roiLimsY,roiLimsX),weighting_function='Cressman',roi_func='dist_beam',h_factor=0.5,nb=1,bsp=1,min_radius=res*2)
else:
grid = map_to_grid(xx[i],yy[i],zz[i],vpp[i],(nz,ny,nx),(roiLimsZ,roiLimsY,roiLimsX),weighting_function='Cressman',roi_func='dist_beam_bistatic',h_factor=0.5,nb=1,bsp=1,rxPos=rxPos2[:,i],min_radius=res*2)
refgrids[i,:,:,:] = grid['data']
print('Gridding Velocity')
if i == nRx - 1:
grid = map_to_grid(xx[i],yy[i],zz[i],vels[i],(nz,ny,nx),(roiLimsZ,roiLimsY,roiLimsX),weighting_function='Cressman',roi_func='dist_beam',h_factor=0.5,nb=1,bsp=1,min_radius=res*2)
else:
grid = map_to_grid(xx[i],yy[i],zz[i],vels[i],(nz,ny,nx),(roiLimsZ,roiLimsY,roiLimsX),weighting_function='Cressman',roi_func='dist_beam_bistatic',h_factor=0.5,nb=1,bsp=1,rxPos=rxPos2[:,i],min_radius=res*2)
velgrids[i,:,:,:] = grid['data']
return refgrids,velgrids
def convertGrids(refgrids,velgrids,xq,yq,zq,rxPos,rxc,ryc):
grids = []
for i in range(refgrids.shape[0]):
time = pyart.config.get_metadata('grid_time')
time['data'] = 0
x = pyart.config.get_metadata('x')
x['data'] = xq
y = pyart.config.get_metadata('y')
y['data'] = yq
z = pyart.config.get_metadata('z')
z['data'] = zq
origin_latitude = pyart.config.get_metadata('origin_latitude')
origin_latitude['data'] = np.array([35.1812+ryc/1000*0.008979])
origin_longitude = pyart.config.get_metadata('origin_longitude')
origin_longitude['data'] = np.array([-97.4368+rxc/1000*0.0109045])
origin_altitude = pyart.config.get_metadata('origin_altitude')
radar_latitude = pyart.config.get_metadata('radar_latitude')
radar_latitude['data'] = np.array([35.1812+rxPos[1,i]/1000*0.008979])
radar_longitude = pyart.config.get_metadata('radar_longitude')
radar_longitude['data'] = np.array([-97.4368+rxPos[0,i]/1000*0.0109045])
radar_altitude = pyart.config.get_metadata('radar_altitude')
radar_altitude['data'] = np.array([rxPos[2,i]])
radar_time = pyart.config.get_metadata('radar_time')
radar_time['data'] = np.array([0])
radar_name = pyart.config.get_metadata('radar_name')
radar_name['data'] = np.array(['nope'+str(i)])
metadata = pyart.config.get_metadata('metadata')
fields = {}
fields['reflectivity'] = pyart.config.get_metadata('reflectivity')
fields['reflectivity']['data'] = np.ma.masked_invalid(refgrids[i,:,:,:])
fields['reflectivity']['_FillValue'] = -32768
fields['corrected_velocity'] = pyart.config.get_metadata('velocity')
fields['corrected_velocity']['data'] = np.ma.masked_invalid(velgrids[i,:,:,:])
g = pyart.core.Grid(time, fields, metadata,
origin_latitude, origin_longitude, origin_altitude, x, y, z,
radar_latitude=radar_latitude, radar_longitude=radar_longitude,
radar_altitude=radar_altitude, radar_name=radar_name,
radar_time=radar_time, projection=None)
grids.append(g)
return grids
def multiDop(xq,yq,zq,rxPos2,refgrids,velgrids,numRad,a,b,c):
uu = -999*np.ones((nz,ny,nx))
vv = -999*np.ones((nz,ny,nx))
ww = -999*np.ones((nz,ny,nx))
nRx = refgrids.shape[0]
for j in range(nz):
ptPos = np.stack((xq[j,:,:],yq[j,:,:],zq[j,:,:]))
gPts = ptPos[np.newaxis,:,:,:]-rxPos2.T[:,:,np.newaxis,np.newaxis]
az = np.pi/2 - np.arctan2(gPts[:,1,:],gPts[:,0,:])
dist = np.sqrt(np.sum(gPts**2,axis=1))
el = np.arcsin(gPts[:,2,:]/dist)
beta = np.arccos(np.cos(el[:-1,:,:])*np.cos(el[-1,:,:])*np.cos(az[:-1,:,:]-az[-1,:,:]) + np.sin(el[:-1,:])*np.sin(el[-1,:,:]))
ptPos = np.stack((xq[j,:,:].flatten(),yq[j,:,:].flatten(),zq[j,:,:].flatten()))
br = np.reshape(np.sqrt(np.sum((ptPos)**2,axis=0)) + np.sqrt(np.sum((ptPos[:,np.newaxis,:]-rxPos2[:,:-1,np.newaxis])**2,axis=0)),beta.shape)
sigma = (1/np.tan(beta/2)+np.tan(beta/2))**2+1/np.tan(beta/2)
Pr = 0.00025*(100000-br)
R = 0.5*np.cos(beta/2)**2
# qualI =(np.exp((np.pi/2-beta)**2/(np.pi**2))-1)*br
qualI = a*Pr+b*R+c*sigma
qualmsk = qualI < 0
qualmsk = np.all(qualmsk,axis=0)
pwrmsk = np.sum(np.isnan(refgrids[:,j,:,:]),axis=0)> 1#,np.nanvar(np.log10(refgrids[:,j,:,:]),axis=0) > 2)
pwrmsk = pwrmsk | qualmsk
npts = np.sum(~pwrmsk)
VR = np.zeros((nRx,1,npts))
UV = np.zeros((3,1,npts))
MMinv = np.zeros((nRx,3,npts))
ptPos = np.stack((xq[j,~pwrmsk],yq[j,~pwrmsk],zq[j,~pwrmsk]))
#ptPos = np.stack((xq,yq,zq))
gPts = ptPos[np.newaxis,:,:]-rxPos2.T[:,:,np.newaxis]
#rilPts = ptPos - rilPos[:,np.newaxis,np.newaxis]
#hscPts = ptPos - hscPos[:,np.newaxis,np.newaxis]
az = np.pi/2 - np.arctan2(gPts[:,1,:],gPts[:,0,:])
dist = np.sqrt(np.sum(gPts**2,axis=1))
el = np.arcsin(gPts[:,2,:]/dist)
beta = np.arccos(np.cos(el[:-1,:])*np.cos(el[-1,:])*np.cos(az[:-1,:]-az[-1,:]) + np.sin(el[:-1,:])*np.sin(el[-1,:]))
#MMinv[0,:,:] = np.stack(((np.sin(rilAz)*np.cos(rilEl) + np.sin(ktlxAz)*np.cos(ktlxEl))/(2*np.cos(rilBeta/2)), (np.cos(rilAz)*np.cos(rilEl) + np.cos(ktlxAz)*np.cos(ktlxEl))/(2*np.cos(rilBeta/2)), (np.sin(rilEl)+np.sin(ktlxEl))/(2*np.cos(rilBeta/2))))
for i in range(nRx-1):
MMinv[i,:,:] = np.stack(((np.sin(az[i,:])*np.cos(el[i,:]) + np.sin(az[-1,:])*np.cos(el[-1,:]))/(2*np.cos(beta[i,:]/2)),
(np.cos(az[i,:])*np.cos(el[i,:]) + np.cos(az[-1,:])*np.cos(el[-1,:]))/(2*np.cos(beta[i,:]/2)),
(np.sin(el[i,:])+np.sin(el[-1,:]))/(2*np.cos(beta[i,:]/2))))
MMinv[-1,:,:] = np.stack((np.sin(az[-1,:])*np.cos(el[-1,:]),np.cos(az[-1,:])*np.cos(el[-1,:]),np.sin(el[-1,:])))
VR[:,0,:] = velgrids[:,j,~pwrmsk]
inds = np.vstack((np.argsort(qualI,axis=0)[:,~pwrmsk],(nRx-1)*np.ones(npts))).astype(int)
betaMsk = np.sum((beta > np.pi/6) & (beta < 5*np.pi/6),axis=0)+1
for ii in range(npts):
try:
num = np.min((numRad,betaMsk[ii]))
if num < 3:
UV[:,0,ii] = np.ones(3)*np.nan
else:
MM = np.linalg.lstsq(MMinv[inds[-num:,ii],:,ii],np.identity(num))[0]
UV[:,0,ii] = MM@VR[inds[-num:,ii],0,ii]
except:
UV[:,0,ii] = np.ones(3)*np.nan
uu[j,~pwrmsk] = np.squeeze(UV[0,0,:])
vv[j,~pwrmsk] = np.squeeze(UV[1,0,:])
ww[j,~pwrmsk] = np.squeeze(UV[2,0,:])
#refgrids[:,j,pwrmsk] = np.nan
inds = np.abs(np.sqrt(uu**2+vv**2)) > 60
uu[inds] = np.nan
vv[inds] = np.nan
ww[np.abs(ww) > 50] = np.nan
# rm = np.mean(10*np.log10(refgrids),axis=0)+145
# msk = rm < 22
# uu[msk] = np.nan
# vv[msk] = np.nan
# ww[msk] = np.nan
return uu,vv,ww
def interpWrf(xq,yq,zq,el):
os.chdir('/Users/semmerson/Documents/cm1r19.10/grinder')
#fh = Dataset('line.nc', 'r')
fh = Dataset('may20.nc', 'r')
XX = fh.variables['x'][:]
YY = fh.variables['y'][:]
ZZ = fh.variables['z'][:]
XX,YY,ZZ = np.meshgrid(XX,YY,ZZ)
UU = np.swapaxes(fh.variables['u'][:],0,1)
VV = np.swapaxes(fh.variables['v'][:],0,1)
WW = np.swapaxes(fh.variables['w'][:],0,1)
rref = np.swapaxes(fh.variables['reflectivity'][:],0,1)
fh.close()
xq = xq[el,:,:]
yq = yq[el,:,:]
zq = zq[el,:,:]
alts = zq
alts[alts >= np.max(ZZ)*1e3] = np.max(ZZ)*1e3-1
#alts[alts <= np.max(ZZ)*1e3] = np.min(ZZ)*1e3+1
# rgi = interpolate.RegularGridInterpolator((XX-wrfOffset[0]-txPos[0]/1000,YY-wrfOffset[1]-txPos[1]/1000,ZZ-wrfOffset[2]-txPos[2]/1000),UU)
# uinterp = np.reshape(rgi(np.array([xq.flatten(),yq.flatten(),alts.flatten()]).T),xq.shape)
# rgi = interpolate.RegularGridInterpolator((XX-wrfOffset[0]-txPos[0]/1000,YY-wrfOffset[1]-txPos[1]/1000,ZZ-wrfOffset[2]-txPos[2]/1000),VV)
# vinterp = np.reshape(rgi(np.array([xq.flatten(),yq.flatten(),alts.flatten()]).T),xq.shape)
# rgi = interpolate.RegularGridInterpolator((XX-wrfOffset[0]-txPos[0]/1000,YY-wrfOffset[1]-txPos[1]/1000,ZZ-wrfOffset[2]-txPos[2]/1000),WW)
# winterp = np.reshape(rgi(np.array([xq.flatten(),yq.flatten(),alts.flatten()]).T),xq.shape)
# rgi = interpolate.RegularGridInterpolator((XX-wrfOffset[0]-txPos[0]/1000,YY-wrfOffset[1]-txPos[1]/1000,ZZ-wrfOffset[2]-txPos[2]/1000),rref)
# zinterp = np.reshape(rgi(np.array([xq.flatten(),yq.flatten(),alts.flatten()]).T),xq.shape)
rgi = interpolate.RBFInterpolator(np.array((XX.ravel()-wrfOffset[0]-txPos[0]/1000,YY.ravel()-wrfOffset[1]-txPos[1]/1000,ZZ.ravel()-wrfOffset[2]-txPos[2]/1000)).T,UU.ravel(),neighbors=4,kernel='linear')
uinterp = np.reshape(rgi(np.array([xq.flatten(),yq.flatten(),alts.flatten()]).T),xq.shape)
rgi = interpolate.RBFInterpolator(np.array((XX.ravel()-wrfOffset[0]-txPos[0]/1000,YY.ravel()-wrfOffset[1]-txPos[1]/1000,ZZ.ravel()-wrfOffset[2]-txPos[2]/1000)).T,VV.ravel(),neighbors=4,kernel='linear')
vinterp = np.reshape(rgi(np.array([xq.flatten(),yq.flatten(),alts.flatten()]).T),xq.shape)
rgi = interpolate.RBFInterpolator(np.array((XX.ravel()-wrfOffset[0]-txPos[0]/1000,YY.ravel()-wrfOffset[1]-txPos[1]/1000,ZZ.ravel()-wrfOffset[2]-txPos[2]/1000)).T,WW.ravel(),neighbors=4,kernel='linear')
winterp = np.reshape(rgi(np.array([xq.flatten(),yq.flatten(),alts.flatten()]).T),xq.shape)
rgi = interpolate.RBFInterpolator(np.array((XX.ravel()-wrfOffset[0]-txPos[0]/1000,YY.ravel()-wrfOffset[1]-txPos[1]/1000,ZZ.ravel()-wrfOffset[2]-txPos[2]/1000)).T,rref.ravel(),neighbors=4,kernel='linear')
zinterp = np.reshape(rgi(np.array([xq.flatten(),yq.flatten(),alts.flatten()]).T),xq.shape)
# uinterp = 10*np.ones(xq.shape)
# vinterp = 10*np.ones(xq.shape)
# winterp = 1*np.ones(xq.shape)
# zinterp = np.ones(xq.shape)*40
# inds = np.logical_and(np.mod(np.round(xq),12) < 6,np.mod(np.round(yq),12) < 6)
# zinterp[inds] = 60
# uinterp[inds] = 20
# vinterp[inds] = 20
return uinterp,vinterp,winterp,zinterp
def verifyStats(uu,uinterp,vv,vinterp,ww,winterp,el):
msk = np.isnan(uu[el,:,:])
uinterp[0,0] += 1e-3
u_mae = np.nansum(np.abs(uu[el,:,:]-uinterp))/np.sum(~msk)
u_rmse = np.sqrt(np.nansum((uu[el,:,:]-uinterp)**2)/np.sum(~msk))
u_cc = np.corrcoef(np.stack((uinterp[~msk],uu[el,:,:][~msk])))[0,1]
u_pct = np.sum(~msk)/len(msk.flatten())
msk = np.isnan(vv[el,:,:])
vinterp[0,0] += 1e-3
v_mae = np.nansum(np.abs(vv[el,:,:]-vinterp))/np.sum(~msk)
v_rmse = np.sqrt(np.nansum((vv[el,:,:]-vinterp)**2)/np.sum(~msk))
v_cc = np.corrcoef(np.stack((vinterp[~msk],vv[el,:,:][~msk])))[0,1]
v_pct = np.sum(~msk)/len(msk.flatten())
msk = np.isnan(ww[el,:,:])
winterp[0,0] += 1e-3
w_mae = np.nansum(np.abs(ww[el,:,:]-winterp))/np.sum(~msk)
w_rmse = np.sqrt(np.nansum((ww[el,:,:]-winterp)**2)/np.sum(~msk))
w_cc = np.corrcoef(np.stack((winterp[~msk],ww[el,:,:][~msk])))[0,1]
w_pct = np.sum(~msk)/len(msk.flatten())
return np.array([u_mae,v_mae,w_mae]),np.array([u_rmse,v_rmse,w_rmse]),np.array([u_cc,v_cc,w_cc]),np.array([u_pct,v_pct,w_pct])
def plotMoments(x,y,xx,yy,vpp,vels,nRx,figsize):
if nRx > 5:
fig = plt.figure(figsize=figsize)
m = int(np.ceil(np.sqrt(nRx)))-1
n = int(np.ceil(nRx/m))
axs = fig.subplots(m,n).flatten()
for i in range(nRx-1):
pc = axs[i].pcolormesh(xx[i][:,el,:]/1000,yy[i][:,el,:]/1000,vels[i][:,el,:],vmin=-40,vmax=40,cmap='pyart_balance',shading='auto')
#ax.quiver(XX[::2,::2,1],YY[::2,::2,1],UU[::2,::2,1],VV[::2,::2,1],scale = 600)
axs[i].set_xlim(x)
axs[i].set_ylim(y)
axs[i].scatter(x=0,y=0,marker='x',color='k',s=100)
axs[i].scatter(x=rxPos2[0,i]/1000,y=rxPos2[1,i]/1000,marker='+',color='r',s=100)
if i == nRx-1:
axs[i].set_title('Tx Simulated Radial Velocity')
else:
axs[i].set_title('Rx '+ str(i+1) +' Simulated Bistatic Velocity')
axs[i].set_xlabel('Zonal Distance from Tx Radar (km)')
axs[i].set_ylabel('Meridional Distance from Tx Radar (km)')
plt.tight_layout()
fig.subplots_adjust(right=0.9)
cbar_ax = fig.add_axes([0.92, 0.05, 0.02, 0.92])
cb = fig.colorbar(pc, cax=cbar_ax)
cb.set_label('Bistatic Velocity (m/s)')
# for ax in fig.get_axes():
# ax.label_outer()
fig = plt.figure(figsize=figsize)
axs = fig.subplots(m,n).flatten()
for i in range(nRx-1):
rFact = (rxPos2[0,i]-xx[i][:,el,:])**2+(rxPos2[1,i]-yy[i][:,el,:])**2++(rxPos2[2,i]-zz[i][:,el,:])**2
pc = axs[i].pcolormesh(xx[i][:,el,:]/1000,yy[i][:,el,:]/1000,10*np.log10(vpp[i][:,el,:]*rFact)+45,vmin=-30,vmax=90,cmap=z_cmap)
#pc = axs[i].pcolormesh(xx[i][:,el,:]/1000,yy[i][:,el,:]/1000,10*np.log10(snr[i][:,el,:]),vmin=-10,vmax=60,cmap='pyart_HomeyerRainbow')
axs[i].set_xlim(x)
axs[i].set_ylim(y)
axs[i].scatter(x=0,y=0,marker='x',color='k',s=100)
axs[i].scatter(x=rxPos2[0,i]/1000,y=rxPos2[1,i]/1000,marker='+',color='r',s=100)
if i == nRx-1:
axs[i].set_title('Tx Simulated Range-Corrected Power')
else:
axs[i].set_title('Rx '+ str(i+1) +' Simulated Range-Corrected Power')
axs[i].set_xlabel('Zonal Distance from Tx Radar (km)')
axs[i].set_ylabel('Meridional Distance from Tx Radar (km)')
plt.tight_layout()
fig.subplots_adjust(right=0.9)
cbar_ax = fig.add_axes([0.92, 0.05, 0.02, 0.92])
cb = fig.colorbar(pc, cax=cbar_ax)
cb.set_label('Range-Corrected Power (dB)')
# for ax in fig.get_axes():
# ax.label_outer()
else:
fig = plt.figure(figsize=figsize)
axs = fig.subplots(2,nRx)
# for ax in fig.get_axes():
# ax.set_aspect('equal')
for i in range(nRx):
# j = 0
rFact = (rxPos2[1,i]-yy[i][:,el,:])**2+(rxPos2[0,i]-xx[i][:,el,:])**2
# pc = axs[0,i].pcolormesh(xx[i][:,el,:]/1000,yy[i][:,el,:]/1000,10*np.log10(hpp[i][:,el,:]*rFact)+45,vmin=-30,vmax=90,cmap=z_cmap)
# axs[0,i].scatter(x=0,y=0,marker='x',s=100)
# axs[0,i].scatter(x=rxPos2[0,i]/1000,y=rxPos2[1,i]/1000,marker='+',s=100)
# if i == nRx-1:
# axs[0,i].set_title('Tx Simulated Horiz. Range-Corrected Power')
# cb = plt.colorbar(pc,ax=axs[0,i])
# cb.set_label('Range-Corrected Power (dB)')
# else:
# axs[0,i].set_title('Rx '+ str(i+1) +' Horiz. Simulated Range-Corrected Power')
# axs[0,i].set_xlabel('Zonal Distance from Tx Radar (km)')
# axs[0,i].set_ylabel('Meridional Distance from Tx Radar (km)')
# axs[0,i].set_xlim(x)
# axs[0,i].set_ylim(y)
j = 0
ax = axs[j,i]
pc = ax.pcolormesh(xx[i][:,el,:]/1000,yy[i][:,el,:]/1000,10*np.log10(vpp[i][:,el,:]*rFact)+45,vmin=-4,vmax=90,cmap=z_cmap)
ax.scatter(x=0,y=0,marker='x',s=100)
ax.scatter(x=rxPos2[0,i]/1000,y=rxPos2[1,i]/1000,marker='+',s=100)
if i == nRx-1:
ax.set_title('Tx Simulated Vert. Range-Corrected Power')
cb = plt.colorbar(pc,ax=ax)
cb.set_label('Range-Corrected Power (dB)')
else:
ax.set_title('Rx '+ str(i+1) +' Vert. Simulated Range-Corrected Power')
ax.set_xlabel('Zonal Distance from Tx Radar (km)')
ax.set_ylabel('Meridional Distance from Tx Radar (km)')
ax.set_xlim(x)
ax.set_ylim(y)
# plt.tight_layout()
# pc = axs[j,i].pcolormesh(xx[i][:,el,:]/1000,yy[i][:,el,:]/1000,rhohv[i][:,el,:],vmin=0.5,vmax=1,cmap=cc_cmap)
# axs[j,i].scatter(x=0,y=0,marker='x',s=100)
# axs[j,i].scatter(x=rxPos2[0,i]/1000,y=rxPos2[1,i]/1000,marker='+',s=100)
# if i == nRx-1:
# axs[j,i].set_title('Tx Simulated Vert. Range-Corrected Power')
# cb = plt.colorbar(pc,ax=axs[j,i])
# cb.set_label('Range-Corrected Power (dB)')
# else:
# axs[j,i].set_title('Rx '+ str(i+1) +' Vert. Simulated Range-Corrected Power')
# axs[j,i].set_xlabel('Zonal Distance from Tx Radar (km)')
# axs[j,i].set_ylabel('Meridional Distance from Tx Radar (km)')
# axs[j,i].set_xlim(x)
# axs[j,i].set_ylim(y)
j=1
ax = axs[j,i]
pc = ax.pcolormesh(xx[i][:,el,:]/1000,yy[i][:,el,:]/1000,vels[i][:,el,:],vmin=-100,vmax=100,cmap=v_cmap,shading='auto')
#ax.quiver(XX[::2,::2,1],YY[::2,::2,1],UU[::2,::2,1],VV[::2,::2,1],scale = 600)
ax.set_xlim(x)
ax.set_ylim(y)
ax.scatter(x=0,y=0,marker='x',s=100)
ax.scatter(x=rxPos2[0,i]/1000,y=rxPos2[1,i]/1000,marker='+',s=100)
if i == nRx-1:
ax.set_title('Tx Simulated Radial Velocity')
cb = plt.colorbar(pc,ax=ax)
cb.set_label('Bistatic Velocity (m/s)')
else:
ax.set_title('Rx '+ str(i+1) +' Simulated Bistatic Velocity')
# rFact = (rxPos2[1,i]-yy[i][:,el,:])**2+(rxPos2[0,i]-xx[i][:,el,:])**2
# pc = ax.pcolormesh(xx[i][:,el,:]/1000,yy[i][:,el,:]/1000,10*np.log10(hpp[i][:,el,:]/vpp[i][:,el,:]),vmin=-6,vmax=6,cmap=z_cmap)
# ax.scatter(x=0,y=0,marker='x',s=100)
# ax.scatter(x=rxPos2[0,i]/1000,y=rxPos2[1,i]/1000,marker='+',s=100)
# if i == nRx-1:
# ax.set_title('Tx Simulated Differential Range-Corrected Power')
# cb = plt.colorbar(pc,ax=ax)
# cb.set_label('Diff. Range-Corrected Power (dB)')
# else:
# ax.set_title('Rx '+ str(i+1) +' Differential Simulated Range-Corrected Power')
# ax.set_xlabel('Zonal Distance from Tx Radar (km)')
# ax.set_ylabel('Meridional Distance from Tx Radar (km)')
# ax.set_xlim(x)
# ax.set_ylim(y)
ax.label_outer()
plt.tight_layout()
def plotMultiDop(x,y,xc,yc,xq,yq,zq,uu,vv,ww,uinterp,vinterp,winterp,el,rxPos2,rmse):
fig = plt.figure(figsize=(16,10))
ax=fig.add_subplot(231)
pc = ax.pcolormesh(xq[el,:,:]/1000,yq[el,:,:]/1000,uinterp,vmin=-50,vmax=50,cmap='pyart_balance',shading='auto')
cb = plt.colorbar(pc,ax=ax)
cb.set_label('U Wind (m/s)')
ax.set_xlim(x)
ax.set_ylim(y)
ax.scatter(x=0,y=0,marker='x',color='k',s=100)
ax.scatter(x=rxPos2[0,:-1]/1000,y=rxPos2[1,:-1]/1000,marker='+',color='r',s=100)
ax.set_title('Model Input U Wind')
ax.set_xlabel('Zonal Distance from Tx Radar (km)')
ax.set_ylabel('Meridional Distance from Tx Radar (km)')
ax=fig.add_subplot(232)
pc = ax.pcolormesh(xq[el,:,:]/1000,yq[el,:,:]/1000,uu[el,:,:],vmin=-50,vmax=50,cmap='pyart_balance',shading='auto')
cb = plt.colorbar(pc,ax=ax)
cb.set_label('V Wind (m/s)')
ax.set_xlim(x)
ax.set_ylim(y)
ax.scatter(x=0,y=0,marker='x',color='k',s=100)
ax.scatter(x=rxPos2[0,:-1]/1000,y=rxPos2[1,:-1]/1000,marker='+',color='r',s=100)
ax.set_title('Retrieved U Wind')
ax.set_xlabel('Zonal Distance from Tx Radar (km)')
ax.set_ylabel('Meridional Distance from Tx Radar (km)')
ax=fig.add_subplot(233)
pc = ax.pcolormesh(xq[el,:,:]/1000,yq[el,:,:]/1000,uu[el,:,:]-uinterp,vmin=-10,vmax=10,cmap='pyart_balance',shading='auto')
cb = plt.colorbar(pc,ax=ax)
cb.set_label('U Wind Error (m/s)')
ax.set_xlim(x)
ax.set_ylim(y)
ax.scatter(x=0,y=0,marker='x',color='k',s=100)
ax.scatter(x=rxPos2[0,:-1]/1000,y=rxPos2[1,:-1]/1000,marker='+',color='r',s=100)
ax.set_title('Retrieved U Wind Error')
ax.set_xlabel('Zonal Distance from Tx Radar (km)')
ax.set_ylabel('Meridional Distance from Tx Radar (km)')
window = (x[1]-x[0])/2
ax.annotate(f'U MAE: {np.round(rmse[0],2)} m/s',(xc,yc-(window*1.35)),annotation_clip=False,ha='center')
#plt.tight_layout()
# #fig = plt.figure(figsize=(16,6))
ax=fig.add_subplot(234)
pc = ax.pcolormesh(xq[el,:,:]/1000,yq[el,:,:]/1000,vinterp,vmin=-50,vmax=50,cmap='pyart_balance',shading='auto')
cb = plt.colorbar(pc,ax=ax)
cb.set_label('V Wind (m/s)')
ax.set_xlim(x)
ax.set_ylim(y)
ax.scatter(x=0,y=0,marker='x',color='k',s=100)
ax.scatter(x=rxPos2[0,:-1]/1000,y=rxPos2[1,:-1]/1000,marker='+',color='r',s=100)
ax.set_title('Model Input V Wind')
ax.set_xlabel('Zonal Distance from Tx Radar (km)')
ax.set_ylabel('Meridional Distance from Tx Radar (km)')
ax=fig.add_subplot(235)
pc = ax.pcolormesh(xq[el,:,:]/1000,yq[el,:,:]/1000,vv[el,:,:],vmin=-50,vmax=50,cmap='pyart_balance',shading='auto')
cb = plt.colorbar(pc,ax=ax)
cb.set_label('V Wind (m/s)')
ax.set_xlim(x)
ax.set_ylim(y)
ax.scatter(x=0,y=0,marker='x',color='k',s=100)
ax.scatter(x=rxPos2[0,:-1]/1000,y=rxPos2[1,:-1]/1000,marker='+',color='r',s=100)
ax.set_title('Retrieved V Wind')
ax.set_xlabel('Zonal Distance from Tx Radar (km)')
ax.set_ylabel('Meridional Distance from Tx Radar (km)')
ax=fig.add_subplot(236)
pc = ax.pcolormesh(xq[el,:,:]/1000,yq[el,:,:]/1000,vv[el,:,:]-vinterp,vmin=-10,vmax=10,cmap='pyart_balance',shading='auto')
cb = plt.colorbar(pc,ax=ax)
cb.set_label('V Wind Error (m/s)')
ax.set_xlim(x)
ax.set_ylim(y)
ax.scatter(x=0,y=0,marker='x',color='k',s=100)
ax.scatter(x=rxPos2[0,:-1]/1000,y=rxPos2[1,:-1]/1000,marker='+',color='r',s=100)
ax.set_title('Retrieved V Wind Error')
ax.set_xlabel('Zonal Distance from Tx Radar (km)')
ax.set_ylabel('Meridional Distance from Tx Radar (km)')
ax.annotate(f'V MAE: {np.round(rmse[1],2)} m/s',(xc,yc-(window*1.35)),annotation_clip=False,ha='center')
plt.tight_layout()
fig = plt.figure(figsize=(16,6))
ax=fig.add_subplot(131)
pc = ax.pcolormesh(xq[el,:,:]/1000,yq[el,:,:]/1000,winterp,vmin=-50,vmax=50,cmap='pyart_balance',shading='auto')
cb = plt.colorbar(pc,ax=ax)
cb.set_label('W Wind (m/s)')
ax.set_xlim(x)
ax.set_ylim(y)
ax.scatter(x=0,y=0,marker='x',color='k',s=100)
ax.scatter(x=rxPos2[0,:-1]/1000,y=rxPos2[1,:-1]/1000,marker='+',color='r',s=100)
ax.set_title('Model Input W Wind')
ax.set_xlabel('Zonal Distance from Tx Radar (km)')
ax.set_ylabel('Meridional Distance from Tx Radar (km)')
ax=fig.add_subplot(132)
pc = ax.pcolormesh(xq[el,:,:]/1000,yq[el,:,:]/1000,ww[el,:,:],vmin=-50,vmax=50,cmap='pyart_balance',shading='auto')
cb = plt.colorbar(pc,ax=ax)
cb.set_label('W Wind (m/s)')
ax.set_xlim(x)
ax.set_ylim(y)
ax.scatter(x=0,y=0,marker='x',color='k',s=100)
ax.scatter(x=rxPos2[0,:-1]/1000,y=rxPos2[1,:-1]/1000,marker='+',color='r',s=100)
ax.set_title('Retrieved W Wind')
ax.set_xlabel('Zonal Distance from Tx Radar (km)')
ax.set_ylabel('Meridional Distance from Tx Radar (km)')
ax=fig.add_subplot(133)
pc = ax.pcolormesh(xq[el,:,:]/1000,yq[el,:,:]/1000,ww[el,:,:]-winterp,vmin=-10,vmax=10,cmap=v_cmap,shading='auto')
cb = plt.colorbar(pc,ax=ax)
cb.set_label('V Wind Error (m/s)')
ax.set_xlim(x)
ax.set_ylim(y)
ax.scatter(x=0,y=0,marker='x',color='k',s=100)
ax.scatter(x=rxPos2[0,:-1]/1000,y=rxPos2[1,:-1]/1000,marker='+',color='r',s=100)
ax.set_title('Retrieved W Wind Error')
ax.set_xlabel('Zonal Distance from Tx Radar (km)')