def save(self, path): com.save(self, path)
# read in the output of "modvsobs.py" df1=pd.read_csv(site[0]+'botttemp_mc_mod_mc_obs.csv',index_col=0) ts1=pd.read_csv(site[0]+'botttemp_mc_obs.csv',index_col=0,names=['yy','mm','dd','count','mean','median','min','max','std','rms']) dfmean1=df1.mean() df2=df1['mean'].fillna(0) dfmean1['max']=max(df2) dfmean1['min']=min(df2) dfmean1['std']=ts1['std'].mean() pdmean1=pd.DataFrame(dfmean1) pdmean1=pdmean1.drop('median') pdmean1.columns=[site[0]] for k in range(len(site)): if k!=0: #df=pd.read_csv(site[k]+'_wtmp_mc_mod_mc_obs.csv',index_col=0) df=pd.read_csv(site[k]+'botttemp_mc_mod_mc_obs.csv',index_col=0) ts=pd.read_csv(site[k]+'botttemp_mc_obs.csv',index_col=0,names=['yy','mm','dd','count','mean','median','min','max','std','rms']) dfmean=df.mean() df3=df['mean'].fillna(0) dfmean['max']=max(df3) dfmean['min']=min(df3) dfmean['std']=ts['std'].mean() pdmean=pd.DataFrame(dfmean) pdmean=pdmean.drop('median') pdmean.columns=[site[k]] pdmean1=pdmean1.join(pdmean) pdmean1=pdmean1.T pdmean1.to_csv('totalcaculate_10Dec2013.csv',index=True) htmlmean=pdmean1.to_html(header=True,index=True,float_format=lambda x: '%10.2f' % x) save(htmlmean,'/net/nwebserver/epd/ocean/MainPage/lob/emoltvsnecofs_diff.html') #save(htmlmean,'emoltvsnecofs_diff.html')
def save(self, path): save(self, path)
dfmean2 = df2['mean'] pdmean2 = pd.DataFrame(dfmean2, index=df2.index) pdmean2.columns = [site2[0]] for k in range(len(site2)): if k != 0: df3 = pd.read_csv(site2[k] + 'temp_mc_mod_mc_obs.csv', index_col=0) dfmean3 = df3['mean'] pdmean3 = pd.DataFrame(dfmean3, index=df3.index) pdmean3.columns = [site2[k]] pdmean2 = pdmean2.join(pdmean3) print pdmean2 pdmean1.to_csv('totalplot.csv', index=True) htmlmean = pdmean1.to_html(header=True, index=True) save(htmlmean, 'totalplot.html') fig = plt.figure() ax = fig.add_subplot(211) #ax.plot(pdmean1.index,pdmean1.values) ax.plot(pdmean1.index, pdmean1['AG01surf'], color='r') ax.plot(pdmean1.index, pdmean1['AG01bott'], color='b') ax.set_ylabel('Temperature difference (degC)') plt.title('observed minus model at AG01') plt.grid() #ax.set_xlabel('Month') plt.setp(ax.get_xticklabels(), visible=False) plt.legend(['surface', 'bottom'], loc='upper right', ncol=3, fancybox=True,
dfmean1['std'] = ts1['std'].mean() pdmean1 = pd.DataFrame(dfmean1) pdmean1 = pdmean1.drop('median') pdmean1.columns = [site[0]] for k in range(len(site)): if k != 0: df = pd.read_csv(site[k] + 'botttemp_mc_mod_mc_obs.csv', index_col=0) ts = pd.read_csv(site[k] + 'botttemp_mc_obs.csv', index_col=0, names=[ 'yy', 'mm', 'dd', 'count', 'mean', 'median', 'min', 'max', 'std' ]) dfmean = df.mean() df3 = df['mean'].fillna(0) dfmean['max'] = max(df3) dfmean['min'] = min(df3) dfmean['std'] = ts['std'].mean() pdmean = pd.DataFrame(dfmean) pdmean = pdmean.drop('median') pdmean.columns = [site[k]] pdmean1 = pdmean1.join(pdmean) pdmean1 = pdmean1.T pdmean1.to_csv('totalcaculate.csv', index=True) htmlmean = pdmean1.to_html(header=True, index=True, float_format=lambda x: '%10.2f' % x) save(htmlmean, '/net/nwebserver/epd/ocean/MainPage/lob/emoltvsnecofs_diff.html') save(htmlmean, 'emoltvsnecofs_diff.html')
pdmean2=pd.DataFrame(dfmean2,index=df2.index) pdmean2.columns=[site2[0]] for k in range(len(site2)): if k!=0: df3=pd.read_csv(site2[k]+'temp_mc_mod_mc_obs.csv',index_col=0) dfmean3=df3['mean'] pdmean3=pd.DataFrame(dfmean3,index=df3.index) pdmean3.columns=[site2[k]] pdmean2=pdmean2.join(pdmean3) print pdmean2 pdmean1.to_csv('totalplot.csv',index=True) htmlmean=pdmean1.to_html(header=True,index=True) save(htmlmean,'totalplot.html') fig=plt.figure() ax=fig.add_subplot(211) #ax.plot(pdmean1.index,pdmean1.values) ax.plot(pdmean1.index,pdmean1['AG01surf'],color='r') ax.plot(pdmean1.index,pdmean1['AG01bott'],color='b') ax.set_ylabel('Temperature difference (degC)') plt.title('observed minus model at AG01') plt.grid() #ax.set_xlabel('Month') plt.setp(ax.get_xticklabels(),visible=False) plt.legend(['surface','bottom'],loc='upper right', ncol=3, fancybox=True, shadow=True) for i in range(len(ax.lines)):#plot in different ways
tmi=tsdc['min'].resample('m',how=['mean'],loffset=timedelta(days=-15)).values tma=tsdc['max'].resample('m',how=['mean'],loffset=timedelta(days=-15)).values tstd=tsdc['std'].resample('m',how=['mean'],loffset=timedelta(days=-15)).values for kk in range(len(tsmc)): tsmc['count'].values[kk]=tcount[kk] tsmc['min'].values[kk]=tmi[kk] tsmc['max'].values[kk]=tma[kk] tsmc['std'].values[kk]=tstd[kk] tsmc['yy']=0 tsmc['mm']=tsmc.index.month tsmc['dd']=0 output_fmt=['yy','mm','dd','count','mean','median','min','max','std'] tsmcp=tsmc.reindex(columns=output_fmt)# found I needed to generate a new dataframe to print in this order tsmcp.to_csv(outdir+site[k]+'_wtmp_mc_'+str(int(depth))+'.csv',index=False,header=False,na_rep='NaN',float_format='%10.2f') output_fmt_html=['mm','count','mean','median','min','max','std'] outhtml=tsmcp.to_html(header=True,index=False,na_rep='NaN',float_format=lambda x: '%10.2f' % x,columns=output_fmt_html) save(outhtml,'/net/home3/ocn/jmanning/py/'+site[k]+'_wtmp_mc_'+str(int(depth))+'.html') #make some plots plt.figure() tsod['mean'].plot() #plot daily mean plt.title(site[k]+' daily means') plt.show() plt.savefig('/net/nwebserver/epd/ocean/MainPage/lob/'+site[k]+'_jt.png') plt.figure() tt=tsmc['mean'].plot() #plot mthly clim tt.xaxis.set_major_formatter(DateFormatter('%b')) plt.title(site[k]+' Monthly Climatology') plt.show() plt.savefig('/net/nwebserver/epd/ocean/MainPage/lob/'+site[k]+'_seacycle.png')
# DO THE SAME AS ABOVE FOR MULTIPLE SITES for k in range(len(site)): print site[k] #if (k!=0) and (os.path.isfile("/net/data5/jmanning/modvsobs/roms/"+site[k]+'botttemp_mc_mod_mc_obs.csv')): if (k!=0) and (os.path.isfile("/net/data5/jmanning/modvsobs/"+site[k]+'botttemp_mc_mod_mc_obs'+mode+'.csv')): df=pd.read_csv("/net/data5/jmanning/modvsobs/"+site[k]+'botttemp_mc_mod_mc_obs'+mode+'.csv',index_col=0) dfmean=df.mean().dropna() dfmean['max']=np.nanmax(df['mean']) dfmean['min']=np.nanmin(df['mean']) if len(dfmean)>4: # cases where there is std dfmean=dfmean.drop('std') dfmean=dfmean.drop('median') std=df['mean'].std() rms=sqrt((np.sum(np.square(df['mean'])))/(np.count_nonzero(df['mean']))) row= pd.DataFrame([dict(rms=rms,std=std)]) row=row.T pdmean=pd.DataFrame(dfmean) pdmean=pdmean.append(row) #pdmean=pdmean.drop('median') pdmean.columns=[site[k]] pdmean1=pdmean1.join(pdmean) pdmean1=pdmean1.T #pdmean1.to_csv('/data5/jmanning/modvsobs/roms/totalcalculate.csv',index=True,float_format='%8.3f') pdmean1.to_csv('/data5/jmanning/modvsobs/totalcalculate'+mode+'.csv',index=True,float_format='%8.3f') htmlmean=pdmean1.to_html(header=True,index=True,float_format=lambda x: '%10.2f' % x) save(htmlmean,'/net/nwebserver/epd/ocean/MainPage/modvsobs/emoltvsnecofs_diff'+mode+'.html') print 'mean='+str(np.mean(pdmean1['mean'])) print 'rms ='+str(np.mean(pdmean1['rms']))