from fuzzywuzzy import fuzz
import shapefile
import dbhydro_util

#--load the attributes of the structure shapefile
shapename = '..\\_gis\\shapes\\sw_structures'
shapes, records = shapefile.load_as_dict(shapename)

#--get a list of stage records
stg_dir = 'SW\\STG\\'
stg_files = os.listdir(stg_dir)

#--build a list of unique station names
station_names = []
for f in stg_files:
    fdict = dbhydro_util.parse_fname(f)
    sname = fdict['STATION']
    if '_' in sname:
        sname = sname.split('_')[0]
    if sname not in station_names:
        station_names.append(sname)

#--find all the records for each structure
shape_dbhydro_names = []
for system, name in zip(records['system'], records['name']):
    if system == 1:
        #--strip out the hyphen
        name = name.replace('-', '')

        match = None
        #--try for a staight-up match
示例#2
0
    if s not in g_sites:
        g_sites.append(s)
        g_str_num.append([snum])
    else:
        idx = g_sites.index(s)
        if snum not in g_str_num[idx]:
            g_str_num[idx].append(snum)

#--for each gate structure
og_dir = 'processed\\SW\\GATE_daily\\'
for g, g_str in zip(g_sites, g_str_num):
    #--find the records for this gate
    for gg_str in g_str:
        this_gate_files, this_gate_info = [], []
        for f in gate_files:
            fdict = dbu.parse_fname(f)
            if fdict['site'] == g and fdict['strnum'] == gg_str:
                this_gate_files.append(f)
                this_gate_info.append(fdict)
        #print this_gate_files
        p_series = []
        for gf, gi in zip(this_gate_files, this_gate_info):
            if gi['dtype'].upper() == 'BK':
                series, flg = dbu.load_series(g_dir + gf)
                series = dbu.interp_breakpoint(series, flg)
                p_series.append(
                    pandas.TimeSeries(series[:, 1], index=series[:, 0]))
            else:
                #raise TypeError,'Only use breakpoint data for gate openings'
                print 'non break point record - skipping'
示例#3
0
        g_sites.append(s)
        g_str_num.append([snum])
    else:
        idx = g_sites.index(s)
        if snum not in g_str_num[idx]:
            g_str_num[idx].append(snum)
                 
       
#--for each gate structure
og_dir = 'processed\\SW\\GATE_daily\\'
for g,g_str in zip(g_sites,g_str_num):
    #--find the records for this gate    
    for gg_str in g_str:
        this_gate_files,this_gate_info = [],[]
        for f in gate_files:
            fdict = dbu.parse_fname(f)            
            if fdict['site'] == g and fdict['strnum'] == gg_str:
                this_gate_files.append(f)
                this_gate_info.append(fdict)
        #print this_gate_files
        p_series = []
        for gf,gi in zip(this_gate_files,this_gate_info):       
            if gi['dtype'].upper() == 'BK':
                series,flg = dbu.load_series(g_dir+gf)            
                series = dbu.interp_breakpoint(series,flg)
                p_series.append(pandas.TimeSeries(series[:,1],index=series[:,0]))
            else:
                #raise TypeError,'Only use breakpoint data for gate openings'                
                print 'non break point record - skipping'
        
        #--create a full record
import os
import pandas
import dbhydro_util

#--load the record for each valid dbkey
data_dir = 'RAIN\\RAIN\\'
data_files = os.listdir(data_dir)
rain_files = []
rain_existing_dbkeys = []

for df in data_files:
    df_dict = dbhydro_util.load_header(data_dir + df)
    fname_dict = dbhydro_util.parse_fname(data_dir + df)
    if df_dict['FQ'] == 'BK':
        dbhydro_util.interp_precip_pandas(data_dir + df)
        break
import os
import pandas
import dbhydro_util


# --load the record for each valid dbkey
data_dir = "RAIN\\RAIN\\"
data_files = os.listdir(data_dir)
rain_files = []
rain_existing_dbkeys = []

for df in data_files:
    df_dict = dbhydro_util.load_header(data_dir + df)
    fname_dict = dbhydro_util.parse_fname(data_dir + df)
    if df_dict["FQ"] == "BK":
        dbhydro_util.interp_precip_pandas(data_dir + df)
        break
df_dir = 'stage_dfs_navd\\'
smp_dir = 'stage_smp_navd\\'
ngvd_2_navd = -1.5
#--load the attributes of the structure shapefile
shapename = '..\\_gis\\shapes\\sw_structures'
records = shapefile.load_as_dict(shapename,attrib_name_list=['system','struct_num','dbhydro'],loadShapes=False)

#--get a list of stage records
stg_dir = 'SW\\STG\\'
stg_files = os.listdir(stg_dir)

#--build a list of station names
rec_attribs = []
for f in stg_files:
    fdict = dbhydro_util.parse_fname(f)    
    rec_attribs.append(fdict)

#--find all the records for each primary structure, headwater only
wl_stats = ['DA','BK','DWR','INST','FWM','MEAN']
for system,name in zip(records['system'],records['dbhydro']):
    if system == 1 and name != None:
        match_h,match_t = [],[]
        for i,rec in enumerate(rec_attribs):
            station = rec['STATION']
            if '_' in station:
                station = station.split('_')[0]
            if station.lower() == name.lower() and rec['STAT'] in wl_stats:
                if rec['STATION'].lower().endswith('h'):
                    match_h.append(rec)
                if rec['STATION'].lower().endswith('t'):