Exemple #1
0
def data():
    data, _, profiles = fileio.read_compressed_track(
        base_path / 'test_data/M1.080_M0.502_P192.67_Z0.01129.h5',
        return_profiles=True)

    stable, ce_age = common_envelope.is_stable(data,
                                               criterion='Mdot',
                                               value=-2)
    data = data[data['age'] <= ce_age]
    return data
Exemple #2
0
def test_apply_ce():
    data, _ = fileio.read_compressed_track(
        base_path / 'test_data/M1.205_M0.413_P505.12_Z0.h5')
    stable, ce_age = common_envelope.is_stable(data,
                                               criterion='J_div_Jdot_div_P',
                                               value=10)
    data = data[data['age'] <= ce_age]

    data = common_envelope.apply_ce(data, ce_formalism='iben_tutukov1984')

    assert data['period_days'][-1] == pytest.approx(25.62, abs=0.01)
    assert data['binary_separation'][-1] == pytest.approx(38.2451, abs=1e-4)
    assert data['star_1_mass'][-1] == pytest.approx(0.4477, abs=1e-4)
    assert data['envelope_mass'][-1] == 0
    assert data['star_2_mass'][-1] == pytest.approx(0.4278, abs=1e-4)
    assert data['mass_ratio'][-1] == pytest.approx(1.0465, abs=1e-4)
    assert data['rl_1'][-1] == pytest.approx(14.6426, abs=1e-4)
    assert data['rl_2'][-1] == pytest.approx(14.3415, abs=1e-4)
    assert data['CE_phase'][-1] == 1
    assert data['CE_phase'][-2] == 1
    assert data['CE_phase'][-3] == 0

    data, _, profiles = fileio.read_compressed_track(
        base_path / 'test_data/M1.080_M0.502_P192.67_Z0.01129.h5',
        return_profiles=True)
    stable, ce_age = common_envelope.is_stable(data,
                                               criterion='Mdot',
                                               value=-2)
    data = data[data['age'] <= ce_age]

    data = common_envelope.apply_ce(data,
                                    profiles=profiles,
                                    ce_formalism='dewi_tauris2000',
                                    a_th=0.5)

    assert data['binary_separation'][-1] == pytest.approx(6.394841,
                                                          abs=0.000001)
    assert data['star_1_mass'][-1] == pytest.approx(0.38572328, abs=0.000001)
    assert data['envelope_mass'][-1] > 0

    with pytest.raises(ValueError):
        data = common_envelope.apply_ce(data, ce_formalism='uk_formalism')
Exemple #3
0
def test_dewi_tauris2000(data):
    data, _, profiles = fileio.read_compressed_track(
        base_path / 'test_data/M1.080_M0.502_P192.67_Z0.01129.h5',
        return_profiles=True)

    stable, ce_age = common_envelope.is_stable(data,
                                               criterion='Mdot',
                                               value=-2)
    data = data[data['age'] <= ce_age]

    profile = profiles['profile_1_mdot-2.0']

    af, M1_final = common_envelope.dewi_tauris2000(data, profile, a_th=0)

    assert af == pytest.approx(4.8597844860, abs=0.00001)
    assert M1_final == pytest.approx(0.38321120, abs=0.00001)

    af, M1_final = common_envelope.dewi_tauris2000(data, profile, a_th=1.0)

    assert af == pytest.approx(9.17843738836, abs=0.00001)
    assert M1_final == pytest.approx(0.39115816046997015, abs=0.00001)
Exemple #4
0
def test_is_stable():
    data, _ = fileio.read_compressed_track(
        base_path / 'test_data/M1.205_M0.413_P505.12_Z0.h5')

    stable, ce_age, ce_mn = common_envelope.is_stable(data,
                                                      criterion='Mdot',
                                                      value=-3,
                                                      return_model_number=True)
    assert stable is False
    assert ce_age == pytest.approx(5179376593.6, abs=0.1)
    assert ce_mn == 11928

    stable, ce_age, ce_mn = common_envelope.is_stable(data,
                                                      criterion='delta',
                                                      value=0.03,
                                                      return_model_number=True)
    assert stable is False
    assert ce_age == pytest.approx(5179376616.1, abs=0.1)
    assert ce_mn == 12057

    stable, ce_age, ce_mn = common_envelope.is_stable(
        data, criterion='J_div_Jdot_div_P', value=10, return_model_number=True)
    assert stable is False
    assert ce_age == pytest.approx(5179376617.0, abs=0.1)
    assert ce_mn == 12108

    stable, ce_age, ce_mn = common_envelope.is_stable(
        data,
        criterion='M_div_Mdot_div_P',
        value=100,
        return_model_number=True)
    assert stable is False
    assert ce_age == pytest.approx(5179376614.6, abs=0.1)
    assert ce_mn == 12021

    stable, ce_age, ce_mn = common_envelope.is_stable(data,
                                                      criterion='R_div_SMA',
                                                      value=0.5,
                                                      return_model_number=True)
    assert stable is False
    assert ce_age == pytest.approx(5179376602.9, abs=0.1)
    assert ce_mn == 11946

    with pytest.raises(ValueError):
        stable, ce_age = common_envelope.is_stable(data,
                                                   criterion='uk_criterion',
                                                   value=0.5)
