def load_model(**extras):

    # set tage_max, fix redshift
    n = [p['name'] for p in model_params]
    zred = model_params[n.index('zred')]['init']
    tuniv = WMAP9.age(zred).value
    model_params[n.index('tage')]['prior'].update(maxi=tuniv)

    return sedmodel.SedModel(model_params)
Exemplo n.º 2
0
def load_model(zred=0.0, add_neb=True, **extras):
    """Instantiate and return a ProspectorParams model subclass.
    
    :param zred: (optional, default: 0.1)
        The redshift of the model
        
    :param add_neb: (optional, default: False)
        If True, turn on nebular emission and add relevant parameters to the
        model.
    """

    # --- Get a basic delay-tau SFH parameter set. ---
    # This has 5 free parameters:
    #   "mass", "logzsol", "dust2", "tage", "tau"
    # And two fixed parameters
    #   "zred"=0.1, "sfh"=4
    # See the python-FSPS documentation for details about most of these
    # parameters.  Also, look at `TemplateLibrary.describe("parameteric")` to
    # view the parameters, their initial values, and the priors in detail
    from prospect.models.templates import TemplateLibrary
    model_params = TemplateLibrary["parametric_sfh"]

    # --- Adjust the basic model ----
    # Add burst parameters (fixed to zero be default)
    model_params.update(TemplateLibrary["burst_sfh"])
    # Add dust emission parameters (fixed)
    model_params.update(TemplateLibrary["dust_emission"])
    # Add nebular emission parameters and turn nebular emission on
    if add_neb:
        model_params.update(TemplateLibrary["nebular"])

    # --- Set dispersions for emcee ---
    model_params["mass"]["init_disp"] = 1e8
    model_params["mass"]["disp_floor"] = 1e7

    # --- Complexify dust attenuation ---
    # Switch to Kriek and Conroy 2013
    model_params["dust_type"] = {
        'N': 1,
        'isfree': False,
        'init': 4,
        'prior': None
    }
    # Slope of the attenuation curve, expressed as the index of the power-law
    # that modifies the base Kriek & Conroy/Calzetti shape.
    # I.e. a value of zero is basically calzetti with a 2175AA bump
    model_params["dust_index"] = {
        'N': 1,
        'isfree': False,
        'init': 0.0,
        'prior': None
    }

    # --- Set initial values ---
    model_params["zred"]["init"] = zred

    return sedmodel.SedModel(model_params)
Exemplo n.º 3
0
def build_model(**kwargs):

    n = [p['name'] for p in model_params]
    model_params[n.index('massmet')]['prior'] = MassMet(z_mini=-1.6,
                                                        z_maxi=0.19,
                                                        mass_mini=7.5,
                                                        mass_maxi=13)
    # Now instantiate the model using this new dictionary of parameter specifications
    model = sedmodel.SedModel(model_params)

    return model
def load_model(zred=0.0, **extras):
    # In principle (and we've done it) you could have the model depend on
    # command line arguments (or anything in run_params) by making changes to
    # `model_params` here before instantiation the SedModel object.  Up to you.

    # Here we are going to set the intial value (and the only value, since it
    # is not a free parameter) of the redshift parameter to whatever was used
    # to generate the mock, listed in the run_params dictionary.
    pn = [p['name'] for p in model_params]
    zind = pn.index('zred')
    model_params[zind]['init'] = zred

    return sedmodel.SedModel(model_params)
Exemplo n.º 5
0
def build_model(**kwargs):

    from prospect.models.templates import TemplateLibrary
    from prospect.models import priors, sedmodel

    model_params = TemplateLibrary["parametric_sfh"]
    model_params.update(TemplateLibrary["dust_emission"])

    #fixed delayed-tau SFH
    model_params['tau']['isfree'] = False
    model_params['tau']['init'] = 1.0
    model_params['sf_start'] = {
        "N": 1,
        "isfree": False,
        "init": 1.0,
        "units": "start of SF, Gyr"
    }
    model_params["lumdist"] = {
        "N": 1,
        "isfree": False,
        "init": 1.0e-5,
        "units": "Mpc"
    }
    model_params['tage']['prior'] = priors.TopHat(mini=1.0, maxi=10.0)
    model_params['tage']['init'] = 5.0
    model_params['mass']['prior'] = priors.TopHat(mini=1e7, maxi=1e13)
    model_params['logzsol']['init'] = 0.2
    model_params['logzsol']['isfree'] = True
    model_params['logzsol']['prior'] = priors.ClippedNormal(mini=-1.5,
                                                            maxi=0.5,
                                                            mean=0.0,
                                                            sigma=0.3)

    #dust emission
    model_params['duste_gamma']['init'] = 0.01
    model_params['duste_qpah']['init'] = 3.5
    model_params['duste_umin']['init'] = 1.0
    model_params = model_library(model_params, int(sys.argv[1]), False)

    model = sedmodel.SedModel(model_params)

    return model
