コード例 #1
0
def calc_site_pwp(sitedf, sitephreeqc, returnPCO2=False):
    have_data = False
    if ('Stream flow, mean. daily' in sitedf.columns) and (
            'Temperature, water' in sitedf.columns) and (
                'CO2_Molality' in sitephreeqc.columns) and (
                    'Ca+2_Activity' in sitephreeqc.columns) and (
                        'CO2_Activity' in sitephreeqc.columns) and (
                            'H+_Activity' in sitephreeqc.columns) and (
                                'HCO3-_Activity' in sitephreeqc.columns):
        have_data = True
    if have_data:
        #create dataframe subset
        subdf = DataFrame({
            'Q': sitedf['Stream flow, mean. daily'],
            'T_C': sitedf['Temperature, water'],
            'CO2': sitephreeqc.CO2_Molality,
            'a_Ca': sitephreeqc['Ca+2_Activity'],
            'a_H2CO3s': sitephreeqc['CO2_Activity'],
            'a_H': sitephreeqc['H+_Activity'],
            'a_HCO3': sitephreeqc['HCO3-_Activity']
        })
        #Clear out NaN values
        subdf = subdf.dropna()
        if subdf.size > 0:
            #Average any duplicate indicies
            g = subdf.groupby(level=0)  #group by duplicate indicies
            subdf = g.mean()  #average duplicate indicies
            #Calculate PCO2
            T_K = CtoK(subdf.T_C)
            K_H = calc_K_H(T_K)
            PCO2 = subdf.CO2 / K_H
            pwp_rates = pwpRateTheory(a_Ca=subdf.a_Ca,
                                      a_H2CO3s=subdf.a_H2CO3s,
                                      a_H=subdf.a_H,
                                      a_HCO3=subdf.a_HCO3,
                                      T_K=T_K,
                                      PCO2=PCO2)
            if returnPCO2:
                return [pwp_rates, PCO2]
            else:
                return pwp_rates
        else:
            if returnPCO2:
                return [None, None]
            else:
                return None
    #Data were missing
    else:
        if returnPCO2:
            return [None, None]
        else:
            return None
コード例 #2
0
ファイル: plots.py プロジェクト: joemyre/olm
def calc_site_pwp(sitedf, sitephreeqc, returnPCO2=False):
    have_data = False
    if ('Stream flow, mean. daily' in sitedf.columns) and ( 'Temperature, water' in sitedf.columns) and ('CO2_Molality' in sitephreeqc.columns) and ('Ca+2_Activity'  in sitephreeqc.columns) and ('CO2_Activity'  in sitephreeqc.columns) and ('H+_Activity'  in sitephreeqc.columns) and ('HCO3-_Activity'  in sitephreeqc.columns):
       have_data = True
    if have_data:
        #create dataframe subset
        subdf = DataFrame({
                'Q':sitedf['Stream flow, mean. daily'],
                'T_C':sitedf['Temperature, water'],
                'CO2':sitephreeqc.CO2_Molality,
                'a_Ca':sitephreeqc['Ca+2_Activity'],
                'a_H2CO3s':sitephreeqc['CO2_Activity'],
                'a_H':sitephreeqc['H+_Activity'],
                'a_HCO3':sitephreeqc['HCO3-_Activity']
                })
        #Clear out NaN values
        subdf = subdf.dropna()
        if subdf.size>0:
            #Average any duplicate indicies
            g = subdf.groupby(level=0)#group by duplicate indicies
            subdf = g.mean()#average duplicate indicies
            #Calculate PCO2
            T_K = CtoK(subdf.T_C)
            K_H = calc_K_H(T_K)
            PCO2 = subdf.CO2/K_H    
            pwp_rates = pwpRateTheory(a_Ca=subdf.a_Ca, a_H2CO3s=subdf.a_H2CO3s, a_H=subdf.a_H, a_HCO3=subdf.a_HCO3, T_K=T_K, PCO2=PCO2)
            if returnPCO2:
                return [pwp_rates, PCO2]
            else:
                return pwp_rates
        else:
            if returnPCO2:
                return [None,None]
            else: 
                return None
    #Data were missing
    else:
        if returnPCO2:
            return [None,None]
        else: 
            return None
コード例 #3
0
def make_pwp_vs_T_plots(sitesDir, siteList=None, siteFile=None, makeHistograms=True, classFile=''):
    sitePanelDict, sitePhreeqcDict = loadSiteListData(processedSitesDir=sitesDir, loadPhreeqc=True)
    if classFile != '':
        class_xls = read_excel(classFile, 'Sheet1',index_col=1, names=['name','site', 'recharge', 'age'])
    rs = []
    ps = []
    slopes = []
    plotsDir = os.path.join(sitesDir, 'plots/')
    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]
        else:
            this_color='black'
        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']
        a_Ca = sitePhreeqcDict[site]['Ca+2_Activity']
        a_H2CO3s = sitePhreeqcDict[site]['CO2_Activity']
        a_HCO3 = sitePhreeqcDict[site]['HCO3-_Activity']
        a_H = sitePhreeqcDict[site]['H+_Activity']
        #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,a_Ca,a_H2CO3s,a_H, a_HCO3])
        Q = Q[good_values]
        T_C = T_C[good_values]
        CO2 = CO2[good_values]
        Ca = Ca[good_values]
        a_Ca = a_Ca[good_values]
        a_H = a_H[good_values]
        a_H2CO3s = a_H2CO3s[good_values]
        a_HCO3 = a_HCO3[good_values]
        #Calculate PCO2
        T_K = CtoK(T_C)
        K_H = calc_K_H(T_K)
        PCO2 = CO2/K_H
        #Calculate PWP rates
        pwp_rates = []
        for i, value in enumerate(Q):
