-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCOORD_AC.py
74 lines (63 loc) · 2.85 KB
/
COORD_AC.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
#!/usr/bin/env python
import numpy as np
def mindist(point, array):
'''Formula to find the minimum distance of an element in an array.'''
mindist = np.abs(array - point).argmin()
return mindist
class AC_GEOreference():
'''Defines the coordinate range that is used in the spatial Aquacrop model and is equal to the coordinates of the HWSDv1.2.
The resolution is 30 arc sec == 1/120 degrees lat/lon.'''
def __init__(self,):
# HWSD
rows_hwsd = np.arange(0, 21600)
cols_hwsd = np.arange(0, 43200)
self.step = (1/120)
hwsd_latini, hwsd_lonini = (-90 + 1/240),(-180 + 1/240)
self.lat_ini = 14400 * self.step + hwsd_latini # ini = 14400: initial point is -90 + (1/240) --> + 120deg is +/- 30deg
self.lon_ini = 20340 * self.step + hwsd_lonini # ini = 20340: initial point is -180 + (1/240) --> + +/- 170 deg is -10deg
# subset 'reepje':
self.reepje_rows = np.arange(719,3000+1)
self.reepje_cols = np.arange(2400,3540+1)
self.reepje_latini = self.reepje_rows[0] * self.step + self.lat_ini
self.reepje_lonini = self.reepje_cols[0] * self.step + self.lon_ini
self.reepje_latend = self.reepje_rows[-1] * self.step + self.lat_ini
self.reepje_lonend = self.reepje_cols[-1] * self.step + self.lon_ini
# general formulas
def lat_to_row(self,lat):
row = round((lat - self.lat_ini) / (self.step))
return row
def lon_to_col(self, lon):
col = round((lon - self.lon_ini) / (self.step))
return col
def row_to_lat(self, row):
lat = row * self.step + self.lat_ini
return lat
def col_to_lon(self, col):
lon = col * self.step + self.lon_ini
return lon
def AC_mindist(self,row, col, ds_lats, ds_lons):
'''Formula to find closest AC row/col pixel in a dataset of lats/lons'''
lat = row * self.step + self.lat_ini
lon = col * self.step + self.lon_ini
lat_id, lon_id = mindist(lat, ds_lats), mindist(lon, ds_lons)
return(lat_id, lon_id)
class MERRA2_GEOreference():
def __init__(self, ):
self.M2AC_ini_lat = 60
self.M2AC_ini_lon = -10.625
self.M2AC_step_lat = 0.5
self.M2AC_step_lon = 0.625
self.CLI_latrange=np.arange(self.M2AC_ini_lat, 30, -self.M2AC_step_lat)
self.CLI_lonrange=np.arange(self.M2AC_ini_lon, 45.625, self.M2AC_step_lon)
def M2AC_row_to_lat(self, row):
lat = self.M2AC_ini_lat - (row * self.M2AC_step_lat)
return lat
def M2AC_lat_to_row(self, lat):
row = round((self.M2AC_ini_lat - lat) / self.M2AC_step_lat)
return row
def M2AC_col_to_lon(self, col):
lon = self.M2AC_ini_lon + (col*self.M2AC_step_lon)
return lon
def M2AC_lon_to_col(self, lon):
col = round((lon-self.M2AC_ini_lon)/self.M2AC_step_lon)
return col