def __init__(self, tpe, d):
        if tpe == "fifteen_min":
            tpe = "fif"
        table = "{}_model_params".format(tpe)
        param_df = get_data_frame_from_table(table)
        param_df.set_index("date", inplace=True)

        self.model_type = param_df["type"][d]
        self.lag_size = "1000.000000"
        self.range = param_df["range"][d]
        self.sill = param_df["sill"][d]
        self.nugget = "0"  # todo get this from R script
        self.sample_num = "27"  # todo make this dynamic?
        self.krad = arcpy.sa.RadiusVariable(27, 20000)
        self.sample_type = "Variable"
# Purpose: Takes a time series and prints some summary stats about the time intervals. Originally designed to do this
# for rainfall data from weatherunderground
# Authors: J. Sadler, M. Morsy, University of Virginia
# Email: [email protected]
# Original date: 1/13/2016

import pandas as pd
import numpy as np
from storm_stats_functions import get_data_frame_from_table, qc_wu, get_date_range

dr = get_date_range()
# connect to db
table_name = "all_data"
# run a query and get the results
df = get_data_frame_from_table(table_name)
df = df[df.src=='WU']
df = qc_wu(df)
df.reset_index(inplace=True)
df.datetime = pd.to_datetime(df.datetime)
intervals = list()
for n in df.site_name.unique():
    df1 = df[df.site_name == n]
    for d in dr:
        df1 = df1.set_index(df1.datetime)
        try:
            df2 = df1[d]
            for i in range(len(df2.index)-1):
                intervals.append((df2.index[i + 1] - df2.index[i]).seconds)
        except:
            continue
                print "      !!! This process has workspace open..."

                # if this process has workspace open, keep trying while it is open...
    while any(_inputWS in pth for pth in [fl.path for fl in psutil.Process(thisPID).open_files()]):
        print "    !!! Trying Exists, Compact, Exists to clear locks: %s" % all(
            [arcpy.Exists(_inputWS), arcpy.Compact_management(_inputWS), arcpy.Exists(_inputWS)]
        )

    return True


# specify type; should be 'fifteen_min', 'hr', or 'daily'
tpe = "daily"

# get data from table
df = get_data_frame_from_table("daily")
a = df.ix[:, 4:]
non_zero_dates = a.columns[a.sum() > 0]

# set up arcpy environment
arcpy.CheckOutExtension("spatial")
env.extent = arcpy.Extent(3705690, 1051630, 3724920, 1068584)
k_dir = "C:/Users/jeff_dsktp/Google Drive/Hampton Roads GIS Data/VA_Beach_Data/kriging1"
check_dir(k_dir)
change_permissions_recursive(k_dir)
os.chmod(k_dir, stat.S_IWRITE)
shutil.rmtree(k_dir, onerror=onerror, ignore_errors=False)
check_dir(k_dir)
change_permissions_recursive(k_dir)

env.overwriteOutput = True