Exemplo n.º 6
0
def build_model(**kwargs):
    n = [p['name'] for p in model_params]
    tuniv = 13.8
    nbins = 10
    tbinmax = (tuniv * 0.85) * 1e9
    lim1, lim2 = 8.0, 8.52  #100 Myr and 330 Myr
    agelims = [0, lim1] + np.linspace(
        lim2, np.log10(tbinmax), nbins - 2).tolist() + [np.log10(tuniv * 1e9)]
    agebins = np.array([agelims[:-1], agelims[1:]])

    ncomp = len(agelims) - 1
    # constant SFR
    zinit = np.array([(i - 1) / float(i) for i in range(ncomp, 1, -1)])

    # Set up the prior in `z` variables that corresponds to a dirichlet in sfr
    # fraction.  THIS IS IMPORTANT
    alpha = np.arange(ncomp - 1, 0, -1)
    zprior = priors.Beta(alpha=alpha,
                         beta=np.ones_like(alpha),
                         mini=0.0,
                         maxi=1.0)

    model_params[n.index('mass')]['N'] = ncomp
    model_params[n.index('agebins')]['N'] = ncomp
    model_params[n.index('agebins')]['init'] = agebins.T
    model_params[n.index('z_fraction')]['N'] = len(zinit)
    model_params[n.index('z_fraction')]['init'] = zinit
    model_params[n.index('z_fraction')]['prior'] = zprior

    model_params[n.index('massmet')]['prior'] = MassMet(z_mini=-1.6,
                                                        z_maxi=0.19,
                                                        mass_mini=7.5,
                                                        mass_maxi=13)
    # Now instantiate the model using this new dictionary of parameter specifications
    model = sedmodel.SedModel(model_params)

    return model
Exemplo n.º 7
0
def build_model(object_redshift=0.0,
                fixed_metallicity=None,
                add_duste=False,
                add_neb=False,
                luminosity_distance=0.0,
                **extras):
    """Construct a model.  This method defines a number of parameter
    specification dictionaries and uses them to initialize a
    `models.sedmodel.SedModel` object.

    :param object_redshift:
        If given, given the model redshift to this value.

    :param add_dust: (optional, default: False)
        Switch to add (fixed) parameters relevant for dust emission.

    :param add_neb: (optional, default: False)
        Switch to add (fixed) parameters relevant for nebular emission, and
        turn nebular emission on.

    :param luminosity_distance: (optional)
        If present, add a `"lumdist"` parameter to the model, and set it's
        value (in Mpc) to this.  This allows one to decouple redshift from
        distance, and fit, e.g., absolute magnitudes (by setting
        luminosity_distance to 1e-5 (10pc))
    """
    from prospect.models.templates import TemplateLibrary
    from prospect.models import priors, sedmodel

    # --- Get a basic delay-tau SFH parameter set. ---
    # This has 5 free parameters:
    #   "mass", "logzsol", "dust2", "tage", "tau"
    # And two fixed parameters
    #   "zred"=0.1, "sfh"=4
    # See the python-FSPS documentation for details about most of these
    # parameters.  Also, look at `TemplateLibrary.describe("parametric_sfh")` to
    # view the parameters, their initial values, and the priors in detail.
    model_params = TemplateLibrary["parametric_sfh"]

    # Add lumdist parameter.  If this is not added then the distance is
    # controlled by the "zred" parameter and a WMAP9 cosmology.
    if luminosity_distance > 0:
        model_params["lumdist"] = {
            "N": 1,
            "isfree": False,
            "init": luminosity_distance,
            "units": "Mpc"
        }

    # Adjust model initial values (only important for optimization or emcee)
    model_params["dust2"]["init"] = 0.1
    model_params["logzsol"]["init"] = -0.3
    model_params["tage"]["init"] = 13.
    model_params["mass"]["init"] = 1e8

    # If we are going to be using emcee, it is useful to provide an
    # initial scale for the cloud of walkers (the default is 0.1)
    # For dynesty these can be skipped
    model_params["mass"]["init_disp"] = 1e7
    model_params["tau"]["init_disp"] = 3.0
    model_params["tage"]["init_disp"] = 5.0
    model_params["tage"]["disp_floor"] = 2.0
    model_params["dust2"]["disp_floor"] = 0.1

    # adjust priors
    model_params["dust2"]["prior"] = priors.TopHat(mini=0.0, maxi=2.0)
    model_params["tau"]["prior"] = priors.LogUniform(mini=1e-1, maxi=10)
    model_params["mass"]["prior"] = priors.LogUniform(mini=1e6, maxi=1e10)

    # Change the model parameter specifications based on some keyword arguments
    if fixed_metallicity is not None:
        # make it a fixed parameter
        model_params["logzsol"]["isfree"] = False
        #And use value supplied by fixed_metallicity keyword
        model_params["logzsol"]['init'] = fixed_metallicity

    if object_redshift != 0.0:
        # make sure zred is fixed
        model_params["zred"]['isfree'] = False
        # And set the value to the object_redshift keyword
        model_params["zred"]['init'] = object_redshift

    if add_duste:
        # Add dust emission (with fixed dust SED parameters)
        model_params.update(TemplateLibrary["dust_emission"])

    if add_neb:
        # Add nebular emission (with fixed parameters)
        model_params.update(TemplateLibrary["nebular"])

    # Now instantiate the model using this new dictionary of parameter specifications
    model = sedmodel.SedModel(model_params)

    return model
