Пример #1
0
def make_saturation_ratio_vs_Q_plots(sitesDir,
                                     siteList=None,
                                     siteFile=None,
                                     makeHistograms=True):
    sitePanelDict, sitePhreeqcDict = loadSiteListData(
        processedSitesDir=sitesDir, loadPhreeqc=True)
    rs = []
    ps = []
    slopes = []
    plotsDir = os.path.join(sitesDir, 'plots/')
    for site in sitePanelDict.keys():
        print("Making plot for: " + site)
        #Read out data into shorter variable names
        Q = sitePanelDict[site].data['Stream flow, mean. daily']
        T_C = sitePanelDict[site].data['Temperature, water']
        CO2 = sitePhreeqcDict[site].CO2_Molality
        Ca = sitePhreeqcDict[site]['Ca']
        #Filter out nan values
        #good_values = ~(Q+T_C+CO2+Ca).isnull()#Addition will create Nans if any of the series contains a NaN
        good_values = get_good_indicies([Q, T_C, CO2, Ca])
        Q = Q[good_values]
        T_C = T_C[good_values]
        CO2 = CO2[good_values]
        Ca = Ca[good_values]
        #Calculate PCO2
        T_K = CtoK(T_C)
        K_H = calc_K_H(T_K)
        PCO2 = CO2 / K_H
        #Calculate Equilibrium Ca concentration
        CaEq = concCaEqFromPCO2(PCO2, T_C=T_C)
        #Check for plots directory and make it if one doesn't exist
        check_plots_dir(sitesDir)
        #Make Discharge vs. Saturation Ratio Plot
        figure()
        loglog(Q, Ca / CaEq, 'o')
        xlabel('Discharge (cfs)')
        ylabel('Saturation Ratio $[Ca]/[Ca]_{eq}$')
        savefig(os.path.join(plotsDir, site + '-Q_vs_SatRatio.pdf'))
        #Calculate correlation coefficient and regression
        slope, intercept, r, p, stderr = linregress(log10(Q), Ca / CaEq)
        rs.append(r)
        ps.append(p)
        slopes.append(slope)
        if makeHistograms:
            figure()
            hist(Ca / CaEq, normed=True)
            xlabel('Saturation Ratio $[Ca]/[Ca]_{eq}$')
            ylabel('Frequency')
            savefig(os.path.join(plotsDir, site + '-SatRatioHist.pdf'))

    #Make histogram of pearson r values
    figure()
    hist(rs, normed=True)
    xlabel('Pearson R')
    ylabel('Frequency')
    savefig(os.path.join(plotsDir, 'PearsonR_Q_SatRatio.pdf'))
Пример #2
0
def make_saturation_ratio_vs_Q_plots(sitesDir, siteList=None, siteFile=None, makeHistograms=True):
    sitePanelDict, sitePhreeqcDict = loadSiteListData(processedSitesDir=sitesDir, loadPhreeqc=True)
    rs = []
    ps = []
    slopes = []
    plotsDir = os.path.join(sitesDir, 'plots/')
    for site in sitePanelDict.keys():
        print("Making plot for: "+site)
        #Read out data into shorter variable names
        Q = sitePanelDict[site].data['Stream flow, mean. daily']
        T_C = sitePanelDict[site].data['Temperature, water']
        CO2 = sitePhreeqcDict[site].CO2_Molality
        Ca = sitePhreeqcDict[site]['Ca']
        #Filter out nan values
        #good_values = ~(Q+T_C+CO2+Ca).isnull()#Addition will create Nans if any of the series contains a NaN
        good_values = get_good_indicies([Q,T_C,CO2,Ca])
        Q = Q[good_values]
        T_C = T_C[good_values]
        CO2 = CO2[good_values]
        Ca = Ca[good_values]
        #Calculate PCO2
        T_K = CtoK(T_C)
        K_H = calc_K_H(T_K)
        PCO2 = CO2/K_H
        #Calculate Equilibrium Ca concentration
        CaEq = concCaEqFromPCO2(PCO2, T_C=T_C)
        #Check for plots directory and make it if one doesn't exist
        check_plots_dir(sitesDir)
        #Make Discharge vs. Saturation Ratio Plot
        figure()
        loglog(Q, Ca/CaEq, 'o')
        xlabel('Discharge (cfs)')
        ylabel('Saturation Ratio $[Ca]/[Ca]_{eq}$')
        savefig(os.path.join(plotsDir,site+'-Q_vs_SatRatio.pdf'))
        #Calculate correlation coefficient and regression
        slope,intercept,r,p,stderr = linregress(log10(Q), Ca/CaEq)
        rs.append(r)
        ps.append(p)
        slopes.append(slope)
        if makeHistograms:
            figure()
            hist(Ca/CaEq, normed=True)
            xlabel('Saturation Ratio $[Ca]/[Ca]_{eq}$')
            ylabel('Frequency')
            savefig(os.path.join(plotsDir,site+'-SatRatioHist.pdf'))

    #Make histogram of pearson r values    
    figure()
    hist(rs,normed=True)
    xlabel('Pearson R')
    ylabel('Frequency')
    savefig(os.path.join(plotsDir,'PearsonR_Q_SatRatio.pdf'))
