splat/evolve.py
def modelParameters(*model,**kwargs):
    '''
    :Purpose: Retrieves the evolutionary model parameters given two of the following parameters: mass, age, temperature, luminosity, gravity, or radius. The inputs can be individual values or arrays.  Using the input parameters, the associated evolutionary model parameters are computed through log-linear interpolation of the original model grid. Parameters that fall outside the grid return nan.

    Required Inputs:

    :param: model: Either a string of the name of the evolutionary model set, which can be one of `baraffe` (default), `burrows`, or `saumon`; or a dictionary output from `loadEvolModel()`_ containing model parameters. 
    
    and two (2) of the following:

    :param: mass: input value or list of values for mass (can also be `masses` or `m`)
    :param: age: input value or list of values for age (can also be `ages`, `time` or `a`)
    :param: temperature: input value or list of values for temperature (can also be `temperatures`, `teff`, `temp` or `t`)
    :param: gravity: input value or list of values for gravity (can also be `gravities`, `grav`, `logg` or `g`)
    :param: luminosity: input value or list of values for luminosity (can also be `luminosities`, `lum`, `lbol` or `l`)
    :param: radius: input value or list of values for radius (can also be `radii`, `rad` and `r`)

    .. _`loadEvolModel()` : api.html#splat_evolve.loadEvolModel

    Optional Inputs:

    :param: Parameters for `loadEvolModel()`_ may also be used.

    Output: 

    Dictionary containing keywords mass, age, temperature, luminosity, gravity, and radius, each linked to the evolutionary parameters retrieved. 


    :Example:
    >>> import splat, numpy
    >>> masses = numpy.random.uniform(0.01,0.1,20)
    >>> ages = numpy.random.uniform(0.01,10,20)
    >>> p = splat.modelParameters('baraffe',mass=masses,age=ages)
    You are using baraffe's models.
    >>> print(p.temperature)
    [ 2502.90132332  2818.85920306  1002.64227134  1330.37273021  1192.86976417
      500.45609068  2604.99966013  1017.03307609  1774.18267474  1675.12181635
      2682.9697321   2512.45223777   346.41152614  2066.19972036   843.28528456
      2264.93051445  2767.85660557   348.84214986   922.87030167  2669.27152307] K    
    '''

# read in model
    if len(model) > 0: model=model[0]
    else: model='baraffe03'
    for k in ['model','set','ref','reference']: model=kwargs.get(k,model)
    if type(model) is not dict: model = loadEvolModel(**kwargs)
    if type(model) is not dict: raise ValueError('Something went wrong in loading in models')
    if kwargs.get('debug',False) == True: print(model)
    keywords = list(kwargs.keys())

# do some key word replacement
    mkwargs = {}
    for k in keywords:
        if k.lower() in list(EVOLUTIONARY_MODEL_PARAMETERS.keys()):
            mkwargs[k.lower()] = kwargs[k]
        for e in list(EVOLUTIONARY_MODEL_PARAMETERS.keys()):
            if k.lower() in EVOLUTIONARY_MODEL_PARAMETERS[e]['altname']:
                mkwargs[e] = kwargs[k]

# determine length of input arrays and assert they must be pure numbers 
    inparams = {}
    inparams['debug'] = kwargs.get('debug',False)
    inparams['alt'] = kwargs.get('alt',False)
    inparams['verbose'] = kwargs.get('verbose',False)
    outparams = {}
    pkeys = list(mkwargs.keys())
    if len(pkeys) < 2:
        raise ValueError('\nNeed at least two parameters provided; only {} given: {}'.format(len(pkeys),pkeys))
    for p in list(EVOLUTIONARY_MODEL_PARAMETERS.keys()):
        outparams[p] = []
        if p in pkeys:
#            print(p,type(mkwargs[p]))
            if isUnit(mkwargs[p]):
                unit = mkwargs[p].unit
                mkwargs[p] = mkwargs[p].value
            if not isinstance(mkwargs[p],list) and not isinstance(mkwargs[p],numpy.ndarray):
                mkwargs[p] = [mkwargs[p]]
            if isUnit(mkwargs[p]):
                unit = mkwargs[p].unit
                mkwargs[p] = mkwargs[p].value
            if isUnit(mkwargs[p][0]):
                mkwargs[p] = [x*value for x in mkwargs[p]]
            

