17 from os.path
import exists, getsize
18 from datetime
import datetime
22 """!Determines if loop current files are still usable for a cycle of interest.
24 @param startdate the cycle of interest as a string, format YYYYMMDDHH
25 @param lfile,rfile the loop current l and r files
26 @param logger a logging.Logger for log messages."""
27 if logger
is None: logger=logging.getLogger(
'pom')
28 if exists(lfile)
and getsize(lfile) > 0
and \
29 exists(rfile)
and getsize(rfile) > 0:
30 logger.info(
'LC: %s and %s exists' %(lfile,rfile))
33 except ValueError
as e:
34 logger.error(
"datestamp can not be accessed from %s" %(lfile))
35 logger.error(
"Error: %s" %(e))
39 except ValueError
as e:
40 logger.error(
"datestamp can not be accessed from %s" %(rfile))
41 logger.error(
"Error: %s" %(e))
44 if isinstance(startdate, str):
47 t1 = datetime(int(ymdh[0:4]),int(ymdh[4:6]),int(ymdh[6:8]),int(ymdh[8:10]))
48 except ValueError
as e:
49 logger.error(
"Invalid startdate format %s" %(startdate))
50 logger.error(
"Error: %s" %(e))
54 t2 = datetime(int(ymdh[0:4]),int(ymdh[4:6]),int(ymdh[6:8]),int(ymdh[8:10]))
55 except ValueError
as e:
56 logger.error(
"Invalid LC datestamp format in %s" %(str(ldate)))
57 logger.error(
"Error: %s " %(e))
60 if days >= 0
and days <= 90:
61 logger.info(
"LC files are created by %i days ago from %s" %(days, startdate))
62 logger.info(
"%s and %s files can be used for sharpening" %(lfile,rfile))
65 logger.warn(
"LC files are created by %i days ago from %s" %(days,startdate))
66 logger.warn(
"%s and %s are OLD and Not using for sharpening" %(lfile,rfile))
69 logger.error(
"Invalid startdate(in Isthis_LCuseful) %s", startdate)
72 logger.error(
"Datestamps in %s and %s do not match" %(lfile,rfile))
75 logger.error(
"%s %s files do not exists" %(lfile,rfile))
79 """!Read the last line of the given file and return it.
80 @param file the file to read"""
81 with open(file)
as fid:
83 return data.split()[len(data.split())-1]
97 if __name__ ==
'__main__':
98 LCdir =
'/mnt/lfs2/projects/hwrf-data/fix-files/hwrf-20140617-fix/fix/loop_curr'
99 lfile = LCdir+
'/hwrf_gfdl_loop_current_rmy5.dat.20131001'
100 rfile = LCdir+
'/hwrf_gfdl_loop_current_wc_ring_rmy5.dat.20131001'
101 startdate =
'2013101123'
def Isthis_LCuseful
Determines if loop current files are still usable for a cycle of interest.
def get_endline(file)
Read the last line of the given file and return it.