Mercurial > repos > jay > gaiac_regression_plot
annotate gaiac_bias_calculation/gaiac_bias_calculation.py @ 3:2ae74925a4fe draft default tip
planemo upload for repository https://github.com/jaidevjoshi83/gaiac commit e9587f93346c7b55e1be00bad5844bf2db3ed03d-dirty
author | jay |
---|---|
date | Thu, 10 Jul 2025 19:40:59 +0000 |
parents | 0a8233db930e |
children |
rev | line source |
---|---|
0
0a8233db930e
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit c29a769ed165f313a6410925be24f776652a9663-dirty
jay
parents:
diff
changeset
|
1 import scipy |
0a8233db930e
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit c29a769ed165f313a6410925be24f776652a9663-dirty
jay
parents:
diff
changeset
|
2 #from scipy.stats.distributions import chi2,t |
0a8233db930e
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit c29a769ed165f313a6410925be24f776652a9663-dirty
jay
parents:
diff
changeset
|
3 from scipy.stats import t |
0a8233db930e
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit c29a769ed165f313a6410925be24f776652a9663-dirty
jay
parents:
diff
changeset
|
4 from scipy import stats |
0a8233db930e
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit c29a769ed165f313a6410925be24f776652a9663-dirty
jay
parents:
diff
changeset
|
5 import pandas as pd |
0a8233db930e
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit c29a769ed165f313a6410925be24f776652a9663-dirty
jay
parents:
diff
changeset
|
6 import numpy as np |
0a8233db930e
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit c29a769ed165f313a6410925be24f776652a9663-dirty
jay
parents:
diff
changeset
|
7 import argparse |
0a8233db930e
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit c29a769ed165f313a6410925be24f776652a9663-dirty
jay
parents:
diff
changeset
|
8 |
0a8233db930e
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit c29a769ed165f313a6410925be24f776652a9663-dirty
jay
parents:
diff
changeset
|
9 def Bias_abs(infile, clm1, clm2, Out): |
0a8233db930e
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit c29a769ed165f313a6410925be24f776652a9663-dirty
jay
parents:
diff
changeset
|
10 |
0a8233db930e
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit c29a769ed165f313a6410925be24f776652a9663-dirty
jay
parents:
diff
changeset
|
11 df = pd.read_csv(infile, sep="\t") |
0a8233db930e
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit c29a769ed165f313a6410925be24f776652a9663-dirty
jay
parents:
diff
changeset
|
12 lOc = int(df.shape[0]) |
0a8233db930e
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit c29a769ed165f313a6410925be24f776652a9663-dirty
jay
parents:
diff
changeset
|
13 cl = df.columns.tolist() |
0a8233db930e
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit c29a769ed165f313a6410925be24f776652a9663-dirty
jay
parents:
diff
changeset
|
14 #making a column of absolute di as per us epa |
0a8233db930e
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit c29a769ed165f313a6410925be24f776652a9663-dirty
jay
parents:
diff
changeset
|
15 df['PM10_OPC_DIFF']=abs(((df[cl[int(clm1)-1]])-(df[cl[int(clm2)-1]]))/(df[cl[int(clm2)-1]]))*100 |
0a8233db930e
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit c29a769ed165f313a6410925be24f776652a9663-dirty
jay
parents:
diff
changeset
|
16 #square of di |
0a8233db930e
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit c29a769ed165f313a6410925be24f776652a9663-dirty
jay
parents:
diff
changeset
|
17 df['PM10_OPC_DIFFs']=(df['PM10_OPC_DIFF'])*(df['PM10_OPC_DIFF']) |
0a8233db930e
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit c29a769ed165f313a6410925be24f776652a9663-dirty
jay
parents:
diff
changeset
|
18 #summation of the columns |
0a8233db930e
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit c29a769ed165f313a6410925be24f776652a9663-dirty
jay
parents:
diff
changeset
|
19 d10=df.PM10_OPC_DIFF.sum() |
0a8233db930e
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit c29a769ed165f313a6410925be24f776652a9663-dirty
jay
parents:
diff
changeset
|
20 d10_2=df.PM10_OPC_DIFFs.sum() |
0a8233db930e
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit c29a769ed165f313a6410925be24f776652a9663-dirty
jay
parents:
diff
changeset
|
21 #AB and AS calculations |
0a8233db930e
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit c29a769ed165f313a6410925be24f776652a9663-dirty
jay
parents:
diff
changeset
|
22 AB= d10/lOc |
0a8233db930e
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit c29a769ed165f313a6410925be24f776652a9663-dirty
jay
parents:
diff
changeset
|
23 AS=(np.sqrt((lOc*(d10_2)-(d10)**2)/(2*lOc*(lOc-1)))) |
0a8233db930e
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit c29a769ed165f313a6410925be24f776652a9663-dirty
jay
parents:
diff
changeset
|
24 |
0a8233db930e
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit c29a769ed165f313a6410925be24f776652a9663-dirty
jay
parents:
diff
changeset
|
25 #T distribution calculation |
0a8233db930e
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit c29a769ed165f313a6410925be24f776652a9663-dirty
jay
parents:
diff
changeset
|
26 T=stats.t.ppf(1-0.05, lOc) |
0a8233db930e
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit c29a769ed165f313a6410925be24f776652a9663-dirty
jay
parents:
diff
changeset
|
27 #Absolute bias calculation |
0a8233db930e
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit c29a769ed165f313a6410925be24f776652a9663-dirty
jay
parents:
diff
changeset
|
28 Bias_abs = abs(AB + T*AS/(np.sqrt(lOc))) |
0a8233db930e
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit c29a769ed165f313a6410925be24f776652a9663-dirty
jay
parents:
diff
changeset
|
29 |
0a8233db930e
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit c29a769ed165f313a6410925be24f776652a9663-dirty
jay
parents:
diff
changeset
|
30 #di column with sign |
0a8233db930e
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit c29a769ed165f313a6410925be24f776652a9663-dirty
jay
parents:
diff
changeset
|
31 df['Di']=(((df[cl[int(clm1)-1]])-(df[cl[int(clm2)-1]]))/(df[cl[int(clm2)-1]]))*100 |
0a8233db930e
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit c29a769ed165f313a6410925be24f776652a9663-dirty
jay
parents:
diff
changeset
|
32 #quantiles of di without sign |
0a8233db930e
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit c29a769ed165f313a6410925be24f776652a9663-dirty
jay
parents:
diff
changeset
|
33 q1=df['Di'].quantile([0.25]) |
0a8233db930e
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit c29a769ed165f313a6410925be24f776652a9663-dirty
jay
parents:
diff
changeset
|
34 q2=df['Di'].quantile([0.75]) |
0a8233db930e
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit c29a769ed165f313a6410925be24f776652a9663-dirty
jay
parents:
diff
changeset
|
35 #assigning sign to absolute bias based on q1 and q2 values |
0a8233db930e
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit c29a769ed165f313a6410925be24f776652a9663-dirty
jay
parents:
diff
changeset
|
36 |
0a8233db930e
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit c29a769ed165f313a6410925be24f776652a9663-dirty
jay
parents:
diff
changeset
|
37 if (q1[0.25] < 0) & (q2[0.75] < 0): |
0a8233db930e
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit c29a769ed165f313a6410925be24f776652a9663-dirty
jay
parents:
diff
changeset
|
38 Bias_abs=Bias_abs*-1 |
0a8233db930e
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit c29a769ed165f313a6410925be24f776652a9663-dirty
jay
parents:
diff
changeset
|
39 elif (q1[0.25] > 0) & (q2[0.75] > 0): |
0a8233db930e
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit c29a769ed165f313a6410925be24f776652a9663-dirty
jay
parents:
diff
changeset
|
40 Bias_abs=Bias_abs |
0a8233db930e
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit c29a769ed165f313a6410925be24f776652a9663-dirty
jay
parents:
diff
changeset
|
41 elif (q1[0.25] >0) & (q2[0.75]<0): |
0a8233db930e
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit c29a769ed165f313a6410925be24f776652a9663-dirty
jay
parents:
diff
changeset
|
42 Bias_abs=(u"\u00B1"+str(Bias_abs)) |
0a8233db930e
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit c29a769ed165f313a6410925be24f776652a9663-dirty
jay
parents:
diff
changeset
|
43 elif (q1[0.25] <0) & (q2[0.75]>0): |
0a8233db930e
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit c29a769ed165f313a6410925be24f776652a9663-dirty
jay
parents:
diff
changeset
|
44 Bias_abs=(u"\u00B1"+str(Bias_abs)) |
0a8233db930e
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit c29a769ed165f313a6410925be24f776652a9663-dirty
jay
parents:
diff
changeset
|
45 |
0a8233db930e
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit c29a769ed165f313a6410925be24f776652a9663-dirty
jay
parents:
diff
changeset
|
46 #output file |
0a8233db930e
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit c29a769ed165f313a6410925be24f776652a9663-dirty
jay
parents:
diff
changeset
|
47 df1 = pd.DataFrame([Bias_abs], columns=['Percent Bias']) |
0a8233db930e
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit c29a769ed165f313a6410925be24f776652a9663-dirty
jay
parents:
diff
changeset
|
48 df1.round(4).to_csv(Out, sep="\t") |
0a8233db930e
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit c29a769ed165f313a6410925be24f776652a9663-dirty
jay
parents:
diff
changeset
|
49 |
0a8233db930e
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit c29a769ed165f313a6410925be24f776652a9663-dirty
jay
parents:
diff
changeset
|
50 |
0a8233db930e
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit c29a769ed165f313a6410925be24f776652a9663-dirty
jay
parents:
diff
changeset
|
51 if __name__=="__main__": |
0a8233db930e
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit c29a769ed165f313a6410925be24f776652a9663-dirty
jay
parents:
diff
changeset
|
52 |
0a8233db930e
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit c29a769ed165f313a6410925be24f776652a9663-dirty
jay
parents:
diff
changeset
|
53 parser = argparse.ArgumentParser() |
0a8233db930e
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit c29a769ed165f313a6410925be24f776652a9663-dirty
jay
parents:
diff
changeset
|
54 |
0a8233db930e
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit c29a769ed165f313a6410925be24f776652a9663-dirty
jay
parents:
diff
changeset
|
55 parser.add_argument("-I", "--infile", required=True, default=None, help="Input file") |
0a8233db930e
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit c29a769ed165f313a6410925be24f776652a9663-dirty
jay
parents:
diff
changeset
|
56 parser.add_argument("-c1", "--column_1", required=True, default=None, help="First column") |
0a8233db930e
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit c29a769ed165f313a6410925be24f776652a9663-dirty
jay
parents:
diff
changeset
|
57 parser.add_argument("-c2", "--column_2", required=True, default=None, help="Second column") |
0a8233db930e
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit c29a769ed165f313a6410925be24f776652a9663-dirty
jay
parents:
diff
changeset
|
58 parser.add_argument("-o", "--output", required=True, default=None, help="OutFile") |
0a8233db930e
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit c29a769ed165f313a6410925be24f776652a9663-dirty
jay
parents:
diff
changeset
|
59 args = parser.parse_args() |
0a8233db930e
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit c29a769ed165f313a6410925be24f776652a9663-dirty
jay
parents:
diff
changeset
|
60 |
0a8233db930e
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit c29a769ed165f313a6410925be24f776652a9663-dirty
jay
parents:
diff
changeset
|
61 Bias_abs(args.infile, args.column_1, args.column_2, args.output) |