From 9c8d3800ed740c5dd8db14967cf4d8f4276cb752 Mon Sep 17 00:00:00 2001 From: Jordan Date: Fri, 17 Apr 2026 15:48:35 +0100 Subject: [PATCH 1/2] Add fast cosmo functions for photoz fitting --- R/ProSpect.R | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/R/ProSpect.R b/R/ProSpect.R index 6f90d6a..6770e55 100644 --- a/R/ProSpect.R +++ b/R/ProSpect.R @@ -593,19 +593,35 @@ ProSpectSEDlike = function(parm = c(8, 9, 10, 10, 0, -0.5, 0.2), Data) { } } - if(is.null(Data$arglist$ref)){ - agemax_new = (celestial::cosdistUniAgeAtz(ztest, H0 = Data$arglist$HO, OmegaM = Data$arglist$OmegaM, OmegaL = Data$arglist$OmegaL))*1e9 ##need to be in years - if(!is.null(z_genSF)){ - agemax_new = (celestial::cosdistUniAgeAtz(ztest, H0 = Data$arglist$HO, OmegaM = Data$arglist$OmegaM, OmegaL = Data$arglist$OmegaL) - celestial::cosdistUniAgeAtz(z_genSF, H0 = Data$arglist$HO, OmegaM = Data$arglist$OmegaM, OmegaL = Data$arglist$OmegaL))*1e9 ##need to be in years + if(is.null(Data$cosmofast)){ + if(is.null(Data$arglist$ref)){ + if(!is.null(z_genSF)){ + agemax_new = (celestial::cosdistUniAgeAtz(ztest, H0 = Data$arglist$HO, OmegaM = Data$arglist$OmegaM, OmegaL = Data$arglist$OmegaL) - + celestial::cosdistUniAgeAtz(z_genSF, H0 = Data$arglist$HO, OmegaM = Data$arglist$OmegaM, OmegaL = Data$arglist$OmegaL))*1e9 ##need to be in years + }else{ + agemax_new = (celestial::cosdistUniAgeAtz(ztest, H0 = Data$arglist$HO, OmegaM = Data$arglist$OmegaM, OmegaL = Data$arglist$OmegaL))*1e9 ##need to be in years + } + LumDist_Mpc_new = celestial::cosdistLumDist(z = ztest, H0 = Data$arglist$HO, OmegaM = Data$arglist$OmegaM, OmegaL = Data$arglist$OmegaL) + }else{ + if(!is.null(z_genSF)){ + agemax_new = (celestial::cosdistUniAgeAtz(ztest, ref = Data$arglist$ref) - + celestial::cosdistUniAgeAtz(z_genSF, ref = Data$arglist$ref))*1e9 ##need to be in years + }else{ + agemax_new = (celestial::cosdistUniAgeAtz(ztest, ref = Data$arglist$ref))*1e9 ##need to be in years + } + LumDist_Mpc_new = celestial::cosdistLumDist(z = ztest, ref = Data$arglist$ref) } - LumDist_Mpc_new = celestial::cosdistLumDist(z = ztest, H0 = Data$arglist$HO, OmegaM = Data$arglist$OmegaM, OmegaL = Data$arglist$OmegaL) - }else{ - agemax_new = (celestial::cosdistUniAgeAtz(ztest, ref = Data$arglist$ref))*1e9 ##need to be in years + }else if (is.function(Data$cosmofast$UniAgeAtz) & is.function(Data$cosmofast$LumDist)){ if(!is.null(z_genSF)){ - agemax_new = (celestial::cosdistUniAgeAtz(ztest, ref = Data$arglist$ref) - celestial::cosdistUniAgeAtz(z_genSF, ref = Data$arglist$ref))*1e9 ##need to be in years - } - LumDist_Mpc_new = celestial::cosdistLumDist(z = ztest, ref = Data$arglist$ref) + agemax_new = (cosmofast$UniAgeAtz(ztest) - cosmofast$UniAgeAtz(z_genSF))*1e9 ##need to be in years + }else{ + agemax_new = cosmofast$UniAgeAtz(ztest) + } + LumDist_Mpc_new = cosmofast$LumDist(ztest) + }else{ + stop("Wrong self-defined cosmology tables") } + magemax_new = agemax_new/1e9 ## need to be in Gyr Zagemax_new = agemax_new/1e9 From 6ecc8ceac974037c0d888752b7095b3f0984dd9d Mon Sep 17 00:00:00 2001 From: Jordan Date: Fri, 17 Apr 2026 16:18:07 +0100 Subject: [PATCH 2/2] Do fewer cosmo calculations in photoz mode --- R/ProSpect.R | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/R/ProSpect.R b/R/ProSpect.R index 6770e55..f8d2fb8 100644 --- a/R/ProSpect.R +++ b/R/ProSpect.R @@ -593,8 +593,7 @@ ProSpectSEDlike = function(parm = c(8, 9, 10, 10, 0, -0.5, 0.2), Data) { } } - if(is.null(Data$cosmofast)){ - if(is.null(Data$arglist$ref)){ + if(is.null(Data$arglist$ref)){ if(!is.null(z_genSF)){ agemax_new = (celestial::cosdistUniAgeAtz(ztest, H0 = Data$arglist$HO, OmegaM = Data$arglist$OmegaM, OmegaL = Data$arglist$OmegaL) - celestial::cosdistUniAgeAtz(z_genSF, H0 = Data$arglist$HO, OmegaM = Data$arglist$OmegaM, OmegaL = Data$arglist$OmegaL))*1e9 ##need to be in years @@ -611,18 +610,7 @@ ProSpectSEDlike = function(parm = c(8, 9, 10, 10, 0, -0.5, 0.2), Data) { } LumDist_Mpc_new = celestial::cosdistLumDist(z = ztest, ref = Data$arglist$ref) } - }else if (is.function(Data$cosmofast$UniAgeAtz) & is.function(Data$cosmofast$LumDist)){ - if(!is.null(z_genSF)){ - agemax_new = (cosmofast$UniAgeAtz(ztest) - cosmofast$UniAgeAtz(z_genSF))*1e9 ##need to be in years - }else{ - agemax_new = cosmofast$UniAgeAtz(ztest) - } - LumDist_Mpc_new = cosmofast$LumDist(ztest) - }else{ - stop("Wrong self-defined cosmology tables") - } - magemax_new = agemax_new/1e9 ## need to be in Gyr Zagemax_new = agemax_new/1e9