-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathget_extrema_min.py
executable file
·95 lines (80 loc) · 3.04 KB
/
get_extrema_min.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
#!/usr/bin/python3
import os
import time
from datetime import date
from datetime import datetime
from datetime import timedelta
import shutil
from ftplib import FTP
test = False
#difaxMinDir = '/home/disk/data/archive/images/difax/difax_min'
difaxMinDir = '/home/disk/data/images/difax/difax_min'
tempDir = '/tmp'
catalogPrefix = 'surface.NWS'
# Field Catalog inputs
if test:
ftpCatalogServer = 'ftp.atmos.washington.edu'
ftpCatalogUser = 'anonymous'
ftpCatalogPassword = '[email protected]'
catalogDestDir = 'brodzik/incoming/impacts'
else:
ftpCatalogServer = 'catalog.eol.ucar.edu'
ftpCatalogUser = 'anonymous'
catalogDestDir = '/pub/incoming/catalog/impacts'
# Open ftp connection to NCAR sever
if test:
catalogFTP = FTP(ftpCatalogServer,ftpCatalogUser,ftpCatalogPassword)
catalogFTP.cwd(catalogDestDir)
else:
catalogFTP = FTP(ftpCatalogServer,ftpCatalogUser)
catalogFTP.cwd(catalogDestDir)
# Look for yesterday's map
today = datetime.utcnow()
yesterday = today - timedelta(days = 1)
dateStr = yesterday.strftime("%Y%m%d")
#yearMonthStr = yesterday.strftime("%Y%m")
# note for 2021: new maps are in DifaxMinDir+'/'+year+month
# e.g. /home/disk/data/archive/images/difax/difax_min/202112
#for file in os.listdir(os.path.join(difaxMinDir,yearMonthStr)):
for file in os.listdir(difaxMinDir):
if dateStr in file and file.endswith('gif'):
print('file = ',file)
(dateTime,ext) = file.split('.')
date = dateTime[0:8]
print('date = ',date)
catalogName = catalogPrefix+'.'+dateTime+'.min_temp.gif'
print('catalogName = ',catalogName)
#shutil.copy(os.path.join(difaxMinDir,yearMonthStr,file),
# tempDir+'/'+catalogName)
shutil.copy(os.path.join(difaxMinDir,file),
tempDir+'/'+catalogName)
# ftp file to catalog location
ftpFile = open(os.path.join(tempDir,catalogName),'rb')
catalogFTP.storbinary('STOR '+catalogName,ftpFile)
ftpFile.close()
# remove file from tempDir
os.remove(os.path.join(tempDir,catalogName))
# Look for today's map
dateStr = today.strftime("%Y%m%d")
#yearMonthStr = today.strftime("%Y%m")
#for file in os.listdir(os.path.join(difaxMinDir,yearMonthStr)):
for file in os.listdir(difaxMinDir):
if dateStr in file and file.endswith('gif'):
print('file = ',file)
(dateTime,ext) = file.split('.')
date = dateTime[0:8]
print('date = ',date)
catalogName = catalogPrefix+'.'+dateTime+'.min_temp.gif'
print('catalogName = ',catalogName)
#shutil.copy(os.path.join(difaxMinDir,month,file),
# tempDir+'/'+catalogName)
shutil.copy(os.path.join(difaxMinDir,file),
tempDir+'/'+catalogName)
# ftp file to catalog location
ftpFile = open(os.path.join(tempDir,catalogName),'rb')
catalogFTP.storbinary('STOR '+catalogName,ftpFile)
ftpFile.close()
# remove file from tempDir
os.remove(os.path.join(tempDir,catalogName))
# Close ftp connection
catalogFTP.quit()