Beispiel #1
0
 def normalize(self, norm_type=None, norm_f=1, cieobs=_CIEOBS):
     """
     Normalize spectral power distributions in SPD instance.
     
     Args:
         :norm_type:
             | None, optional 
             |   - 'lambda': make lambda in norm_f equal to 1
             |   - 'area': area-normalization times norm_f
             |   - 'max': max-normalization times norm_f
             |   - 'ru': to :norm_f: radiometric units 
             |   - 'pu': to :norm_f: photometric units 
             |   - 'pusa': to :norm_f: photometric units (with Km corrected
             |                         to standard air, cfr. CIE TN003-2015)
             |   - 'qu': to :norm_f: quantal energy units
         :norm_f: 
             | 1, optional
             | Determines size of normalization for 'max' and 'area' 
               or which wavelength is normalized to 1 for 'lambda' option.
         :cieobs:
             | _CIEOBS or str, optional
             | Type of cmf set to use for normalization using photometric 
               units (norm_type == 'pu')
     """
     self.value = spd_normalize(self.get_(),
                                norm_type=norm_type,
                                norm_f=norm_f,
                                cieobs=cieobs)[1:]
     return self
Beispiel #2
0
 def test_spd_normalize(self, getvars):
     # check spd_normalize:
     S, spds, rfls, xyz, xyzw = getvars
     rfls_np_cp = rfls.copy()
     rfls_norm = lx.spd_normalize(rfls)
     rfls_norm = lx.spd_normalize(rfls_np_cp, norm_type='area', norm_f=2)
     rfls_norm = lx.spd_normalize(rfls_np_cp,
                                  norm_type='lambda',
                                  norm_f=560)
     rfls_norm = lx.spd_normalize(rfls_np_cp, norm_type='max', norm_f=1)
     rfls_norm = lx.spd_normalize(rfls_np_cp, norm_type='pu', norm_f=1)
     rfls_norm = lx.spd_normalize(rfls_np_cp, norm_type='ru', norm_f=1)
     rfls_norm = lx.spd_normalize(rfls_np_cp, norm_type='qu', norm_f=1)
def spd_to_aopicE(sid, Ee = None, E = None, Q = None, cieobs = _CIEOBS, sid_units = 'W/m2', out = 'Eeas,Eas'):
    """
    Calculate alpha-opic irradiance (Ee,α) and equivalent luminance (Eα) values
    for the l-cone, m-cone, s-cone, rod and iprgc (α) photoreceptor cells 
    following CIE technical note TN 003:2015.
    
    Args:
        :sid: 
            | numpy.ndarray with retinal spectral irradiance in :sid_units: 
            | (if 'uW/cm2', sid will be converted to SI units 'W/m2')
        :Ee: 
            | None, optional
            | If not None: normalize :sid: to an irradiance of :Ee:
        :E: 
            | None, optional
            | If not None: normalize :sid: to an illuminance of :E:
            | Note that E is calculate using a Km factor corrected to standard air.
        :Q: 
            | None, optional
            | If not None: nNormalize :sid: to a quantal energy of :Q:
        :cieobs:
            | _CIEOBS or str, optional
            | Type of cmf set to use for photometric units.
        :sid_units:
            | 'W/m2', optional
            | Other option 'uW/m2', input units of :sid:
        :out: 
            | 'Eeas, Eas' or str, optional
            | Determines values to return.
            
    Returns:
        :returns: 
            | (Eeas, Eas) with Eeas and Eas resp. numpy.ndarrays with the 
              α-opic irradiance and equivalent illuminance values 
              of all spectra in :sid: in SI-units. 
         
            | (other choice can be set using :out:)
    """
    outlist = out.split(',')
    
    # Convert to Watt/m²:
    if sid_units == 'uW/cm2':
        sid[1:] = sid[1:]/100

    elif sid_units == 'W/m2':
        pass
    else:
        raise Exception("spd_to_aopicE(): {} unsupported units for SID.".format(sid_units))
    
    
    # Normalize sid to Ee:
    if Ee is not None:
        sid = spd_normalize(sid, norm_type = 'ru', norm_f = Ee)  
    elif E is not None:
        sid = spd_normalize(sid, norm_type = 'pusa', norm_f = E) 
    elif Q is not None:
        sid = spd_normalize(sid, norm_type = 'qu', norm_f = Q) 
    
    
    # Get sid irradiance (W/m²):
    if 'Ee' in outlist:
        Ee = spd_to_power(sid, cieobs = cieobs, ptype = 'ru')
    
    # Get sid illuminance (lx):
    if 'E' in outlist:
        E = spd_to_power(sid, cieobs = cieobs, ptype = 'pusa') #photometric units (Km corrected to standard air)
    
    # Get sid quantal energy (photons/m²/s):
    if 'Q' in outlist:
        Q = spd_to_power(sid, cieobs = cieobs, ptype = 'qu')


    # get SI actinic action spectra, sa:
    sa = spd(_ACTIONSPECTRA, wl = sid[0], interpolation = 'cmf', norm_type = 'max')
    
    # get wavelength spacing:
    dl = getwld(sid[0])
    
    # Calculate all alpha-opics Ee's:
    Eeas = (np.dot((sa[1:]*dl),sid[1:].T)).T

    # Calculate equivalent alpha-opic E's:
    Vl, Km = vlbar(cieobs = cieobs, wl_new = sid[0], out = 2)
    Eas = Km*Km_correction_factor*Eeas*(Vl[1].sum()/sa[1:].sum(axis = 1))

    #Prepare output:
    if out == 'Eeas,Eas':
        return Eeas,Eas
    elif out == 'Eeas':
        return Eeas
    elif out == 'Eas':
        return Eas
    else:
        eval(out)
