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)
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