-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathregion.py
79 lines (57 loc) · 2.31 KB
/
region.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
'''
To extract a region:
>>> bounds = bp.region.Country.china
>>> cube = bp.region.extract(cube, bounds)
'''
###############################
### Pre-defined named locations
###############################
class City:
london = { 'lon':0.739, 'lat':51.3026 }
mumbai = { 'lon':72.4933, 'lat':18.5830 }
chongqing = { 'lon':106.3400, 'lat':28.3330 }
hangzhou = { 'lon':120.1233, 'lat':30.2649 }
class Ice_Cores:
palmer = { 'lon':-65.2795, 'lat':-73.5176 }
gomez = { 'lon':-70.3669, 'lat':-73.5940 }
jurassic = { 'lon':-73.0358, 'lat':-74.1987 }
rendezvous = { 'lon':-78.0994, 'lat':-74.2694 }
bryan_coast = { 'lon':-81.4041, 'lat':-74.2946 }
ferrigno = { 'lon':-86.5416, 'lat':-74.3437 }
###############################
### Pre-defined regional bounds
###############################
nh = {'lat_bnds':(0, 90) }
sh = {'lat_bnds':(-90, 0) }
arctic_circle = {'lat_bnds':(66, 90) }
antarctic_60_90S = {'lat_bnds':(-90, -60)}
mid_latitudes = {'lat_bnds':(-60, 78) } # to leave off the poles from plots
class Continent:
europe = {'lon_bnds':(-11.25, 33.75), 'lat_bnds':(35.1, 72.5) }
europe_atlantic = {'lon_bnds':(-50., 33.75), 'lat_bnds':(25.0, 72.5) }
class Country:
uk = {'lon_bnds':(-11, 2), 'lat_bnds':(48, 60) }
france = {'lon_bnds':(-5, 9), 'lat_bnds':(41, 52) }
spain = {'lon_bnds':(-11, 6), 'lat_bnds':(35, 45) }
egypt = {'lon_bnds':(22, 39), 'lat_bnds':(20, 34) }
china = {'lon_bnds':(72,135), 'lat_bnds':(20,55) }
class Sub_regions:
central_england = {'lon_bnds':(-3.5, 0.), 'lat_bnds':(51.5, 53.5) }
himalayas = {'lon_bnds':(60, 100), 'lat_bnds':(15, 45) }
###############################
### Definitions
###############################
def extract(data, bounds):
'''
Extract region using pre-defined lat/lon bounds
>>> bounds = bp.region.Country.china
>>> data = bp.region.extract(data, bounds)
where 'data' can be either an iris.cube or a xarray.DataArray
'''
if 'iris' in str(type(data)):
from baspy._iris.util import extract_region
data = extract_region(data, bounds)
if 'xarray' in str(type(data)):
from baspy._xarray.util import extract_region
data = extract_region(data, bounds)
return data