-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkitimat
146 lines (106 loc) · 4.38 KB
/
kitimat
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
# -*- coding: utf-8 -*-
"""
@author: cbourgaultbrunelle
"""
#!/usr/bin/env python
# This script shows selected netCDF file attributes
from osgeo import gdal
import geopandas as gpd
from netCDF4 import Dataset
#import cmocean
import os
import numpy as np
import matplotlib as mpl
#--------------------------------------------------------------------------------
##################################################
def plot_globalDataScatter(lons, lats, data, title, cbar_min, cbar_max, \
lon_min, lon_max, lat_min, lat_max, cmap, \
outputFilename, saveFigure, plotZebre):
import matplotlib.pyplot as plt
import cartopy.feature as cfeature
import cartopy
import matplotlib as mpl
import cartopy.crs as ccrs
from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER
import cartopy.feature as cfeature
fontsize = 16
# Plot figure
fig = plt.figure(figsize=(15,8))
projection=ccrs.PlateCarree()
crs=projection
ax = fig.add_subplot(projection=projection)
ax.set_extent([lon_min, lon_max, lat_min, lat_max])
norm = mpl.colors.Normalize(vmin = cbar_min, vmax = cbar_max)
plot = ax.scatter(lons, lats, c = data, s = 2, marker = "o", edgecolors='none', transform = projection, \
cmap = cmap, norm = norm, \
zorder = 1, rasterized = False)
#ax.coastlines(resolution='10m')
# resol = '10m'
# lakes = cartopy.feature.NaturalEarthFeature('physical', 'lakes','10m', \
# edgecolor='black', facecolor="None")
# ax.add_feature(lakes)
# resol = '10m'
# coasts = cartopy.feature.NaturalEarthFeature('physical', 'coasts','10m', \
# edgecolor='black', facecolor="None")
# ax.add_feature(coasts)
# rivers = cartopy.feature.NaturalEarthFeature(category='physical', name='rivers_lake_centerlines',
# scale='10m', facecolor='none', edgecolor='black')
ax.grid(False)
ax.set_facecolor("none")
#gl = ax.gridlines(crs=ccrs.PlateCarree(), draw_labels = False, linewidth = 1., \
# color = 'none', alpha = 1, linestyle = '-', zorder = 3)
#gl = ax.gridlines(crs=ccrs.PlateCarree())
#gl.xlabels_top = False
#gl.ylabels_left = False
#gl.xformatter = LONGITUDE_FORMATTER
#gl.yformatter = LATITUDE_FORMATTER
#gl.xlabel_style = {'size': fontsize}
#gl.ylabel_style = {'size': fontsize}
ax.set_title(title, fontsize = fontsize)
# Colorbar
cbar = plt.colorbar(plot, ax = ax, extend = 'both',spacing = 'uniform', \
orientation = 'horizontal', pad = 0.1, shrink = 0.6 )
cbar.ax.tick_params(labelsize = fontsize)
cbar.set_label('m')
fig.tight_layout()
if saveFigure:
fig.savefig(outputFilename, format='png', dpi = 300., transparent=True)
else:
plt.show()
##################################################
# Input file name
inputFile=r"C:\Users\cbourgaultbrunelle\Documents\SWOT\Case study\Kitimat\SWOT_L2_HR_Raster_250m_UTM09U_N_x_x_x_018_580_030F_20240730T145739_20240730T145800_PIC0_01.nc"
# Output plot file name
outputPlotFile=r"C:\Users\cbourgaultbrunelle\Documents\SWOT\Case study\Kitimat\SWOT_L2_HR_Raster_250m_UTM09U_N_x_x_x_018_580_030F_20240730T145739_20240730T145800_PIC0_01.png"
data_local = Dataset(inputFile, 'r')
data = data_local['wse'][:]
lon = data_local['longitude'][:]
lat = data_local['latitude'][:]
data[data > 1] = np.nan
data[data < 0] = np.nan
print(data.min(), data.max(), data.shape)
##########################################################################
plot = True
if plot:
print("Generating plot...")
cmap=mpl.colormaps['jet']
#cmap = cmocean.cm.diff
title = "SWOT water surface elevation (m) from SWOT_L2_HR_Raster_250m 20240730 14:57:39 - 14:58:00 "
lon_min = -129.5
lon_max = -128.5
lat_min = 53.0
lat_max = 54.0
cbar_min = 0.
cbar_max = 1.
plot_globalDataScatter(lon, lat, data, \
title, \
cbar_min = cbar_min, cbar_max = cbar_max, \
lon_min = lon_min, \
lon_max = lon_max, \
lat_min = lat_min, \
lat_max = lat_max, \
cmap = cmap, \
outputFilename = outputPlotFile, \
saveFigure = True, \
plotZebre = False)
##########################################################################