Exemplo n.º 8
0
def build_model(object_redshift=0.0,
                fixed_metallicity=None,
                add_duste=False,
                add_neb=False,
                luminosity_distance=0.0,
                **extras):

    no_dust = False  # if True, get rid of all dust related parameters

    # set dust model type by hand
    dust_type = 0
    """Construct a model.  This method defines a number of parameter
    specification dictionaries and uses them to initialize a
    `models.sedmodel.SedModel` object.

    :param object_redshift:
        If given, given the model redshift to this value.

    :param add_dust: (optional, default: False)
        Switch to add (fixed) parameters relevant for dust emission.

    :param add_neb: (optional, default: False)
        Switch to add (fixed) parameters relevant for nebular emission, and
        turn nebular emission on.

    :param luminosity_distance: (optional)
        If present, add a `"lumdist"` parameter to the model, and set it's
        value (in Mpc) to this.  This allows one to decouple redshift from
        distance, and fit, e.g., absolute magnitudes (by setting
        luminosity_distance to 1e-5 (10pc))
    """

    # ----------------------------------------------------------- #
    # get dust model from config file

    # HAVING THIS MAKES THE MODEL NONETYPE
    # store config.txt inputs as dictionary
    #new_dict = {}
    #with open(args.path+"/config.txt") as config_file:
    #  for line in config_file:
    #    (key, val) = line.split()
    #    new_dict[key] = val
    #config_file.close()
    #
    #for name, value in new_dict.items():
    #  split_name = name.split('/')
    #
    #  if split_name[0] == 'dust_model':
    #    config_dust_model = int(value)
    #    print('dust_model from config file:', config_dust_model)

    # ----------------------------------------------------------- #

    from prospect.models.templates import TemplateLibrary
    from prospect.models import priors, sedmodel

    # --- Get a basic delay-tau SFH parameter set. ---
    # This has 5 free parameters:
    #   "mass", "logzsol", "dust2", "tage", "tau"
    # And two fixed parameters
    #   "zred"=0.1, "sfh"=4
    # See the python-FSPS documentation for details about most of these
    # parameters.  Also, look at `TemplateLibrary.describe("parametric_sfh")` to
    # view the parameters, their initial values, and the priors in detail.

    model_params = TemplateLibrary["parametric_sfh"]
    print('redshift is ', object_redshift)
    model_params["zred"]['init'] = object_redshift
    #print('template dust type:', model_params["dust_type"]['init'])

    # set dust type based on value set above
    model_params["dust_type"]['init'] = dust_type

    # set dust type to Chabrier (to match SKIRT)
    model_params["imf_type"]['init'] = 1

    #model_params["dust_type"] = {"N": 1, "isfree": False, "init": config_dust_model}
    #model_params["zred"] = {"N": 1, "isfree": False, "init": object_redshift}
    #print('dust type set by config file:', model_params["dust_type"]['init'])
    #print('redshift is ', model_params["zred"]['init'])

    # Add lumdist parameter.  If this is not added then the distance is
    # controlled by the "zred" parameter and a WMAP9 cosmology.
    if luminosity_distance > 0:
        print('applying luminosity distance', luminosity_distance)
        model_params["lumdist"] = {
            "N": 1,
            "isfree": False,
            "init": luminosity_distance,
            "units": "Mpc"
        }

    # mass logzsol dust2 tage tau duste_umin duste_qpah duste_gamma

    # Adjust model initial values (only important for optimization or emcee)
    model_params["mass"]["init"] = 1e11
    model_params["logzsol"]["init"] = -1
    model_params["dust2"]["init"] = 5
    model_params["tage"]["init"] = 11
    model_params["tau"]["init"] = 25

    # If we are going to be using emcee, it is useful to provide an
    # initial scale for the cloud of walkers (the default is 0.1 times initial value)
    # For dynesty these can be skipped
    model_params["mass"]["init_disp"] = 1e10
    model_params["logzsol"]["init_disp"] = 0.5
    model_params["dust2"]["init_disp"] = 2.5
    model_params["tage"]["init_disp"] = 2
    model_params["tau"]["init_disp"] = 12.5

    # adjust priors
    model_params["mass"]["prior"] = priors.LogUniform(mini=1e8, maxi=1e13)
    model_params["dust2"]["prior"] = priors.TopHat(mini=0.0, maxi=10.0)
    model_params["logzsol"]["prior"] = priors.TopHat(mini=-2.0, maxi=0.5)
    model_params["tage"]["prior"] = priors.LogUniform(mini=9, maxi=14)
    model_params["tau"]["prior"] = priors.LogUniform(mini=1e-1,
                                                     maxi=50)  # can go to 100

    if no_dust:
        print('getting rid of all dust parameters')
        model_params["dust2"]["init"] = 0
        model_params["dust2"]["isfree"] = False
    else:
        print('applying dust parameters')
        if add_duste:
            # Add dust emission (with fixed dust SED parameters)
            print('adding dust emission')
            model_params.update(TemplateLibrary["dust_emission"])
            model_params["duste_umin"]["isfree"] = True
            model_params["duste_qpah"]["isfree"] = True
            model_params["duste_gamma"]["isfree"] = True

            model_params["duste_umin"]["prior"] = priors.TopHat(mini=0.1,
                                                                maxi=25.0)
            model_params["duste_qpah"]["prior"] = priors.TopHat(mini=0.0,
                                                                maxi=10.0)
            model_params["duste_gamma"]["prior"] = priors.TopHat(mini=0.0,
                                                                 maxi=1.0)

            model_params["duste_umin"]['init'] = 12.5
            model_params["duste_qpah"]['init'] = 5
            model_params["duste_gamma"]['init'] = 0.5

            model_params["duste_umin"]['init_disp'] = 6.25
            model_params["duste_qpah"]['init_disp'] = 2.5
            model_params["duste_gamma"]['init_disp'] = 0.25

            #model_params["duste_qpah"]["init"] = 9.0282 # calculated from https://skirt.ugent.be/skirt9/class_draine_li_dust_mix.html#a397683515561f08b8aae8f6107900337 under detailed description Mdust/MH values

        # ------------- DUST MODELS -------------- #

        # Set dust type from config file
        #model_params["dust_type"]['init'] = config_dust_model
        print('dust type set by config file:',
              model_params["dust_type"]['init'])

        # power law with index dust index set by dust_index
        if model_params["dust_type"]['init'] == 0:

            print('in the dust_type=0 if statement')

            model_params["dust1"] = {
                "N": 1,
                "isfree": True,
                "init": 0.0,
                "units": "optical depth for young population"
            }
            model_params["dust1"]["prior"] = priors.TopHat(mini=0.0, maxi=10.0)

            model_params["dust_index"] = {
                "N": 1,
                "isfree": True,
                "init": -0.7,
                "units": "Power law index of the attenuation curve"
            }
            model_params["dust_index"]["prior"] = priors.TopHat(
                mini=-5, maxi=5)  # just guessing the range

            model_params["dust1_index"] = {
                "N": 1,
                "isfree": True,
                "init": -1,
                "units":
                "Power law index of the attenuation curve for young stars"
            }
            model_params["dust1_index"]["prior"] = priors.TopHat(
                mini=-5, maxi=5)  # just guessing the range

        # Milky Way extinction law (with the R=AV/E(B−V) value given by mwr) parameterized by Cardelli et al. (1989), with variable UV bump strength
        if model_params["dust_type"]['init'] == 1:

            print('in the dust_type=1 if statement')

            model_params["dust1"] = {
                "N": 1,
                "isfree": True,
                "init": 0.0,
                "units": "optical depth for young population"
            }
            model_params["dust1"]["prior"] = priors.TopHat(mini=0.0, maxi=10.0)

            # mwr: The ratio of total to selective absorption which characterizes the MW extinction curve: R=AV/E(B−V)
            model_params["mwr"] = {"N": 1, "isfree": True, "init": 3.1}
            model_params["mwr"]["prior"] = priors.TopHat(mini=0.1, maxi=10.0)

            # uvb: Parameter characterizing the strength of the 2175A extinction feature with respect to the standard Cardelli et al. determination for the MW.
            model_params["uvb"] = {"N": 1, "isfree": True, "init": 1}
            model_params["uvb"]["prior"] = priors.TopHat(mini=0.1, maxi=10.0)

        # Calzetti et al. (2000) attenuation curve. Note that if this value is set then the dust attenuation is applied to all starlight equally (not split by age), and therefore the only relevant parameter is dust2, which sets the overall normalization
        if model_params["dust_type"]['init'] == 2:
            print('in the dust_type=2 if statement')

        # allows the user to access a variety of attenuation curve models from Witt & Gordon (2000) using the parameters wgp1 and wgp2. In this case the parameters dust1 and dust2 have no effect because the WG00 models specify the full attenuation curve.
        if model_params["dust_type"]['init'] == 3:
            print('in the dust_type=3 if statement')
            model_params["dust2"]["isfree"] = False

            # wgp1: Integer specifying the optical depth in the Witt & Gordon (2000) models
            model_params["wgp1"] = {"N": 1, "isfree": True, "init": 1}
            model_params["wgp1"]["prior"] = priors.TopHat(mini=1, maxi=18)

            # wgp2: Integer specifying the type of large-scale geometry and extinction curve
            model_params["wgp2"] = {"N": 1, "isfree": True, "init": 1}
            model_params["wgp2"]["prior"] = priors.TopHat(mini=1, maxi=6)

        # Kriek & Conroy (2013) attenuation curve. In this model the slope of the curve, set by the parameter dust_index, is linked to the strength of the UV bump
        if model_params["dust_type"]['init'] == 4:
            print('in the dust_type=4 if statement')

            # dust_index: Power law index of the attenuation curve.
            model_params["dust_index"] = {"N": 1, "isfree": True, "init": -0.7}
            model_params["dust_index"]["prior"] = priors.TopHat(mini=-5,
                                                                maxi=5)

        # ---------------------------------------- #

    # Change the model parameter specifications based on some keyword arguments
    if fixed_metallicity is not None:
        # make it a fixed parameter
        print('fixing metallicity')
        model_params["logzsol"]["isfree"] = False
        #And use value supplied by fixed_metallicity keyword
        model_params["logzsol"]['init'] = fixed_metallicity

    if object_redshift != 0.0:
        print('applying redshift')
        # make sure zred is fixed
        model_params["zred"]['isfree'] = False
        # And set the value to the object_redshift keyword
        model_params["zred"]['init'] = object_redshift

    if add_neb:
        # Add nebular emission (with fixed parameters)
        print('adding nebular emission')
        model_params.update(TemplateLibrary["nebular"])

    # Now instantiate the model using this new dictionary of parameter specifications
    model = sedmodel.SedModel(model_params)

    return model
