-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmems_Geocat_visualization_temperature.py
150 lines (93 loc) · 4.23 KB
/
cmems_Geocat_visualization_temperature.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
import numpy as np
import xarray as xr
import cartopy.feature as cfeature
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
import os,sys
import pandas as pd
import geocat.datafiles as gdf
from geocat.viz import cmaps as gvcmaps
from geocat.viz import util as gvutil
##################################################################
# Read a netCDF data file using xarray default engine and load the data into xarrays
fn_temp = '2020-11-16T12:00:00_Daily_temp_2020_AdriaticSea_Z10_CF.nc'
nut_nc=[os.path.join(fn_temp) for f in fn_temp]
nut_ds=[xr.open_dataset(nc) for nc in nut_nc]
j=0
##################################################################
# Extract a slice of the data
t = nut_ds[j].thetao.isel(time=0,depth=0).sel(lat=slice(37, 46), lon=slice(12, 22))
##################################################################
fig = plt.figure(figsize=(10, 10), dpi=200)
##################################################################
# coastlines, and adding features
m = plt.axes(projection=ccrs.PlateCarree())
land_resolution = '10m'
land_def = cfeature.NaturalEarthFeature('physical', 'land', land_resolution,
edgecolor='k',
facecolor=cfeature.COLORS['land'], color ='g')
states_provinces = cfeature.NaturalEarthFeature(
category='cultural',
name='admin_1_states_provinces_lines',
scale='10m',
facecolor='none')
boundry_lines = cfeature.NaturalEarthFeature(
category='cultural',
name='admin_0_boundary_lines_land',
scale='10m',
facecolor='none')
##################################################################
m.add_feature(land_def,linewidth=0.5)
m.add_feature(cfeature.COASTLINE,linewidths=0.5,alpha=0.9999)
m.add_feature(cfeature.OCEAN,color='turquoise', linewidth=0.3)
m.add_feature(boundry_lines, edgecolor='k', linewidth=0.3)
m.add_feature(states_provinces, edgecolor='k', linewidth=0.3)
m.add_feature(cfeature.RIVERS,color='aqua',linewidth=0.7)
m.add_feature(cfeature.LAKES, color="b")
##################################################################
newcmp = gvcmaps.BlAqGrYeOrReVi200
# heat map creation based on temperature at given date and statistics
heatmap = t.plot.contourf(m=m,
levels=50,
vmin=11,
vmax=23,
cmap=newcmp,
add_colorbar=False)
##################################################################
#internal contour per Temperature
# alpha is the transparency value for each color levels(small islands contours= VMAX-VMIN)
lines=t.plot.contour(m=m,alpha=1,linewidths=0.3,colors = 'k',linestyles='None',levels=12)
##################################################################
#projection extent
m.set_extent([12, 22, 37, 46], crs=ccrs.PlateCarree())
##################################################################
cbar = plt.colorbar(heatmap, ticks=np.arange(11, 24, 1))
cbar.ax.set_yticklabels([str(i) for i in np.arange(11, 24, 1)])
##################################################################
# Set axes limits, and tick values
gvutil.set_axes_limits_and_ticks(m,
xlim=(5, 26),
ylim=(35, 48),
xticks=np.linspace(5, 26, 3),
yticks=np.linspace(35, 48, 3))
# Use geocat.viz.util convenience function to make plots
gvutil.add_lat_lon_ticklabels(m)
# Use geocat.viz.util convenience function to add minor and major tick lines
gvutil.add_major_minor_ticks(m, labelsize=10)
##################################################################
# Use geocat.viz.util convenience function to set titles and labels
gvutil.set_titles_and_labels(
m,
maintitle="MEDITERRANEAN SEA PHYSICS\nANALYSIS AND FORECAST\nOCEAN PRODUCT\nTemperature at 5 m",
maintitlefontsize=16,
lefttitle="16-November-2020",
lefttitlefontsize=14,
righttitle="T[degC]",
righttitlefontsize=14,
xlabel="",
ylabel="")
m.xlabel_style = {'size': 16, 'color': 'k'}
m.ylabel_style = {'size': 16, 'color': 'k'}
##################################################################
plt.savefig('temperature_november_2020_at5.png')
plt.show()