-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathzones.py
144 lines (116 loc) · 3.66 KB
/
zones.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Autopep8: https://pypi.org/project/autopep8/
# Check with http://pep8online.com/
import matplotlib.patches as mpatches
import cartopy.crs as ccrs
# =============================================================================
# Zones
# =============================================================================
def get_zone(zone):
"""
Get the latitude and longitude limits for the corresponding zone.
Parameters
----------
zone : str
Zone name. Options are:
- 'GLOB', 'global', 'GLOBAL', 'GLOB-land'
- 'NH' : North Hemisphere
- 'HMA' : High Mountain of Asia
- 'NA' : North America
Returns
-------
latlim, lonlim : slice
Latitude and longitude limits of the zone.
Example
-------
>>> import sys
>>> sys.path.insert(1, '/home/mlalande/notebooks/utils')
>>> import utils as u
>>>
>>>
>>> latlim, lonlim = u.get_zone('HMA')
"""
# Global
if zone in ['GLOB', 'global', 'GLOBAL', 'GLOB-land']:
latlim = slice(None)
lonlim = slice(None)
# North Hemisphere
elif zone in ['NH']:
latlim = slice(0, 90)
lonlim = slice(None)
# High Mountain of Asia (HMA)
elif zone in ['HMA']:
latlim = slice(20, 50)
lonlim = slice(60, 110)
# latlim = slice(20,45)
# lonlim = slice(60,110)
# North America
elif zone in ['NA']:
latlim = slice(0, 70)
lonlim = slice(-150, -80)
else:
raise ValueError(
f"""Invalid zone argument: '{zone}'. Valid zones are:
- 'GLOB', 'global', 'GLOBAL'
- 'NH' : North Hemisphere
- 'HMA' : High Mountain of Asia
- 'NA' : North America
"""
)
return latlim, lonlim
def get_domain_HMA():
latlim = slice(20, 45)
lonlim = slice(60, 110)
return latlim, lonlim
# HKK: Hindu-Kush / Karakoram / Western Himalay
# HM: Central and Est Himalaya
# TB: Tibetan Plateau
def get_zones():
lonlim_HK = slice(70, 81)
latlim_HK = slice(31, 40)
lonlim_HM = slice(79, 98)
latlim_HM = slice(26, 31)
lonlim_TP = slice(81, 104)
latlim_TP = slice(31, 39)
return lonlim_HK, latlim_HK, lonlim_HM, latlim_HM, lonlim_TP, latlim_TP
def plot_zones(ax):
lonlim_HK, latlim_HK, lonlim_HM, latlim_HM, lonlim_TP, latlim_TP = \
get_zones()
# HKK
ax.text(lonlim_HK.start + 0.5, latlim_HK.stop - 2, 'HK', zorder=10)
ax.add_patch(
mpatches.Rectangle(
xy=[lonlim_HK.start, latlim_HK.start],
width=lonlim_HK.stop - lonlim_HK.start,
height=latlim_HK.stop - latlim_HK.start,
transform=ccrs.PlateCarree(),
fill=False,
zorder=10
)
)
# HM
ax.text(lonlim_HM.start + 0.5, latlim_HM.stop - 2, 'HM', zorder=10)
ax.add_patch(
mpatches.Rectangle(
xy=[lonlim_HM.start, latlim_HM.start],
width=lonlim_HM.stop - lonlim_HM.start,
height=latlim_HM.stop - latlim_HM.start,
transform=ccrs.PlateCarree(),
fill=False,
zorder=10
)
)
# TP
ax.text(lonlim_TP.start + 0.5, latlim_TP.stop - 2, 'TP', zorder=10)
ax.add_patch(
mpatches.Rectangle(
xy=[lonlim_TP.start, latlim_TP.start],
width=lonlim_TP.stop - lonlim_TP.start,
height=latlim_TP.stop - latlim_TP.start,
transform=ccrs.PlateCarree(),
fill=False,
zorder=10
)
)
return None