-
Notifications
You must be signed in to change notification settings - Fork 1
/
plot_l1c.py
118 lines (107 loc) · 4.12 KB
/
plot_l1c.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
#!/usr/bin/env python
# Code to quickly plot L1C orbits from FIDUCEO Easy FCDR:
# ======================================================
# Version 0.4
# 15 June, 2019
# michael.taylor AT reading DOT ac DOT uk
# patternizer.github.io
# ======================================================
from optparse import OptionParser
import numpy as np
import numpy.ma as ma
import xarray
import matplotlib.pyplot as plt; plt.close("all")
import matplotlib.dates as mdates
import matplotlib.colors as mcolors
import matplotlib.ticker as mticker
import cartopy
import cartopy.crs as ccrs
from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter
from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER
#####################################################################################
# plot_orbit_var(lat, lon, var, vmin, vmax, projection, filestr, titlestr, varstr)
#####################################################################################
#
# REQUIRES:
#
# lat: np.array
# lon: np.array
# var: np.array
# vmin: e.g. 270
# vmax: e.g. 305
#
# projection: string - one of:
# ['platecarree','molleweide','robinson','equalearth','geostationary',
# 'goodehomolosine','europp','northpolarstereo','southpolarstereo','lambertconformal']
#
# filestr: string (including file extension) e.g. 'plot_l1c.png'
# titlestr: string e.g. 'L1C Orbit'
# varstr: e.g. 'ch4'
#
#####################################################################################
def plot_orbit_var(lat, lon, var, vmin, vmax, projection, filestr, titlestr, varstr):
x = lon[::10,::10]
y = lat[::10,::10]
z = var[::10,::10]
fig = plt.figure()
if projection == 'platecarree':
p = ccrs.PlateCarree(central_longitude=0)
threshold = 0
if projection == 'mollweide':
p = ccrs.Mollweide(central_longitude=0)
threshold = 1e6
if projection == 'robinson':
p = ccrs.Robinson(central_longitude=0)
threshold = 0
if projection == 'equalearth':
p = ccrs.EqualEarth(central_longitude=0)
threshold = 0
if projection == 'geostationary':
p = ccrs.Geostationary(central_longitude=0)
threshold = 0
if projection == 'goodehomolosine':
p = ccrs.InterruptedGoodeHomolosine(central_longitude=0)
threshold = 0
if projection == 'europp':
p = ccrs.EuroPP()
threshold = 0
if projection == 'northpolarstereo':
p = ccrs.NorthPolarStereo()
threshold = 0
if projection == 'southpolarstereo':
p = ccrs.SouthPolarStereo()
threshold = 0
if projection == 'lambertconformal':
p = ccrs.LambertConformal(central_longitude=0)
threshold = 0
ax = plt.axes(projection=p)
ax.stock_img()
ax.coastlines(resolution='50m')
ax.gridlines()
colormap = 'gnuplot2'
g = ccrs.Geodetic()
trans = ax.projection.transform_points(g, x, y)
x0 = trans[:,:,0]
x1 = trans[:,:,1]
if projection == 'platecarree':
ax.set_extent([-180, 180, -90, 90], crs=p)
gl = ax.gridlines(crs=p, draw_labels=True, linewidth=1, color='gray', alpha=0.5, linestyle='-')
gl.xlabels_top = False
gl.ylabels_right = False
gl.xlines = True
gl.ylines = True
gl.xlocator = mticker.FixedLocator([-180,-120,-60,0,60,120,180])
gl.ylocator = mticker.FixedLocator([-90,-60,-30,0,30,60,90])
gl.xformatter = LONGITUDE_FORMATTER
gl.yformatter = LATITUDE_FORMATTER
for mask in (x0>=threshold,x0<=threshold):
im = ax.pcolor(ma.masked_where(mask, x), ma.masked_where(mask, y), ma.masked_where(mask, z), vmin=vmin, vmax=vmax, transform=ax.projection, cmap=colormap)
else:
for mask in (x0>=threshold,x0<=threshold):
im = ax.pcolor(ma.masked_where(mask, x0), ma.masked_where(mask, x1), ma.masked_where(mask, z), vmin=vmin, vmax=vmax, transform=ax.projection, cmap=colormap)
im.set_clim(vmin,vmax)
cb = plt.colorbar(im, orientation="horizontal", extend='both', label=varstr)
plt.title(titlestr)
plt.savefig(filestr)
plt.close('all')
return