forked from knaughten/roms_tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mip_iceshelf_figures.py
1838 lines (1728 loc) · 80 KB
/
mip_iceshelf_figures.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
from netCDF4 import Dataset
from numpy import *
from numpy.ma import MaskedArray
from matplotlib.pyplot import *
from matplotlib.patches import Polygon, Rectangle
from matplotlib.collections import PatchCollection, LineCollection
from matplotlib.cm import *
from matplotlib.colors import LinearSegmentedColormap, ListedColormap
from matplotlib import rcParams
from rotate_vector_roms import *
from cartesian_grid_3d import *
from calc_z import *
from interp_lon_roms import *
# Import FESOM scripts (have to modify path first)
import sys
sys.path.insert(0, '/short/y99/kaa561/fesomtools')
from patches import *
from fesom_grid import *
from fesom_sidegrid import *
from unrotate_vector import *
from unrotate_grid import *
from in_triangle import *
# This is the giant monster script to generate 8 multi-part figures showing
# ice shelf processes in the 8 regions defined in the intercomparison paper.
# Each figure is size Nx3 where N=3,4,5 is the number of variables shown
# (current options are ice shelf melt rate, ice shelf draft, bottom water
# temperature or salinity, vertically averaged velocity, zonal slices of
# temperature and salinity) and 3 is the number of models (MetROMS, low-res
# FESOM, high-res FESOM). All variables are averaged over the period 2002-2016,
# i.e. the first 10 years of the simulation are discarded as spinup, and
# seasonal cycles and interannual variability are not considered.
# In order to avoid unnecessarily repetitive code, this script contains
# multiple functions which accept location bounds as arguments (eg to calculate
# min/max over the given region, to plot ice shelf draft over the given region
# for each model, etc.) but in order to prevent the function argument lists from
# getting out of control, most of the variables are global and so the majority
# of this script is not wrapped within a function. Be very careful if you are
# running this script in an active python session to make sure there are no
# conflicting variable names previously defined.
# To modify for your purposes, adjust the file paths (immediately below
# functions) as needed, and then scroll down to "USER MODIFIED SECTION" to see
# examples of how to call the functions to create multi-part figures. You will
# have to fiddle around with the x and y bounds, GridSpec arguments, colourbar
# axes, etc. so that the positioning looks okay.
# For the given variable in MetROMS, low-res FESOM, and high-res FESOM, find
# the max and min values across all 3 models in the given region.
# Input:
# roms_data = 2D field of data on the MetROMS grid (lat x lon)
# fesom_data_lr, fesom_data_hr = data for each 2D element on the FESOM low-res
# and high-res meshes respectively
# x_min, x_max, y_min, y_max = bounds on x and y (using polar coordinate
# transformation from above) for the desired region
# cavity = optional boolean indicating to only consider values in ice shelf
# cavities (default True)
# Output:
# var_min, var_max = min and max data values in this region across all 3 models
def get_min_max (roms_data, fesom_data_lr, fesom_data_hr, x_min, x_max, y_min, y_max, cavity=True):
# Start with ROMS
loc = (roms_x >= x_min)*(roms_x <= x_max)*(roms_y >= y_min)*(roms_y <= y_max)
var_min = amin(roms_data[loc])
var_max = amax(roms_data[loc])
# Modify with FESOM
# Low-res
i = 0
for elm in elements_lr:
if (not cavity) or (cavity and elm.cavity):
if any(elm.x >= x_min) and any(elm.x <= x_max) and any(elm.y >= y_min) and any(elm.y <= y_max):
if fesom_data_lr[i] < var_min:
var_min = fesom_data_lr[i]
if fesom_data_lr[i] > var_max:
var_max = fesom_data_lr[i]
i += 1
# High-res
i = 0
for elm in elements_hr:
if (not cavity) or (cavity and elm.cavity):
if any(elm.x >= x_min) and any(elm.x <= x_max) and any(elm.y >= y_min) and any(elm.y <= y_max):
if fesom_data_hr[i] < var_min:
var_min = fesom_data_hr[i]
if fesom_data_hr[i] > var_max:
var_max = fesom_data_hr[i]
i += 1
return var_min, var_max
# Interpolate FESOM's bathymetry to a regular grid in the given region so that
# we can contour isobaths later.
# Input:
# lon_min, lon_max = bounds on longitude for regular grid (-180 to 180)
# lat_min, lat_max = bounds on latitude (-90 to 90)
# Output:
# x_reg, y_reg = polar coordinates of regular grid for plotting
# fesom_bathy_reg_lr, fesom_bathy_reg_hr = bathymetry interpolated to the
# regular grid, from the low-res and high-res mesh
# respectively
def fesom_interpolate_bathy (lon_min, lon_max, lat_min, lat_max):
# Size of regular grid
num_lon = 500
num_lat = 500
# Set up regular grid
# Start with boundaries
lon_reg_edges = linspace(lon_min, lon_max, num_lon+1)
lat_reg_edges = linspace(lat_min, lat_max, num_lat+1)
# Now get centres
lon_reg = 0.5*(lon_reg_edges[:-1] + lon_reg_edges[1:])
lat_reg = 0.5*(lat_reg_edges[:-1] + lat_reg_edges[1:])
# Make 2D versions
lon_reg_2d, lat_reg_2d = meshgrid(lon_reg, lat_reg)
# Calculate polar coordinates transformation for plotting
x_reg = -(lat_reg_2d+90)*cos(lon_reg_2d*deg2rad+pi/2)
y_reg = (lat_reg_2d+90)*sin(lon_reg_2d*deg2rad+pi/2)
# Set up array for bathymetry on this regular grid, for each FESOM mesh
fesom_bathy_reg_lr = zeros([num_lat, num_lon])
fesom_bathy_reg_hr = zeros([num_lat, num_lon])
# Low-res
# For each element, check if a point on the regular lat-lon grid lies
# within. If so, do barycentric interpolation to that point, of bottom
# node depths (i.e. bathymetry).
for elm in elements_lr:
# Ignore ice shelf cavities
if not elm.cavity:
# Check if we are within domain of regular grid
if amax(elm.lon) > lon_min and amin(elm.lon) < lon_max and amax(elm.lat) > lat_min and amin(elm.lat) < lat_max:
# Find largest regular longitude value west of Element
tmp = nonzero(lon_reg > amin(elm.lon))[0]
if len(tmp) == 0:
# Element crosses the western boundary
iW = 0
else:
iW = tmp[0] - 1
# Find smallest regular longitude value east of Element
tmp = nonzero(lon_reg > amax(elm.lon))[0]
if len(tmp) == 0:
# Element crosses the eastern boundary
iE = num_lon
else:
iE = tmp[0]
# Find largest regular latitude value south of Element
tmp = nonzero(lat_reg > amin(elm.lat))[0]
if len(tmp) == 0:
# Element crosses the southern boundary
jS = 0
else:
jS = tmp[0] - 1
# Find smallest regular latitude value north of Element
tmp = nonzero(lat_reg > amax(elm.lat))[0]
if len(tmp) == 0:
# Element crosses the northern boundary
jN = num_lat
else:
jN = tmp[0]
for i in range(iW+1,iE):
for j in range(jS+1,jN):
# There is a chance that the regular gridpoint at (i,j)
# lies within this element
lon0 = lon_reg[i]
lat0 = lat_reg[j]
if in_triangle(elm, lon0, lat0):
# Yes it does
# Get area of entire triangle
area = triangle_area(elm.lon, elm.lat)
# Get area of each sub-triangle formed by
# (lon0, lat0)
area0 = triangle_area([lon0, elm.lon[1], elm.lon[2]], [lat0, elm.lat[1], elm.lat[2]])
area1 = triangle_area([lon0, elm.lon[0], elm.lon[2]], [lat0, elm.lat[0], elm.lat[2]])
area2 = triangle_area([lon0, elm.lon[0], elm.lon[1]], [lat0, elm.lat[0], elm.lat[1]])
# Find fractional area of each
cff = [area0/area, area1/area, area2/area]
# Find bottom depth of each node
bathy_vals = []
for n in range(3):
bathy_vals.append(elm.nodes[n].find_bottom().depth)
# Barycentric interpolation to lon0, lat0
fesom_bathy_reg_lr[j,i] = sum(array(cff)*array(bathy_vals))
# Mask out points which are identically zero (land and ice shelves)
fesom_bathy_reg_lr = ma.masked_where(fesom_bathy_reg_lr==0, fesom_bathy_reg_lr)
# Repeat for high-res
for elm in elements_hr:
if not elm.cavity:
if amax(elm.lon) > lon_min and amin(elm.lon) < lon_max and amax(elm.lat) > lat_min and amin(elm.lat) < lat_max:
tmp = nonzero(lon_reg > amin(elm.lon))[0]
if len(tmp) == 0:
iW = 0
else:
iW = tmp[0] - 1
tmp = nonzero(lon_reg > amax(elm.lon))[0]
if len(tmp) == 0:
iE = num_lon
else:
iE = tmp[0]
tmp = nonzero(lat_reg > amin(elm.lat))[0]
if len(tmp) == 0:
jS = 0
else:
jS = tmp[0] - 1
tmp = nonzero(lat_reg > amax(elm.lat))[0]
if len(tmp) == 0:
jN = num_lat
else:
jN = tmp[0]
for i in range(iW+1,iE):
for j in range(jS+1,jN):
lon0 = lon_reg[i]
lat0 = lat_reg[j]
if in_triangle(elm, lon0, lat0):
area = triangle_area(elm.lon, elm.lat)
area0 = triangle_area([lon0, elm.lon[1], elm.lon[2]], [lat0, elm.lat[1], elm.lat[2]])
area1 = triangle_area([lon0, elm.lon[0], elm.lon[2]], [lat0, elm.lat[0], elm.lat[2]])
area2 = triangle_area([lon0, elm.lon[0], elm.lon[1]], [lat0, elm.lat[0], elm.lat[1]])
cff = [area0/area, area1/area, area2/area]
bathy_vals = []
for n in range(3):
bathy_vals.append(elm.nodes[n].find_bottom().depth)
fesom_bathy_reg_hr[j,i] = sum(array(cff)*array(bathy_vals))
fesom_bathy_reg_hr = ma.masked_where(fesom_bathy_reg_hr==0, fesom_bathy_reg_hr)
return x_reg, y_reg, fesom_bathy_reg_lr, fesom_bathy_reg_hr
# Create a 2D vector field for vertically averaged velocity in MetROMS, low-res
# FESOM, and high-res FESOM for the given region. Average velocity over
# horizontal bins (in x and y) for easy plotting.
# Input:
# x_min, x_max, y_min, y_max = bounds on x and y (using polar coordinate
# transformation from above) for the desired region
# num_bins_x, num_bins_y = number of bins to use for x and y dimensions
# Output:
# x_centres, y_centres = 1D arrays of length num_bins containing x and y
# coordinates of the bin centres
# roms_ubin, roms_vbin = 2D arrays of size num_bins_y x num_bins_x containing
# vector components for MetROMS at each bin
# fesom_ubin_lr, fesom_vbin_lr = same for FESOM low-res
# fesom_ubin_hr, fesom_vbin_hr = same for FESOM high-res
def make_vectors (x_min, x_max, y_min, y_max, num_bins_x, num_bins_y):
# Set up bins (edges)
x_bins = linspace(x_min, x_max, num=num_bins_x+1)
y_bins = linspace(y_min, y_max, num=num_bins_y+1)
# Calculate centres of bins (for plotting)
x_centres = 0.5*(x_bins[:-1] + x_bins[1:])
y_centres = 0.5*(y_bins[:-1] + y_bins[1:])
# ROMS
# First set up arrays to integrate velocity in each bin
# Simple averaging of all the points inside each bin
roms_ubin = zeros([size(y_centres), size(x_centres)])
roms_vbin = zeros([size(y_centres), size(x_centres)])
roms_num_pts = zeros([size(y_centres), size(x_centres)])
# First convert to polar coordinates, rotate to account for
# longitude in circumpolar projection, and convert back to vector
# components
theta_roms = arctan2(roms_v, roms_u)
theta_circ_roms = theta_roms - roms_lon*deg2rad
u_circ_roms = roms_speed*cos(theta_circ_roms)
v_circ_roms = roms_speed*sin(theta_circ_roms)
# Loop over all points (can't find a better way to do this)
for j in range(size(roms_speed,0)):
for i in range(size(roms_speed,1)):
# Make sure data isn't masked (i.e. land)
if u_circ_roms[j,i] is not ma.masked:
# Check if we're in the region of interest
if roms_x[j,i] > x_min and roms_x[j,i] < x_max and roms_y[j,i] > y_min and roms_y[j,i] < y_max:
# Figure out which bins this falls into
x_index = nonzero(x_bins > roms_x[j,i])[0][0]-1
y_index = nonzero(y_bins > roms_y[j,i])[0][0]-1
# Integrate
roms_ubin[y_index, x_index] += u_circ_roms[j,i]
roms_vbin[y_index, x_index] += v_circ_roms[j,i]
roms_num_pts[y_index, x_index] += 1
# Convert from sums to averages
# First mask out points with no data
roms_ubin = ma.masked_where(roms_num_pts==0, roms_ubin)
roms_vbin = ma.masked_where(roms_num_pts==0, roms_vbin)
# Divide everything else by the number of points
flag = roms_num_pts > 0
roms_ubin[flag] = roms_ubin[flag]/roms_num_pts[flag]
roms_vbin[flag] = roms_vbin[flag]/roms_num_pts[flag]
# FESOM low-res
fesom_ubin_lr = zeros([size(y_centres), size(x_centres)])
fesom_vbin_lr = zeros([size(y_centres), size(x_centres)])
fesom_num_pts_lr = zeros([size(y_centres), size(x_centres)])
theta_fesom_lr = arctan2(node_v_lr, node_u_lr)
theta_circ_fesom_lr = theta_fesom_lr - fesom_lon_lr*deg2rad
u_circ_fesom_lr = node_speed_lr*cos(theta_circ_fesom_lr)
v_circ_fesom_lr = node_speed_lr*sin(theta_circ_fesom_lr)
# Loop over 2D nodes to fill in the velocity bins as before
for n in range(fesom_n2d_lr):
if fesom_x_lr[n] > x_min and fesom_x_lr[n] < x_max and fesom_y_lr[n] > y_min and fesom_y_lr[n] < y_max:
x_index = nonzero(x_bins > fesom_x_lr[n])[0][0]-1
y_index = nonzero(y_bins > fesom_y_lr[n])[0][0]-1
fesom_ubin_lr[y_index, x_index] += u_circ_fesom_lr[n]
fesom_vbin_lr[y_index, x_index] += v_circ_fesom_lr[n]
fesom_num_pts_lr[y_index, x_index] += 1
fesom_ubin_lr = ma.masked_where(fesom_num_pts_lr==0, fesom_ubin_lr)
fesom_vbin_lr = ma.masked_where(fesom_num_pts_lr==0, fesom_vbin_lr)
flag = fesom_num_pts_lr > 0
fesom_ubin_lr[flag] = fesom_ubin_lr[flag]/fesom_num_pts_lr[flag]
fesom_vbin_lr[flag] = fesom_vbin_lr[flag]/fesom_num_pts_lr[flag]
# FESOM high-res
fesom_ubin_hr = zeros([size(y_centres), size(x_centres)])
fesom_vbin_hr = zeros([size(y_centres), size(x_centres)])
fesom_num_pts_hr = zeros([size(y_centres), size(x_centres)])
theta_fesom_hr = arctan2(node_v_hr, node_u_hr)
theta_circ_fesom_hr = theta_fesom_hr - fesom_lon_hr*deg2rad
u_circ_fesom_hr = node_speed_hr*cos(theta_circ_fesom_hr)
v_circ_fesom_hr = node_speed_hr*sin(theta_circ_fesom_hr)
for n in range(fesom_n2d_hr):
if fesom_x_hr[n] > x_min and fesom_x_hr[n] < x_max and fesom_y_hr[n] > y_min and fesom_y_hr[n] < y_max:
x_index = nonzero(x_bins > fesom_x_hr[n])[0][0]-1
y_index = nonzero(y_bins > fesom_y_hr[n])[0][0]-1
fesom_ubin_hr[y_index, x_index] += u_circ_fesom_hr[n]
fesom_vbin_hr[y_index, x_index] += v_circ_fesom_hr[n]
fesom_num_pts_hr[y_index, x_index] += 1
fesom_ubin_hr = ma.masked_where(fesom_num_pts_hr==0, fesom_ubin_hr)
fesom_vbin_hr = ma.masked_where(fesom_num_pts_hr==0, fesom_vbin_hr)
flag = fesom_num_pts_hr > 0
fesom_ubin_hr[flag] = fesom_ubin_hr[flag]/fesom_num_pts_hr[flag]
fesom_vbin_hr[flag] = fesom_vbin_hr[flag]/fesom_num_pts_hr[flag]
return x_centres, y_centres, roms_ubin, roms_vbin, fesom_ubin_lr, fesom_vbin_lr, fesom_ubin_hr, fesom_vbin_hr
# Plot ice shelf draft for MetROMS, low-res FESOM, and high-res FESOM for the
# given region, in the given axes.
# Input:
# x_min, x_max, y_min, y_max = bounds on x and y (using polar coordinate
# transformation from above) for the desired region
# gs = GridSpec object of size 1x3 to plot in
# cbaxes = Axes object for location of colourbar
# cbar_ticks = 1D array containing values for ticks on colourbar
# letter = 'a', 'b', 'c', etc. to add before the ice shelf draft title, for
# use in a figure showing multiple variables
def plot_draft (x_min, x_max, y_min, y_max, gs, cbaxes, cbar_ticks, letter):
# Set up a grey square for FESOM to fill the background with land
x_reg_fesom, y_reg_fesom = meshgrid(linspace(x_min, x_max, num=100), linspace(y_min, y_max, num=100))
land_square = zeros(shape(x_reg_fesom))
# Find bounds on variable in this region
var_min, var_max = get_min_max(roms_draft, fesom_draft_lr, fesom_draft_hr, x_min, x_max, y_min, y_max)
# MetROMS
ax = subplot(gs[0,0], aspect='equal')
# First shade land and zice in grey
grey_cmap = ListedColormap([(0.6, 0.6, 0.6)])
pcolor(roms_x, roms_y, land_zice, cmap=grey_cmap)
# Fill in the missing circle
pcolor(x_reg_roms, y_reg_roms, land_circle, cmap=grey_cmap)
# Now shade the data
pcolor(roms_x, roms_y, roms_draft, vmin=var_min, vmax=var_max, cmap='jet')
xlim([x_min, x_max])
ylim([y_min, y_max])
ax.set_xticks([])
ax.set_yticks([])
# FESOM low-res
ax = subplot(gs[0,1], aspect='equal')
# Start with land background
contourf(x_reg_fesom, y_reg_fesom, land_square, 1, colors=(('0.6', '0.6', '0.6')))
# Add ice shelf elements
img = PatchCollection(patches_lr, cmap='jet')
img.set_array(array(fesom_draft_lr))
img.set_edgecolor('face')
img.set_clim(vmin=var_min, vmax=var_max)
ax.add_collection(img)
# Mask out the open ocean in white
overlay = PatchCollection(mask_patches_lr, facecolor=(1,1,1))
overlay.set_edgecolor('face')
ax.add_collection(overlay)
xlim([x_min, x_max])
ylim([y_min, y_max])
ax.set_xticks([])
ax.set_yticks([])
# Main title
title(letter + ') Ice shelf draft (m)', fontsize=20)
# FESOM high-res
ax = subplot(gs[0,2], aspect='equal')
contourf(x_reg_fesom, y_reg_fesom, land_square, 1, colors=(('0.6', '0.6', '0.6')))
img = PatchCollection(patches_hr, cmap='jet')
img.set_array(array(fesom_draft_hr))
img.set_edgecolor('face')
img.set_clim(vmin=var_min, vmax=var_max)
ax.add_collection(img)
overlay = PatchCollection(mask_patches_hr, facecolor=(1,1,1))
overlay.set_edgecolor('face')
ax.add_collection(overlay)
xlim([x_min, x_max])
ylim([y_min, y_max])
ax.set_xticks([])
ax.set_yticks([])
# Colourbar
cbar = colorbar(img, cax=cbaxes, ticks=cbar_ticks)
# Plot water column thickness for MetROMS, low-res FESOM, and high-res FESOM
# for the given region, in the given axes.
# Input:
# x_min, x_max, y_min, y_max = bounds on x and y (using polar coordinate
# transformation from above) for the desired region
# gs = GridSpec object of size 1x3 to plot in
# cbaxes = Axes object for location of colourbar
# cbar_ticks = 1D array containing values for ticks on colourbar
# letter = 'a', 'b', 'c', etc. to add before the variable title, for
# use in a figure showing multiple variables
def plot_wct (x_min, x_max, y_min, y_max, gs, cbaxes, cbar_ticks, letter):
# Set up a grey square for FESOM to fill the background with land
x_reg_fesom, y_reg_fesom = meshgrid(linspace(x_min, x_max, num=100), linspace(y_min, y_max, num=100))
land_square = zeros(shape(x_reg_fesom))
# Find bounds on variable in this region
var_min, var_max = get_min_max(roms_wct, fesom_wct_lr, fesom_wct_hr, x_min, x_max, y_min, y_max)
# MetROMS
ax = subplot(gs[0,0], aspect='equal')
# First shade land and zice in grey
grey_cmap = ListedColormap([(0.6, 0.6, 0.6)])
pcolor(roms_x, roms_y, land_zice, cmap=grey_cmap)
# Fill in the missing circle
pcolor(x_reg_roms, y_reg_roms, land_circle, cmap=grey_cmap)
# Now shade the data
pcolor(roms_x, roms_y, roms_wct, vmin=var_min, vmax=var_max, cmap='jet')
xlim([x_min, x_max])
ylim([y_min, y_max])
ax.set_xticks([])
ax.set_yticks([])
# FESOM low-res
ax = subplot(gs[0,1], aspect='equal')
# Start with land background
contourf(x_reg_fesom, y_reg_fesom, land_square, 1, colors=(('0.6', '0.6', '0.6')))
# Add ice shelf elements
img = PatchCollection(patches_lr, cmap='jet')
img.set_array(array(fesom_wct_lr))
img.set_edgecolor('face')
img.set_clim(vmin=var_min, vmax=var_max)
ax.add_collection(img)
# Mask out the open ocean in white
overlay = PatchCollection(mask_patches_lr, facecolor=(1,1,1))
overlay.set_edgecolor('face')
ax.add_collection(overlay)
xlim([x_min, x_max])
ylim([y_min, y_max])
ax.set_xticks([])
ax.set_yticks([])
# Main title
title(letter + ') Water column thickness (m)', fontsize=20)
# FESOM high-res
ax = subplot(gs[0,2], aspect='equal')
contourf(x_reg_fesom, y_reg_fesom, land_square, 1, colors=(('0.6', '0.6', '0.6')))
img = PatchCollection(patches_hr, cmap='jet')
img.set_array(array(fesom_wct_hr))
img.set_edgecolor('face')
img.set_clim(vmin=var_min, vmax=var_max)
ax.add_collection(img)
overlay = PatchCollection(mask_patches_hr, facecolor=(1,1,1))
overlay.set_edgecolor('face')
ax.add_collection(overlay)
xlim([x_min, x_max])
ylim([y_min, y_max])
ax.set_xticks([])
ax.set_yticks([])
# Colourbar
cbar = colorbar(img, cax=cbaxes, ticks=cbar_ticks)
# Plot ice shelf melt rate for MetROMS, low-res FESOM, and high-res FESOM for
# the given region, in the given axes.
# Input:
# x_min, x_max, y_min, y_max = bounds on x and y (using polar coordinate
# transformation from above) for the desired region
# gs = GridSpec object of size 1x3 to plot in
# cbaxes = Axes object for location of colourbar
# cbar_ticks = 1D array containing values for ticks on colourbar
# change_points = list of size 3 containing values where the colourmap should
# transition (1) from yellow to orange, (2) from orange to red,
# (3) from red to magenta. Should not include the minimum value,
# 0, or the maximum value. This way the custom colourmap can be
# adjusted so that all melt rates are visible, particularly
# for ice shelves with strong spatial variations in melt.
# letter = 'a', 'b', 'c', etc. to add before the ice shelf melt rate title, for
# use in a figure showing multiple variables
# y0 = y-coordinate of model titles for the entire plot, assuming melt rate is
# always at the top (i.e. letter='a'). Play around between 1.15 and 1.35.
# lon_lines = list of longitudes to overlay as dotted lines on the first panel
# (-180 to 180)
# lat_lines = list of latitudes to overlay (-90 to 90)
# rect_bounds = optional list of size 4 containing x_min, x_max, y_min, y_max
# of a rectangle to superimpose on the third panel
def plot_melt (x_min, x_max, y_min, y_max, gs, cbaxes, cbar_ticks, change_points, letter, y0, lon_lines, lat_lines, rect_bounds=None):
# Set up a grey square for FESOM to fill the background with land
x_reg_fesom, y_reg_fesom = meshgrid(linspace(x_min, x_max, num=100), linspace(y_min, y_max, num=100))
land_square = zeros(shape(x_reg_fesom))
# Find bounds on variable in this region
var_min, var_max = get_min_max(roms_melt, fesom_melt_lr, fesom_melt_hr, x_min, x_max, y_min, y_max)
# Special colour map
if var_min < 0:
# There is refreezing here; include blue for elements < 0
cmap_vals = array([var_min, 0, change_points[0], change_points[1], change_points[2], var_max])
cmap_colors = [(0.26, 0.45, 0.86), (1, 1, 1), (1, 0.9, 0.4), (0.99, 0.59, 0.18), (0.5, 0.0, 0.08), (0.96, 0.17, 0.89)]
cmap_vals_norm = (cmap_vals - var_min)/(var_max - var_min)
cmap_vals_norm[-1] = 1
cmap_list = []
for i in range(size(cmap_vals)):
cmap_list.append((cmap_vals_norm[i], cmap_colors[i]))
mf_cmap = LinearSegmentedColormap.from_list('melt_freeze', cmap_list)
else:
# No refreezing
cmap_vals = array([0, change_points[0], change_points[1], change_points[2], var_max])
cmap_colors = [(1, 1, 1), (1, 0.9, 0.4), (0.99, 0.59, 0.18), (0.5, 0.0, 0.08), (0.96, 0.17, 0.89)]
cmap_vals_norm = cmap_vals/var_max
cmap_vals_norm[-1] = 1
cmap_list = []
for i in range(size(cmap_vals)):
cmap_list.append((cmap_vals_norm[i], cmap_colors[i]))
mf_cmap = LinearSegmentedColormap.from_list('melt_freeze', cmap_list)
# Make sure longitudes to overlay are between 0 and 360, to suit ROMS
# convention
for i in range(len(lon_lines)):
if lon_lines[i] < 0:
lon_lines[i] += 360
# Plot MetROMS
ax = subplot(gs[0,0], aspect='equal')
# First shade land and zice in grey
grey_cmap = ListedColormap([(0.6, 0.6, 0.6)])
pcolor(roms_x, roms_y, land_zice, cmap=grey_cmap)
# Fill in the missing circle
pcolor(x_reg_roms, y_reg_roms, land_circle, cmap=grey_cmap)
# Now shade the data
pcolor(roms_x, roms_y, roms_melt, vmin=var_min, vmax=var_max, cmap=mf_cmap)
# Overlay longitudes
contour(roms_x, roms_y, roms_lon, lon_lines, colors='black', linestyles='dotted')
# Overlay latitudes
contour(roms_x, roms_y, roms_lat, lat_lines, colors='black', linestyles='dotted')
xlim([x_min, x_max])
ylim([y_min, y_max])
ax.set_xticks([])
ax.set_yticks([])
# Melt rate is always at the top, so add model labels
text(0.5, y0, 'MetROMS', fontsize=18, horizontalalignment='center', transform=ax.transAxes)
# FESOM low-res
ax = subplot(gs[0,1], aspect='equal')
# Start with land background
contourf(x_reg_fesom, y_reg_fesom, land_square, 1, colors=(('0.6', '0.6', '0.6')))
# Add ice shelf elements
img = PatchCollection(patches_lr, cmap=mf_cmap)
img.set_array(array(fesom_melt_lr))
img.set_edgecolor('face')
img.set_clim(vmin=var_min, vmax=var_max)
ax.add_collection(img)
# Mask out the open ocean in white
overlay = PatchCollection(mask_patches_lr, facecolor=(1,1,1))
overlay.set_edgecolor('face')
ax.add_collection(overlay)
xlim([x_min, x_max])
ylim([y_min, y_max])
ax.set_xticks([])
ax.set_yticks([])
title(letter + ') Ice shelf melt rate (m/y)', fontsize=20)
text(0.5, y0, 'FESOM (low-res)', fontsize=18, horizontalalignment='center', transform=ax.transAxes)
# FESOM high-res
ax = subplot(gs[0,2], aspect='equal')
contourf(x_reg_fesom, y_reg_fesom, land_square, 1, colors=(('0.6', '0.6', '0.6')))
img = PatchCollection(patches_hr, cmap=mf_cmap)
img.set_array(array(fesom_melt_hr))
img.set_edgecolor('face')
img.set_clim(vmin=var_min, vmax=var_max)
ax.add_collection(img)
overlay = PatchCollection(mask_patches_hr, facecolor=(1,1,1))
overlay.set_edgecolor('face')
ax.add_collection(overlay)
xlim([x_min, x_max])
ylim([y_min, y_max])
ax.set_xticks([])
ax.set_yticks([])
if rect_bounds is not None:
# Overlay rectangle
ax.add_patch(Rectangle((rect_bounds[0], rect_bounds[2]), rect_bounds[1]-rect_bounds[0], rect_bounds[3]-rect_bounds[2], fill=False))
# Colourbar
cbar = colorbar(img, cax=cbaxes, ticks=cbar_ticks)
text(0.5, y0, 'FESOM (high-res)', fontsize=18, horizontalalignment='center', transform=ax.transAxes)
# Plot bottom water temperature for MetROMS, low-res FESOM, and high-res FESOM
# for the given region, in the given axes.
# Input:
# x_min, x_max, y_min, y_max = bounds on x and y (using polar coordinate
# transformation from above) for the desired region
# gs = GridSpec object of size 1x3 to plot in
# cbaxes = Axes object for location of colourbar
# cbar_ticks = 1D array containing values for ticks on colourbar
# letter = 'a', 'b', 'c', etc. to add before the bottom water temp title, for
# use in a figure showing multiple variables
# bathy_contour = optional float containing single isobath to contour (positive,
# in metres; make sure you call fesom_interpolate_bathy first)
def plot_bwtemp (x_min, x_max, y_min, y_max, gs, cbaxes, cbar_ticks, letter, bathy_contour=None):
# Set up a grey square for FESOM to fill the background with land
x_reg_fesom, y_reg_fesom = meshgrid(linspace(x_min, x_max, num=100), linspace(y_min, y_max, num=100))
land_square = zeros(shape(x_reg_fesom))
# Find bounds on variable in this region
var_min, var_max = get_min_max(roms_bwtemp, fesom_bwtemp_lr, fesom_bwtemp_hr, x_min, x_max, y_min, y_max, cavity=False)
# Plot MetROMS
ax = subplot(gs[0,0], aspect='equal')
# First shade land and zice in grey
grey_cmap = ListedColormap([(0.6, 0.6, 0.6)])
pcolor(roms_x, roms_y, land_zice, cmap=grey_cmap)
# Fill in the missing circle
pcolor(x_reg_roms, y_reg_roms, land_circle, cmap=grey_cmap)
# Now shade the data
pcolor(roms_x, roms_y, roms_bwtemp, vmin=var_min, vmax=var_max, cmap='jet')
# Add a black contour for the ice shelf front
rcParams['contour.negative_linestyle'] = 'solid'
contour(roms_x, roms_y, zice_contour, levels=[min_zice], colors=('black'))
if bathy_contour is not None:
# Dashed line to contour isobath
contour(roms_x, roms_y, roms_bathy, levels=[bathy_contour], colors=('black'), linestyles=('dashed'))
xlim([x_min, x_max])
ylim([y_min, y_max])
ax.set_xticks([])
ax.set_yticks([])
# FESOM low-res
ax = subplot(gs[0,1], aspect='equal')
# Start with land background
contourf(x_reg_fesom, y_reg_fesom, land_square, 1, colors=(('0.6', '0.6', '0.6')))
# Add ice shelf elements
img = PatchCollection(patches_all_lr, cmap='jet')
img.set_array(array(fesom_bwtemp_lr))
img.set_edgecolor('face')
img.set_clim(vmin=var_min, vmax=var_max)
ax.add_collection(img)
# Add ice shelf front contour lines
fesom_contours_lr = LineCollection(contour_lines_lr, edgecolor='black', linewidth=1)
ax.add_collection(fesom_contours_lr)
if bathy_contour is not None:
# Overlay contour on regular grid
contour(x_reg, y_reg, fesom_bathy_reg_lr, levels=[bathy_contour], colors=('black'), linestyles=('dashed'))
xlim([x_min, x_max])
ylim([y_min, y_max])
ax.set_xticks([])
ax.set_yticks([])
# Main title
title(letter + r') Bottom water temperature ($^{\circ}$C)', fontsize=20)
# FESOM high-res
ax = subplot(gs[0,2], aspect='equal')
contourf(x_reg_fesom, y_reg_fesom, land_square, 1, colors=(('0.6', '0.6', '0.6')))
img = PatchCollection(patches_all_hr, cmap='jet')
img.set_array(array(fesom_bwtemp_hr))
img.set_edgecolor('face')
img.set_clim(vmin=var_min, vmax=var_max)
ax.add_collection(img)
fesom_contours_hr = LineCollection(contour_lines_hr, edgecolor='black', linewidth=1)
ax.add_collection(fesom_contours_hr)
if bathy_contour is not None:
contour(x_reg, y_reg, fesom_bathy_reg_hr, levels=[bathy_contour], colors=('black'), linestyles=('dashed'))
xlim([x_min, x_max])
ylim([y_min, y_max])
ax.set_xticks([])
ax.set_yticks([])
# Colourbar
cbar = colorbar(img, cax=cbaxes, ticks=cbar_ticks)
# Plot bottom water salinity for MetROMS, low-res FESOM, and high-res FESOM
# for the given region, in the given axes.
# Input:
# x_min, x_max, y_min, y_max = bounds on x and y (using polar coordinate
# transformation from above) for the desired region
# gs = GridSpec object of size 1x3 to plot in
# cbaxes = Axes object for location of colourbar
# cbar_ticks = 1D array containing values for ticks on colourbar
# letter = 'a', 'b', 'c', etc. to add before the bottom water salinity title,
# for use in a figure showing multiple variables
# bathy_contour = optional float containing single isobath to contour (positive,
# in metres; make sure you call fesom_interpolate_bathy first)
def plot_bwsalt (x_min, x_max, y_min, y_max, gs, cbaxes, cbar_ticks, letter, bathy_contour=None):
# Set up a grey square for FESOM to fill the background with land
x_reg_fesom, y_reg_fesom = meshgrid(linspace(x_min, x_max, num=100), linspace(y_min, y_max, num=100))
land_square = zeros(shape(x_reg_fesom))
# Find bounds on variable in this region
var_min, var_max = get_min_max(roms_bwsalt, fesom_bwsalt_lr, fesom_bwsalt_hr, x_min, x_max, y_min, y_max, cavity=False)
# Plot MetROMS
ax = subplot(gs[0,0], aspect='equal')
# First shade land and zice in grey
grey_cmap = ListedColormap([(0.6, 0.6, 0.6)])
pcolor(roms_x, roms_y, land_zice, cmap=grey_cmap)
# Fill in the missing circle
pcolor(x_reg_roms, y_reg_roms, land_circle, cmap=grey_cmap)
# Now shade the data
pcolor(roms_x, roms_y, roms_bwsalt, vmin=var_min, vmax=var_max, cmap='jet')
# Add a black contour for the ice shelf front
rcParams['contour.negative_linestyle'] = 'solid'
contour(roms_x, roms_y, zice_contour, levels=[min_zice], colors=('black'))
if bathy_contour is not None:
# Dashed line to contour isobath
contour(roms_x, roms_y, roms_bathy, levels=[bathy_contour], colors=('black'), linestyles=('dashed'))
xlim([x_min, x_max])
ylim([y_min, y_max])
ax.set_xticks([])
ax.set_yticks([])
# FESOM low-res
ax = subplot(gs[0,1], aspect='equal')
# Start with land background
contourf(x_reg_fesom, y_reg_fesom, land_square, 1, colors=(('0.6', '0.6', '0.6')))
# Add ice shelf elements
img = PatchCollection(patches_all_lr, cmap='jet')
img.set_array(array(fesom_bwsalt_lr))
img.set_edgecolor('face')
img.set_clim(vmin=var_min, vmax=var_max)
ax.add_collection(img)
# Add ice shelf front contour lines
fesom_contours_lr = LineCollection(contour_lines_lr, edgecolor='black', linewidth=1)
ax.add_collection(fesom_contours_lr)
if bathy_contour is not None:
# Overlay contour on regular grid
contour(x_reg, y_reg, fesom_bathy_reg_lr, levels=[bathy_contour], colors=('black'), linestyles=('dashed'))
xlim([x_min, x_max])
ylim([y_min, y_max])
ax.set_xticks([])
ax.set_yticks([])
# Main title
title(letter + ') Bottom water salinity (psu)', fontsize=20)
# FESOM high-res
ax = subplot(gs[0,2], aspect='equal')
contourf(x_reg_fesom, y_reg_fesom, land_square, 1, colors=(('0.6', '0.6', '0.6')))
img = PatchCollection(patches_all_hr, cmap='jet')
img.set_array(array(fesom_bwsalt_hr))
img.set_edgecolor('face')
img.set_clim(vmin=var_min, vmax=var_max)
ax.add_collection(img)
fesom_contours_hr = LineCollection(contour_lines_hr, edgecolor='black', linewidth=1)
ax.add_collection(fesom_contours_hr)
xlim([x_min, x_max])
ylim([y_min, y_max])
if bathy_contour is not None:
contour(x_reg, y_reg, fesom_bathy_reg_hr, levels=[bathy_contour], colors=('black'), linestyles=('dashed'))
ax.set_xticks([])
ax.set_yticks([])
# Colourbar
cbar = colorbar(img, cax=cbaxes, ticks=cbar_ticks)
# Plot vertically averaged velocity for MetROMS, low-res FESOM, and high-res
# FESOM for the given region, in the given axes.
# Input:
# x_min, x_max, y_min, y_max = bounds on x and y (using polar coordinate
# transformation from above) for the desired region
# gs = GridSpec object of size 1x3 to plot in
# cbaxes = Axes object for location of colourbar
# cbar_ticks = 1D array containing values for ticks on colourbar
# x_centres, y_centres, roms_ubin, roms_vbin, fesom_ubin_lr, fesom_vbin_lr,
# fesom_ubin_hr, fesom_vbin_hr = output variables from the
# "make_vectors" function for the given region
# letter = 'a', 'b', 'c', etc. to add before the bottom water salinity title,
# for use in a figure showing multiple variables
# loc_string = optional string containing location title, in the case of
# velocity being zoomed into a smaller region to the other
# variables (eg "George VI Ice Shelf" for the Bellingshausen plot)
# arrow_scale, arrow_headwidth, arrow_headlength = optional parameters for
# arrows on vector overlay
# model_titles = optional boolean indicating to add model titles to the top
# of the plot (only for Filchner-Ronne). Default False.
# y0 = if model_titles=True, y-coordinate of model titles. Play around between
# 1.15 and 1.35. Default 1.25.
def plot_velavg (x_min, x_max, y_min, y_max, gs, cbaxes, cbar_ticks, x_centres, y_centres, roms_ubin, roms_vbin, fesom_ubin_lr, fesom_vbin_lr, fesom_ubin_hr, fesom_vbin_hr, letter, loc_string=None, arrow_scale=0.9, arrow_headwidth=8, arrow_headlength=9, model_titles=False, y0=1.25):
# Set up a grey square for FESOM to fill the background with land
x_reg_fesom, y_reg_fesom = meshgrid(linspace(x_min, x_max, num=100), linspace(y_min, y_max, num=100))
land_square = zeros(shape(x_reg_fesom))
# Find bounds on variable in this region
var_min, var_max = get_min_max(roms_speed, fesom_speed_lr, fesom_speed_hr, x_min, x_max, y_min, y_max, cavity=False)
# Plot MetROMS
ax = subplot(gs[0,0], aspect='equal')
# First shade land and zice in grey
grey_cmap = ListedColormap([(0.6, 0.6, 0.6)])
pcolor(roms_x, roms_y, land_zice, cmap=grey_cmap)
# Fill in the missing circle
pcolor(x_reg_roms, y_reg_roms, land_circle, cmap=grey_cmap)
# Now shade the data
pcolor(roms_x, roms_y, roms_speed, vmin=var_min, vmax=var_max, cmap='cool')
# Add a black contour for the ice shelf front
rcParams['contour.negative_linestyle'] = 'solid'
if x_centres is not None:
# Overlay vectors
quiver(x_centres, y_centres, roms_ubin, roms_vbin, scale=arrow_scale, headwidth=arrow_headwidth, headlength=arrow_headlength, color='black')
contour(roms_x, roms_y, zice_contour, levels=[min_zice], colors=('black'))
xlim([x_min, x_max])
ylim([y_min, y_max])
ax.set_xticks([])
ax.set_yticks([])
if model_titles:
text(0.5, y0, 'MetROMS', fontsize=18, horizontalalignment='center', transform=ax.transAxes)
# FESOM low-res
ax = subplot(gs[0,1], aspect='equal')
# Start with land background
contourf(x_reg_fesom, y_reg_fesom, land_square, 1, colors=(('0.6', '0.6', '0.6')))
# Add ice shelf elements
img = PatchCollection(patches_all_lr, cmap='cool')
img.set_array(array(fesom_speed_lr))
img.set_edgecolor('face')
img.set_clim(vmin=var_min, vmax=var_max)
ax.add_collection(img)
# Add ice shelf front contour lines
fesom_contours_lr = LineCollection(contour_lines_lr, edgecolor='black', linewidth=1)
ax.add_collection(fesom_contours_lr)
if x_centres is not None:
# Overlay vectors
quiver(x_centres, y_centres, fesom_ubin_lr, fesom_vbin_lr, scale=arrow_scale, headwidth=arrow_headwidth, headlength=arrow_headlength, color='black')
xlim([x_min, x_max])
ylim([y_min, y_max])
ax.set_xticks([])
ax.set_yticks([])
if model_titles:
text(0.5, y0, 'FESOM (low-res)', fontsize=18, horizontalalignment='center', transform=ax.transAxes)
# Main title
if loc_string is None:
title(letter + ') Vertically averaged ocean velocity (m/s)', fontsize=20)
else:
title(letter + ') Vertically averaged ocean velocity (m/s): '+loc_string, fontsize=15)
# FESOM high-res
ax = subplot(gs[0,2], aspect='equal')
contourf(x_reg_fesom, y_reg_fesom, land_square, 1, colors=(('0.6', '0.6', '0.6')))
img = PatchCollection(patches_all_hr, cmap='cool')
img.set_array(array(fesom_speed_hr))
img.set_edgecolor('face')
img.set_clim(vmin=var_min, vmax=var_max)
ax.add_collection(img)
fesom_contours_hr = LineCollection(contour_lines_hr, edgecolor='black', linewidth=1)
ax.add_collection(fesom_contours_hr)
if x_centres is not None:
quiver(x_centres, y_centres, fesom_ubin_hr, fesom_vbin_hr, scale=arrow_scale, headwidth=arrow_headwidth, headlength=arrow_headlength, color='black')
xlim([x_min, x_max])
ylim([y_min, y_max])
ax.set_xticks([])
ax.set_yticks([])
# Colourbar
cbar = colorbar(img, cax=cbaxes, ticks=cbar_ticks)
if model_titles:
text(0.5, y0, 'FESOM (high-res)', fontsize=18, horizontalalignment='center', transform=ax.transAxes)
# Plot zonal slices (latitude vs depth) of temperature and salinity for
# MetROMS, low-res FESOM, and high-res FESOM through the given longitude, in the
# given axes.
# Input:
# lon0 = longitude to plot (-180 to 180)
# lat_min, lat_max = bounds on latitude to plot (-90 to 90)
# lat_ticks = array of floats containing latitude values to tick
# lat_labels = array of strings containing label for each tick
# depth_min, depth_max = bounds on depth to plot (negative, in metres)
# depth_ticks, depth_labels = tick locations and labels as for latitude
# gs1, gs2 = GridSpec objects of size 1x3, in which to plot temperature and
# salinity respectively
# cbaxes1, cbaxes2 = Axes objects for locations of temperature and salinity
# colourbars
# cbar_ticks1, cbar_ticks2 = 1D arrays containing values for ticks on
# temperature and salinity colourbars
# letter1, letter2 = 'a', 'b', 'c', etc. to add before the temperature and
# salinity titles
# loc_string = optional string containing location title, in the case of
# plotting slices through a single ice shelf in a large region
# (eg "Fimbul Ice Shelf" for the Eastern Weddell plot)
def plot_zonal_ts (lon0, lat_min, lat_max, lat_ticks, lat_labels, depth_min, depth_max, depth_ticks, depth_labels, gs1, gs2, cbaxes1, cbaxes2, cbar_ticks1, cbar_ticks2, letter1, letter2, loc_string=None):
# Figure out what to write on the title about longitude
if lon0 < 0:
lon_string = str(-lon0)+r'$^{\circ}$W'
else:
lon_string = str(lon0)+r'$^{\circ}$E'
# ROMS
# Read temperature and salinity
id = Dataset(roms_file, 'r')
roms_temp_3d = id.variables['temp'][0,:,:,:]
roms_salt_3d = id.variables['salt'][0,:,:,:]
id.close()
# Get a 3D array of z-coordinates; sc_r and Cs_r are unused in this script
roms_z_3d, sc_r, Cs_r = calc_z(roms_h, roms_zice, theta_s, theta_b, hc, N)
# Make sure we are in the range 0-360
if lon0 < 0:
lon0 += 360
# Interpolate to lon0
roms_temp, roms_z_1d, roms_lat_1d = interp_lon_roms(roms_temp_3d, roms_z_3d, roms_lat, roms_lon, lon0)
roms_salt, roms_z_1d, roms_lat_1d = interp_lon_roms(roms_salt_3d, roms_z_3d, roms_lat, roms_lon, lon0)
# Switch back to range -180-180
if lon0 > 180:
lon0 -= 360
# FESOM low-res
# Read temperature and salinity
id = Dataset(fesom_file_lr_o, 'r')
fesom_temp_nodes_lr = id.variables['temp'][0,:]
fesom_salt_nodes_lr = id.variables['salt'][0,:]
id.close()
# Build arrays of SideElements making up zonal slices
selements_temp_lr = fesom_sidegrid(elm2D_lr, fesom_temp_nodes_lr, lon0, lat_max)
selements_salt_lr = fesom_sidegrid(elm2D_lr, fesom_salt_nodes_lr, lon0, lat_max)
# Build array of quadrilateral patches for the plots, and data values
# corresponding to each SideElement
spatches_lr = []
fesom_temp_lr = []
for selm in selements_temp_lr:
# Make patch
coord = transpose(vstack((selm.y, selm.z)))
spatches_lr.append(Polygon(coord, True, linewidth=0.))
# Save data value
fesom_temp_lr.append(selm.var)
fesom_temp_lr = array(fesom_temp_lr)
# Salinity has same patches but different values
fesom_salt_lr = []
for selm in selements_salt_lr:
fesom_salt_lr.append(selm.var)
fesom_salt_lr = array(fesom_salt_lr)
# FESOM high-res
id = Dataset(fesom_file_hr_o, 'r')
fesom_temp_nodes_hr = id.variables['temp'][0,:]
fesom_salt_nodes_hr = id.variables['salt'][0,:]
id.close()
selements_temp_hr = fesom_sidegrid(elm2D_hr, fesom_temp_nodes_hr, lon0, lat_max)
selements_salt_hr = fesom_sidegrid(elm2D_hr, fesom_salt_nodes_hr, lon0, lat_max)
spatches_hr = []
fesom_temp_hr = []
for selm in selements_temp_hr:
coord = transpose(vstack((selm.y, selm.z)))
spatches_hr.append(Polygon(coord, True, linewidth=0.))
fesom_temp_hr.append(selm.var)
fesom_temp_hr = array(fesom_temp_hr)
fesom_salt_hr = []
for selm in selements_salt_hr:
fesom_salt_hr.append(selm.var)
fesom_salt_hr = array(fesom_salt_hr)
# Find bounds on each variable
flag = (roms_lat_1d >= lat_min)*(roms_lat_1d <= lat_max)
temp_min = amin(array([amin(roms_temp[flag]), amin(fesom_temp_lr), amin(fesom_temp_hr)]))
temp_max = amax(array([amax(roms_temp[flag]), amax(fesom_temp_lr), amax(fesom_temp_hr)]))
salt_min = amin(array([amin(roms_salt[flag]), amin(fesom_salt_lr), amin(fesom_salt_hr)]))
salt_max = amax(array([amax(roms_salt[flag]), amax(fesom_salt_lr), amax(fesom_salt_hr)]))
# Plot temperature
# MetROMS
ax = subplot(gs1[0,0])
pcolor(roms_lat_1d, roms_z_1d, roms_temp, vmin=temp_min, vmax=temp_max, cmap='jet')
ylabel('Depth (m)', fontsize=12)
xlabel('Latitude', fontsize=12)
xlim([lat_min, lat_max])
ylim([depth_min, depth_max])
ax.set_xticks(lat_ticks)
ax.set_xticklabels(lat_labels)
ax.set_yticks(depth_ticks)
ax.set_yticklabels(depth_labels)
# FESOM low-res
ax = subplot(gs1[0,1])
img = PatchCollection(spatches_lr, cmap='jet')
img.set_array(fesom_temp_lr)
img.set_edgecolor('face')
img.set_clim(vmin=temp_min, vmax=temp_max)
ax.add_collection(img)
xlim([lat_min, lat_max])
ylim([depth_min, depth_max])
ax.set_xticklabels([])
ax.set_yticklabels([])
if loc_string is None:
title(letter1 + r') Temperature ($^{\circ}$C) through ' + lon_string, fontsize=20)
else:
title(letter1 + r') Temperature ($^{\circ}$C) through ' + lon_string + ': ' + loc_string, fontsize=20)
# FESOM high-res
ax = subplot(gs1[0,2])
img = PatchCollection(spatches_hr, cmap='jet')
img.set_array(fesom_temp_hr)
img.set_edgecolor('face')
img.set_clim(vmin=temp_min, vmax=temp_max)
ax.add_collection(img)
xlim([lat_min, lat_max])