# return values are 2-D (N,3) array scaled and interpolated. bar = ryfiles.loadColumnTextFile('data/colourcoordinates/ciexyz31_1.txt', abscissaOut=wavelength, loadCol=[1,2,3], comment='%', delimiter=',', abscissaScale=1e-3) ## ------------------------ sources ------------------------------------------ #build a 2-D array with the source radiance values, where each column #represents a different source. Wavelength extends along rows. #Spectral interval for all source spectra is the same, which is 'wavelength' #Blackbody radiance spectra are calculated at the required wavelength intervals #Data read from files are interpolated to the required wavelength intervals #Use np.hstack to stack columns horizontally. sources = ryfiles.loadColumnTextFile('data/colourcoordinates/fluorescent.txt', abscissaOut=wavelength,comment='%', normalize=1).reshape(-1,1) sources = np.hstack((sources, ryplanck.planckel(wavelength,5900).reshape(-1,1))) sources = np.hstack((sources, ryplanck.planckel(wavelength,2850).reshape(-1,1))) sources = np.hstack((sources, ryfiles.loadColumnTextFile( 'data/colourcoordinates/LowPressureSodiumLamp.txt', abscissaOut=wavelength, comment='%', normalize=1).reshape(-1,1))) #label sources in order of appearance sourcesTxt=['Fluorescent', 'Planck 5900 K', 'Planck 2850 K', 'Sodium'] #normalize the source data (along axis-0, which is along columns) #this is not really necessary for CIE xy calc, which normalizes itself. #It is however useful for plotting the curves. sources /= np.max(sources,axis=0) ##------------------------- sample data ---------------------------------------- # read space separated file containing wavelength in um, then sample data. # select the samples to be read in and then load all in one call!
def lllPhotonrates(self, specranges=None ): """Calculate the approximate photon rate radiance for low light conditions The colour temperature of various sources are used to predict the photon flux. The calculation uses the colour temperature of the source and the ratio of real low light luminance to the luminance of a Planck radiator at the same temperature as the source colour temperature. This procedure critically depends on the sources' spectral radiance in the various different spectral bands. For this calculation the approach is taken that for natural scenes the spectral shape can be modelled by a Planck curve at the appropriate colour temperature. The steps followed are as follows: 1. Calculate the photon rate for the scene at the appropriate colour temperature, spectrally weighted by the eye's luminous efficiency response. Do this for photopic and scotopic vision. 2. Weigh the photopic and scotopic photon rates according to illumination level 3. Determine the ratio k of low light level scene illumination to photon irradiance. This factor k is calculated in the visual band, but then applied to scale the other spectral bands by the same scale. 4. Use Planck radiation at the appropriate colour temperature to calculate the radiance in any spectral band, but then scale the value with the factor k. The specranges format is as follows:: numpts = 300 specranges = { key: [wavelength vector, response vector ], 'VIS': [np.linspace(0.43,0.69,numpts).reshape(-1,1),np.ones((numpts,1)) ], 'NIR': [np.linspace(0.7, 0.9,numpts).reshape(-1,1),np.ones((numpts,1)) ], 'SWIR': [np.linspace(1.0, 1.7,numpts).reshape(-1,1),np.ones((numpts,1)) ], 'MWIR': [np.linspace(3.6,4.9,numpts).reshape(-1,1),np.ones((numpts,1)) ], 'LWIR': [np.linspace(7.5,10,numpts).reshape(-1,1),np.ones((numpts,1)) ], } If specranges is None, the predefined values are used, as shown above. The function returns scene radiance in a Pandas datatable with the following columns:: u'Irradiance-lm/m2', u'ColourTemp', u'FracPhotop', u'k', u'Radiance-q/(s.m2.sr)-NIR', u'Radiance-q/(s.m2.sr)-VIS', u'Radiance-q/(s.m2.sr)-MWIR', u'Radiance-q/(s.m2.sr)-LWIR', u'Radiance-q/(s.m2.sr)-SWIR' and rows with the following index:: u'Overcast night', u'Star light', u'Quarter moon', u'Full moon', u'Deep twilight', u'Twilight', u'Very dark day', u'Overcast day', u'Full sky light', u'Sun light' Args: | specranges (dictionary): User-supplied dictionary defining the spectral | responses. See the dictionary format above and an example in the code. Returns: | Pandas dataframe with radiance in the specified spectral bands. Raises: | No exception is raised. """ self.dfPhotRates = pd.DataFrame(self.lllux).transpose() self.dfPhotRates.columns = ['Irradiance-lm/m2','ColourTemp','FracPhotop'] self.dfPhotRates.sort_values(by='Irradiance-lm/m2',inplace=True) wl = np.linspace(0.3, 0.8, 100) photLumEff,wl = ryutils.luminousEfficiency(vlamtype='photopic', wavelen=wl) scotLumEff,wl = ryutils.luminousEfficiency(vlamtype='scotopic', wavelen=wl) self.dfPhotRates['k'] = (self.dfPhotRates['Irradiance-lm/m2']) / (\ self.dfPhotRates['FracPhotop'] * 683 * np.trapz(photLumEff.reshape(-1,1) * \ ryplanck.planckel(wl, self.dfPhotRates['ColourTemp']),wl, axis=0)\ + \ (1-self.dfPhotRates['FracPhotop']) * 1700 * np.trapz(scotLumEff.reshape(-1,1) * \ ryplanck.planckel(wl, self.dfPhotRates['ColourTemp']),wl, axis=0)) \ if specranges is None: numpts = 300 specranges = { 'VIS': [np.linspace(0.43,0.69,numpts).reshape(-1,1),np.ones((numpts,1)) ], 'NIR': [np.linspace(0.7, 0.9,numpts).reshape(-1,1),np.ones((numpts,1)) ], 'SWIR': [np.linspace(1.0, 1.7,numpts).reshape(-1,1),np.ones((numpts,1)) ], 'MWIR': [np.linspace(3.6,4.9,numpts).reshape(-1,1),np.ones((numpts,1)) ], 'LWIR': [np.linspace(7.5,10,numpts).reshape(-1,1),np.ones((numpts,1)) ], } for specrange in specranges.keys(): wlsr = specranges[specrange][0] self.dfPhotRates['Radiance-q/(s.m2.sr)-{}'.format(specrange)] = (self.dfPhotRates['k'] /np.pi ) * \ np.trapz(specranges[specrange][1] * ryplanck.planck(wlsr, self.dfPhotRates['ColourTemp'],'ql'),wlsr, axis=0) self.dfPhotRates.sort_values(by='Irradiance-lm/m2',inplace=True) return self.dfPhotRates
# return values are 2-D (N,3) array scaled and interpolated. bar = ryfiles.loadColumnTextFile('data/colourcoordinates/ciexyz31_1.txt', abscissaOut=wavelength, loadCol=[1,2,3], comment='%', delimiter=',', abscissaScale=1e-3) ## ------------------------ sources ------------------------------------------ #build a 2-D array with the source radiance values, where each column #represents a different source. Wavelength extends along rows. #Spectral interval for all source spectra is the same, which is 'wavelength' #Blackbody radiance spectra are calculated at the required wavelength intervals #Data read from files are interpolated to the required wavelength intervals #Use numpy.hstack to stack columns horizontally. sources = ryfiles.loadColumnTextFile('data/colourcoordinates/fluorescent.txt', abscissaOut=wavelength,comment='%', normalize=1) sources = numpy.hstack((sources, ryplanck.planckel(wavelength,5900))) sources = numpy.hstack((sources, ryplanck.planckel(wavelength,2850))) sources = numpy.hstack((sources, ryfiles.loadColumnTextFile( 'data/colourcoordinates/LowPressureSodiumLamp.txt', abscissaOut=wavelength, comment='%', normalize=1))) #label sources in order of appearance sourcesTxt=['Fluorescent', 'Planck 5900 K', 'Planck 2850 K', 'Sodium'] #normalize the source data (along axis-0, which is along columns) #this is not really necessary for CIE xy calc, which normalizes itself. #It is however useful for plotting the curves. sources /= numpy.max(sources,axis=0) ##------------------------- sample data ---------------------------------------- # read space separated file containing wavelength in um, then sample data. # select the samples to be read in and then load all in one call!
# here we simply multiply the responsivity and spectral filter spectral curves. # this is a silly example, but demonstrates the spectral integral. filtreps = responsivities * filters parameterTxt = [str(s)+' & '+str(f) for (s, f) in zip(params, filterExp) ] ##------------------------- plot filtered detector ------------------------------ smpleplt = ryplot.Plotter(1, 1, 1) smpleplt.plot(1, wavelength, filtreps, "Filtered Detector Responsivity", r'Wavelength $\mu$m',\ r'Responsivity', \ ['r-', 'g-', 'y-','g--', 'b-', 'm-'],label=parameterTxt,legendAlpha=0.5) smpleplt.saveFig('filtrespVar'+figtype) ##++++++++++++++++++++ demo the demo effectivevalue ++++++++++++++++++++++++++++ #test and demo effective value function temperature = 5900 spectralBaseline = ryplanck.planckel(wavelength,temperature) # do for each detector in the above example for i in range(responsivities.shape[1]): effRespo = effectiveValue(wavelength, responsivities[:, i], spectralBaseline) print('Effective responsivity {0} of detector with parameters {1} ' 'and source temperature {2} K'.\ format(effRespo, params[i], temperature)) print(' ') ##++++++++++++++++++++ demo the absolute humidity function ++++++++++++++++++++++++++++ #http://rolfb.ch/tools/thtable.php?tmin=-25&tmax=50&tstep=5&hmin=10&hmax=100&hstep=10&acc=2&calculate=calculate # check absolute humidity function. temperature in C and humudity in g/m3 data=np.asarray([ [ 50 , 82.78 ] , [ 45 , 65.25 ] , [ 40 , 50.98 ] ,