Exemplo n.º 9
0
def load_model(**extras):
    # In principle (and we've done it) you could have the model depend on
    # command line arguments (or anything in run_params) by making changes to
    # `model_params` here before instantiation the SedModel object.  Up to you.
    return sedmodel.SedModel(model_params)
Exemplo n.º 10
0
def load_model(objname, field, agelims=[], **extras):
    # REDSHIFT
    # open file, load data

    photname, zname, fname, filtername, filts = get_names(field)

    with open(photname, 'r') as f:
        hdr = f.readline().split()
    dtype = np.dtype([(hdr[1], 'S20')] + [(n, np.float) for n in hdr[2:]])
    dat = np.loadtxt(photname, comments='#', delimiter=' ', dtype=dtype)

    with open(zname, 'r') as fz:
        hdr_z = fz.readline().split()
    dtype_z = np.dtype([(hdr_z[1], 'S20')] + [(n, np.float)
                                              for n in hdr_z[2:]])
    zout = np.loadtxt(zname, comments='#', delimiter=' ', dtype=dtype_z)

    with open(fname, 'r') as f:
        hdr = f.readline().split()
    # fdtype = np.dtype([(hdr[1], 'S20')] + [(n, np.float) for n in hdr[2:]])
    fast = np.loadtxt(fname, comments='#', delimiter=' ')  # , dtype=dtype)

    idx = dat[
        'id'] == objname  # creates array of True/False: True when dat[id] = objname
    zred = zout['z_spec'][idx][0]  # use z_spec
    if zred == -99:  # if z_spec doesn't exist
        zred = zout['z_peak'][idx][0]  # use z_phot

    print(zred, 'zred')

    # CALCULATE AGE OF THE UNIVERSE (TUNIV) AT REDSHIFT ZRED
    tuniv = WMAP9.age(zred).value
    print(tuniv, 'tuniv')

    n = [p['name'] for p in model_params]
    # model_params[n.index('tage')]['prior_args']['maxi'] = tuniv
    '''
    # NONPARAMETRIC SFH  # NEW
    agelims = [0.0, 8.0, 8.7, 9.0, (9.0 + (np.log10(tuniv*1e9) - 9.0)/3), (9.0 + 2 * (np.log10(tuniv*1e9) - 9.0)/3),
               np.log10(tuniv*1e9)]
    ncomp = len(agelims) - 1
    agebins = np.array([agelims[:-1], agelims[1:]])  # why agelims[1:] instead of agelims[0:]?
    '''
    # INSERT REDSHIFT INTO MODEL PARAMETER DICTIONARY
    zind = n.index('zred')
    model_params[zind]['init'] = zred

    # SET UP AGEBINS
    #model_params[n.index('agebins')]['N'] = ncomp
    #model_params[n.index('agebins')]['init'] = agebins.T

    # INIT SFH
    logtau = fast[int(objname) - 1][2] / 1e9  # 10 ** 7.80 / 1e9  #
    tage = 10**fast[int(objname) - 1][4] / 1e9  # 10 ** 8.40 / 1e9  #
    logmass = fast[int(objname) - 1][6]  # 11.23  #
    dust2 = fast[int(objname) - 1][5] / 1.086  # 1.70 / 1.086  #
    '''
    logtau = np.log10(10**fast['ltau'][idx][0]/1e9)
    tage = 10**fast['lage'][idx][0]/1e9
    logmass = fast['lmass'][idx][0]
    dust2 = fast['Av'][idx][0]/1.086
    '''
    model_params[n.index('logtau')]['init'] = logtau
    model_params[n.index('tage')]['init'] = tage
    model_params[n.index('logmass')]['init'] = logmass
    model_params[n.index('dust2')]['init'] = dust2
    model_params[n.index('tage')]['prior_args'].update(maxi=tuniv)
    '''
    # FRACTIONAL MASS INITIALIZATION  # NEW
    # N-1 bins, last is set by x = 1 - np.sum(sfr_fraction)
    model_params[n.index('sfr_fraction')]['N'] = ncomp-1
    model_params[n.index('sfr_fraction')]['prior_args'] = {
                                                           'maxi': np.full(ncomp-1, 1.0),
                                                           'mini': np.full(ncomp-1, 0.0),
                                                           # NOTE: ncomp instead of ncomp-1 makes the prior take into
                                                           # account the implicit Nth variable too
                                                          }
    model_params[n.index('sfr_fraction')]['init'] = np.zeros(ncomp-1)+1./ncomp
    model_params[n.index('sfr_fraction')]['init_disp'] = 0.02
    '''
    # CREATE MODEL
    model = sedmodel.SedModel(model_params)  # BurstyModel(model_params)

    return model