Exemple #5
0
def extract_mesa(file_list,
                 stability_criterion='J_div_Jdot_div_P',
                 stability_limit=10,
                 n_ml_phases=0,
                 ce_formalism='iben_tutukov1984',
                 ce_parameters={'al': 1},
                 ce_profile_name=None,
                 parameters=[],
                 phase_flags=[],
                 extra_info_parameters=[],
                 add_setup_pars_to_result=True,
                 verbose=False,
                 flatten_output=False,
                 **kwargs):

    parameters, column_names = _process_parameters(parameters)

    extra_info_parameters, extra_names = _process_parameters(
        extra_info_parameters)

    columns = ['path', 'stability', 'n_ML_phases'
               ] + extra_names + column_names + phase_flags
    if add_setup_pars_to_result:
        columns += [
            'stability_criterion', 'stability_limit', 'ce_profile_name',
            'ce_formalism', 'ce_parameters'
        ]
    columns += ['error_flags']
    results = []

    # check if the same extraction parameters are used for all models, or if specific parameters are already
    # provided in the files list
    file_list = process_file_list(file_list,
                                  stability_criterion=stability_criterion,
                                  stability_limit=stability_limit,
                                  ce_formalism=ce_formalism,
                                  ce_parameters=ce_parameters,
                                  ce_profile_name=ce_profile_name,
                                  verbose=verbose)

    for i, model in file_list.iterrows():

        if verbose:
            print(i, model['path'])

        # 1: Get the data
        try:
            data, extra_info, profiles = fileio.read_compressed_track(
                model['path'], return_profiles=True)
        except Exception as e:
            if verbose:
                print(e)
            continue

        # 2: check for stability and cut data at start of CE
        stable, ce_age = common_envelope.is_stable(
            data,
            criterion=model['stability_criterion'],
            value=model['stability_limit'])
        stability = 'stable'

        if not stable:
            # if the model is not stable, cut of the evolution at the start of the CE as anything after than
            # is non physical anyway.
            data = data[data['age'] <= ce_age]

            if ce_profile_name is not None:
                try:
                    profiles = profiles[model['ce_profile_name']]
                except Exception:
                    # todo: deal correctly with the missing profile!
                    print('CE: profile missing')
            data = common_envelope.apply_ce(data,
                                            profiles=profiles,
                                            ce_formalism=model['ce_formalism'],
                                            **model['ce_parameters'])

            # check if CE is ejected or if the system is a merger or a contact binary
            s = np.where((data['star_2_radius'] >= 0.99 * data['rl_2'])
                         & (data['star_1_radius'] >= 0.99 * data['rl_1']))

            if data['binary_separation'][-1] <= 0:
                stability = 'merger'
                print('CE: Merged')
            elif len(data['model_number'][s]) > 0:
                stability = 'contact'
                print('CE: Contact')
            else:
                stability = 'CE'

        # 3: extract some standard parameters: Path, stability and nr of ML phases.
        pars = [model['path'].split('/')[-1]]
        pars += [stability, count_ml_phases(data)]

        # 4: add the extra info to the output
        for p in extra_info_parameters:
            pars.append(extra_info[p])

        # 5: extract the requested parameters & 6: add the requested phase flags
        extracted_pars = extract_parameters(data,
                                            parameters,
                                            phase_flags,
                                            n_ml_phases=n_ml_phases)
        pars += extracted_pars

        # 7: Add the extraction setup parameters if requested
        if add_setup_pars_to_result:
            setup_pars = [
                model['stability_criterion'], model['stability_limit'],
                model['ce_profile_name'], model['ce_formalism'],
                model['ce_parameters']
            ]
            pars += setup_pars

        # 8: todo: check for some possible errors and flag them
        error_flags = evolution_errors.check_error_flags(
            data, extra_info['termination_code'])
        pars.append(error_flags)

        results.append(pars)

    results = pd.DataFrame(results, columns=columns)

    if flatten_output:
        # go over all columns. If a column contains a list instead of a value flatten that column
        results = _flatten_dataframe(results, n_ml_phases)

    return results