-
Notifications
You must be signed in to change notification settings - Fork 2
/
Mask.py
131 lines (114 loc) · 3.63 KB
/
Mask.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
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
import imageio
from netCDF4 import Dataset
import pickle
# Define Functions
def get(string):
"""
"Lakes":0,
"Oceans":1,
"Okhotsk":2,
"Bering":3,
"Hudson":4,
"St Lawrence":5,
"Baffin":6,
"Greenland":7,
"Barents":8,
"Kara":9,
"Laptev":10,
"East Siberian":11,
"Chukchi":12,
"Beaufort":13,
"Canadian Archipelago":14,
"Central Arctic":15,
"Land":20,
"Coast":21}
"""
path_grid = "grid.nc"
if string == 'lon':
grid_data = Dataset(path_grid)
lon = np.array(grid_data.variables["lon"])
return(lon)
elif string == 'lat':
grid_data = Dataset(path_grid)
lat = np.array(grid_data.variables["lat"])
return(lat)
elif string == 'mask':
im = imageio.imread('J_Mask.tif')
mask = np.flipud(np.array(im))
return(mask)
def EASE():
"""
"Lakes":0,
"Oceans":1,
"Okhotsk":2,
"Bering":3,
"Hudson":4,
"St Lawrence":5,
"Baffin":6,
"Greenland":7,
"Barents":8,
"Kara":9,
"Laptev":10,
"East Siberian":11,
"Chukchi":12,
"Beaufort":13,
"Canadian Archipelago":14,
"Central Arctic":15,
"Land":20,
"Coast":21}
"""
mask = pickle.load( open( "mask_348x348.p", "rb" ) )
return(mask)
# Returns mask on OSISAF grid
def OSISAF():
"""
"Lakes":0,
"Oceans":1,
"Okhotsk":2,
"Bering":3,
"Hudson":4,
"St Lawrence":5,
"Baffin":6,
"Greenland":7,
"Barents":8,
"Kara":9,
"Laptev":10,
"East Siberian":11,
"Chukchi":12,
"Beaufort":13,
"Canadian Archipelago":14,
"Central Arctic":15,
"Land":20,
"Coast":21}
"""
mask = pickle.load( open( "mask_1120x760.p", "rb" ) )
return(mask)
# Plotter function
def plot(region_string):
regions_dict = {"Lakes":0,
"Oceans":1,
"Okhotsk":2,
"Bering":3,
"Hudson":4,
"St Lawrence":5,
"Baffin":6,
"Greenland":7,
"Barents":8,
"Kara":9,
"Laptev":10,
"East Siberian":11,
"Chukchi":12,
"Beaufort":13,
"Canadian Archipelago":14,
"Central Arctic":15,
"Land":20,
"Coast":21}
code = regions_dict[region_string]
fig = plt.figure(figsize=(10, 8))
m = Basemap(projection='npstere',boundinglat=50,lon_0=360,resolution='l')
m.drawcoastlines(linewidth=0.5)
m.pcolormesh(get('lon'), get('lat'), get('mask'), latlon=True,cmap='plasma',vmax=code+1,vmin=code-1)
plt.show()