Exemplo n.º 11
0
def load_model(zred=0.1, seed=None):
    """Initialize the priors on each free and fixed parameter.
    TBD: Do we need to define priors on dust, fburst, etc., etc.???
    Args:
      zred (float): input (fixed) galaxy redshift.
      mass (float): initial stellar mass (Msun)
      logzsol (float): initial metallicity
      tage (float): initial age (Gyr)
      tau (float): initial SFH timescale (Gyr)
      dust2 (float): initial diffuse dust attenuation (dimensionless optical depth)
    Returns:
      sed (prospect.models.sedmodel.SedModel): SED priors and other stuff.
    Notes:
#FSPS is Flexible Stellar Population systhesis or Something.
      FSPS parameters are documented here:
        http://dan.iel.fm/python-fsps/current/stellarpop_api/#api-reference
      Initialization parameters:
        * compute_vega_mags (must be set at initialization)
        * vactoair_flag (must be set at initialization)
        * zcontinuous (must be set at initialization)
# MESS WITH THESE:     
      Metallicity parameters:
        * zmet (default 1, ignored if zcontinuous>0)
        * logzsol (default 0.0, used if zcontinuous>0)
        * pmetals (default 2.0, only used if zcontinuous=2)
      Dust parameters:
        * add_agb_dust_model (default True)
        * add_dust_emission (default True)
        * cloudy_dust (default False)
        * agb_dust (default 1.0)
        * dust_type (default 0=power law)
        * dust_index, dust1_index
        * dust_tesc
        * dust1 (default 0.0) - extra optical depth towards young stars at 5500A
        * dust2 (default 0.0) - diffuse dust optical depth towards all stars at 5500A
        * dust_clumps, frac_nodust, frac_obrun
        * mwr, uvb, wgp1, wgp2, wgp3, 
        * duste_gamma, duste_umin, duste_qpah
      Star formation history parameters:
        * sfh (default 0=SSP, 1=tau, 4=delayed, 5=truncated delayed tau)
        * tau (default 1)
        * const, sf_start, sf_trunc
        * tage (default 0.0)
        * fburst, tburst, sf_slope
    
      Miscellaneous parameters:
        * add_igm_absorption (default False)
        * igm_factor (default 1.0)
        * smooth_velocity (default True)
        * sigma_smooth, min_wave_smooth, max_wave_smooth
        * redshift_colors (default False, do not use)
        * compute_light_ages (default False, do not use)
       
      Stellar population parameters:
        * add_stellar_remnants (default True)
        * tpagb_norm_type (default 2)
        * dell (default 0.0, do not use)
        * delt (default 0.0, do not use)
        * redgb (default 1.0)
        * fcstar (default 1.0)
        * sbss (default 0.0)
        * fbhb (default 0.0)
        * pagb (default 1.0)
        * imf_type (default 2=Kroupa01)
        * imf1, imf2, imf3, vdmc, mdave, masscut
        * evtype (default 1)
        * tpagb_norm_type
      Emission lines:
        * add_neb_emission (default False)
        * add_neb_continuum (default False)
        * gas_logz (default 0.0)
        * gas_logu (default -2)
      Galaxy properties:
        * zred (default 0.0)
      AGN properties:
        * fagn (default 0.0)
        * agn_tau (default 10)
      Calibration parameters:
        * phot_jitter
    """
    from prospect.models import priors, sedmodel

    model_params = []

    ##################################################
    # Fixed priors

    # Galaxy redshift
    model_params.append({
        'name': 'zred',
        'N': 1,
        'isfree': False,
        'init': zred,
        'units': '',
        'prior': None,
    })

    model_params.append({ # current mass in stars, not integral of SFH
        'name': 'mass_units',
        'N': 1,
        'isfree': False,
        'init': 'mstar', # 'mformed'
        'prior': None,
        })

    # IMF (Chabrier)
    model_params.append({
        'name': 'imf_type',
        'N': 1,
        'isfree': False,
        'init': 1,  # 1 - Chabrier
        'units': '',
        'prior': None,
    })

    # SFH parameterization (delayed-tau)
    model_params.append({
        'name': 'sfh',
        'N': 1,
        'isfree': False,
        'init': 4,  # 4 = delayed tau model
        'units': 'type',
        'prior': None,
    })

    # Do not include dust emission
    model_params.append({
        'name': 'add_dust_emission',
        'N': 1,
        'isfree': False,
        'init': False,  # do not include dust emission
        'units': 'index',
        'prior': None,
    })

    ##################################################
    # Free priors / parameters

    # Priors on stellar mass and stellar metallicity
    logmass_prior = priors.TopHat(mini=9.0, maxi=13.0)  #, seed=seed)
    logmass_init = np.diff(logmass_prior.range) / 2.0 + logmass_prior.range[
        0]  # logmass_prior.sample()
    model_params.append({
        'name': 'logmass',
        'N': 1,
        'isfree': True,
        'init': logmass_init,  # mass, 
        'init_disp': 0.5,  # dex
        'units': r'$M_{\odot}$',
        'prior': logmass_prior,
    })

    model_params.append({
        'name': 'mass',
        'N': 1,
        'isfree': False,
        'init': 10**logmass_init,
        'units': '',
        'prior': None,
        'depends_on': logmass2mass,
    })

    logzsol_prior = priors.TopHat(mini=np.log10(0.004 / 0.019),
                                  maxi=np.log10(0.04 / 0.019))  #, seed=seed)
    logzsol_init = np.diff(logzsol_prior.range) / 2.0 + logzsol_prior.range[
        0]  # logzsol_prior.sample(), # logzsol,
    model_params.append({
        'name': 'logzsol',
        'N': 1,
        'isfree': True,
        'init': logzsol_init,
        'init_disp': 0.3,  # logzsol_prior.range[1] * 0.1,
        'units': r'$\log_{10}\, (Z/Z_\odot)$',
        'prior': logzsol_prior,  # roughly (0.2-2)*Z_sun
    })

    # Prior(s) on dust content
    dust2_prior = priors.TopHat(mini=0.0, maxi=3.0)  #, seed=seed)
    dust2_init = np.diff(dust2_prior.range) / 2.0 + dust2_prior.range[
        0]  # dust2_prior.sample(), # dust2,
    model_params.append({
        'name': 'dust2',
        'N': 1,
        'isfree': True,
        'init': dust2_init,
        'init_disp': 0.5,  # dust2_prior.range[1] * 0.1,
        'units': '',  # optical depth
        'prior': dust2_prior,
    })

    # Priors on tau and age
    #tau_prior = priors.TopHat(mini=0.1, maxi=10.0)#, seed=seed)
    tau_prior = priors.LogUniform(mini=0.1, maxi=10.0)  #, seed=seed)
    tau_init = np.diff(tau_prior.range) / 2.0 + tau_prior.range[
        0]  # tau_prior.sample(), # tau,
    model_params.append({
        'name': 'tau',
        'N': 1,
        'isfree': True,
        'init': tau_init,
        'init_disp': 1.0,  # tau_prior.range[1] * 0.1,
        'units': 'Gyr',
        'prior': tau_prior,
    })

    tage_prior = priors.TopHat(mini=0.5, maxi=15)  #, seed=seed)
    tage_init = np.diff(tage_prior.range) / 2.0 + tage_prior.range[
        0]  # tage_prior.sample(), # tage,
    model_params.append({
        'name': 'tage',
        'N': 1,
        'isfree': True,
        'init': tage_init,
        'init_disp': 2.0,  # tage_prior.range[1] * 0.1,
        'units': 'Gyr',
        'prior': tage_prior,
    })

    model = sedmodel.SedModel(model_params)

    return model
