def load(widget): clear_output(wait=True) pyplot.close('all') display(frame._object_list['window']) #CR data = None mass = float(frame.get_attribute("mass", "value")) Z = float(frame.get_attribute("Z", "value")) dir = frame.get_attribute("address_bar", "value") if frame.get_attribute("model_select", "value") != "": model = int(frame.get_attribute("model_select", "value")) else: model = 1 module = frame.get_attribute("select_module", "value") if module == "H5 out": if manual_data_select == 'visible': data = mp.se(dir) else: data = mp.se(mass=mass, Z=Z) frame.set_state("nugrid_w_data") properties = ["mass", "radius", "rho", "temperature"] frame.set_attributes("xaxis", options=properties+data.se.isotopes) frame.set_attributes("yaxis", options=properties+data.se.isotopes) elif module == "History": if manual_data_select == 'visible': data = ms.history_data(dir) else: data = ms.history_data(mass=mass, Z=Z) frame.set_state("mesa_w_data") frame.set_attributes("xaxis", options=sorted(data.cols.keys())) frame.set_attributes("yaxis", options=sorted(data.cols.keys())) elif module == "Profile": if manual_data_select == 'visible': data = ms.mesa_profile(dir, num=model) else: data = ms.mesa_profile(mass=mass, Z=Z, num=model) frame.set_state("mesa_w_data") frame.set_attributes("xaxis", options=sorted(data.cols.keys())) frame.set_attributes("yaxis", options=sorted(data.cols.keys())) else: nugrid_or_mesa = frame.get_attribute("select_nugrid_mesa", 'value') if nugrid_or_mesa == "NuGrid": frame.set_state("nugrid") elif nugrid_or_mesa == "Mesa": frame.set_state("mesa") frame.set_state_data("class_instance", data) frame.set_attributes("select_plot", selected_label="")
def mass_Z_handler(name, value): #if frame.get_attribute("contain_model_select", "visibility"): mass = float(frame.get_attribute("mass", "value")) Z = float(frame.get_attribute("Z", "value")) dir = frame.get_attribute("address_bar", "value") if manual_data_select == 'visible': mdir, mmodel = frame.get_state_data("model_data") if (mdir != dir) or (mmodel == None): clear_output(wait=True) pyplot.close('all') display(frame._object_list['window']) #CR pre_data = ms.mesa_profile(dir) frame.set_state_data("model_data", (dir, pre_data.model)) else: mmass, mZ, mmodel = frame.get_state_data("model_data") if (mmass != mass) or (mZ != Z) or (mmodel == None): clear_output(wait=True) pyplot.close('all') display(frame._object_list['window']) #CR pre_data = ms.mesa_profile(mass=mass, Z=Z) frame.set_state_data("model_data", (mass, Z, pre_data.model))
def change_module(widget, value): if value == "History": frame.set_state_attribute("select_plot", states_mesa[1:], options={"":"mesa_w_data", "HR-Diagram":"hrd", "Plot":"plot", "Kippenhahn":"kippenhahn", "Kippenhahn contour":"kip_cont", "TCRhoC plot":"tcrhoc", "Get data":"get_data"}) frame.set_state_attribute("contain_model_select", states_mesa, visibility='hidden') frame.set_attributes("contain_model_select", visibility='hidden') elif value == "Profile": frame.set_attributes("load_data", disabled=True) frame.set_state_attribute("select_plot", states_mesa[1:], options={"":"mesa_w_data", "Plot":"plot", "Get data":"get_data"}) mass = float(frame.get_attribute("mass", "value")) Z = float(frame.get_attribute("Z", "value")) dir = frame.get_attribute("address_bar", "value") if manual_data_select == 'visible': mdir, mmodel = frame.get_state_data("model_data") if (mdir != dir) or (mmodel == None): clear_output(wait=True) pyplot.close('all') display(frame._object_list['window']) #CR pre_data = ms.mesa_profile(dir) mmodel = pre_data.model frame.set_state_data("model_data", (dir, mmodel)) else: mmass, mZ, mmodel = frame.get_state_data("model_data") if (mmass != mass) or (mZ != Z) or (mmodel == None): clear_output(wait=True) pyplot.close('all') display(frame._object_list['window']) #CR pre_data = ms.mesa_profile(mass=mass, Z=Z) mmodel = pre_data.model frame.set_state_data("model_data", (mass, Z, mmodel)) frame.set_state_attribute("contain_model_select", states_mesa, visibility='visible') frame.set_attributes("contain_model_select", visibility='visible') frame.set_attributes("model_select", value=str(mmodel[-1])) frame.set_attributes("load_data", disabled=False) else: frame.set_state_attribute("contain_model_select", states_mesa, visibility='hidden') frame.set_attributes("contain_model_select", visibility='hidden')
def get_prof_data(data_dir,model): ''' This function returns the mesa profile data needed for a ppm setup. It must and only returns what is needed in the order specified. usage : log_conv_vel, radius_mesa, P_mesa, T_mesa, entropy_mesa, rho_mesa, mass_mesa, mu_mesa ,\ pgas_div_ptotal = ps.get_prof_data(ddir,model) ''' mprof=ms.mesa_profile(data_dir,num=model) print("returning log_conv_vel, radius_mesa, P_mesa, T_mesa, entropy_mesa, rho_mesa, mass_mesa, mu_mesa and pgas_div_ptotal") log_conv_vel=mprof.get('log_conv_vel') radius_mesa = mprof.get('radius') P_mesa = mprof.get('pressure') T_mesa = mprof.get('temperature') entropy_mesa = mprof.get('entropy') rho_mesa = 10**mprof.get('logRho') mass_mesa = mprof.get('mass') mu_mesa = mprof.get('mu') pgas_div_ptotal = mprof.get('pgas_div_ptotal') return(log_conv_vel, radius_mesa, P_mesa, T_mesa, entropy_mesa, rho_mesa, mass_mesa, mu_mesa , pgas_div_ptotal)
def UnitConvert(datadir, quantity, convertto='PPMUnits', fromtype='mesaprof', modordump=1, filename=None): ''' Converts from units used in MESA(cgs and solar) to PPMStar code units and vice versa. datadir, str: path to mesa profile or rprofile to be read quantity, str : which quantity you want to convert. Options are density, radius, mass, pressure, temperature convertto, str: the unit system to convert to, default is PPMUnits but can choose MESAUnits. fromtype, str: what kind of data are you giving? Options are mesaprof, rprof or ppmsetup modndump, int : model number for mesa profile read if going fro mesa to ppm and ppm dump number if going from ppm to mesa. filename, str: default None, only needed if you are converting from type ppmsetup because ascii_table requires a dir and filename out: array in units converted to ''' to_cgs = {'density': 10**3, 'pressure': 10**19, 'temperature': 10**9, 'radius': 1.0 / 695.99} error_msg_quantity = "[%s] Quantity not recognized '%s'." % (convertto, quantity) error_msg_convertto = "Unrecognized unit system '%s'." % convertto if convertto == 'PPMUnits' and fromtype == 'mesaprof': m = ms.mesa_profile(datadir, modordump) if quantity == 'density': inarray = 10**m.get('logRho') print("Converting from g/cm**3 to kg/cm**3") elif quantity == 'pressure': inarray = m.get('pressure') print("Converting from barye to 10**19 barye") elif quantity == 'temperature': print("Converting from K to 10**9 K") inarray = m.get('temperature') elif quantity == 'radius': print("Converting from R_sun to Mm") inarray = m.get('radius') else: raise NotImplementedError(error_msg_quantity) return(inarray / to_cgs[quantity]) elif convertto == 'MESAUnits' and fromtype == 'rprof' : l = ppm.RprofSet(datadir) if quantity == 'density': inarray = l.get('Rho0',fname=modordump, num_type='NDump', resolution='h')[::2]\ +l.get('Rho1',fname=modordump, num_type='NDump', resolution='h')[::2] print("Converting from kg/cm**3 to g/cm**3") elif quantity == 'pressure': print("Converting from 10**19 barye to barye") inarray = l.get('P0',fname=modordump, num_type='NDump', resolution='h')[::2]\ +l.get('P1',fname=modordump, num_type='NDump', resolution='h')[::2] elif quantity == 'temperature': print("Converting from 10**9 K to K") inarray = l.get('T9', fname=modordump, num_type='NDump', resolution='l') elif quantity == 'radius': print("Converting from Mm to R_sun") inarray = l.get('R', fname=modordump, num_type='NDump', resolution='l') else: raise NotImplementedError(error_msg_quantity) return(inarray * to_cgs[quantity]) elif convertto == 'MESAUnits' and fromtype == 'ppmsetup': data = ascii_table(sldir=datadir, filename=filename) if quantity == 'density': inarray = data.get('rho') print("Converting from kg/cm**3 to g/cm**3") elif quantity == 'pressure': print("Converting from 10**19 barye to barye") inarray = data.get('P') elif quantity == 'temperature': print("Converting from 10**9 K to K") inarray = data.get('T') elif quantity == 'radius': print("Converting from Mm to R_sun") inarray = data.get('radius') else: raise NotImplementedError(error_msg_quantity) return(inarray * to_cgs[quantity]) else: raise NotImplementedError(error_msg_convertto)