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
def compute_flows_phi_g_v_g(gas,liquid,reaction_tuple,chamber_params,inlet_conds,T_boil,oderesults,Hrefchoice='y'): """ compute_flows_phi_g_v_g = compute_flows_phi_g_v_g(gas,liquid,reaction_tuple,T_boil,P,Hrefchoice) oderesults - <CCDroplet.T_gDv_d_Tuple> """ P = inlet_conds.TP[1] h_fg,T_boil,rho_l,h_l=CCDroplet._process_liquid_Droplet(gas,liquid,reaction_tuple,T_boil,P,Hrefchoice) Fu_ind = gas.species_index(reaction_tuple.Fuelstr) Ox_ind = gas.species_index(reaction_tuple.Oxstr) gas.X = CCDroplet.phi_to_X(1, reaction_tuple) F_over_O = gas.Y[Fu_ind]/gas.Y[Ox_ind] flow_inlet,initial_conds = CCDroplet.get_initial_flow_vals(gas,reaction_tuple,chamber_params,inlet_conds,rho_l,F_over_O) dotm_Ox0 = flow_inlet.dotm_Ox # kg/s # Additional Python step: create vectors to store data # try if it's a named_tuple; then try if it's a panda DataFrame try: NUM_STEPS = len(oderesults[0]) except: NUM_STEPS = oderesults.count()[0] dotm_l = np.zeros(NUM_STEPS) dotm_g = np.zeros(NUM_STEPS) phi_g = np.zeros(NUM_STEPS) v_g = np.zeros(NUM_STEPS) dotm_l[0] = flow_inlet.dotm_l dotm_g[0] = flow_inlet.dotm_g phi_g[0] = inlet_conds.phi_g v_g[0] = flow_inlet.v_g # first try if oderesults is a namedtuple; then try if it's a panda DataFrame try: D_0 = oderesults.D[0,0] except: D_0 = oderesults.D.loc[0] for k in range(1,NUM_STEPS): # first try if oderesults is a namedtuple; then try if it's a panda DataFrame try: dotm_lx = flow_inlet.dotm_l* (oderesults.D[k]/D_0)**3 except: dotm_lx = flow_inlet.dotm_l*(oderesults.D.iloc[k]/D_0)**3 dotm_gx = flow_inlet.dotm_g + flow_inlet.dotm_l - dotm_lx phi_gx = ((dotm_gx/dotm_Ox0)-1)/F_over_O gas.X = CCDroplet.phi_to_X(phi_gx,reaction_tuple) MW_gphi_g = gas.mean_molecular_weight try: v_gx = dotm_gx*ct.gas_constant*oderesults.T_g[k]/(MW_gphi_g*P*chamber_params.A_cc) except: v_gx = dotm_gx*ct.gas_constant*oderesults.T_g.iloc[k]/(MW_gphi_g*P*chamber_params.A_cc) dotm_l[k] = dotm_lx dotm_g[k] = dotm_gx phi_g[k] = phi_gx v_g[k] = v_gx flows = CCDroplet.Flow_Tuple(dotm_l=dotm_l,dotm_Ox=dotm_Ox0,dotm_g=dotm_g,v_g=v_g) return flows, phi_g