def CH4results(): choicesaveresults = raw_input("Save results? (y/n)") results = [] for D_0 in CH4INLETS_VARY_D_0: result = CCDroplet.main(gri30_gas,ctCH4,"methane",CH4_TUP,CH4CH_PARAMS,D_0,Hrefchoice='y', T_boilo=111.5) results.append(result) if choicesaveresults == 'y': for result in results: # sanity check try: Dsizestr = str(result['cleandat'].D[0]*10**6).split('.')[0] except KeyError: print "KeyError still! I'll print the type:" print type(result) filename = CH4_TUP.Fuelstr+str(CCDroplet.NUM_STEPS)+"steps"+"D"+Dsizestr+'v_d'+str(result['cleandat'].v_d[0]).split('.')[0] tosave = pd.DataFrame(result['cleandat']._asdict(),index=result['xclean']) # EY : 20160311 I wanted to implement hdf5 requiring PyTables but pip install # of PyTables was nontrivial; received warning # Warning! ***HDF5 library version mismatched error*** # Abort trap: 6 # would like to know best practices for serialization of pandas DataFrame # try: # tosave.to_hdf("./data/"+filename,filename) # except: # print "We're not in a directory where there's a subdirectory for data. Saving into working directory." # try: # tosave.to_hdf(filename,filename) # except: # print "PyTables may not be installed. Try pickle. Be careful of reading unknown pickles (see pandas doc for warning)" try: tosave.to_pickle("./data/"+filename+'.pkl') except: print "We're not in a directory where there's a subdirectory for data. Saving into working directory." tosave.to_pickle(filename+'.pkl') # (surjective) transforming from list of dicts, that includes raw data, to list of namedtuples of pandas dataframe, which only includes clean data results = [pd.DataFrame(result['cleandat']._asdict(),index=result['xclean']) for result in results] # D_0s = [int(str(result.D[0]*10**6).split('.')[0]) for result in results] D_0s = [str(result.D[0]*10**6).split('.')[0] for result in results] results = pd.concat(results,axis=1, keys=D_0s) filename = CH4_TUP.Fuelstr+str(CCDroplet.NUM_STEPS)+"steps"+ str(results[D_0s[0]].v_d[0.0]).split('.')[0] try: results.to_pickle("./data/"+filename+'.pkl') except: print "We're not in a directory where there's a subdirectory for data. Saving into working directory." results.to_pickle(filename+'.pkl') return results
def output_from_main(gas,liquid,speciesname,reaction_tuple,chamber_params,inlet_conds,Hrefchoice,T_boilo): """ output_from_main(gas,liquid,speciesname,reaction_tuple,chamber_params,inlet_conds,T_boilo) """ choicesaveresults = raw_input("Save results? (y/n)") results = [] for D_0 in inlet_conds: result = CCDroplet.main(gas,liquid,speciesname,reaction_tuple,chamber_params,D_0,Hrefchoice, T_boilo) results.append(result) if choicesaveresults == 'y': for result in results: try: Dsizestr = str(result['cleandat'].D[0]*10**6).split('.')[0] except KeyError: print "KeyError still! I'll print the type:" print type(result) filename = speciesname+"steps"+str(CCDroplet.NUM_STEPS)+"D"+Dsizestr+'v_d'+str(result['cleandat'].v_d[0]).split('.')[0] tosave = pd.DataFrame(result['cleandat']._asdict(),index=result['xclean']) try: tosave.to_pickle("./data/"+filename) except: print "We're not in a directory where there's a subdirectory for data. Saving into working directory." tosave.to_pickle(filename) # (surjective) transforming from list of dicts, that includes raw data, to list of namedtuples of pandas dataframe, which only includes clean data results = [pd.DataFrame(result['cleandat']._asdict(),index=result['xclean']) for result in results] # D_0s = [int(str(result.D[0]*10**6).split(',')[0]) for result in results] D_0s = [str(result.D[0]*10**6).split(',')[0] for result in results] results = pd.concat(results,axis=1, keys=D_0s) filename = speciesname+str(CCDroplet.NUM_STEPS)+"steps"+ str(results[D_0s[0]].v_d[0.0]).split('.')[0] +'v_d' try: results.to_pickle("./data/"+filename) except: print "We're not in a directory where there's a subdirectory for data. Saving into working directory." results.to_pickle(filename) return results
def CH4result(key): """ calculations for a single initial droplet size only """ result = CCDroplet.main(gri30_gas,ctCH4,"methane",CH4_TUP,CH4CH_PARAMS,CH4INLETS_VARY_D_0[key],Hrefchoice='y', Tboilo=111.5) return result