def eval_baryon_density(self, p): if isinstance(p, list) or isinstance(p, np.ndarray): rho = np.zeros(len(p)) for i, pres in enumerate(p): rho [i] = lalsim.SimNeutronStarEOSRestMassDensityOfPseudoEnthalpy( lalsim.SimNeutronStarEOSPseudoEnthalpyOfPressure(pres,self.eos), self.eos) else: rho = lalsim.SimNeutronStarEOSRestMassDensityOfPseudoEnthalpy( lalsim.SimNeutronStarEOSPseudoEnthalpyOfPressure(p,self.eos), self.eos) return rho
def pressure_density_on_grid(self, logrho_grid, reference_pair=None, enforce_causal=False): """ pressure_density_on_grid. Input and output grid units are in SI (rho: kg/m^3; p = N/m^2) POTENTIAL PROBLEMS OF USING LALSUITE - lalinference_o2 / master: Unless patched, the *rest mass* density is not reliable. To test with the unpatched LI version, use reference_pair to specify a low-density EOS. This matching is highly suboptimal, so preferably test either (a) a patched code or (b) the alternative code below """ dat_out = np.zeros(len(logrho_grid)) fam = self.eos_fam eos = self.eos npts_internal = 10000 p_internal = np.zeros(npts_internal) rho_internal = np.zeros(npts_internal) hmax = lalsim.SimNeutronStarEOSMaxPseudoEnthalpy(eos) if enforce_causal: # strip out everything except the causal part. hmax = lalsim.SimNeutronStarEOSMinAcausalPseudoEnthalpy(eos) h = np.linspace(0.0001, hmax, npts_internal) for indx in np.arange(npts_internal): rho_internal[ indx] = lalsim.SimNeutronStarEOSRestMassDensityOfPseudoEnthalpy( h[indx], eos) # SI. Multiply by 10^(-3) to get CGS p_internal[ indx] = lalsim.SimNeutronStarEOSPressureOfPseudoEnthalpy( h[indx], eos) # SI. Multiply by 10 to get CGS if not (reference_pair is None): indx_match = np.argmin( np.abs(np.log10(p_internal) - np.log10(reference_pair[1])) ) # force agreement of densities at target pressure, if requested! Addresses bug /ambiguity in scaling of rest mass estimate; intend to apply in highly nonrelativistic regime delta_rho = np.log10(reference_pair[0]) - np.log10( rho_internal[indx_match]) rho_internal *= np.power(10, delta_rho) # print np.log10(np.c_[rho_internal,p_internal]) logp_of_logrho = interp.interp1d( np.log10(rho_internal), np.log10(p_internal), kind='linear', bounds_error=False, fill_value=np.inf) # should change to Monica's spline # print logrho_grid, return logp_of_logrho(logrho_grid)
logp1[i] - 1, gamma1[i], gamma2[i], gamma3[i]) if model == 'spectral': eos = lalsim.SimNeutronStarEOSSpectralDecomposition_for_plot( sd_gamma0[i], sd_gamma1[i], sd_gamma2[i], sd_gamma3[i], spec_size) assert eos is not None fam = lalsim.CreateSimNeutronStarFamily(eos) h = np.linspace(0.0001, lalsim.SimNeutronStarEOSMaxPseudoEnthalpy(eos), 10000) rho = [] p = [] # Populates p(h) and rho(h) arrays given your enthalpy array for k in range(len(h)): # With CGS conversions rho.append( lalsim.SimNeutronStarEOSRestMassDensityOfPseudoEnthalpy( h[k], eos) * .001) #print h[k], "here 1" p.append( lalsim.SimNeutronStarEOSPressureOfPseudoEnthalpy(h[k], eos) * 10) #print h[k], "here 2" # Creates a callable function for logp(logrho) logp_of_logrho = interp.interp1d(np.log10(rho), np.log10(p), kind='linear') # Loop over density (rho) bins for j in range(len(logr)): if logr[j] <= max(np.log10(rho)): logp["%g" % logr[j]].append(logp_of_logrho(logr[j])) #else: # logp["%g"%logr[j]].append(None)