# -*- coding: utf-8 -*- #---------------------------------------------------------------------# # WSSI Summer # # Filename: wssi_summary.py # # Description: Finds max impact from snow amount, snow load # # (or snow load winter), blowing snow, ice accumulation, flash freeze # # and ground blizzard for rolling 24 hr period and full period # # Authors: Nathan Foster/Josh Kastman # # Created by Nathan Foster (WFO Las Vegas) nathan.foster@noaa.gov # # Change Log: # # Output for rolling 24 hour periods - Kastman 2018-10-11 # # Updated for rolling 24 hr output - Kastman 2021-6-30 # #---------------------------------------------------------------------# import arcpy, os, shutil, datetime, time, sys from datetime import datetime from time import gmtime, strftime from shutil import copyfile import glob import os.path from os import path import wssi_config as cfg def wssi_summary(): arcpy.env.overwriteOutput = True arcpy.SetLogHistory(False) ## precip_num_list = cfg.precip_num_list ## precip_hrs = cfg.precip_hrs ## wgust_num_list = cfg.wgust_num_list ## wgust_hrs = cfg.wgust_hrs ## ## last_gust = wgust_num_list[-1] ## ## precip_num_list_d4 = cfg.precip_num_list_d4 ## precip_d4_hrs = cfg.precip_d4_hrs ## rdict = cfg.rdict ## rdict_d4 = cfg.rdict_d4 file = cfg.work_dir+'precp_num_list.txt' data = open(file, 'r') precip_num_text = data.readline() precip_num_list = precip_num_text.split() file = cfg.work_dir+'precip_hrs.txt' data = open(file, 'r') precip_hrs_txt = data.readline() precip_hrs = precip_hrs_txt.split() file = cfg.work_dir+'wgust_num_list.txt' data = open(file, 'r') wgust_num_text = data.readline() wgust_num_list = wgust_num_text.split() #print wgust_num_list file = cfg.work_dir+'wgust_hrs.txt' data = open(file, 'r') wgust_hrs_txt = data.readline() wgust_hrs = wgust_hrs_txt.split() #print wgust_hrs file = cfg.work_dir+'d4wgust_num_list.txt' data = open(file, 'r') d4wgust_num_text = data.readline() d4wgust_num_list = d4wgust_num_text.split() print d4wgust_num_list file = cfg.work_dir+'d4wgust_hrs.txt' data = open(file, 'r') d4wgust_hrs_txt = data.readline() d4wgust_hrs = d4wgust_hrs_txt.split() print d4wgust_hrs file = cfg.work_dir+'wgust_max_valid.txt' data = open(file, 'r') max_vars = data.readline() #print max_vars #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # DAY 4 TEMPORARILY COMMENTED OUT ! #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! try: precip_num_list_d4 = cfg.precip_num_list_d4 precip_d4_hrs = cfg.precip_d4_hrs rdict = cfg.rdict rdict_d4 = cfg.rdict_d4 except: print(traceback.format_exc()) print ("DAY 4 ERROR") logging.error(traceback.format_exc()) logging.error("DAY 4 ERROR") pass all_hrs = [] for hr in precip_hrs: all_hrs.append(hr) for d4hr in precip_d4_hrs: all_hrs.append(d4hr) last_gust = wgust_num_list[-1] wgust_dict = dict(zip(wgust_num_list, wgust_hrs)) print wgust_dict d4wgust_dict = dict(zip(d4wgust_num_list, d4wgust_hrs)) print d4wgust_dict all_hrs = precip_hrs print all_hrs if path.exists(cfg.grb_dir+"ds.wpc_d4snow.bin") == True: all_hrs.append('96') d3lhr = precip_hrs[-1] print "d3lhr: "+str(d3lhr) d4lhr = all_hrs[-1] print "d4lhr: "+str(d4lhr) try: if arcpy.CheckExtension("Spatial") == "Available": arcpy.CheckOutExtension("Spatial") else: # Raise a custom exception # raise LicenseError except LicenseError: print "Spatial Analyst license is unavailable" ############## # Days 1 - 3 # ############## arcpy.env.mask = cfg.States gb_status = 'yes' #manually edit based on SNODAS print gb_status # Full Summary ground blizzard staus = 'yes'# if gb_status == 'yes': print "Ground Blizzard Present" #logging.debug ("Ground Blizzard Present") # Full Summary out to corresponding timecheck hours full_snowload_re.tif #------------# # Leaf - OFF # #------------# arcpy.gp.CellStatistics_sa(cfg.work_dir+"finalicemax.tif;"+cfg.work_dir+"total_snamt_I.tif;"+cfg.work_dir+"total_cum_max.tif;"+cfg.work_dir+"ff_max.tif;"+cfg.work_dir+"WSII_GB_FINAL.tif;"+cfg.work_dir+"WSII_SnowLoad.tif", cfg.work_dir+"wsii_total.tif", "MAXIMUM", "DATA") #-----------# # Leaf - ON # #-----------# #arcpy.gp.CellStatistics_sa(cfg.work_dir+"finalicemax.tif;"+cfg.work_dir+"total_snamt_I.tif;"+cfg.work_dir+"total_cum_max.tif;"+cfg.work_dir+"ff_max.tif;"+cfg.work_dir+"WSII_GB_FINAL.tif;"+cfg.work_dir+"full_snowload_re.tif", cfg.work_dir+"wsii_total.tif", "MAXIMUM", "DATA") arcpy.DefineProjection_management(cfg.work_dir+"wsii_total.tif", "PROJCS['NDFD',GEOGCS['GCS_Unknown',DATUM['D_unknown',SPHEROID['Sphere',6371000.0,0.0]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Lambert_Conformal_Conic'],PARAMETER['false_easting',0.0],PARAMETER['false_northing',0.0],PARAMETER['central_meridian',-95.0],PARAMETER['standard_parallel_1',25.0],PARAMETER['standard_parallel_2',25.0],PARAMETER['latitude_of_origin',25.0],UNIT['Meter',1.0]]") print ("Total Sumary Complete") ######### # Day 4 # ######### if gb_status == 'yes': print "Ground Blizzard Present" #logging.debug ("Ground Blizzard Present") # Full Summary out to corresponding timecheck hours full_snowload_re.tif #------------# # Leaf - OFF # #------------# arcpy.env.mask = cfg.States if path.exists(cfg.grb_dir+"ds.wpc_d4snow.bin") == True: arcpy.Resample_management(cfg.comp_out+"sn_ld_d4.tif", cfg.work_dir+"sn_ld_d4_rs.tif", 2539.703, "NEAREST") arcpy.Resample_management(cfg.comp_out+"sn_ld_win_d4.tif", cfg.work_dir+"sn_ld_win_d4_rs.tif", 2539.703, "NEAREST") arcpy.Resample_management(cfg.comp_out+"snow_d4.tif", cfg.work_dir+"snow_d4_rs.tif", 2539.703, "NEAREST") arcpy.Resample_management(cfg.comp_out+"bl_sn_d4.tif", cfg.work_dir+"bl_sn_d4_rs.tif", 2539.703, "NEAREST") arcpy.gp.CellStatistics_sa(cfg.comp_out+"bl_sn_fp.tif;"+cfg.work_dir+"bl_sn_d4_rs.tif",cfg.comp_out+"bl_sn_d4fp.tif", "MAXIMUM", "DATA") arcpy.gp.CellStatistics_sa(cfg.comp_out+"sn_ld_win_fp.tif;"+cfg.work_dir+"sn_ld_win_d4_rs.tif",cfg.comp_out+"sn_ld_win_d4fp.tif", "MAXIMUM", "DATA") arcpy.gp.CellStatistics_sa(cfg.comp_out+"snow_fp.tif;"+cfg.work_dir+"snow_d4_rs.tif",cfg.comp_out+"snow_d4fp.tif", "MAXIMUM", "DATA") #arcpy.gp.CellStatistics_sa(cfg.comp_out+"finalicemax.tif;"+cfg.work_dir+"total_thru_d4_snamt_I.tif;"+cfg.work_dir+"total_cum_max_d4.tif;"+cfg.work_dir+"ff_max.tif;"+cfg.work_dir+"WSII_GB_FINAL.tif;"+cfg.work_dir+"WSII_thru_d4_SnowLoad.tif", cfg.work_dir+"wsii_thru_d4_total.tif", "MAXIMUM", "DATA") arcpy.gp.CellStatistics_sa(cfg.work_dir+"wsii_total.tif;"+cfg.work_dir+"sn_ld_win_d4_rs.tif;"+cfg.work_dir+"snow_d4_rs.tif;"+cfg.work_dir+"bl_sn_d4_rs.tif",cfg.comp_out+"wsii_thru_d4_total.tif", "MAXIMUM", "DATA") #-----------# # Leaf - ON # #-----------# #arcpy.gp.CellStatistics_sa(cfg.work_dir+"finalicemax.tif;"+cfg.work_dir+"total_thru_d4_snamt_I.tif;"+cfg.work_dir+"total_cum_max_d4.tif;"+cfg.work_dir+"ff_max.tif;"+cfg.work_dir+"WSII_GB_FINAL.tif;"+cfg.work_dir+"d4_snowload_re.tif", cfg.work_dir+"wsii_thru_d4_total.tif", "MAXIMUM", "DATA") #arcpy.Resample_management(cfg.comp_out+"sn_ld_d4.tif", cfg.work_dir+"sn_ld_d4_rs.tif", cfg.work_dir+"wsii_total.tif", "NEAREST") #arcpy.gp.CellStatistics_sa(cfg.work_dir+"wsii_total.tif;"+cfg.work_dir+"sn_ld_d4_rs.tif;"+cfg.work_dir+"snow_d4_rs.tif;"+cfg.work_dir+"bl_sn_d4_rs.tif",cfg.comp_out+"wsii_thru_d4_total.tif", "MAXIMUM", "DATA") arcpy.DefineProjection_management(cfg.comp_out+"wsii_thru_d4_total.tif", "PROJCS['NDFD',GEOGCS['GCS_Unknown',DATUM['D_unknown',SPHEROID['Sphere',6371000.0,0.0]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Lambert_Conformal_Conic'],PARAMETER['false_easting',0.0],PARAMETER['false_northing',0.0],PARAMETER['central_meridian',-95.0],PARAMETER['standard_parallel_1',25.0],PARAMETER['standard_parallel_2',25.0],PARAMETER['latitude_of_origin',25.0],UNIT['Meter',1.0]]") print ("Total Sumary Complete") # 24 Hour summaries for each six hour peroid for n in all_hrs[3:]: if int(n) <= 36: print "HR: "+n+" Including Flash Freeze and Ground Blizzard" #logging.debug ("HR: "+n+" Including Flash Freeze and Ground Blizzard") #------------# # Leaf - OFF # #------------# arcpy.gp.CellStatistics_sa(cfg.work_dir+"finalicemax_v"+n+".tif;"+cfg.work_dir+"v"+n+"hrsnamt_I.tif;"+cfg.work_dir+"v"+n+"hr_cum_max.tif;"+cfg.work_dir+"ff_max_"+n+"hr.tif;"+cfg.work_dir+"WSII_GB_FINAL"+n+"hr.tif;"+cfg.work_dir+"WSSI_"+n+"_SnLd.tif", cfg.work_dir+"wsii_f"+n+".tif", "MAXIMUM", "DATA") #-----------# # Leaf - ON # #-----------# #arcpy.gp.CellStatistics_sa(cfg.work_dir+"finalicemax_v"+n+".tif;"+cfg.work_dir+"v"+n+"hrsnamt_I.tif;"+cfg.work_dir+"v"+n+"hr_cum_max.tif;"+cfg.work_dir+"ff_max_"+n+"hr.tif;"+cfg.work_dir+"WSII_GB_FINAL"+n+"hr.tif;"+cfg.work_dir+"v"+n+"hr_snowload_re.tif", cfg.work_dir+"wsii_f"+n+".tif", "MAXIMUM", "DATA") arcpy.DefineProjection_management(cfg.work_dir+"wsii_f"+n+".tif", "PROJCS['NDFD',GEOGCS['GCS_Unknown',DATUM['D_unknown',SPHEROID['Sphere',6371000.0,0.0]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Lambert_Conformal_Conic'],PARAMETER['false_easting',0.0],PARAMETER['false_northing',0.0],PARAMETER['central_meridian',-95.0],PARAMETER['standard_parallel_1',25.0],PARAMETER['standard_parallel_2',25.0],PARAMETER['latitude_of_origin',25.0],UNIT['Meter',1.0]]") elif int(n) <= 48: print "HR: "+n+" Including Ground Blizzard" #logging.debug ("HR: "+n+" Including Ground Blizzard") #------------# # Leaf - OFF # #------------# arcpy.gp.CellStatistics_sa(cfg.work_dir+"finalicemax_v"+n+".tif;"+cfg.work_dir+"v"+n+"hrsnamt_I.tif;"+cfg.work_dir+"v"+n+"hr_cum_max.tif;"+cfg.work_dir+"WSII_GB_FINAL"+n+"hr.tif;"+cfg.work_dir+"WSSI_"+n+"_SnLd.tif", cfg.work_dir+"wsii_f"+n+".tif", "MAXIMUM", "DATA") #-----------# # Leaf - ON # #-----------# #arcpy.gp.CellStatistics_sa(cfg.work_dir+"finalicemax_v"+n+".tif;"+cfg.work_dir+"v"+n+"hrsnamt_I.tif;"+cfg.work_dir+"v"+n+"hr_cum_max.tif;"+cfg.work_dir+"WSII_GB_FINAL"+n+"hr.tif;"+cfg.work_dir+"v"+n+"hr_snowload_re.tif", cfg.work_dir+"wsii_f"+n+".tif", "MAXIMUM", "DATA") arcpy.DefineProjection_management(cfg.work_dir+"wsii_f"+n+".tif", "PROJCS['NDFD',GEOGCS['GCS_Unknown',DATUM['D_unknown',SPHEROID['Sphere',6371000.0,0.0]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Lambert_Conformal_Conic'],PARAMETER['false_easting',0.0],PARAMETER['false_northing',0.0],PARAMETER['central_meridian',-95.0],PARAMETER['standard_parallel_1',25.0],PARAMETER['standard_parallel_2',25.0],PARAMETER['latitude_of_origin',25.0],UNIT['Meter',1.0]]") elif int(n) <= 72: print "HR: "+n+" SN AMT, SN LD, ICE AMT, BL SN only" #logging.debug ("HR: "+n+" SN AMT, SN LD, ICE AMT, BL SN only") #------------# # Leaf - OFF # #------------# arcpy.gp.CellStatistics_sa(cfg.work_dir+"finalicemax_v"+n+".tif;"+cfg.work_dir+"v"+n+"hrsnamt_I.tif;"+cfg.work_dir+"v"+n+"hr_cum_max.tif;"+cfg.work_dir+"WSSI_"+n+"_SnLd.tif", cfg.work_dir+"wsii_f"+n+".tif", "MAXIMUM", "DATA") #-----------# # Leaf - ON # #-----------# #arcpy.gp.CellStatistics_sa(cfg.work_dir+"finalicemax_v"+n+".tif;"+cfg.work_dir+"v"+n+"hrsnamt_I.tif;"+cfg.work_dir+"v"+n+"hr_cum_max.tif;"+cfg.work_dir+"v"+n+"hr_snowload_re.tif", cfg.work_dir+"wsii_f"+n+".tif", "MAXIMUM", "DATA") arcpy.DefineProjection_management(cfg.work_dir+"wsii_f"+n+".tif", "PROJCS['NDFD',GEOGCS['GCS_Unknown',DATUM['D_unknown',SPHEROID['Sphere',6371000.0,0.0]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Lambert_Conformal_Conic'],PARAMETER['false_easting',0.0],PARAMETER['false_northing',0.0],PARAMETER['central_meridian',-95.0],PARAMETER['standard_parallel_1',25.0],PARAMETER['standard_parallel_2',25.0],PARAMETER['latitude_of_origin',25.0],UNIT['Meter',1.0]]") else: print "HR: "+n+" SN AMT, SN LD, BL SN only" #ICE AMT, #logging.debug ("HR: "+n+" SN AMT, SN LD, ICE AMT, BL SN only") #------------# # Leaf - OFF # #------------# arcpy.gp.CellStatistics_sa(cfg.work_dir+"v"+n+"hrsnamt_I.tif;"+cfg.work_dir+"v"+n+"hr_cum_max.tif;"+cfg.work_dir+"WSSI_"+n+"_SnLd.tif", cfg.work_dir+"wsii_f"+n+".tif", "MAXIMUM", "DATA") #-----------# # Leaf - ON # #-----------# #arcpy.gp.CellStatistics_sa(cfg.work_dir+"v"+n+"hrsnamt_I.tif;"+cfg.work_dir+"v"+n+"hr_cum_max.tif;"+cfg.work_dir+"v"+n+"hr_snowload_re.tif", cfg.work_dir+"wsii_f"+n+".tif", "MAXIMUM", "DATA") #cfg.work_dir+"finalicemax_v"+n+".tif;"+ arcpy.DefineProjection_management(cfg.work_dir+"wsii_f"+n+".tif", "PROJCS['NDFD',GEOGCS['GCS_Unknown',DATUM['D_unknown',SPHEROID['Sphere',6371000.0,0.0]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Lambert_Conformal_Conic'],PARAMETER['false_easting',0.0],PARAMETER['false_northing',0.0],PARAMETER['central_meridian',-95.0],PARAMETER['standard_parallel_1',25.0],PARAMETER['standard_parallel_2',25.0],PARAMETER['latitude_of_origin',25.0],UNIT['Meter',1.0]]") else: print "Ground Blizzard NOT Present" #logging.debug ("Ground Blizzard Present") # Full Summary out to corresponding timecheck hours full_snowload_re.tif #------------# # Leaf - OFF # #------------# arcpy.gp.CellStatistics_sa(cfg.work_dir+"finalicemax.tif;"+cfg.work_dir+"total_snamt_I.tif;"+cfg.work_dir+"total_cum_max.tif;"+cfg.work_dir+"ff_max.tif;"+cfg.work_dir+"WSII_SnowLoad.tif", cfg.work_dir+"wsii_total.tif", "MAXIMUM", "DATA") #-----------# # Leaf - ON # #-----------# #arcpy.gp.CellStatistics_sa(cfg.work_dir+"finalicemax.tif;"+cfg.work_dir+"total_snamt_I.tif;"+cfg.work_dir+"total_cum_max.tif;"+cfg.work_dir+"ff_max.tif;"+cfg.work_dir+"full_snowload_re.tif", cfg.work_dir+"wsii_total.tif", "MAXIMUM", "DATA") arcpy.DefineProjection_management(cfg.work_dir+"wsii_total.tif", "PROJCS['NDFD',GEOGCS['GCS_Unknown',DATUM['D_unknown',SPHEROID['Sphere',6371000.0,0.0]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Lambert_Conformal_Conic'],PARAMETER['false_easting',0.0],PARAMETER['false_northing',0.0],PARAMETER['central_meridian',-95.0],PARAMETER['standard_parallel_1',25.0],PARAMETER['standard_parallel_2',25.0],PARAMETER['latitude_of_origin',25.0],UNIT['Meter',1.0]]") print ("Total Sumary Complete") ######### # Day 4 # ######### #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # DAY 4 TEMPORARILY COMMENTED OUT ! #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! print "Ground Blizzard NOT Present" #logging.debug ("Ground Blizzard NOT Present") # Full Summary out to corresponding timecheck hours full_snowload_re.tif #------------# # Leaf - OFF # #------------# if path.exists(cfg.grb_dir+"ds.wpc_d4snow.bin") == True: arcpy.Resample_management(cfg.comp_out+"sn_ld_d4.tif", cfg.work_dir+"sn_ld_d4_rs.tif", 2539.703, "NEAREST") arcpy.Resample_management(cfg.comp_out+"sn_ld_win_d4.tif", cfg.work_dir+"sn_ld_win_d4_rs.tif", 2539.703, "NEAREST") arcpy.Resample_management(cfg.comp_out+"snow_d4.tif", cfg.work_dir+"snow_d4_rs.tif", 2539.703, "NEAREST") arcpy.Resample_management(cfg.comp_out+"bl_sn_d4.tif", cfg.work_dir+"bl_sn_d4_rs.tif", 2539.703, "NEAREST") arcpy.gp.CellStatistics_sa(cfg.comp_out+"bl_sn_fp.tif;"+cfg.work_dir+"bl_sn_d4_rs.tif",cfg.comp_out+"bl_sn_d4fp.tif", "MAXIMUM", "DATA") arcpy.gp.CellStatistics_sa(cfg.comp_out+"sn_ld_win_fp.tif;"+cfg.work_dir+"sn_ld_win_d4_rs.tif",cfg.comp_out+"sn_ld_win_d4fp.tif", "MAXIMUM", "DATA") arcpy.gp.CellStatistics_sa(cfg.comp_out+"snow_fp.tif;"+cfg.work_dir+"snow_d4_rs.tif",cfg.comp_out+"snow_d4fp.tif", "MAXIMUM", "DATA") #arcpy.gp.CellStatistics_sa(cfg.comp_out+"finalicemax.tif;"+cfg.work_dir+"total_thru_d4_snamt_I.tif;"+cfg.work_dir+"total_cum_max_d4.tif;"+cfg.work_dir+"ff_max.tif;"+cfg.work_dir+"WSII_GB_FINAL.tif;"+cfg.work_dir+"WSII_thru_d4_SnowLoad.tif", cfg.work_dir+"wsii_thru_d4_total.tif", "MAXIMUM", "DATA") arcpy.gp.CellStatistics_sa(cfg.work_dir+"wsii_total.tif;"+cfg.work_dir+"sn_ld_win_d4_rs.tif;"+cfg.work_dir+"snow_d4_rs.tif;"+cfg.work_dir+"bl_sn_d4_rs.tif",cfg.comp_out+"wsii_thru_d4_total.tif", "MAXIMUM", "DATA") #-----------# # Leaf - ON # #-----------# #arcpy.gp.CellStatistics_sa(cfg.work_dir+"finalicemax.tif;"+cfg.work_dir+"total_thru_d4_snamt_I.tif;"+cfg.work_dir+"total_cum_max_d4.tif;"+cfg.work_dir+"ff_max.tif;"+cfg.work_dir+"d4_snowload_re.tif", cfg.work_dir+"wsii_thru_d4_total.tif", "MAXIMUM", "DATA") #arcpy.gp.CellStatistics_sa(cfg.work_dir+"wsii_total.tif;"+cfg.comp_out+"sn_ld_d4.tif;"+cfg.comp_out+"snow_d4.tif;"+cfg.comp_out+"bl_sn_d4.tif",cfg.work_dir+"wsii_thru_d4_total.tif", "MAXIMUM", "DATA") #arcpy.Resample_management(cfg.comp_out+"sn_ld_d4.tif", cfg.work_dir+"sn_ld_d4_rs.tif", 2539.703, "NEAREST") #arcpy.Resample_management(cfg.comp_out+"snow_d4.tif", cfg.work_dir+"snow_d4_rs.tif", 2539.703, "NEAREST") #arcpy.Resample_management(cfg.comp_out+"bl_sn_d4.tif", cfg.work_dir+"bl_sn_d4_rs.tif", 2539.703, "NEAREST") #arcpy.Resample_management(cfg.comp_out+"sn_ld_d4.tif", cfg.work_dir+"sn_ld_d4_rs.tif", cfg.work_dir+"wsii_total.tif", "NEAREST") #arcpy.gp.CellStatistics_sa(cfg.work_dir+"wsii_total.tif;"+cfg.work_dir+"sn_ld_d4_rs.tif;"+cfg.work_dir+"snow_d4_rs.tif;"+cfg.work_dir+"bl_sn_d4_rs.tif",cfg.work_dir+"wsii_thru_d4_total.tif", "MAXIMUM", "DATA") arcpy.DefineProjection_management(cfg.comp_out+"wsii_thru_d4_total.tif", "PROJCS['NDFD',GEOGCS['GCS_Unknown',DATUM['D_unknown',SPHEROID['Sphere',6371000.0,0.0]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Lambert_Conformal_Conic'],PARAMETER['false_easting',0.0],PARAMETER['false_northing',0.0],PARAMETER['central_meridian',-95.0],PARAMETER['standard_parallel_1',25.0],PARAMETER['standard_parallel_2',25.0],PARAMETER['latitude_of_origin',25.0],UNIT['Meter',1.0]]") print ("Total Sumary Complete") # 24 Hour summaries for each six hour peroid for n in all_hrs[3:]: if int(n) <= 36: print "HR: "+n+" Including Flash Freeze and NO Ground Blizzard" #logging.debug ("HR: "+n+" Including Flash Freeze and NO Ground Blizzard") #------------# # Leaf - OFF # #------------# arcpy.gp.CellStatistics_sa(cfg.work_dir+"finalicemax_v"+n+".tif;"+cfg.work_dir+"v"+n+"hrsnamt_I.tif;"+cfg.work_dir+"v"+n+"hr_cum_max.tif;"+cfg.work_dir+"ff_max_"+n+"hr.tif;"+cfg.work_dir+"WSSI_"+n+"_SnLd.tif", cfg.work_dir+"wsii_f"+n+".tif", "MAXIMUM", "DATA") #-----------# # Leaf - ON # #-----------# #arcpy.gp.CellStatistics_sa(cfg.work_dir+"finalicemax_v"+n+".tif;"+cfg.work_dir+"v"+n+"hrsnamt_I.tif;"+cfg.work_dir+"v"+n+"hr_cum_max.tif;"+cfg.work_dir+"ff_max_"+n+"hr.tif;"+cfg.work_dir+"v"+n+"hr_snowload_re.tif", cfg.work_dir+"wsii_f"+n+".tif", "MAXIMUM", "DATA") arcpy.DefineProjection_management(cfg.work_dir+"wsii_f"+n+".tif", "PROJCS['NDFD',GEOGCS['GCS_Unknown',DATUM['D_unknown',SPHEROID['Sphere',6371000.0,0.0]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Lambert_Conformal_Conic'],PARAMETER['false_easting',0.0],PARAMETER['false_northing',0.0],PARAMETER['central_meridian',-95.0],PARAMETER['standard_parallel_1',25.0],PARAMETER['standard_parallel_2',25.0],PARAMETER['latitude_of_origin',25.0],UNIT['Meter',1.0]]") elif int(n) <= 48: print "HR: "+n+" NOT Including Ground Blizzard" #logging.debug ("HR: "+n+" Including Ground Blizzard") #------------# # Leaf - OFF # #------------# arcpy.gp.CellStatistics_sa(cfg.work_dir+"finalicemax_v"+n+".tif;"+cfg.work_dir+"v"+n+"hrsnamt_I.tif;"+cfg.work_dir+"v"+n+"hr_cum_max.tif;"+cfg.work_dir+"WSSI_"+n+"_SnLd.tif", cfg.work_dir+"wsii_f"+n+".tif", "MAXIMUM", "DATA") #-----------# # Leaf - ON # #-----------# #arcpy.gp.CellStatistics_sa(cfg.work_dir+"finalicemax_v"+n+".tif;"+cfg.work_dir+"v"+n+"hrsnamt_I.tif;"+cfg.work_dir+"v"+n+"hr_cum_max.tif;"+cfg.work_dir+"v"+n+"hr_snowload_re.tif", cfg.work_dir+"wsii_f"+n+".tif", "MAXIMUM", "DATA") arcpy.DefineProjection_management(cfg.work_dir+"wsii_f"+n+".tif", "PROJCS['NDFD',GEOGCS['GCS_Unknown',DATUM['D_unknown',SPHEROID['Sphere',6371000.0,0.0]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Lambert_Conformal_Conic'],PARAMETER['false_easting',0.0],PARAMETER['false_northing',0.0],PARAMETER['central_meridian',-95.0],PARAMETER['standard_parallel_1',25.0],PARAMETER['standard_parallel_2',25.0],PARAMETER['latitude_of_origin',25.0],UNIT['Meter',1.0]]") elif int(n) <= 72: print "HR: "+n+" SN AMT, SN LD, ICE AMT, BL SN only" #logging.debug ("HR: "+n+" SN AMT, SN LD, ICE AMT, BL SN only") #------------# # Leaf - OFF # #------------# arcpy.gp.CellStatistics_sa(cfg.work_dir+"finalicemax_v"+n+".tif;"+cfg.work_dir+"v"+n+"hrsnamt_I.tif;"+cfg.work_dir+"v"+n+"hr_cum_max.tif;"+cfg.work_dir+"WSSI_"+n+"_SnLd.tif", cfg.work_dir+"wsii_f"+n+".tif", "MAXIMUM", "DATA") #-----------# # Leaf - ON # #-----------# #arcpy.gp.CellStatistics_sa(cfg.work_dir+"finalicemax_v"+n+".tif;"+cfg.work_dir+"v"+n+"hrsnamt_I.tif;"+cfg.work_dir+"v"+n+"hr_cum_max.tif;"+cfg.work_dir+"v"+n+"hr_snowload_re.tif", cfg.work_dir+"wsii_f"+n+".tif", "MAXIMUM", "DATA") arcpy.DefineProjection_management(cfg.work_dir+"wsii_f"+n+".tif", "PROJCS['NDFD',GEOGCS['GCS_Unknown',DATUM['D_unknown',SPHEROID['Sphere',6371000.0,0.0]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Lambert_Conformal_Conic'],PARAMETER['false_easting',0.0],PARAMETER['false_northing',0.0],PARAMETER['central_meridian',-95.0],PARAMETER['standard_parallel_1',25.0],PARAMETER['standard_parallel_2',25.0],PARAMETER['latitude_of_origin',25.0],UNIT['Meter',1.0]]") else: print "HR: "+n+" SN AMT, SN LD, BL SN only" #ICE AMT, #logging.debug ("HR: "+n+" SN AMT, SN LD, ICE AMT, BL SN only") #------------# # Leaf - OFF # #------------# arcpy.gp.CellStatistics_sa(cfg.work_dir+"v"+n+"hrsnamt_I.tif;"+cfg.work_dir+"v"+n+"hr_cum_max.tif;"+cfg.work_dir+"WSSI_"+n+"_SnLd.tif", cfg.work_dir+"wsii_f"+n+".tif", "MAXIMUM", "DATA") #-----------# # Leaf - ON # #-----------# #arcpy.gp.CellStatistics_sa(cfg.work_dir+"v"+n+"hrsnamt_I.tif;"+cfg.work_dir+"v"+n+"hr_cum_max.tif;"+cfg.work_dir+"v"+n+"hr_snowload_re.tif", cfg.work_dir+"wsii_f"+n+".tif", "MAXIMUM", "DATA") #cfg.work_dir+"finalicemax_v"+n+".tif;"+ arcpy.DefineProjection_management(cfg.work_dir+"wsii_f"+n+".tif", "PROJCS['NDFD',GEOGCS['GCS_Unknown',DATUM['D_unknown',SPHEROID['Sphere',6371000.0,0.0]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Lambert_Conformal_Conic'],PARAMETER['false_easting',0.0],PARAMETER['false_northing',0.0],PARAMETER['central_meridian',-95.0],PARAMETER['standard_parallel_1',25.0],PARAMETER['standard_parallel_2',25.0],PARAMETER['latitude_of_origin',25.0],UNIT['Meter',1.0]]") ## infiles = ["wsii_total.tif","wsii_f24.tif","wsii_f48.tif"] ## outfiles = ["wssi_overall_fp.tif","wssi_overall_d1.tif","wssi_overall_d2.tif"] ## for i,o in zip(infiles,outfiles): ## copyfile(cfg.work_dir+i, cfg.comp_dir+o) #----------------------------------------------------------------------------------------------------# # Copy total, day1 and day2 output to components output folder. Day3 will be coppied in summary step # #----------------------------------------------------------------------------------------------------# os.chdir(cfg.work_dir) if precip_num_list[-1] == str(11): d3 = "wsii_f66.tif" else: d3 = "wsii_f72.tif" infiles = ['wsii_total.tif',"wsii_f24.tif","wsii_f48.tif",d3, "wsii_f96.tif"] outfiles = ['wssi_overall_fp.tif','wssi_overall_d1.tif','wssi_overall_d2.tif','wssi_overall_d3.tif','wssi_overall_d4.tif'] for i,o in zip(infiles,outfiles): try: copyfile(cfg.work_dir+i, cfg.comp_out+o) except: #logging.error(traceback.format_exc()) pass rolling_web_list = [] for file in glob.glob("wsii_f*"+"*.tif"): rolling_web_list.append(file) print rolling_web_list for f in rolling_web_list: rf = 'r24h_WSSI_f'+f[6:8]+'.tif' copyfile(cfg.work_dir+f, cfg.roll_out+rf) def GIS_prep(): import glob wssi_tifs_all = ['finalicemax.tif|Days_1_3','total_snamt_I.tif|Days_1_3','total_cum_max.tif|Days_1_3','ff_max.tif|Days_1_3','WSII_GB_FINAL.tif|Days_1_3','full_snowload_re.tif|Days_1_3','WSII_SnowLoad.tif|Days_1_3','wsii_total.tif|Days_1_3', 'finalicemax_v24.tif|Day_1','v24hrsnamt_I.tif|Day_1','v24hr_cum_max.tif|Day_1','ff_max_24hr.tif|Day_1','WSII_GB_FINAL24hr.tif|Day_1','v24hr_snowload_re.tif|Day_1','WSII_24_SnLd.tif|Day_1','wsii_f24.tif|Day_1', 'finalicemax_v48.tif|Day_2','v48hrsnamt_I.tif|Day_2','v48hr_cum_max.tif|Day_2','WSII_GB_FINAL48hr.tif|Day_2','v48hr_snowload_re.tif|Day_2','WSII_48_SnLd.tif|Day_2','wsii_f48.tif|Day_2', 'finalicemax_d3.tif|Day_3','d3_hrsnamt_I.tif|Day_3','d3_cum_max.tif|Day_3','d3_snowload_re.tif|Day_3','WSII_d3_SnLd.tif|Day_3','wsii_f_d3.tif|Day_3'] os.chdir(cfg.comp_out) tiff_list = [] for file in glob.glob("*.tif"): print file tiff_list.append(file) for t in tiff_list: f = open(cfg.gis_dir+"tiff_list.txt", "a") f.write(str(t)+ "\n") f.close() def clean_logs(path): import datetime from time import gmtime, strftime print "remove logfiles older than 5 days" path = path today = datetime.datetime.today() os.chdir(path) print (path) print (today) for root,directories,files in os.walk(path,topdown=False): for name in files: #this is the last modified time t = os.stat(os.path.join(root, name))[8] print (t) filetime = datetime.datetime.fromtimestamp(t) - today print (filetime) if filetime.days <= -5: print(os.path.join(root, name), filetime.days) os.remove(os.path.join(root, name)) else: print ("files fresher than 5 days; nothing to delete") wssi_summary() GIS_prep() clean_logs(path = "O:\\wssi\\operational\\data\\logs\\")