# fill in extra parameters if the number provided is unequal (i.e., default to "most" parameters)            
    numberValues = numpy.max([len(mkwargs[p]) for p in list(mkwargs.keys())])
    for p in list(mkwargs.keys()):
        while len(mkwargs[p]) < numberValues: mkwargs[p].append(mkwargs[p][-1])

# now loop through each parameter set to determine remaining parameters
    for i in range(numberValues):
        for p in pkeys:
            inparams[p] = mkwargs[p][i]
        par = _modelParametersSingle(model,**inparams)
        for p in list(EVOLUTIONARY_MODEL_PARAMETERS.keys()):
            outparams[p].append(par[p])


# remove lists if only one parameter set is being calculated
    if len(outparams['temperature']) == 1:
        for e in list(EVOLUTIONARY_MODEL_PARAMETERS.keys()):
            outparams[e] = outparams[e][0]

# add units
    for e in list(EVOLUTIONARY_MODEL_PARAMETERS.keys()):
        outparams[e] *= EVOLUTIONARY_MODEL_PARAMETERS[e]['unit']

    return outparams

    :Purpose: Retrieves the evolutionary model parameters given two of the following parameters: mass, age, temperature, luminosity, gravity, or radius. The inputs can be individual values or arrays.  Using the input parameters, the associated evolutionary model parameters are computed through log-linear interpolation of the original model grid. Parameters that fall outside the grid return nan.

    Required Inputs:

    :param: model: Either a string of the name of the evolutionary model set, which can be one of `baraffe` (default), `burrows`, or `saumon`; or a dictionary output from `loadEvolModel()`_ containing model parameters. 
    
    and two (2) of the following:

    :param: mass: input value or list of values for mass (can also be `masses` or `m`)
    :param: age: input value or list of values for age (can also be `ages`, `time` or `a`)
    :param: temperature: input value or list of values for temperature (can also be `temperatures`, `teff`, `temp` or `t`)
    :param: gravity: input value or list of values for gravity (can also be `gravities`, `grav`, `logg` or `g`)
    :param: luminosity: input value or list of values for luminosity (can also be `luminosities`, `lum`, `lbol` or `l`)
    :param: radius: input value or list of values for radius (can also be `radii`, `rad` and `r`)

    .. _`loadEvolModel()` : api.html#splat_evolve.loadEvolModel

    Optional Inputs:

    :param: Parameters for `loadEvolModel()`_ may also be used.

    Output: 

    Dictionary containing keywords mass, age, temperature, luminosity, gravity, and radius, each linked to the evolutionary parameters retrieved. 


    :Example:
    >>> import splat, numpy
    >>> masses = numpy.random.uniform(0.01,0.1,20)
    >>> ages = numpy.random.uniform(0.01,10,20)
    >>> p = splat.modelParameters('baraffe',mass=masses,age=ages)
    You are using baraffe's models.
    >>> print(p.temperature)
    [ 2502.90132332  2818.85920306  1002.64227134  1330.37273021  1192.86976417
      500.45609068  2604.99966013  1017.03307609  1774.18267474  1675.12181635
      2682.9697321   2512.45223777   346.41152614  2066.19972036   843.28528456
      2264.93051445  2767.85660557   348.84214986   922.87030167  2669.27152307] K    
    
:Purpose: Retrieves the evolutionary model parameters given two of the following parameters: mass, age, temperature, luminosity, gravity, or radius. The inputs can be individual values or arrays.  Using the input parameters, the associated evolutionary model parameters are computed through log-linear interpolation of the original model grid. Parameters that fall outside the grid return nan.
Required Inputs.



and two (2) of the following.





Optional Inputs.

:param: Parameters for `loadEvolModel()`_ may also be used.



Dictionary containing keywords mass, age, temperature, luminosity, gravity, and radius, each linked to the evolutionary parameters retrieved.


