-
Notifications
You must be signed in to change notification settings - Fork 0
/
aaf_func.py
77 lines (64 loc) · 1.94 KB
/
aaf_func.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
from datetime import datetime,timezone
import numpy as np
#from aaf_usersettings import *
#from aaf_plot_mod import *
#import netCDF4
#import fnmatch
import time as timer
import netrc
import ftplib
def todayAt (hr, min=0, sec=0, micros=0):
now = datetime.now()
return now.replace(hour=hr, minute=min, second=sec, microsecond=micros)
def PointIdx(latPoint,lonPoint,latGrid,lonGrid):
abslat = np.abs(latGrid-latPoint)
abslon = np.abs(lonGrid-lonPoint)
c = np.maximum(abslon,abslat)
y_idx, x_idx = np.where(c == np.min(c))
return y_idx,x_idx
def ReadLoc(filename):
lon=[]
lat=[]
f = open(filename,'r')
pos =f.readlines()
f.close()
print('printpos')
print(pos)
print(pos[0])
if len(pos)>1:
print ('long')
for locs in pos:
print (locs)
#lon.append,lat.append=str.split(locs)
lont,latt=str.split(locs)
lon.append(lont)
lat.append(latt)
else:
#lon,lat=str.split(pos)
lont,latt=str.split(pos[0])
lon.append(lont)
lat.append(latt)
print (filename)
print (lon)
print (lat)
#return float(lat),float(lon)
return lat,lon
def fetchOden():
filename = "Odenloc.txt"
nnetrc = netrc.netrc()
remoteHostName = "bolftp.ecmwf.int"
authTokens = nnetrc.authenticators(remoteHostName)
if authTokens:
print('token exists for bolftp.ecmwf.int, fetching Oden location')
# Print the access tokens
#print("Remote Host Name:%s" % (remoteHostName))
ftp_server = ftplib.FTP(remoteHostName, authTokens[0],authTokens[2])
ftp_server.cwd('/artofmelt/')
# Write file in binary mode
with open(filename, "wb") as file:
# Command for Downloading the file "RETR filename"
ftp_server.retrbinary(f"RETR {filename}", file.write)
ftp_server.quit()
else:
print('token for bolftp.ecmwf.int does not exist')
print('update ~/.netrc with credentials to download Odenloc.txt')