# ------------------------------------------------------------------------------------# # 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, timedelta from dateutil import tz from_zone = tz.tzutc() to_zone = tz.tzlocal() from time import gmtime, strftime import glob import wssi_config as cfg #-------# # PATHS # #-------# #home_dir = os.getcwd() home_dir = cfg.wssi_dir datadir = home_dir+"\\data\\grb\\" refdir = home_dir+"\\data\\reference\\" workdir = home_dir+"\\data\\working\\" new_gb_dir = home_dir+"\\data\\ground_blizzard\\working\\" log_dir = home_dir+"\\data\\logs\\" comp_dir = home_dir+"\\images\\components_output\\" gis_wdir = home_dir+"\\gis\\working\\" webmaps = home_dir+"\\images\\web_map_images\\" static = home_dir+"\\images\\static\\" xmldir = home_dir+"\\images\\xmls\\" mxd_dir = home_dir+"\\mxds\\" key = "C:\\Users\\joshua.kastman\\gis\\keys\\kastman_wpc_vs_wpcgsops_private.ppk" plink="C:\Program Files\PuTTY\plink.exe" pscp="C:\Program Files\PuTTY\pscp.exe" key = "C:\\Users\\joshua.kastman\\gis\\keys\\kastman_wpc_vs_wpcgsops_private.ppk" ### set up log file ##log_stamp = strftime("%Y%m%d%H", gmtime()) ##logging.basicConfig(filename=log_dir+'/wssi_log_'+str(log_stamp)+'STATIC_IMGs2.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 #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 web_archive(): linux_user = "hpc" #temp block --> linux_cpu = "hpcrzdm:" linux_cpu = "vm-lnx-rzdm01:" #pwd = "4Bunnies+Thunder" #pwd = "4Mouse!Sticky@feet" #pwd = "2LemonPollywogs!" pwd = "Rotten_Peaches4U" tday = strftime("%Y%m%d", gmtime()) print tday+" UTC" #/home/www/wpc/htdocs/wwd/internal/wssi/images/WSSI_Archive #workdir = 'C://Users//joshua.kastman//degrib//data//wsii//working//' f = open(workdir+"time_vars.txt", "r") lines = f.readlines() run_time = lines[6][:-1] f.close() #if run_time == "09": #time = strftime("%H", gmtime()) time = str(run_time) print int(time) full_utc = strftime("%Y%m%d_%H_UTC", gmtime()) print full_utc #date_test = strftime("%H UTC %d/%m/%Y", gmtime()) #print date_test print int(time) #pageNameList = ["ABQ","ALY","AMA","APX","ARX","BGM","BTV","DDC","GJT","GRR","ICT","LKN","MFR","OAX","PAH","PHI","JAN","OHX","MEG","MRX","DLH","CONUS","ESRI"] #wssi_dir = "C:\\Users\\joshua.kastman\\Desktop" plink="C:\Program Files\PuTTY\plink.exe" pscp="C:\Program Files\PuTTY\pscp.exe" linux_user = "hpc" #temp block --> linux_cpu = "hpcrzdm:" linux_cpu = "vm-lnx-rzdm01:" linux_user2 = "jkastman" pwd2 = "Arya+Anna&Josh26!" linux_cpu2 = "hpc-lw-hmtdev3.ncep.noaa.gov:" #pwd = "4Mouse!Sticky@feet" #pwd = "2LemonPollywogs!" #wssi_dir = "//home/www//hpc//htdocs//wwd//wssi//images//WSSI_Archive" wssi_dir = "//home//people//hpc//ftp//WSSI_Archive" #//home//people//hpc//ftp//WSSI_Archive//20201123 wssi_img_dir = "//home//www//hpc//htdocs//wwd//wssi//images//" wssi_dir_linux = "//export//hpc-lw-hmtdev3//jkastman//wssi_archive//static" print "archive initiated for "+time try: #create daily, runtime and pageNameList directories ...send to ftp subprocess.call(plink+" -ssh -batch"+" "+linux_user+"@"+linux_cpu+" "+"-i"+" "+key+" "+"mkdir"+" "+wssi_dir+"//"+tday) #print plink+" -ssh"+" "+"hpc@hpcrzdm.ncep.noaa.gov"+" "+"-pw"+" "+"!!HPC!!"+" "+"mkdir"+" "+wssi_dir+"//"+tday subprocess.call(plink+" -ssh -batch"+" "+linux_user+"@"+linux_cpu+" "+"-i"+" "+key+" "+"cp"+" "+wssi_dir+"//"+"allow_ph"+"//*"+" "+wssi_dir+"//"+tday) subprocess.call(plink+" -ssh -batch"+" "+linux_user+"@"+linux_cpu+" "+"-i"+" "+key+" "+"mkdir"+" "+wssi_dir+"//"+tday+"//"+time+"_UTC") subprocess.call(plink+" -ssh -batch"+" "+linux_user+"@"+linux_cpu+" "+"-i"+" "+key+" "+"cp"+" "+wssi_dir+"//"+"allow_ph"+"//*"+" "+wssi_dir+"//"+tday+"//"+time+"_UTC") # archive on jkastman linux machine print (plink+" -ssh -batch"+" "+linux_user2+"@"+linux_cpu2+" "+"-i"+" "+key+" "+"mkdir"+" "+wssi_dir_linux+"//"+tday) subprocess.call(plink+" -ssh -batch"+" "+linux_user2+"@"+linux_cpu2+" "+"-i"+" "+key+" "+"mkdir"+" "+wssi_dir_linux+"//"+tday) subprocess.call(plink+" -ssh -batch"+" "+linux_user2+"@"+linux_cpu2+" "+"-i"+" "+key+" "+"cp"+" "+wssi_dir_linux+"//"+"allow_ph"+"//*"+" "+wssi_dir_linux+"//"+tday) subprocess.call(plink+" -ssh -batch"+" "+linux_user2+"@"+linux_cpu2+" "+"-i"+" "+key+" "+"mkdir"+" "+wssi_dir_linux+"//"+tday+"//"+time+"_UTC") subprocess.call(plink+" -ssh -batch"+" "+linux_user2+"@"+linux_cpu2+" "+"-i"+" "+key+" "+"cp"+" "+wssi_dir_linux+"//"+"allow_ph"+"//*"+" "+wssi_dir_linux+"//"+tday+"//"+time+"_UTC") #archive all by hour dest_dir = wssi_dir+"//"+tday+"//"+time+"_UTC" #C:\Users\joshua.kastman\gis\wsii\operational\images\static dest_dir2 = wssi_dir_linux+"//"+tday+"//"+time+"_UTC" target_file = static+"*.png" target_file2 = comp_dir+"*.tif" #print pscp+" -pw "+pwd+" "+target_file+" "+linux_user+"@"+linux_cpu+dest_dir subprocess.call(pscp+" -i "+key+" "+target_file+" "+linux_user+"@"+linux_cpu+dest_dir) subprocess.call(pscp+" -i "+key+" "+target_file+" "+linux_user+"@"+linux_cpu+wssi_img_dir) subprocess.call('aws s3 cp O:\wssi\operational\images\static s3://s3-east-www.wpc.woc.noaa.gov/public/wwd/wssi/images/ --recursive --exclude "*" --include "*.png"') #aws print "TIF "+(pscp+" -i "+key+" "+target_file2+" "+linux_user+"@"+linux_cpu+dest_dir) subprocess.call(pscp+" -i "+key+" "+target_file2+" "+linux_user+"@"+linux_cpu+dest_dir) subprocess.call(pscp+" -i "+key+" "+target_file2+" "+linux_user+"@"+linux_cpu+wssi_img_dir) subprocess.call('aws s3 cp O:\wssi\operational\images\components_output s3://s3-east-www.wpc.woc.noaa.gov/public/wwd/wssi/images/ --recursive --exclude "*" --include "*.tif"') #aws # archive on jkastman linux machine subprocess.call(pscp+" -i "+key+" "+target_file+" "+linux_user2+"@"+linux_cpu2+dest_dir2) subprocess.call(pscp+" -i "+key+" "+target_file2+" "+linux_user2+"@"+linux_cpu2+dest_dir2) #logging.debug('Static Images Sent to web') #target_file2 = "C:\\Users\\joshua.kastman\\gis\\wsii\\images\\conus\\*.png" #subprocess.call(pscp+" -pw "+pwd+" "+target_file2+" "+linux_user+"@"+linux_cpu+dest_dir) except : subprocess.call(plink+" -ssh -batch"+" "+linux_user+"@"+linux_cpu+" "+"-i"+" "+key+" "+"mkdir"+" "+wssi_dir+"//"+tday+"//"+time+"_UTC") #print "PLINK "+(plink+" -ssh -batch"+" "+linux_user+"@"+linux_cpu+" "+"-i"+" "+key+" "+"mkdir"+" "+wssi_dir+"//"+tday+"//"+time+"_UTC") dest_dir = wssi_dir+"//"+tday+"//"+time+"_UTC" target_file = static+"*.png" target_file2 = comp_dir+"*.tif" #print pscp+" -i "+pwd+" "+target_file+" "+linux_user+"@"+linux_cpu+dest_dir subprocess.call(pscp+" -i "+key+" "+target_file+" "+linux_user+"@"+linux_cpu+dest_dir) subprocess.call(pscp+" -i "+key+" "+target_file+" "+linux_user+"@"+linux_cpu+wssi_img_dir) subprocess.call('aws s3 cp O:\wssi\operational\images\static s3://s3-east-www.wpc.woc.noaa.gov/public/wwd/wssi/images/ --recursive --exclude "*" --include "*.png"') #aws subprocess.call(pscp+" -i "+key+" "+target_file2+" "+linux_user+"@"+linux_cpu+dest_dir) subprocess.call(pscp+" -i "+key+" "+target_file2+" "+linux_user+"@"+linux_cpu+wssi_img_dir) subprocess.call('aws s3 cp O:\wssi\operational\images\components_output s3://s3-east-www.wpc.woc.noaa.gov/public/wwd/wssi/images/ --recursive --exclude "*" --include "*.tif"') #aws # archive on jkastman linux machine print (plink+" -ssh -batch"+" "+linux_user2+"@"+linux_cpu2+" "+"-i"+" "+key+" "+"mkdir"+" "+wssi_dir_linux+"//"+tday+"//"+time+"_UTC") subprocess.call(plink+" -ssh -batch"+" "+linux_user2+"@"+linux_cpu2+" "+"-i"+" "+key+" "+"mkdir"+" "+wssi_dir_linux+"//"+tday+"//"+time+"_UTC") dest_dir2 = wssi_dir_linux+"//"+tday+"//"+time+"_UTC" subprocess.call(pscp+" -i "+key+" "+target_file+" "+linux_user2+"@"+linux_cpu2+dest_dir2) subprocess.call(pscp+" -i "+key+" "+target_file2+" "+linux_user2+"@"+linux_cpu2+dest_dir2) #logging.debug('Static Images Sent to web; exception called') #target_file2 = "C:\\Users\\joshua.kastman\\gis\\wsii\\images\\conus\\*.png" #subprocess.call(pscp+" -pw "+pwd+" "+target_file2+" "+linux_user+"@"+linux_cpu+dest_dir) def remove_old_day(): wssi_dir = "//home//people//hpc//ftp//WSSI_Archive" linux_user = "hpc" #temp block --> linux_cpu = "hpcrzdm:" linux_cpu = "vm-lnx-rzdm01:" d2 = datetime.today() - timedelta(days=32) d2re = d2.strftime("%Y%m%d") print d2re old_dir = wssi_dir+"//"+d2re print(plink+" -ssh -batch"+" "+linux_user+"@"+linux_cpu+" "+"-i"+" "+key+" "+"rm -rf"+" "+old_dir) subprocess.call(plink+" -ssh -batch"+" "+linux_user+"@"+linux_cpu+" "+"-i"+" "+key+" "+"rm -rf"+" "+old_dir) ######################################################################################################################## ##################### # Execute Functions # ##################### #workdir = 'C://Users//joshua.kastman//degrib//data//wsii//working//' f = open(workdir+"time_vars.txt", "r") lines = f.readlines() run_time = lines[6][:-1] f.close() print run_time from subprocess import Popen import os, os.path import time #DIR = r'C:\Users\joshua.kastman\gis\wsii\operational\images\static' #print dcount #while (int(dcount) < 2875): # print "not finished wating 10 seconds" # time.sleep(20) # dcount = len([name for name in os.listdir(DIR) if os.path.isfile(os.path.join(DIR, name))]) #if dcount == 2875: # print "send to web" #while (count < 9): if run_time == "01": #DIR = r'C:\Users\joshua.kastman\gis\wsii\operational\images\static' DIR = static subprocess.call(home_dir+"\\scripts"+"\\make_wssi_static_images.bat") dcount = len([name for name in os.listdir(DIR) if os.path.isfile(os.path.join(DIR, name))]) print dcount while (int(dcount) < 4059): print "not finished wating 30 seconds" time.sleep(30) dcount = len([name for name in os.listdir(DIR) if os.path.isfile(os.path.join(DIR, name))]) if dcount == 4059: print "call web_archive" #logging.debug("call web_archive") web_archive() remove_old_day() ####temperorary block for PQR ##elif run_time == "03": ## subprocess.call(home_dir+"\\scripts"+"\\make_wssi_static_images.bat") ## DIR = static ## dcount = len([name for name in os.listdir(DIR) if os.path.isfile(os.path.join(DIR, name))]) ## print dcount ## while (int(dcount) < 3050): ## print "not finished wating 30 seconds" ## time.sleep(30) ## dcount = len([name for name in os.listdir(DIR) if os.path.isfile(os.path.join(DIR, name))]) ## if dcount == 3050: ## print "call web_archive" ## #logging.debug("call web_archive") ## web_archive() elif run_time == "09": subprocess.call(home_dir+"\\scripts"+"\\make_wssi_static_images.bat") DIR = static dcount = len([name for name in os.listdir(DIR) if os.path.isfile(os.path.join(DIR, name))]) print dcount while (int(dcount) < 4059): print "not finished wating 30 seconds" time.sleep(30) dcount = len([name for name in os.listdir(DIR) if os.path.isfile(os.path.join(DIR, name))]) if dcount == 4059: print "call web_archive" #logging.debug("call web_archive") web_archive() elif run_time == "11": subprocess.call(home_dir+"\\scripts"+"\\make_wssi_static_images.bat") DIR = static dcount = len([name for name in os.listdir(DIR) if os.path.isfile(os.path.join(DIR, name))]) print dcount while (int(dcount) < 4059): print "not finished wating 30 seconds" time.sleep(30) dcount = len([name for name in os.listdir(DIR) if os.path.isfile(os.path.join(DIR, name))]) if dcount == 4059: print "call web_archive" #logging.debug("call web_archive") web_archive() elif run_time == "13": subprocess.call(home_dir+"\\scripts"+"\\make_wssi_static_images.bat") DIR = static dcount = len([name for name in os.listdir(DIR) if os.path.isfile(os.path.join(DIR, name))]) print dcount while (int(dcount) < 4059): print "not finished wating 30 seconds" time.sleep(30) dcount = len([name for name in os.listdir(DIR) if os.path.isfile(os.path.join(DIR, name))]) if dcount == 4059: print "call web_archive" #logging.debug("call web_archive") web_archive() ##elif run_time == "15": ## subprocess.call(home_dir+"\\scripts"+"\\make_wssi_static_images.bat") ## DIR = static ## dcount = len([name for name in os.listdir(DIR) if os.path.isfile(os.path.join(DIR, name))]) ## print dcount ## while (int(dcount) < 4059): ## print "not finished wating 30 seconds" ## time.sleep(30) ## dcount = len([name for name in os.listdir(DIR) if os.path.isfile(os.path.join(DIR, name))]) ## if dcount == 4059: ## print "call web_archive" ## #logging.debug("call web_archive") ## web_archive() #elif run_time == "19": elif run_time == "19": #p = Popen("make_wssi_static_images.bat", cwd=r"C:\Users\joshua.kastman\gis\wsii\operational") #stdout, stderr = p.communicate() subprocess.call(home_dir+"\\scripts"+"\\make_wssi_static_images.bat") DIR = static dcount = len([name for name in os.listdir(DIR) if os.path.isfile(os.path.join(DIR, name))]) print dcount while (int(dcount) < 4059): print "not finished wating 30 seconds" time.sleep(30) dcount = len([name for name in os.listdir(DIR) if os.path.isfile(os.path.join(DIR, name))]) if dcount == 4059: print "call web_archive" #logging.debug("call web_archive") web_archive() elif run_time == "21": subprocess.call(home_dir+"\\scripts"+"\\make_wssi_static_images.bat") DIR = static dcount = len([name for name in os.listdir(DIR) if os.path.isfile(os.path.join(DIR, name))]) print dcount while (int(dcount) < 4059): print "not finished wating 30 seconds" time.sleep(30) dcount = len([name for name in os.listdir(DIR) if os.path.isfile(os.path.join(DIR, name))]) if dcount == 4059: print "call web_archive" #logging.debug("call web_archive") web_archive() else: print run_time + " is not a static image run" #logging.debug(run_time + " is not a static image run") finish_time = strftime("%a, %d %b %Y %H:%M:%S", gmtime()) print ("WSSI Web Image Scripts Start Time "+start_time) #logging.debug("WSSI Web Image Scripts Start Time "+start_time) print ("WSSI Web Image Scripts Finished "+finish_time) #logging.debug("WSSI Web Image Scripts Finished "+finish_time) #logging.shutdown()