Example #1
0
def test_modelgrid_object():
    """Test to see that ModelGrid object can be created"""
    print('Testing ModelGrid object creation...')

    # Load model grid
    mgrid = mg.ModelGrid(resource_filename('exoctk', 'data/core/modelgrid/'))

    assert isinstance(mgrid, mg.ModelGrid)
Example #2
0
def test_model_getter_off_grid():
    """Test to see that an off-grid model can be pulled from a ModelGrid
    object"""
    print('Testing off-grid model getter from ModelGrid object...')

    # Load model grid
    mgrid = mg.ModelGrid(resource_filename('exoctk', 'data/core/modelgrid/'))

    # Fetch model
    model = mgrid.get(4023, 4.1, -0.1)

    assert isinstance(model.get('flux'), np.ndarray)
Example #3
0
    suppress verbose output to stdout):
    ::

        pytest -s test_limb_darkening.py
"""

import os
from pkg_resources import resource_filename

from svo_filters import Filter

from exoctk import modelgrid as mg
from exoctk.limb_darkening import limb_darkening_fit as ldf

# Load local modelgrid
MODELGRID = mg.ModelGrid(resource_filename('exoctk', 'data/core/modelgrid/'))


def test_ldc_object():
    """Test to see that an LDC object can be loaded"""
    print('Testing LDC object creation...')

    ld_session = ldf.LDC(MODELGRID)

    assert isinstance(ld_session, ldf.LDC)


def test_ldc_plot():
    """Test that the LDC plots work"""
    print('Testing LDC object plotting...')
Example #4
0
def generate_SOSS_ldcs(wavelengths,
                       ld_profile,
                       grid_point,
                       model_grid='',
                       subarray='SUBSTRIP256',
                       n_bins=100,
                       plot=False,
                       save=''):
    """
    Generate a lookup table of limb darkening coefficients for full
    SOSS wavelength range

    Parameters
    ----------
    wavelengths: sequence
        The wavelengths at which to calculate the LDCs
    ld_profile: str
        A limb darkening profile name supported by
        `ExoCTK.ldc.ldcfit.ld_profile()`
    grid_point: dict, sequence
        The stellar parameters [Teff, logg, FeH] or stellar model
        dictionary from `ExoCTK.modelgrid.ModelGrid.get()`
    n_bins: int
        The number of bins to break up the grism into
    save: str
        The path to save to file to

    Example
    -------
    from awesimsoss.sim2D import awesim
    lookup = awesim.soss_ldc('quadratic', [3300, 4.5, 0])
    """
    try:
        from exoctk import modelgrid
        from exoctk.limb_darkening import limb_darkening_fit as lf
    except ImportError:
        return

    # Get the model grid
    if not isinstance(model_grid, modelgrid.ModelGrid):
        model_grid = modelgrid.ModelGrid(os.environ['MODELGRID_DIR'],
                                         resolution=700)

    # Load the model grid
    model_grid = modelgrid.ModelGrid(os.environ['MODELGRID_DIR'],
                                     resolution=700,
                                     wave_rng=(0.6, 2.8))

    # Get the grid point
    if isinstance(grid_point, (list, tuple, np.ndarray)):
        grid_point = model_grid.get(*grid_point)

    # Abort if no stellar dict
    if not isinstance(grid_point, dict):
        print(
            'Please provide the grid_point argument as [Teff, logg, FeH] or ExoCTK.modelgrid.ModelGrid.get(Teff, logg, FeH).'
        )
        return

    # Break the bandpass up into n_bins pieces
    bandpass = svo.Filter('NIRISS.GR700XD', n_bins=n_bins, verbose=False)

    # Calculate the LDCs
    ldc_results = lf.ldc(None,
                         None,
                         None,
                         model_grid, [ld_profile],
                         bandpass=bandpass,
                         grid_point=grid_point.copy(),
                         mu_min=0.08,
                         verbose=False)

    # Interpolate the LDCs to the desired wavelengths
    coeff_table = ldc_results[ld_profile]['coeffs']
    coeff_cols = [c for c in coeff_table.colnames if c.startswith('c')]
    coeffs = [
        np.interp(wavelengths, coeff_table['wavelength'], coeff_table[c])
        for c in coeff_cols
    ]

    return np.array(coeffs).T