Exemplo n.º 12
0
def build_model(fixed_metallicity=None, luminosity_distance=None, **extras):
    """Construct a model.  This method defines a number of parameter
    specification dictionaries and uses them to initialize a
    `models.sedmodel.SedModel` object.
    :param object_redshift:
        If given, given the model redshift to this value.
    :param add_dust: (optional, default: False)
        Switch to add (fixed) parameters relevant for dust emission.
    :param add_neb: (optional, default: False)
        Switch to add (fixed) parameters relevant for nebular emission, and
        turn nebular emission on.
    :param luminosity_distance: (optional)
        If present, add a `"lumdist"` parameter to the model, and set it's
        value (in Mpc) to this.  This allows one to decouple redshift from
        distance, and fit, e.g., absolute magnitudes (by setting
        luminosity_distance to 1e-5 (10pc))
    """
    from prospect.models.templates import TemplateLibrary, adjust_continuity_agebins
    from prospect.models import priors, sedmodel, transforms

    model_params = TemplateLibrary['continuity_sfh']

    ### BASIC PARAMETERS ###

    model_params["imf_type"] = {
        'N': 1,
        'isfree': False,
        'init': 1,  #1=Chabrier
        'prior': None
    }

    model_params['zred'] = {
        'N': 1,
        'isfree': True,
        'init': obj_red,
        "prior": priors.TopHat(mini=obj_red - 0.05, maxi=obj_red + 0.05)
    }

    model_params['add_igm_absorption'] = {
        'N': 1,
        'isfree': False,
        'init': 1,
        'units': None,
        'prior': None
    }

    model_params['add_agb_dust_model'] = {
        'N': 1,
        'isfree': False,
        'init': 1,
        'units': None,
        'prior': None
    }

    # model_params['pmetals'] = {'N': 1,
    #                             'isfree': False,
    #                             'init': -99,
    #                             'units': '',
    #                             'prior': priors.TopHat(mini=-3, maxi=-1)}

    ### SFH ###

    tuniv = WMAP9.age(obj_red).value
    model_params = adjust_continuity_agebins(model_params,
                                             tuniv=tuniv,
                                             nbins=7)

    ### DUST ABSORPTION ###

    model_params['dust_type'] = {
        'N': 1,
        'isfree': False,
        'init': 4,  #4=Kriek & Conroy
        'units': 'index',
        'prior': None
    }

    model_params['dust1'] = {
        'N': 1,
        'isfree': False,
        'depends_on': transforms.dustratio_to_dust1,
        'init': 0.,
        'units': 'optical depth towards young stars'
    }

    model_params['dust_ratio'] = {
        'N': 1,
        'isfree': True,
        'init': 1.0,
        'init_disp': 0.8,
        'disp_floor': 0.8,
        'units': 'ratio of birth-cloud to diffuse dust',
        'prior': priors.ClippedNormal(mini=0.0, maxi=2.0, mean=1.0, sigma=0.3)
    }

    model_params['dust2'] = {
        'N': 1,
        'isfree': True,
        'init': 1.0,
        'init_disp': 0.25,
        'disp_floor': 0.15,
        'units': 'optical depth at 5500AA',
        'prior': priors.ClippedNormal(mini=0.0, maxi=4.0, mean=0.3, sigma=1)
    }

    model_params['dust_index'] = {
        'N': 1,
        'isfree': True,
        'init': 0.0,
        'init_disp': 0.25,
        'disp_floor': 0.15,
        'units': 'power-law multiplication of Calzetti',
        'prior': priors.TopHat(mini=-2.0, maxi=0.5)
    }

    ### DUST EMISSION ###

    model_params.update(TemplateLibrary["dust_emission"])

    ### NEBULAR EMISSION ###

    model_params['add_neb_emission'] = {
        'N': 1,
        'isfree': False,
        'init': True,
        'prior': None
    }

    model_params['add_neb_continuum'] = {
        'N': 1,
        'isfree': False,
        'init': True,
        'prior': None
    }

    model_params['gas_logz'] = {
        'N': 1,
        'isfree': True,
        'init': 0.0,
        'units': r'log Z/Z_\odot',
        'prior': priors.TopHat(mini=-2.0, maxi=0.5)
    }

    model_params['gas_logu'] = {
        'N': 1,
        'isfree': True,
        'init': -1.0,
        'units': '',
        'prior': priors.TopHat(mini=-4.0, maxi=-1.0)
    }

    ### CALIBRATION ###
    model_params['polyorder'] = {'N': 1, 'init': 10, 'isfree': False}

    model_params['spec_norm'] = {
        'N': 1,
        'init': 1.0,
        'isfree': True,
        'prior': priors.Normal(sigma=0.2, mean=1.0),
        'units': 'f_true/f_obs'
    }

    model_params['spec_jitter'] = {
        "N": 1,
        "isfree": True,
        "init": 1.0,
        "prior": priors.TopHat(mini=0., maxi=4.0)
    }

    model_params['f_outlier_spec'] = {
        "N": 1,
        "isfree": True,
        "init": 0.01,
        "prior": priors.TopHat(mini=1e-5, maxi=0.5)
    }

    model_params['nsigma_outlier_spec'] = {
        "N": 1,
        "isfree": False,
        "init": 5.0
    }

    ### SMOOTHING ###

    model_params.update(TemplateLibrary["spectral_smoothing"])
    model_params["sigma_smooth"]["prior"] = priors.TopHat(mini=150, maxi=250)

    # Now instantiate the model using this new dictionary of parameter specifications
    model = sedmodel.SedModel(model_params)

    return model
