# ------------------------------------------------------------------------------------# # WSSI_web_images.py # # Description: Winter Storm Severity Index (WSSI) - Image generator for webmaps # # Authors: Josh Kastman # # Contact: joshua.kastman@noaa.gov # # Established - Kastman 2019-09-26 # # ------------------------------------------------------------------------------------# import subprocess import arcpy, os from arcpy import mapping as m import logging import traceback from datetime import datetime from dateutil import tz from_zone = tz.tzutc() to_zone = tz.tzlocal() from time import gmtime, strftime import glob import wssi_config as cfg #log_stamp = strftime("%Y%m%d%H", gmtime()) #logging.basicConfig(filename='C:/Users/joshua.kastman/gis/wsii/operational/logs/wssi_log_'+str(log_stamp)+'.log',level=logging.DEBUG, format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p') start_time = strftime("%a, %d %b %Y %H:%M:%S", gmtime()) print ("WSSI Web Image Scripts Start Time "+start_time) arcpy.env.overwriteOutput = True home_dir = cfg.wssi_dir datadir = home_dir+"\\data\\grb\\" refdir = home_dir+"\\data\\reference\\" workdir = home_dir+"\\data\\working\\" webmaps = home_dir+"\\images\\web_map_images\\" static = home_dir+"\\images\\static\\" xmldir = home_dir+"\\images\\xmls\\" mxd_dir = home_dir+"\\mxds\\" log_dir = home_dir+"\\data\\logs\\" #webmaps ="C://Users//joshua.kastman//gis/wsii//operational/images//web_map_images//" #static ="C://Users//joshua.kastman//gis//wsii//operational//images//static//" #xmldir = 'C://Users//joshua.kastman//gis//wsii//operational//images//xmls//' def WFO_statics_images(): workdir = home_dir+"\\data\\working\\" f = open(cfg.work_dir+"time_vars.txt", "r") lines = f.readlines() d1_it = lines[0][:-1] d1_et = lines[1][:-1] d2_et = lines[2][:-1] d3_et = lines[3][:-1] d4_et = lines[5][:-1] f.close() #pageNameList = ["ABR","ABQ","ALY","AMA","APX","ARX","BGM","BTV","DDC","GJT","GRR","ICT","LKN","MFR","OAX","PAH","PHI","JAN","OHX","MEG","MRX","DLH","LZK"] pageNameList = ["ABR","ALY","ABQ","AMA","EWX","LWX","BYZ","BGM","BMX","BIS","RNK","BOI","BOX","BRO","BUF","BTV","CAR","MPX","CHS","RLX","CYS","LOT","CLE","CAE","CRP","DVN","BOU","DMX","DTX","DDC","DLH","EPZ","LKN","EKA","FGZ","FWD","APX","GGW","GLD","FGF","GJT","GRR","GYX","TFX","GRB","GSP","GID","HGX","HUN","IND","JAN","JKL","JAX","EAX","KEY","ARX","LCH","VEF","ILX","LZK","LOX","LMK","LUB","MQT","MFR","MLB","MEG","MFL","MAF","MKX","MSO","MOB","MRX","PHI","OHX","LIX","OKX","MHX","OUN","LBF","IWX","OAX","PAH","FFC","PDT","PSR","PBZ","PIH","GYX","PUB","RAH","UNR","REV","RIW","STO","SLC","SJT","SGX","MTR","HNX","SEW","SHV","FSD","OTX","SGF","LSX","CTP","TAE","TBW","TOP","TWC","TSA","AKQ","ICT","ILM","ILN","PQR"] components =["WSSI_Overall","Snow_Amount","Snow_Load","Blowing_Snow","Ice_Accumulation","Ground_Blizzard","Flash_Freeze"] comp = ["Overall", "Snow Amount", "Snow Load", "Blowing Snow", "Ice Accumulation", "Ground Blizzard", "Flash Freeze"] ## ## mapPath = r'C:\Users\joshua.kastman\gis\wsii\operational\mxds\WSSI_all_data_for_web.mxd' outpath = home_dir+"\\images\\static\\" ## DATA = "DATE PLACEHOLDER" #-----------------------------------------------# # Day 1 - 3 summary graphics for each component # #-----------------------------------------------# ## print 'WSII - WFOs' ## for a,b in zip (components,comp): ## wfo_path = "C:\\Users\\joshua.kastman\\gis\\wsii\\operational\\mxds\\"+a+"_WFO.mxd" ## mxd = m.MapDocument (wfo_path) ## try: ## for pageName in pageNameList: ## png = os.path.join(outpath, a+'_'+pageName+ '.png') ## pageID= mxd.dataDrivenPages.getPageIDFromName(pageName) ## mxd.dataDrivenPages.currentPageID = pageID ## fieldValue = mxd.dataDrivenPages.pageRow.WFO ## for textElement in m.ListLayoutElements(mxd, "TEXT_ELEMENT"): ## ## # Check if the text element contains the out of date text ## if textElement.text == "Valid": ## print 'Changing: ' + str(textElement.text) ## ## #replace it with the new text ## textElement.text = 'WSSI '+b+ ' Component - Valid Through '+ str(d3_et) + ' ET' ## m.ExportToPNG(mxd, png, resolution=120) ## except Exception as e: ## print e.message, e.args ## del mxd def day_subf(**kwargs): for key, value in kwargs.items(): print (value) print "Valid from "+str(value[0])+" through "+str(value[1])+" for "+str(value[2]) pageNameList = ["ABR","ALY","ABQ","AMA","EWX","LWX","BYZ","BGM","BMX","BIS","RNK","BOI","BOX","BRO","BUF","BTV","CAR","MPX","CHS","RLX","CYS","LOT","CLE","CAE","CRP","DVN","BOU","DMX","DTX","DDC","DLH","EPZ","LKN","EKA","FGZ","FWD","APX","GGW","GLD","FGF","GJT","GRR","GYX","TFX","GRB","GSP","GID","HGX","HUN","IND","JAN","JKL","JAX","EAX","KEY","ARX","LCH","VEF","ILX","LZK","LOX","LMK","LUB","MQT","MFR","MLB","MEG","MFL","MAF","MKX","MSO","MOB","MRX","PHI","OHX","LIX","OKX","MHX","OUN","LBF","IWX","OAX","PAH","FFC","PDT","PSR","PBZ","PIH","GYX","PUB","RAH","UNR","REV","RIW","STO","SLC","SJT","SGX","MTR","HNX","SEW","SHV","FSD","OTX","SGF","LSX","CTP","TAE","TBW","TOP","TWC","TSA","AKQ","ICT","ILM","ILN","PQR"] if str(value[2]) == "Day1": components = ["WSSI_Overall_Day1"]#,"Snow_Amount_Day1","Snow_Load_Day1","Blowing_Snow_Day1","Ice_Accumulation_Day1","Ground_Blizzard_Day1","Flash_Freeze_Day1"] comp = ["Overall"]#, "Snow Amount", "Snow Load", "Blowing Snow", "Ice Accumulation", "Ground Blizzard", "Flash Freeze"] elif str(value[2]) == "Day2": components = ["WSSI_Overall_Day2"]#,"Snow_Amount_Day2","Snow_Load_Day2","Blowing_Snow_Day2","Ice_Accumulation_Day2","Ground_Blizzard_Day2"] comp = ["Overall"]#, "Snow Amount", "Snow Load", "Blowing Snow", "Ice Accumulation", "Ground Blizzard"] elif str(value[2]) == "Day3": components = ["WSSI_Overall_Day3"]#,"Snow_Amount_Day3","Snow_Load_Day3","Blowing_Snow_Day3","Ice_Accumulation_Day3"] comp = ["Overall"]#, "Snow Amount", "Snow Load", "Blowing Snow", "Ice Accumulation"] elif str(value[2]) == "Day4": components = ["WSSI_Overall_Day4"]#,"Snow_Amount_Day3","Snow_Load_Day3","Blowing_Snow_Day3","Ice_Accumulation_Day3"] comp = ["Overall"]#, "Snow Amount", "Snow Load", "Blowing Snow", "Ice Accumulation"] else: print "value[2] error" #print components #components =["WSSI_Overall_Day1","Snow_Amount_Day1","Snow_Load_Day1","Blowing_Snow_Day1","Ice_Accumulation_Day1","Ground_Blizzard_Day1","Flash_Freeze_Day1", # "WSSI_Overall_Day2","Snow_Amount_Day2","Snow_Load_Day2","Blowing_Snow_Day2","Ice_Accumulation_Day2","Ground_Blizzard_Day2", # "WSSI_Overall_Day3","Snow_Amount_Day3","Snow_Load_Day3","Blowing_Snow_Day3","Ice_Accumulation_Day3"] #comp = ["Overall", "Snow Amount", "Snow Load", "Blowing Snow", "Ice Accumulation", "Ground Blizzard", "Flash Freeze"] mapPath = home_dir+"\\mxds\\WSSI_all_data_for_web.mxd" outpath = home_dir+"\\images\\static\\" DATA = "DATE PLACEHOLDER" print 'WSII - Dailyies WFOs' for a,b in zip (components,comp): wfo_path = home_dir+"\\mxds\\"+a+"_WFO.mxd" mxd = m.MapDocument (wfo_path) try: for pageName in pageNameList: png = os.path.join(outpath, a+'_'+pageName+'_'+str(value[2])+ '.png') pageID= mxd.dataDrivenPages.getPageIDFromName(pageName) mxd.dataDrivenPages.currentPageID = pageID fieldValue = mxd.dataDrivenPages.pageRow.WFO for textElement in m.ListLayoutElements(mxd, "TEXT_ELEMENT"): ## # Check if the text element contains the out of date text if textElement.text == "Valid": print 'Changing: ' + str(textElement.text) ## #replace it with the new text textElement.text = 'WSSI '+b+ ' - Valid From '+str(value[0])+' ET To '+ str(value[1]) + ' ET' m.ExportToPNG(mxd, png, resolution=120) except Exception as e: print e.message, e.args del mxd tr_d1 = [time.strftime("%a, %b %d, %Y %I %p ", time.localtime()),d1_et, "Day1"] tr_d2 = [d1_et,d2_et,"Day2"] tr_d3 = [d2_et,d3_et,"Day3"] tr_d4 = [d3_et,d4_et,"Day4"] day_subf(d1=tr_d1, d2=tr_d2, d3=tr_d3, d4=tr_d4) ##################### # Execute Functions # ##################### WFO_statics_images()