Пример #3
0
def make_pwp_vs_saturation_ratio_plots(sitesDir, siteList=None, siteFile=None,  classFile='', plotloglog=True):
    sitePanelDict, sitePhreeqcDict = loadSiteListData(processedSitesDir=sitesDir, loadPhreeqc=True)
    if classFile != '':
        class_xls = read_excel(classFile, 'Sheet1',index_col=1, names=['name','site', 'recharge', 'age'])
    site_class = []
    rs =[]
    ps = []
    spp = []
    spr = []
    slopes= []
    plotsDir = os.path.join(sitesDir, 'plots/')
    #Check for plots directory and make it if one doesn't exist
    check_plots_dir(sitesDir)
    for site in list(sitePanelDict.keys()):
        if classFile !='':
            #read in classification for this site
            this_class = class_xls['recharge'][site]
            this_color=class_colors[this_class]
            site_class.append(this_class)
        else:
            this_color='black'
        print(("Making plot for: "+site))
        Q = sitePanelDict[site].data['Stream flow, mean. daily']
        pwp_rates = calc_site_pwp(sitePanelDict[site], sitePhreeqcDict[site])
        pwp_rates = pwp_to_mm_yr(pwp_rates)
        T_C = sitePanelDict[site].data['Temperature, water']
        T_K = CtoK(T_C)
        K_H = calc_K_H(T_K)
        CO2 = sitePhreeqcDict[site].CO2_Molality
        PCO2 = CO2/K_H
        CaEq = concCaEqFromPCO2(PCO2, T_C=T_C)
        sat_ratio = sitePhreeqcDict[site].Ca/CaEq
        df = DataFrame({'Q':Q, 'pwp':pwp_rates, 'sat_ratio':sat_ratio})
        df = df.dropna()
        #Make PWP vs. Saturation Ratio Plot
        figure()
        if plotloglog:
            loglog(df.pwp, df.sat_ratio, '.', color=this_color)
        else:
            semilogx(df.pwp, df.sat_ratio, '.', color=this_color)
        xlabel('PWP Dissolution Rate (mm/yr)')
        ylabel('Saturation ratio')
        savefig(os.path.join(plotsDir,site+'-Sat_ratio_vs_PWP.pdf'))
        #Calculate correlation coefficient and regression
        slope,intercept,r,p,stderr = linregress(df.pwp, df.sat_ratio)        
        rs.append(r)
        ps.append(p)
        [this_spr, this_spp] = spearmanr(df.pwp, df.sat_ratio)
        spr.append(this_spr)
        spp.append(this_spp)
        slopes.append(slope)

    #Make histogram of pearson r values    
    figure()
    arr_rs = array(rs)
    print("size arr_rs=", arr_rs.size)
    arr_ps = array(ps)
    arr_spr = array(spr)
    arr_spp = array(spp)
    arr_site_class = array(site_class)
    hist(arr_rs[arr_site_class==1],color=class_colors[1], alpha=0.5)
    hist(arr_rs[arr_site_class==2],color=class_colors[2], alpha=0.5)
    hist(arr_rs[arr_site_class==3],color=class_colors[3], alpha=0.5)
    xlabel('Pearson R')
    ylabel('Frequency')
    savefig(os.path.join(plotsDir,'PearsonR_PWP_SatRatio.pdf'))
    #Make histogram of pearson p values
    figure()
    hist(arr_ps[arr_site_class==1],color=class_colors[1], alpha=0.5)
    hist(arr_ps[arr_site_class==2],color=class_colors[2], alpha=0.5)
    hist(arr_ps[arr_site_class==3],color=class_colors[3], alpha=0.5)
    xlabel('Pearson p')
    ylabel('Frequency')
    savefig(os.path.join(plotsDir, 'PearsonP_PWP_SatRatio.pdf'))
    #Make histogram of spearman r values
    figure()
    hist(arr_spr[arr_site_class==1],color=class_colors[1], alpha=0.5)
    hist(arr_spr[arr_site_class==2],color=class_colors[2], alpha=0.5)
    hist(arr_spr[arr_site_class==3],color=class_colors[3], alpha=0.5)
    xlabel('Spearman R')
    ylabel('Frequency')
    savefig(os.path.join(plotsDir, 'SpearmanR_PWP_SatRatio.pdf'))
    #Make histogram of spearman p values
    figure()
    hist(arr_spp[arr_site_class==1],color=class_colors[1], alpha=0.5)
    hist(arr_spp[arr_site_class==2],color=class_colors[2], alpha=0.5)
    hist(arr_spp[arr_site_class==3],color=class_colors[3], alpha=0.5)
    xlabel('Spearman p')
    ylabel('Frequency')
    savefig(os.path.join(plotsDir, 'SpearmanP_PWP_SatRatio.pdf'))