: Purpose : Retrieves the evolutionary model parameters given two of the following parameters : mass age temperature luminosity gravity or radius . The inputs can be individual values or arrays . Using the input parameters the associated evolutionary model parameters are computed through log - linear interpolation of the original model grid . Parameters that fall outside the grid return nan . Required Inputs . and two ( 2 ) of the following . Optional Inputs . : param : Parameters for ` loadEvolModel () ` _ may also be used . Dictionary containing keywords mass age temperature luminosity gravity and radius each linked to the evolutionary parameters retrieved .
def modelParameters(*model,**kwargs):
    if len(model) > 0: model=model[0]
    else: model='baraffe03'
    for k in ['model','set','ref','reference']: model=kwargs.get(k,model)
    if type(model) is not dict: model = loadEvolModel(**kwargs)
    if type(model) is not dict: raise ValueError('Something went wrong in loading in models')
    if kwargs.get('debug',False) == True: print(model)
    keywords = list(kwargs.keys())
    mkwargs = {}
    for k in keywords:
        if k.lower() in list(EVOLUTIONARY_MODEL_PARAMETERS.keys()):
            mkwargs[k.lower()] = kwargs[k]
        for e in list(EVOLUTIONARY_MODEL_PARAMETERS.keys()):
            if k.lower() in EVOLUTIONARY_MODEL_PARAMETERS[e]['altname']:
                mkwargs[e] = kwargs[k]
    inparams = {}
    inparams['debug'] = kwargs.get('debug',False)
    inparams['alt'] = kwargs.get('alt',False)
    inparams['verbose'] = kwargs.get('verbose',False)
    outparams = {}
    pkeys = list(mkwargs.keys())
    if len(pkeys) < 2:
        raise ValueError('\nNeed at least two parameters provided; only {} given: {}'.format(len(pkeys),pkeys))
    for p in list(EVOLUTIONARY_MODEL_PARAMETERS.keys()):
        outparams[p] = []
        if p in pkeys:
            if isUnit(mkwargs[p]):
                unit = mkwargs[p].unit
                mkwargs[p] = mkwargs[p].value
            if not isinstance(mkwargs[p],list) and not isinstance(mkwargs[p],numpy.ndarray):
                mkwargs[p] = [mkwargs[p]]
            if isUnit(mkwargs[p]):
                unit = mkwargs[p].unit
                mkwargs[p] = mkwargs[p].value
            if isUnit(mkwargs[p][0]):
                mkwargs[p] = [x*value for x in mkwargs[p]]
    numberValues = numpy.max([len(mkwargs[p]) for p in list(mkwargs.keys())])
    for p in list(mkwargs.keys()):
        while len(mkwargs[p]) < numberValues: mkwargs[p].append(mkwargs[p][-1])
    for i in range(numberValues):
        for p in pkeys:
            inparams[p] = mkwargs[p][i]
        par = _modelParametersSingle(model,**inparams)
        for p in list(EVOLUTIONARY_MODEL_PARAMETERS.keys()):
            outparams[p].append(par[p])
    if len(outparams['temperature']) == 1:
        for e in list(EVOLUTIONARY_MODEL_PARAMETERS.keys()):
            outparams[e] = outparams[e][0]
    for e in list(EVOLUTIONARY_MODEL_PARAMETERS.keys()):
        outparams[e] *= EVOLUTIONARY_MODEL_PARAMETERS[e]['unit']
    return outparams
