Ejemplo n.º 1
0
def predict_model(param,
                  config,
                  obs_data,
                  sim_data,
                  smf_only=False,
                  ds_only=False):
    """Return all model predictions.
    Parameters
    ----------
    param: list, array, or tuple.
        Input model parameters.
    config : dict
        Configurations of the data and model.
    obs_data: dict
        Dictionary for observed data.
    sim_data: dict
        Dictionary for UniverseMachine data.
    constant_bin : boolen
        Whether to use constant bin size for logMs_tot or not.
    return_all : bool, optional
        Return all model information.
    show_smf : bool, optional
        Show the comparison of SMF.
    show_dsigma : bool, optional
        Show the comparisons of WL.
    """

    mass_x_field = config['sim_mass_x_field']
    halotools = config['sim_halotools']

    if halotools:
        print("USING HALOTOOLS with halo_mvir")
        # build_model and populate mock
        if 'model' in sim_data:  # save memory if model already exists
            for i, model_param in enumerate(config['param_labels']):
                sim_data['model'].param_dict[model_param] = param[i]

            # set redshift dependence to 0
            for i, model_param in enumerate(config['redshift_param_labels']):
                sim_data['model'].param_dict[model_param] = 0

            sim_data['model'].mock.populate()
            print('mock.populate')

        else:
            sim_data['model'] = PrebuiltSubhaloModelFactory(
                'behroozi10',
                redshift=config['sim_z'],
                scatter_abscissa=[12, 15],
                scatter_ordinates=[param[0], param[1]])

            for i, model_param in enumerate(config['param_labels']):
                sim_data['model'].param_dict[model_param] = param[i]

            # set redshift dependence to 0
            for i, model_param in enumerate(config['redshift_param_labels']):
                sim_data['model'].param_dict[model_param] = 0

            # populate mock
            # sim_data['model'].populate_mock(deepcopy(sim_data['halocat']))
            sim_data['model'].populate_mock(sim_data['halocat'])
            print('populate_mock')

        print(sim_data['model'].param_dict)

        stellar_masses = np.log10(
            sim_data['model'].mock.galaxy_table['stellar_mass'])

    else:  #use Chris' code instead of halotools
        print("USING CHRIS' CODE with {0}".format(mass_x_field))
        stellar_masses = get_chris_stellar_masses(param, config, sim_data)

    # Predict SMFs
    smf_mass_bins, smf_log_phi = compute_SMF(stellar_masses, config, nbins=100)
    print('SMF computed')
    if smf_only:
        return smf_mass_bins, smf_log_phi, None, None, stellar_masses

    # Predict DeltaSigma profiles
    wl_r, wl_ds = compute_deltaSigma(stellar_masses, config, obs_data,
                                     sim_data)
    print('DS computed')
    if ds_only:
        return None, None, wl_r, wl_ds, stellar_masses

    return smf_mass_bins, smf_log_phi, wl_r, wl_ds, stellar_masses