Пример #4
0
def make_pwp_vs_saturation_ratio_plots(sitesDir, siteList=None, siteFile=None,  classFile='', plotloglog=True):
    sitePanelDict, sitePhreeqcDict = loadSiteListData(processedSitesDir=sitesDir, loadPhreeqc=True)
    if classFile != '':
        class_xls = read_excel(classFile, 'Sheet1',index_col=1, names=['name','site', 'recharge', 'age'])
    site_class = []
    rs =[]
    ps = []
    spp = []
    spr = []
    slopes= []
    plotsDir = os.path.join(sitesDir, 'plots/')
    #Check for plots directory and make it if one doesn't exist
    check_plots_dir(sitesDir)
    for site in sitePanelDict.keys():
        if classFile !='':
            #read in classification for this site
            this_class = class_xls['recharge'][site]
            this_color=class_colors[this_class]
            site_class.append(this_class)
        else:
            this_color='black'
        print("Making plot for: "+site)
        Q = sitePanelDict[site].data['Stream flow, mean. daily']
        pwp_rates = calc_site_pwp(sitePanelDict[site], sitePhreeqcDict[site])
        pwp_rates = pwp_to_mm_yr(pwp_rates)
        T_C = sitePanelDict[site].data['Temperature, water']
        T_K = CtoK(T_C)
        K_H = calc_K_H(T_K)
        CO2 = sitePhreeqcDict[site].CO2_Molality
        PCO2 = CO2/K_H
        CaEq = concCaEqFromPCO2(PCO2, T_C=T_C)
        sat_ratio = sitePhreeqcDict[site].Ca/CaEq
        df = DataFrame({'Q':Q, 'pwp':pwp_rates, 'sat_ratio':sat_ratio})
        df = df.dropna()
        #Make PWP vs. Saturation Ratio Plot
        figure()
        if plotloglog:
            loglog(df.pwp, df.sat_ratio, '.', color=this_color)
        else:
            semilogx(df.pwp, df.sat_ratio, '.', color=this_color)
        xlabel('PWP Dissolution Rate (mm/yr)')
        ylabel('Saturation ratio')
        savefig(os.path.join(plotsDir,site+'-Sat_ratio_vs_PWP.pdf'))
        #Calculate correlation coefficient and regression
        slope,intercept,r,p,stderr = linregress(df.pwp, df.sat_ratio)        
        rs.append(r)
        ps.append(p)
        [this_spr, this_spp] = spearmanr(df.pwp, df.sat_ratio)
        spr.append(this_spr)
        spp.append(this_spp)
        slopes.append(slope)

    #Make histogram of pearson r values    
    figure()
    arr_rs = array(rs)
    print "size arr_rs=", arr_rs.size
    arr_ps = array(ps)
    arr_spr = array(spr)
    arr_spp = array(spp)
    arr_site_class = array(site_class)
    hist(arr_rs[arr_site_class==1],color=class_colors[1], alpha=0.5)
    hist(arr_rs[arr_site_class==2],color=class_colors[2], alpha=0.5)
    hist(arr_rs[arr_site_class==3],color=class_colors[3], alpha=0.5)
    xlabel('Pearson R')
    ylabel('Frequency')
    savefig(os.path.join(plotsDir,'PearsonR_PWP_SatRatio.pdf'))
    #Make histogram of pearson p values
    figure()
    hist(arr_ps[arr_site_class==1],color=class_colors[1], alpha=0.5)
    hist(arr_ps[arr_site_class==2],color=class_colors[2], alpha=0.5)
    hist(arr_ps[arr_site_class==3],color=class_colors[3], alpha=0.5)
    xlabel('Pearson p')
    ylabel('Frequency')
    savefig(os.path.join(plotsDir, 'PearsonP_PWP_SatRatio.pdf'))
    #Make histogram of spearman r values
    figure()
    hist(arr_spr[arr_site_class==1],color=class_colors[1], alpha=0.5)
    hist(arr_spr[arr_site_class==2],color=class_colors[2], alpha=0.5)
    hist(arr_spr[arr_site_class==3],color=class_colors[3], alpha=0.5)
    xlabel('Spearman R')
    ylabel('Frequency')
    savefig(os.path.join(plotsDir, 'SpearmanR_PWP_SatRatio.pdf'))
    #Make histogram of spearman p values
    figure()
    hist(arr_spp[arr_site_class==1],color=class_colors[1], alpha=0.5)
    hist(arr_spp[arr_site_class==2],color=class_colors[2], alpha=0.5)
    hist(arr_spp[arr_site_class==3],color=class_colors[3], alpha=0.5)
    xlabel('Spearman p')
    ylabel('Frequency')
    savefig(os.path.join(plotsDir, 'SpearmanP_PWP_SatRatio.pdf'))