#            sol = solutionFromCaPCO2(Ca[i], PCO2[i], T_C = T_C[i])
#            this_pwp = pwpFromSolution(sol)
            this_pwp =  pwpRateTheory(a_Ca=a_Ca[i], a_H2CO3s=a_H2CO3s[i], a_H=a_H[i], a_HCO3=a_HCO3[i], T_K=T_K[i], PCO2=PCO2[i])
            this_rate_mm_yr = pwp_to_mm_yr(this_pwp)
            pwp_rates.append(this_rate_mm_yr)
        #Check for plots directory and make it if one doesn't exist
        check_plots_dir(sitesDir)
        #Make Discharge vs. Saturation Ratio Plot
        figure()
        plot(T_C, pwp_rates, 'o', color=this_color)
        xlabel('Temperature ($^\circ C$)')
        ylabel('PWP Dissolution Rate (mm/yr)')
        savefig(os.path.join(plotsDir,site+'-T_vs_PWP.pdf'))
        #Calculate correlation coefficient and regression
        slope,intercept,r,p,stderr = linregress(T_C, pwp_rates)
        rs.append(r)
        ps.append(p)
        slopes.append(slope)
        if makeHistograms:
            figure()
            hist(pwp_rates, normed=True, color=this_color)
            xlabel('PWP Rate mm/yr')
            ylabel('Frequency')
            savefig(os.path.join(plotsDir,site+'-PWPHist.pdf'))

    #Make histogram of pearson r values    
    figure()
    hist(rs,normed=True)
    xlabel('Pearson R')
    ylabel('Frequency')
    savefig(os.path.join(plotsDir,'PearsonR_T_PWP.pdf'))
コード例 #4
0
ファイル: plots.py プロジェクト: joemyre/olm
def make_pwp_vs_T_plots(sitesDir, siteList=None, siteFile=None, makeHistograms=True, classFile=''):
    sitePanelDict, sitePhreeqcDict = loadSiteListData(processedSitesDir=sitesDir, loadPhreeqc=True)
    if classFile != '':
        class_xls = read_excel(classFile, 'Sheet1',index_col=1, names=['name','site', 'recharge', 'age'])
    rs = []
    ps = []
    slopes = []
    plotsDir = os.path.join(sitesDir, 'plots/')
    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]
        else:
            this_color='black'
        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']
        a_Ca = sitePhreeqcDict[site]['Ca+2_Activity']
        a_H2CO3s = sitePhreeqcDict[site]['CO2_Activity']
        a_HCO3 = sitePhreeqcDict[site]['HCO3-_Activity']
        a_H = sitePhreeqcDict[site]['H+_Activity']
        #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,a_Ca,a_H2CO3s,a_H, a_HCO3])
        Q = Q[good_values]
        T_C = T_C[good_values]
        CO2 = CO2[good_values]
        Ca = Ca[good_values]
        a_Ca = a_Ca[good_values]
        a_H = a_H[good_values]
        a_H2CO3s = a_H2CO3s[good_values]
        a_HCO3 = a_HCO3[good_values]
        #Calculate PCO2
        T_K = CtoK(T_C)
        K_H = calc_K_H(T_K)
        PCO2 = CO2/K_H
        #Calculate PWP rates
        pwp_rates = []
        for i, value in enumerate(Q):
#            sol = solutionFromCaPCO2(Ca[i], PCO2[i], T_C = T_C[i])
#            this_pwp = pwpFromSolution(sol)
            this_pwp =  pwpRateTheory(a_Ca=a_Ca[i], a_H2CO3s=a_H2CO3s[i], a_H=a_H[i], a_HCO3=a_HCO3[i], T_K=T_K[i], PCO2=PCO2[i])
            this_rate_mm_yr = pwp_to_mm_yr(this_pwp)
            pwp_rates.append(this_rate_mm_yr)
        #Check for plots directory and make it if one doesn't exist
        check_plots_dir(sitesDir)
        #Make Discharge vs. Saturation Ratio Plot
        figure()
        plot(T_C, pwp_rates, 'o', color=this_color)
        xlabel('Temperature ($^\circ C$)')
        ylabel('PWP Dissolution Rate (mm/yr)')
        savefig(os.path.join(plotsDir,site+'-T_vs_PWP.pdf'))
        #Calculate correlation coefficient and regression
        slope,intercept,r,p,stderr = linregress(T_C, pwp_rates)
        rs.append(r)
        ps.append(p)
        slopes.append(slope)
        if makeHistograms:
            figure()
            hist(pwp_rates, normed=True, color=this_color)
            xlabel('PWP Rate mm/yr')
            ylabel('Frequency')
            savefig(os.path.join(plotsDir,site+'-PWPHist.pdf'))

    #Make histogram of pearson r values    
    figure()
    hist(rs,normed=True)
    xlabel('Pearson R')
    ylabel('Frequency')
    savefig(os.path.join(plotsDir,'PearsonR_T_PWP.pdf'))