def modelParameters ( * model , ** kwargs ) : if len ( model ) > 0 : model = model [ 0 ] else : model = 'baraffe03' for k in [ 'model' , 'set' , 'ref' , 'reference' ] : model = kwargs . get ( k , model ) if type ( model ) is not dict : model = loadEvolModel ( ** kwargs ) if type ( model ) is not dict : raise ValueError ( 'Something went wrong in loading in models' ) if kwargs . get ( 'debug' , False ) == True : print ( model ) keywords = list ( kwargs . keys ( ) ) mkwargs = { } for k in keywords : if k . lower ( ) in list ( EVOLUTIONARY_MODEL_PARAMETERS . keys ( ) ) : mkwargs [ k . lower ( ) ] = kwargs [ k ] for e in list ( EVOLUTIONARY_MODEL_PARAMETERS . keys ( ) ) : if k . lower ( ) in EVOLUTIONARY_MODEL_PARAMETERS [ e ] [ 'altname' ] : mkwargs [ e ] = kwargs [ k ] inparams = { } inparams [ 'debug' ] = kwargs . get ( 'debug' , False ) inparams [ 'alt' ] = kwargs . get ( 'alt' , False ) inparams [ 'verbose' ] = kwargs . get ( 'verbose' , False ) outparams = { } pkeys = list ( mkwargs . keys ( ) ) if len ( pkeys ) < 2 : raise ValueError ( '\nNeed at least two parameters provided; only {} given: {}' . format ( len ( pkeys ) , pkeys ) ) for p in list ( EVOLUTIONARY_MODEL_PARAMETERS . keys ( ) ) : outparams [ p ] = [ ] if p in pkeys : if isUnit ( mkwargs [ p ] ) : unit = mkwargs [ p ] . unit mkwargs [ p ] = mkwargs [ p ] . value if not isinstance ( mkwargs [ p ] , list ) and not isinstance ( mkwargs [ p ] , numpy . ndarray ) : mkwargs [ p ] = [ mkwargs [ p ] ] if isUnit ( mkwargs [ p ] ) : unit = mkwargs [ p ] . unit mkwargs [ p ] = mkwargs [ p ] . value if isUnit ( mkwargs [ p ] [ 0 ] ) : mkwargs [ p ] = [ x * value for x in mkwargs [ p ] ] numberValues = numpy . max ( [ len ( mkwargs [ p ] ) for p in list ( mkwargs . keys ( ) ) ] ) for p in list ( mkwargs . keys ( ) ) : while len ( mkwargs [ p ] ) < numberValues : mkwargs [ p ] . append ( mkwargs [ p ] [ - 1 ] ) for i in range ( numberValues ) : for p in pkeys : inparams [ p ] = mkwargs [ p ] [ i ] par = _modelParametersSingle ( model , ** inparams ) for p in list ( EVOLUTIONARY_MODEL_PARAMETERS . keys ( ) ) : outparams [ p ] . append ( par [ p ] ) if len ( outparams [ 'temperature' ] ) == 1 : for e in list ( EVOLUTIONARY_MODEL_PARAMETERS . keys ( ) ) : outparams [ e ] = outparams [ e ] [ 0 ] for e in list ( EVOLUTIONARY_MODEL_PARAMETERS . keys ( ) ) : outparams [ e ] *= EVOLUTIONARY_MODEL_PARAMETERS [ e ] [ 'unit' ] return outparams
:Purpose: Retrieves the evolutionary model parameters given two of the following parameters: mass, age, temperature, luminosity, gravity, or radius.
: Purpose : Retrieves the evolutionary model parameters given two of the following parameters : mass age temperature luminosity gravity or radius .
'''
    :Purpose: Retrieves the evolutionary model parameters given two of the following parameters: mass, age, temperature, luminosity, gravity, or radius. The inputs can be individual values or arrays.  Using the input parameters, the associated evolutionary model parameters are computed through log-linear interpolation of the original model grid. Parameters that fall outside the grid return nan.

    Required Inputs:

    :param: model: Either a string of the name of the evolutionary model set, which can be one of `baraffe` (default), `burrows`, or `saumon`; or a dictionary output from `loadEvolModel()`_ containing model parameters. 
    
    and two (2) of the following:

    :param: mass: input value or list of values for mass (can also be `masses` or `m`)
    :param: age: input value or list of values for age (can also be `ages`, `time` or `a`)
    :param: temperature: input value or list of values for temperature (can also be `temperatures`, `teff`, `temp` or `t`)
    :param: gravity: input value or list of values for gravity (can also be `gravities`, `grav`, `logg` or `g`)
    :param: luminosity: input value or list of values for luminosity (can also be `luminosities`, `lum`, `lbol` or `l`)
    :param: radius: input value or list of values for radius (can also be `radii`, `rad` and `r`)

    .. _`loadEvolModel()` : api.html#splat_evolve.loadEvolModel

    Optional Inputs:

    :param: Parameters for `loadEvolModel()`_ may also be used.

    Output: 

    Dictionary containing keywords mass, age, temperature, luminosity, gravity, and radius, each linked to the evolutionary parameters retrieved. 


    :Example:
    >>> import splat, numpy
    >>> masses = numpy.random.uniform(0.01,0.1,20)
    >>> ages = numpy.random.uniform(0.01,10,20)
    >>> p = splat.modelParameters('baraffe',mass=masses,age=ages)
    You are using baraffe's models.
    >>> print(p.temperature)
    [ 2502.90132332  2818.85920306  1002.64227134  1330.37273021  1192.86976417
      500.45609068  2604.99966013  1017.03307609  1774.18267474  1675.12181635
      2682.9697321   2512.45223777   346.41152614  2066.19972036   843.28528456
      2264.93051445  2767.85660557   348.84214986   922.87030167  2669.27152307] K    
    ''' # read in model # do some key word replacement # determine length of input arrays and assert they must be pure numbers  #            print(p,type(mkwargs[p])) # fill in extra parameters if the number provided is unequal (i.e., default to "most" parameters)             # now loop through each parameter set to determine remaining parameters # remove lists if only one parameter set is being calculated # add units