# -*- coding: utf-8 -*- # --------------------------------------------------------------------# # Filename: wssi_general_functions.py # # Description: Winter Storm Severity Index (WSSI) - general functions # # Authors: Josh Kastman # # Contact: joshua.kastman@noaa.gov # # Established Functions - Kastman 2019-03-19 # # Change Log: # #---------------------------------------------------------------------# #imports import arcpy, os, traceback, subprocess, urllib2, shutil from time import gmtime, strftime from datetime import datetime, timedelta import wssi_config as cfg #------------------------------------------------# # clean() - Cleans all data in a given directory # #------------------------------------------------# def clean(clean_path): print ("Cleaning out old files") try: for root, dirs, files in os.walk(clean_path): for f in files: os.unlink(os.path.join(root, f)) for d in dirs: shutil.rmtree(os.path.join(root, d)) except Exception as e: print(traceback.format_exc()) #-----------------# # End of Function # #-----------------# #---------------------------------------# # Generating rolling list of time steps # #---------------------------------------# def rolling_periods(fp, rHR, step, hr_list): """ Parameters ---------- fp : last time step of the master time step list rHR : number of hours to group together for the rolling period step : length of each time step hr_list : master time step list Returns ------- rollingHRs : TYPE list of lists to generate rolling timesteps Sample for rolling 24 hr list with 6 hour time step: rolling_periods(fp = fcst_hr[-1], rHR=4, step=6, hr_list = fcst_hr) """ #rHR = 6 #step = 1 lhr = int(fp) + int(step) rollingHRs = [] for i in range(rHR,lhr): init = i - rHR rollList = hr_list[init:i] rollingHRs.append(rollList) if rollList[-1] == hr_list[-1]: break #print rollList return rollingHRs #-----------------# # End of Function # #-----------------#