-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrotate_data.py
44 lines (33 loc) · 1.54 KB
/
rotate_data.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
''' Function to rotate iris cubes plotted on a rotated pole grid to regular lat/lons.
======================================================================================================================
Inputs:
- cube to rotate
- dimensions to add the newly rotated latitudes and longitudes to.
Outputs:
- 1-D arrays of 'real', rotated latitudes and longitudes.
Dependencies:
- iris
- numpy
Author: Ella Gilbert, 2018.
'''
import iris
def rotate_data(var, lat_dim, lon_dim):
## Rotate projection
#create numpy arrays of coordinates
rotated_lat = var.coord('grid_latitude').points
rotated_lon = var.coord('grid_longitude').points
## set up parameters for rotated projection
pole_lon = var.coord('grid_longitude').coord_system.grid_north_pole_longitude
pole_lat = var.coord('grid_latitude').coord_system.grid_north_pole_latitude
#rotate projection
real_lon, real_lat = iris.analysis.cartography.unrotate_pole(rotated_lon,rotated_lat, pole_lon, pole_lat)
print ('\nunrotating pole...')
lat = var.coord('grid_latitude')
lon = var.coord('grid_longitude')
lat = iris.coords.DimCoord(real_lat, standard_name='latitude',long_name="grid_latitude",var_name="lat",units=lat.units)
lon= iris.coords.DimCoord(real_lon, standard_name='longitude',long_name="grid_longitude",var_name="lon",units=lon.units)
var.remove_coord('grid_latitude')
var.add_dim_coord(lat, data_dim=lat_dim)
var.remove_coord('grid_longitude')
var.add_dim_coord(lon, data_dim=lon_dim)
return real_lon, real_lat