Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 70 additions & 43 deletions R/ProSpect.R
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,25 @@ ProSpectSEDlike = function(parm = c(8, 9, 10, 10, 0, -0.5, 0.2), Data) {

names(parm) = Data$parm.names

if (!requireNamespace("ParmOff", quietly = TRUE)) {
stop("The ParmOff package is needed for parameter mapping in ProSpectSEDlike. Please install it from GitHub/asgr/ParmOff.", call. = FALSE)
}

logged_parm_names = NULL
if (!is.null(Data$logged)) {
if(is.logical(Data$logged)){
if (length(Data$logged) == 1) {
if (Data$logged) {
logged_parm_names = Data$parm.names
}
} else {
logged_parm_names = Data$parm.names[Data$logged]
}
}else{
logged_parm_names = Data$logged
}
}

if(is.null(Data$photom) & isTRUE(Data$mode == 'photom')){
Data$photom = Data$flux
}
Expand Down Expand Up @@ -573,7 +592,7 @@ ProSpectSEDlike = function(parm = c(8, 9, 10, 10, 0, -0.5, 0.2), Data) {
z_genSF = Data$arglist$z_genSF ## What redshift should we start star formation?

ztest = parm["z"]
if(Data$logged[Data$parm.names == "z"]){
if("z" %in% logged_parm_names){
ztest = 10^ztest
}

Expand Down Expand Up @@ -622,40 +641,42 @@ ProSpectSEDlike = function(parm = c(8, 9, 10, 10, 0, -0.5, 0.2), Data) {
parm = Data$constraints(parm)
}

parm_lower = NULL
parm_upper = NULL
if (!is.null(Data$intervals)) {
#parm[parm < Data$intervals$lo] = Data$intervals$lo[parm < Data$intervals$lo]
#parm[parm > Data$intervals$hi] = Data$intervals$hi[parm > Data$intervals$hi]
parm = pmin(pmax(parm, Data$intervals$lo), Data$intervals$hi)
parm_lower = as.list(Data$intervals$lo)
parm_upper = as.list(Data$intervals$hi)
names(parm_lower) = Data$parm.names
names(parm_upper) = Data$parm.names
}

if (!is.null(Data$logged)) {
if (length(Data$logged) == 1) {
if (Data$logged) {
parmlist = 10 ^ parm
} else{
parmlist = parm
}
} else{
parmlist = parm
parmlist[Data$logged] = 10 ^ parm[Data$logged]
}
} else{
parmlist = parm
}
parmlist = ParmOff::ParmOff(
.func = ProSpectSED,
.args = parm,
.lower = parm_lower,
.upper = parm_upper,
.logged = logged_parm_names,
.return = 'args',
.check = FALSE
)$current_args

if (Data$verbose) {
message(parmlist)
if(any(lengths(parmlist) != 1L)){
stop('All fitting parameters must be scalar values.')
}

if('scat_scale' %in% Data$parm.names){
sel = which('scat_scale' == Data$parm.names)
scat_scale = parmlist[sel]
parmlist = parmlist[-sel]
Data$parm.names = Data$parm.names[-sel]
scat_scale = parmlist[['scat_scale']]
#parm = parm[-sel]
#Data$parm.names = Data$parm.names[-sel]
}else{
scat_scale = 1
}

if (Data$verbose) {
parmlist_print = unlist(parmlist, recursive = FALSE, use.names = TRUE)
message(parmlist_print)
}

Monitor = {}

if(isTRUE(Data$mode == 'spec') | isTRUE(Data$mode == 'both')){
Expand All @@ -666,20 +687,23 @@ ProSpectSEDlike = function(parm = c(8, 9, 10, 10, 0, -0.5, 0.2), Data) {
}

if (returnall) {
SEDout = do.call(
'ProSpectSED',
args = c(
SEDout = ParmOff::ParmOff(
.func = ProSpectSED,
.args = c(
parmlist,
list(SFH = quote(Data$SFH)),
list(speclib = quote(Data$speclib)),
list(Dale = quote(Data$Dale)),
list(AGN = quote(Data$AGN)),
list(filtout = quote(filtout)),
list(SFH = Data$SFH),
list(speclib = Data$speclib),
list(Dale = Data$Dale),
list(AGN = Data$AGN),
list(filtout = filtout),
list(filters = NULL),
list(returnall = TRUE),
list(Dale_M2L_func = quote(Data$Dale_M2L_func)),
list(Dale_M2L_func = Data$Dale_M2L_func),
Data$arglist
)
),
.rem_args = 'scat_scale',
.return = 'func',
.check = FALSE
)
if(is.null(Data$filtout) | isTRUE(Data$mode == 'spec') | isTRUE(Data$mode == 'both')){
#this means we are in spec-z mode
Expand Down Expand Up @@ -718,19 +742,22 @@ ProSpectSEDlike = function(parm = c(8, 9, 10, 10, 0, -0.5, 0.2), Data) {
}
} else{

Photom = do.call(
'ProSpectSED',
args = c(
Photom = ParmOff::ParmOff(
.func = ProSpectSED,
.args = c(
parmlist,
list(SFH = quote(Data$SFH)),
list(speclib = quote(Data$speclib)),
list(Dale = quote(Data$Dale)),
list(AGN = quote(Data$AGN)),
list(filtout = quote(filtout)),
list(SFH = Data$SFH),
list(speclib = Data$speclib),
list(Dale = Data$Dale),
list(AGN = Data$AGN),
list(filtout = filtout),
list(filters = NULL),
list(returnall = FALSE),
Data$arglist
)
),
.rem_args = 'scat_scale',
.return = 'func',
.check = FALSE
)

if(is.null(filtout)){
Expand Down
2 changes: 1 addition & 1 deletion man/AGNinterp.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Stalevski et al, 2016, MNRAS, 458, 2288
Aaron Robotham & Adam Marshall
}
\seealso{
\code{\link{Fritz}}, \code{\link{SKIRTOR}}
\code{\link[ProSpectData:Fritz]{Fritz}}, \code{\link[ProSpectData:SKIRTOR]{SKIRTOR}}
}
\examples{
\dontrun{
Expand Down
8 changes: 4 additions & 4 deletions man/Dale_interp.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ Numeric scalar; desired interpolated alpha slope of the star forming population.
Numeric scalar; desired interpolated AGN fraction linearly mixed in energy over the range 5-20 microns (see Dale 2014).
}
\item{type}{
Character scalar; type of Dale template to interpolate. One of: Orig, Msol, NormTot, NormAGN, NormSFR (see \code{\link{Dale}}).
Character scalar; type of Dale template to interpolate. One of: Orig, Msol, NormTot, NormAGN, NormSFR (see \code{\link[ProSpectData:Dale]{Dale}}).
}
\item{Dale}{
Pass in the Dale dust library directly. Must be one of \code{\link{Dale_Orig}}, \code{\link{Dale_Msol}}, \code{\link{Dale_NormTot}}, \code{\link{Dale_NormAGN}}, \code{\link{Dale_NormSFR}}. Doing this speeds up the compute time, since there is no need to lazy load from the package.
Pass in the Dale dust library directly. Must be one of \code{\link[ProSpectData:Dale_Orig]{Dale_Orig}}, \code{\link[ProSpectData:Dale_Msol]{Dale_Msol}}, \code{\link[ProSpectData:Dale_NormTot]{Dale_NormTot}}, \code{\link[ProSpectData:Dale_NormAGN]{Dale_NormAGN}}, \code{\link[ProSpectData:Dale_NormSFR]{Dale_NormSFR}}. Doing this speeds up the compute time, since there is no need to lazy load from the package.
}
}
\details{
This function does a simple 2D bilinear interpolation to create templates for values of \option{AGNfrac} and \option{alpha_SF} that are not precisely provided by \code{\link{Dale}}.
This function does a simple 2D bilinear interpolation to create templates for values of \option{AGNfrac} and \option{alpha_SF} that are not precisely provided by \code{\link[ProSpectData:Dale]{Dale}}.
}
\value{
Two column data.frame containing the wavelength (Wave) and the interpolated luminosity values (Aspec) in the same units as the input Dale dust library (from argument \option{Dale}).
Expand All @@ -38,7 +38,7 @@ Dale et al, 2014, ApJ, 784, 11
Aaron Robotham
}
\seealso{
\code{\link{Dale}}, \code{\link{interp_param}}
\code{\link[ProSpectData:Dale]{Dale}}, \code{\link{interp_param}}
}
\examples{
#Example output showing also the 4 surrounding interpolation points used.
Expand Down
22 changes: 11 additions & 11 deletions man/ProSpectSED.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ Numeric scalar; power to further raise the dust attenuation of the dust screen.
Numeric scalar; power to further raise the dust attenuation of the AGN torus. See \code{\link{CF_screen}}.
}
\item{alpha_SF_birth}{
Numeric scalar; alpha slope of the birth cloud dust. Lower values mean hotter dust. See \code{\link{Dale}}.
Numeric scalar; alpha slope of the birth cloud dust. Lower values mean hotter dust. See \code{\link[ProSpectData:Dale]{Dale}}.
}
\item{alpha_SF_screen}{
Numeric scalar; alpha slope of the screen dust. Lower values mean hotter dust. See \code{\link{Dale}}.
Numeric scalar; alpha slope of the screen dust. Lower values mean hotter dust. See \code{\link[ProSpectData:Dale]{Dale}}.
}
\item{alpha_SF_AGN}{
Numeric scalar; alpha slope of the AGN torus dust. Lower values mean hotter dust. See \code{\link{Dale}}.
Numeric scalar; alpha slope of the AGN torus dust. Lower values mean hotter dust. See \code{\link[ProSpectData:Dale]{Dale}}.
}
\item{AGNlum}{
Numeric scalar; AGN bolometric luminosity in erg/s for both the Fritz and SKIRTOR.
Expand All @@ -65,13 +65,13 @@ Numeric scalar; AGN bolometric luminosity in erg/s for both the Fritz and SKIRTO
Numeric scalar; amount of sparse sampling of the spectra to make.
}
\item{speclib}{
Object; optional. Pass in the spectral library directly. Must be one of \code{\link{BC03lr}}, \code{\link{BC03hr}}, \code{\link{EMILES}} or \code{\link{BPASS}}. Default of NULL will load the \code{\link{BC03lr}} library, but faster to pass it in if being used for e.g. fitting.
Object; optional. Pass in the spectral library directly. Must be one of \code{\link[ProSpectData:BC03lr]{BC03lr}}, \code{\link[ProSpectData:BC03hr]{BC03hr}}, \code{\link[ProSpectData:EMILES]{EMILES}} or \code{\link[ProSpectData:BPASS]{BPASS}}. Default of NULL will load the \code{\link[ProSpectData:BC03lr]{BC03lr}} library, but faster to pass it in if being used for e.g. fitting.
}
\item{Dale}{
Object or scalar logical; optional. Pass in the Dale dust library \code{\link{Dale_NormTot}} directly (otherwise will run, but not work correctly). Default of NULL will load the \code{\link{Dale_NormTot}} library, but faster to pass it in if being used for e.g. fitting. If FALSE it will not re-emit the attenuated light in the MIR/FIR using Dale templates. This might be desired if the range of interest is purely the UV-NIR and you want faster generation/fitting (since the re-emitted dust will not be notable until at least the MIR).
Object or scalar logical; optional. Pass in the Dale dust library \code{\link[ProSpectData:Dale_NormTot]{Dale_NormTot}} directly (otherwise will run, but not work correctly). Default of NULL will load the \code{\link[ProSpectData:Dale_NormTot]{Dale_NormTot}} library, but faster to pass it in if being used for e.g. fitting. If FALSE it will not re-emit the attenuated light in the MIR/FIR using Dale templates. This might be desired if the range of interest is purely the UV-NIR and you want faster generation/fitting (since the re-emitted dust will not be notable until at least the MIR).
}
\item{AGN}{
Object; optional. Pass in the AGN template to use. Must be one of \code{\link{AGN_UnOb}}, \code{\link{AGN_UnOb_Sparse}}, \code{\link{Fritz}}, or \code{\link{SKIRTOR}}. These objects have classes attached, when ensures the correct AGN code is executed (so users should not simply try to load their own specific AGN model).
Object; optional. Pass in the AGN template to use. Must be one of \code{\link{AGN_UnOb}}, \code{\link{AGN_UnOb_Sparse}}, \code{\link[ProSpectData:Fritz]{Fritz}}, or \code{\link[ProSpectData:SKIRTOR]{SKIRTOR}}. These objects have classes attached, when ensures the correct AGN code is executed (so users should not simply try to load their own specific AGN model).
}

\item{filtout}{
Expand All @@ -81,7 +81,7 @@ Object; required. Pass in the photometric filters directly (either matrices of f
Character vector; names of filters to use. See \code{\link{filters}} for options. Default 'all' selects all filters, 'GAMA' returns just the classic GAMA survey filters. Can also be a list of matrices or functions to pass into \code{\link{bandpass}}. This creates increasingly faster code, but requires more user effort.
}
\item{Dale_M2L_func}{
Function; if dust masses and luminosities are desired then the user should supply a function to convert \option{alpha_SF} to mass-to-light, e.g. \code{\link{Dale_M2L_func}}
Function; if dust masses and luminosities are desired then the user should supply a function to convert \option{alpha_SF} to mass-to-light, e.g. \code{\link[ProSpectData:Dale_M2L_func]{Dale_M2L_func}}
}
\item{returnall}{
Logical; if true then returns all the various sub SEDs. See Details. If FALSE then code just returns \option{photom_out} (photometry in Jansky).
Expand All @@ -99,7 +99,7 @@ Numeric scalar; Omega Lambda today (default is for a flat Universe with OmegaL =
Numeric vector; desired output log10 wavelength grid to use in Ang. Default covers typical range of galaxy SED data at a resolution good enough for broad band photometry. Spectroscopic work requires the resolution to be increase by a factor ~10. If \option{emission}=TRUE (to be passed down to \code{\link{SFHfunc}}) and \option{waveout} is missing (so not explicitly supplied by the user) then \option{waveout} is internally set to NULL, meaning the full available resolution is used to ensure a good reproduction of the emission features. This operation is generally desirable, since it would be a bad idea to produce emission features, but then sample the wavelength range too coarsely to see any!
}
\item{ref}{
The name of a reference cosmology to use, one of 137 / 737 / Planck / Planck13 / Planck15 / Planck18 / WMAP / WMAP9 / WMAP7 / WMAP5 / WMAP3 / WMAP1 / Millennium / GiggleZ. Planck = Planck18 and WMAP = WMAP9. The usage is case insensitive, so wmap9 is an allowed input. This overrides any other settings for H0, OmegaM and OmegaL. If OmegaR is missing from the reference set then it is inherited from the function input (0 by default). See \code{\link{cosref}} for details.
The name of a reference cosmology to use, one of 137 / 737 / Planck / Planck13 / Planck15 / Planck18 / WMAP / WMAP9 / WMAP7 / WMAP5 / WMAP3 / WMAP1 / Millennium / GiggleZ. Planck = Planck18 and WMAP = WMAP9. The usage is case insensitive, so wmap9 is an allowed input. This overrides any other settings for H0, OmegaM and OmegaL. If OmegaR is missing from the reference set then it is inherited from the function input (0 by default). See \code{\link[celestial:cosref]{cosref}} for details.
}
\item{unimax}{
Numeric scalar; maximum allowed age of any stellar population relative to z=0 (i.e. today) in years. Any star formation that is older than this will be set to 0. Overridden by \option{agemax} if that is provided.
Expand All @@ -111,7 +111,7 @@ Numeric scalar; maximum allowed age of any stellar population relative to the re
Numeric scalar; Luminosity distance computed in units of cm. Default is NULL. The luminosity distance can be supplied for repeated computations when the redshift of the object is constant. This should be supplied using the "correct" cosmology (as near as possible), i.e. using H0 ~ 70 km/s/Mpc (not 100).
}
\item{addradio_SF}{
Logical scalar; should free-free and synchrotron radio continuum linked to star-formation be computed and appended to the spectrum? If TRUE, emission range is controlled by \option{waveout}. Uses the \code{\link{radiocont}} function to compute and append the radio continuum (see there for details). Note that even with this set to FALSE (default) the output spectrum will still have the radio continuum computed for the \code{\link{Dale}} templates. The default arguments almost perfectly reproduce the \code{\link{Dale}} results, so it is only necessary to set \option{addradio_SF} = TRUE if you want to change the \option{Te}, \option{ff_frac}, \option{ff_power} and \option{sy_power} parameters to non-default values.
Logical scalar; should free-free and synchrotron radio continuum linked to star-formation be computed and appended to the spectrum? If TRUE, emission range is controlled by \option{waveout}. Uses the \code{\link{radiocont}} function to compute and append the radio continuum (see there for details). Note that even with this set to FALSE (default) the output spectrum will still have the radio continuum computed for the \code{\link[ProSpectData:Dale]{Dale}} templates. The default arguments almost perfectly reproduce the \code{\link[ProSpectData:Dale]{Dale}} results, so it is only necessary to set \option{addradio_SF} = TRUE if you want to change the \option{Te}, \option{ff_frac}, \option{ff_power} and \option{sy_power} parameters to non-default values.
}
\item{Te_SF}{
Numeric scalar; effective HII nebular plasma temperature in Kelvin used in \code{\link{radiocont}}. Leave as the default (10,000 K), unless you know what you are doing.
Expand All @@ -126,7 +126,7 @@ Numeric scalar; power-law slope of the free-free nebular plasma thermal radio em
Numeric scalar; power-law slope of the synchrotron radio emission associated with star-formation used in \code{\link{radiocont}} (should be between -0.8 and -0.6 typically).
}
\item{addradio_AGN}{
Logical; should separate free-free and synchrotron radio continuum associated with an AGN be added? Uses the \code{\link{radiocont}} function to compute and append the radio continuum (see there for details). If FALSE (default) then any radio continuum computed for the AGN component within \code{\link{Dale}} will be subtracted regardless of the value of \option{addradio_SF}.
Logical; should separate free-free and synchrotron radio continuum associated with an AGN be added? Uses the \code{\link{radiocont}} function to compute and append the radio continuum (see there for details). If FALSE (default) then any radio continuum computed for the AGN component within \code{\link[ProSpectData:Dale]{Dale}} will be subtracted regardless of the value of \option{addradio_SF}.
}
\item{Te_AGN}{
Numeric scalar; effective HII nebular plasma temperature in Kelvin used in \code{\link{radiocont}} for the AGN component. Leave as the default (10,000 K), unless you know what you are doing.
Expand Down Expand Up @@ -216,7 +216,7 @@ List, optional; named arguments and values that are passed directly into \code{P
There are also additional arguments for redshift fitting mode: 'photoz', Boolean, fit for redshift or not; 'IGMfunc', a function that takes in z and returns IGM absorption between 0 and 1, can also be numeric/NULL/'Inoue14', if numeric this is the same as function(z)\{const\} where const is some constant IGM absorption value, if NULL no IGM absorption, if "Songaila04" use pnorm(z,3.2,1.8), if 'Inoue14' use IGM absorption from Inoue (2014); z_genSF, numeric scalar, redshift at which stars began forming, if NULL then stars start forming at the beginning of the Universe.
}
\item{Data$speclib}{
List, optional but recommended; pass in the spectral library directly. Must be one of \code{\link{BC03lr}}, \code{\link{BC03hr}}, \code{\link{EMILES}}.
List, optional but recommended; pass in the spectral library directly. Must be one of \code{\link[ProSpectData:BC03lr]{BC03lr}}, \code{\link[ProSpectData:BC03hr]{BC03hr}}, \code{\link[ProSpectData:EMILES]{EMILES}}.
}
\item{Data$Dale}{
List, optional but recommended; pass in the Dale dust library directly (should be one of \option{Dale_NormTot}, \option{Dale_NormSFR} otherwise will run, but not work correctly). If set to FALSE then there will be no FIR re-emission.
Expand Down
Loading