Beispiel #4
0

.. codeauthor:: Kevin A.G. Smet (ksmet1977 at gmail.com)
"""
import luxpy as lx

# get some spectral data:
spds = lx._IESTM30['S']['data'][:5]
rfls = lx._IESTM30['R']['99']['5nm'][:6]

# check getdata():
rfls_df = lx.getdata(rfls, kind='df')
rfls_np = lx.getdata(rfls_df, kind='np')

# check spd_normalize:
rfls_norm = lx.spd_normalize(rfls_np)
rfls_np_cp = rfls_np.copy()
rfls_norm = lx.spd_normalize(rfls_np_cp, norm_type='area', norm_f=2)
rfls_norm = lx.spd_normalize(rfls_np_cp, norm_type='lambda', norm_f=560)
rfls_norm = lx.spd_normalize(rfls_np_cp, norm_type='max', norm_f=1)
rfls_norm = lx.spd_normalize(rfls_np_cp, norm_type='pu', norm_f=1)
rfls_norm = lx.spd_normalize(rfls_np_cp, norm_type='ru', norm_f=1)
rfls_norm = lx.spd_normalize(rfls_np_cp, norm_type='qu', norm_f=1)

# check spd_to_xyz:
xyz = lx.spd_to_xyz(spds)
xyz = lx.spd_to_xyz(spds, relative=False)
xyz = lx.spd_to_xyz(spds, rfl=rfls)
xyz, xyzw = lx.spd_to_xyz(spds, rfl=rfls, cieobs='1931_2', out=2)

# check xyz_to_cct():
Beispiel #5
0
def plot_tm30_spd(spd, cri_type = 'ies-tm30', axh = None, 
                  font_size = _TM30_FONT_SIZE, **kwargs):
    """
    Plot test SPD and reference illuminant, both normalized to the same luminous power.
    
    Args:
        :spd:
            | ndarray or dict
            | If ndarray: single spectral power distribution.
            | If dict: dictionary with pre-computed parameters (using _tm30_process_spd()).
            |  required keys:
            |   'Rf','Rg','cct','duv','Sr','cri_type','xyzri','xyzrw',
            |   'hbinnrs','Rfi','Rfhi','Rcshi','Rhshi',
            |   'jabt_binned','jabr_binned',
            |   'nhbins','start_hue','normalize_gamut','normalized_chroma_ref'
            | see cri.spd_to_cri() for more info on parameters.
        :cri_type:
            | _CRI_TYPE_DEFAULT or str or dict, optional
            |   -'str: specifies dict with default cri model parameters 
            |     (for supported types, see luxpy.cri._CRI_DEFAULTS['cri_types'])
            |   - dict: user defined model parameters 
            |     (see e.g. luxpy.cri._CRI_DEFAULTS['cierf'] 
            |     for required structure)
            | Note that any non-None input arguments (in kwargs) 
            | to the function will override default values in cri_type dict.
        :axh: 
            | None, optional
            | If None: create new figure with single axes, else plot on specified axes.   
        :font_size:
            | _TM30_FONT_SIZE, optional
            | Font size of text, axis labels and axis values.
        :kwargs:
            | Additional optional keyword arguments, 
            | the same as in cri.spd_to_cri()
            
    Returns:
        :axh: 
            | handle to figure axes.
        :data:
            | dictionary with required parameters for plotting functions.  
  
    """

    data = _tm30_process_spd(spd, cri_type = 'ies-tm30',**kwargs)
    
    # Normalize Sr to same luminous power as spd:
    Phiv_spd = spd_to_power(data['spd'], ptype = 'pu', cieobs = data['cri_type']['cieobs']['cct'])
    #Phiv_Sr = spd_to_power(data['Sr'], ptype = 'pu', cieobs = data['cri_type']['cieobs']['cct'])
    data['Sr'] = spd_normalize(data['Sr'], norm_type = 'pu', norm_f = Phiv_spd, cieobs = data['cri_type']['cieobs']['cct'])
    
    # Plot test and ref SPDs:
    if axh is None:
        fig, axh = plt.subplots(nrows = 1, ncols = 1)
    axh.plot(data['Sr'][0,:], data['Sr'][1,:],'k-', label = 'Reference')
    axh.plot(data['spd'][0,:], data['spd'][1,:],'r-', label = 'Test')
    axh.set_xlabel('Wavelength (nm)', fontsize = font_size)
    axh.set_ylabel('Radiant power\n(Equal Luminous Flux)', fontsize = font_size)
    axh.set_xlim([360,830]) 
    axh.set_yticklabels([])
    axh.legend(loc = 'upper right', fontsize = font_size)
    
    return axh, data