Exemplo n.º 13
0
def build_model(object_redshift=0.0,
                fixed_metallicity=None,
                add_duste=False,
                add_neb=False,
                luminosity_distance=0.0,
                **extras):
    '''
    Construct a model. This method defines a number of parameter specification
    dictionaries and uses them to initialize a `models.sedmodel.SedModel`
    object.
    
    Parameters
    ----------
    object_redshift : float, optional
        If given, the model uses this redshift value. The default is 0.0.
    fixed_metallicity : bool, optional
        Boolean to set the metallicity to a fixed value. The default is None.
    add_duste : bool, optional
        Boolean to add (fixed) parameters relevant for dust emission. The
        default is False.
    add_neb : bool, optional
        Boolean to add (fixed) parameters relevant for nebular emission, and
        to turn nebular emission on. The default is False.
    luminosity_distance : float, optional
        If present, add a `lumdist` parameter to the model, and set it's value
        (in Mpc) to this. This allows one to decouple redshift from distance,
        and fit, for example, absolute magnitudes. The default is 0.0.
    **extras : kwargs
        Additional keyword arguments.
    
    Returns
    -------
    model : models.sedmodel.SedModel
        The model to use when fitting.
    
    '''

    import numpy as np

    from prospect.models.templates import TemplateLibrary
    from prospect.models import priors
    from prospect.models import sedmodel

    # Get a basic non-parametric SFH parameter set.
    # This has 5 free parameters:
    #   'zred', 'logmass', 'logzsol', 'dust2', 'logsfr_ratios'
    # and 5 fixed parameters:
    #   'mass'=1e6, 'sfh'=3, 'imf_type'=1, 'dust_type'=1,
    #   'agebins'=[[0.0, 7.47], ..., [10.11, 10.13]]
    # See the python-FSPS documentation for details about most of these
    # parameters. Also look at `TemplateLibrary.describe('continuity_sfh')` to
    # view the parameters, their initial values, and the priors in detail.
    model_params = TemplateLibrary['continuity_sfh']

    # add lumdist parameter. If this is not added then the distance is
    # controlled by the 'zred' parameter and a WMAP9 cosmology.
    '''
    if luminosity_distance > 0 :
        model_params['lumdist'] = {'N': 1, 'isfree': False,
                                   'init': luminosity_distance, 'units':'Mpc'}
    '''

    # change the model parameter specifications based on some keyword arguments
    if fixed_metallicity is not None:
        # make it a fixed parameter
        model_params['logzsol']['isfree'] = False
        # and use value supplied by fixed_metallicity keyword
        model_params['logzsol']['init'] = fixed_metallicity

    if object_redshift != 0.0:
        # make sure zred is free
        model_params['zred']['isfree'] = False
        # and set the value to the object_redshift keyword
        model_params['zred']['init'] = object_redshift
        # also set the prior for the redshift
        # model_params['zred']['prior'] = priors.TopHat(
        #     mini=object_redshift-0.01, maxi=object_redshift+0.01)

    if add_duste:
        # add dust emission (with fixed dust SED parameters)
        model_params.update(TemplateLibrary['dust_emission'])

    if add_neb:
        # add nebular emission (with fixed parameters)
        model_params.update(TemplateLibrary['nebular'])

    # modify the age bins
    nbins = 10
    model_params['agebins']['N'] = nbins
    model_params['agebins']['init'] = [[0.0, 7.47712125], [7.47712125, 8.0],
                                       [8.0, 8.69897], [8.69897, 9.0],
                                       [9.0, 9.5261747],
                                       [9.5261747, 9.75720267],
                                       [9.75720267, 9.90720604],
                                       [9.90720604, 10.01848862],
                                       [10.01848862, 10.10699395],
                                       [10.10699395, 10.12927034]]

    # update the number of bins for the mass in each bin
    model_params['mass']['N'] = nbins

    # update the number of bins for the logsfr_ratios parameter
    mean = np.zeros(nbins - 1)
    scale = np.ones_like(mean) * 0.3
    df = np.ones_like(mean) * 2
    rprior = priors.StudentT(mean=mean, scale=scale, df=df)
    model_params['logsfr_ratios']['N'] = nbins - 1
    model_params['logsfr_ratios']['init'] = mean
    model_params['logsfr_ratios']['prior'] = rprior

    # change the IMF to that of Chabrier (2003)
    model_params['imf_type']['init'] = 1

    # change the dust extinction curve to that of Cardelli+ (1989) for the MW
    model_params['dust_type']['init'] = 1

    # add dispersion values when using MCMC
    model_params['mass']['init_disp'] = 1e7
    model_params['dust2']['disp_floor'] = 0.1

    # now instantiate the model using this new dictionary of parameter specs
    model = sedmodel.SedModel(model_params)

    return model