예제 #1
0
        def plot_into_subplot(self, subplot):


            res = pyprosail.run(1.5, 40, 8, 0, 0.1, 0.009, 1, 3, 0.01, 30, 0, 10, 0, pyprosail.Planophile)

            data_series = ProSAILSeries("ProSAIL Output", xdata=res[:,0],
                                              ydata=res[:,1])

            subplot.add_data_series(data_series)

            return True
예제 #2
0
    def update_plot(self, evnt):
        """
        Event handler for frequency slider change events.
        """
        ewt = self.sliders['EWT'].GetValue()
        chloro = self.sliders['Chloro'].GetValue()
        carot = self.sliders['Carot'].GetValue()
        N = self.sliders['N'].GetValue()


        res = pyprosail.run(N, chloro, carot, 0, ewt, 0.009, 1, 3, 0.01, 30, 0, 10, 0, pyprosail.Planophile)
        
        #change the data in the series object
        self.series.set_xy_data(xdata=res[:,0], ydata=res[:,1])
        
        #draw our changes on the display
        self.series.update()
예제 #3
0
def GetReflectance(N, chloro, caroten, brown, EWT, LMA, psoil, LAI, hot_spot, solar_zenith, solar_azimuth, view_zenith, view_azimuth, LIDF):
	spectrum = pyprosail.run(N, chloro, caroten, brown, EWT, LMA, psoil, LAI, hot_spot, solar_zenith, solar_azimuth, view_zenith, view_azimuth, LIDF)
		#spectrum = pyprosail.run(1.5, chloro, 8, 0, 0.01, .009, 1, LAI, 0.01, 30, 0, 10, 0, pyprosail.Planophile)
		#spectrum = pyprosail.run(1.5, chloro, 8, 0, 0.01, .009, 1, 3, 0.01, 30, 0, 10, 0, pyprosail.Planophile)
	'''
	pyprosail.run arguments
	N - Structure co-efficient
	chloro - Chlorophyll content (ug per cm^2)
	caroten - Carotenoid content (ug per cm^2)
	brown - Brown pigment content (arbitrary units)
	EWT - Equivalent Water Thickness (cm)
	LMA - Leaf Mass per unit area (g per cm^2)
	soil_reflectance - Soil reflectance: wet soil = 0, dry soil = 1
	LAI - Leaf Area Index
	hot_spot - Hot spot parameter
	solar_zenith - Solar zenith angle (degrees)
	solar_azimuth - Solar azimuth angle (degrees)
	view_zenith - View zenith angle (degrees)
	view_azimuth - View azimuth angle (degrees)
	LIDF - Leaf distibution function parameter(s) (see below)
	'''
	return spectrum
예제 #4
0
def electrons_in_pixel(wavelength_qe, b_qe, g_qe, r_qe, nir_qe, integration_time, const, detector_pixel_width, focal_length, diameter_obscuration, diameter_apreture, scene_albedo, atmospheric_transmission, gain, gain_step, hr_from_noon, latitude, bit_depth, full_well_e, dark_current_e_per_s, read_noise_e, temperature, dark_noise_2x_temperature, dark_noise_measure_temperature):
	pixel_e = []
	pixel_e_per_10nm = numpy.zeros((len(wavelength_qe),4))
	solar_radiance = numpy.zeros(len(wavelength_qe))

	# pixel_etendue_center_field
	# detector_pixel_width = 0.009 # mm
	focal_length = 1368 # mm
	diameter_obscuration = 29.0 # mm
	diameter_apreture = 89.0 # mm
	area_of_optics = ( diameter_apreture ** 2 - diameter_obscuration ** 2 ) / 4 * math.pi
	solid_angle_FOV = ( numpy.arctan( detector_pixel_width / ( 2 * focal_length ) ) * 2 ) ** 2 # steradians
	pixel_etendue_center_field = solid_angle_FOV * area_of_optics / 100 # sr-cm^2
	print 'pixel etendue, center of field: \t', pixel_etendue_center_field, ' sr-cm2'

	gain_multiplier = ( 10 ** ( gain_step / 20 ) ) ** gain
	print 'gain: \t\t\t\t', gain, '\ngain multiplier: \t\t', gain_multiplier

	optics_transmission = .9 # 0-1
	for w in range(0,len(wavelength_qe)):
		source_spectral_radiance = solar_blackbody(wavelength_qe[w]) * ( wavelength_qe[1] - wavelength_qe[0] ) * ( const[1] / const[2] ) ** 2 # W/cm2/sr/10nm
		spectral_radiance = source_spectral_radiance * optics_transmission * 1000.0 # mW/cm2-sr-10nm
		total_photon_power = spectral_radiance * pixel_etendue_center_field # mW/10nm
		power_per_photon = const[3] * const[0] / ( wavelength_qe[w] *1e-6) * 1000 # mW/photon/sec or mJ/photon
		photon_flux = total_photon_power / power_per_photon # photons/sec/10nm
		reflectance = crop_reflectance_vector(pyprosail.run(N, chloro, caroten, brown, EWT, LMA, psoil, LAI, hot_spot, solar_zenith, solar_azimuth, view_zenith, view_azimuth, LIDF), wavelength_qe[w])
		replaced_with_prosail = atmospheric_transmission * reflectance * numpy.cos( latitude * math.pi / 180.0 ) * numpy.cos( math.pi * hr_from_noon / 12.0 ) # all the reflectance modeling that PROSAIL does; careful here! Prosail may use latitude and LToD to calculate reflectance only and not take into account illumination
		photons_at_pixel = photon_flux * ( integration_time / 1000000.0 ) * replaced_with_prosail # photons/10nm
		# print 'photons in the pixel: ' + str(photons_at_pixel)
		# print b_qe
		pixel_e_per_10nm[w,0] = b_qe[w] * photons_at_pixel
		pixel_e_per_10nm[w,1] = g_qe[w] * photons_at_pixel
		pixel_e_per_10nm[w,2] = r_qe[w] * photons_at_pixel
		pixel_e_per_10nm[w,3] = nir_qe[w] * photons_at_pixel
	sum_e = numpy.zeros(4)
	for i in range(0, len(sum_e)):
		sum_e[i] = sum(pixel_e_per_10nm[:,i])
	# sum_e = sum(pixel_e_per_10nm[:,0])
	# sum_e = sum(pixel_e_per_10nm[:,1])
	# sum_e = sum(pixel_e_per_10nm[:,2])
	# sum_e = sum(pixel_e_per_10nm[:,3])
	int_sum_e = [int(f) for f in sum_e]
	print "b,g,r,n e-: \t\t\t", int_sum_e
	# DN = sum_e * gain_multiplier	
	DN = e_to_DN(sum_e * gain_multiplier, full_well_e, bit_depth)
	int_DN = [int(f) for f in DN]
	print "b,g,r,n DN: \t\t\t", int_DN
	# print "green e-: \t", int(sum_g)
	# print "red e-: \t", int(sum_r)
	# print "NIR e-: \t", int(sum_n)

	max_b = max(pixel_e_per_10nm[:,0])
	max_g = max(pixel_e_per_10nm[:,1])
	max_r = max(pixel_e_per_10nm[:,2])
	max_n = max(pixel_e_per_10nm[:,3])
	max_y = max(max_b, max_g, max_r, max_n)
	'''
	fit_plotting(wavelength_qe, pixel_e_per_10nm[:,0], 'photons at pixel', 'wavelength [um]', 'blue photons', 'b-', max_y)
	fit_plotting(wavelength_qe, pixel_e_per_10nm[:,1], 'photons at pixel', 'wavelength [um]', 'green photons', 'g-', max_y)
	fit_plotting(wavelength_qe, pixel_e_per_10nm[:,2], 'photons at pixel', 'wavelength [um]', 'red photons', 'r-', max_y)
	fit_plotting(wavelength_qe, pixel_e_per_10nm[:,3], 'photons at pixel', 'wavelength [um]', 'NIR photons', 'k-', max_y)
	plt.show()
	'''

	# pixel_e_total = numpy.asarray()
	# max_y = max(solar_radiance)
	# fit_plotting(wavelength_qe, solar_radiance, 'solar radiance', 'wavelength [um]', 'W/cm2/sr/10nm', 'b-', max_y)
	# plt.show()
	descretization_noise_e = ( full_well_e / gain_multiplier / 2 ** bit_depth ) / ( 12 ** 0.5 )
	print 'Descretization Noise, e-: \t', descretization_noise_e
	dark_noise = dark_current_e_per_s * ( integration_time / 1000000.0 ) * 2 ** ( ( temperature -dark_noise_measure_temperature ) / dark_noise_2x_temperature )
	print 'Dark Noise, e-: \t\t', dark_noise ** 0.5
	print 'Read Noise, e-: \t\t', read_noise_e
	print 'Shot Noise, e-: \t\t', sum_e ** 0.5
	noise_e = ( sum_e + dark_noise + descretization_noise_e ** 2 + read_noise_e ** 2 ) ** 0.5 # root-sum-squared noise
	noise_DN = e_to_DN(noise_e * gain_multiplier, full_well_e, bit_depth)
	print "b,g,r,n noise, DN: \t\t", noise_DN
	bar_plot_DN(DN, noise_DN)
	snr_DN = DN / noise_DN
	plt.annotate('SNR = ' + str(round(snr_DN[0],2)), xy=(0.25, 2), xytext=(0.25, 1),)
	plt.annotate('SNR = ' + str(round(snr_DN[1],2)), xy=(0.25, 2), xytext=(1.25, 1),)
	plt.annotate('SNR = ' + str(round(snr_DN[2],2)), xy=(0.25, 2), xytext=(2.25, 1),)
	plt.annotate('SNR = ' + str(round(snr_DN[3],2)), xy=(0.25, 2), xytext=(3.25, 1),)
	snr_DN = DN / noise_DN
	# bar_plot_SNR(snr_DN, 0)
	print "b,g,r,n SNR, DN: \t\t", snr_DN
	
	name = 'NDVI'
	index_DN = get_index(name, DN)
	index_noise = get_index_noise(name, noise_DN, index_DN, DN) # must send the standard deviation
	
	index_ann = name + ': ' + str(round(index_DN,3))
	index_noise_ann = name + ' noise: ' + str(round(index_noise,3))
	index_snr_ann = name + ' SNR: ' + str(round(index_DN / index_noise,2))
	print index_ann
	print index_noise_ann
	print index_snr_ann
	plt.annotate( index_ann + '\n' + index_noise_ann + '\n' + index_snr_ann, xy=(0.25, 2), xytext=(0.1, 100),)
	plt.savefig('NDVI' + '_' + str(chloro) + '_' + str(LAI) + '_test.png')
	plt.show()
	return
def GetReflectance(N, chloro, caroten, brown, EWT, LMA, psoil, LAI, hot_spot, solar_zenith, solar_azimuth, view_zenith, view_azimuth, LIDF):
	spectrum = pyprosail.run(N, chloro, caroten, brown, EWT, LMA, psoil, LAI, hot_spot, solar_zenith, solar_azimuth, view_zenith, view_azimuth, LIDF)
		#spectrum = pyprosail.run(1.5, chloro, 8, 0, 0.01, .009, 1, LAI, 0.01, 30, 0, 10, 0, pyprosail.Planophile)
		#spectrum = pyprosail.run(1.5, chloro, 8, 0, 0.01, .009, 1, 3, 0.01, 30, 0, 10, 0, pyprosail.Planophile)
	return spectrum
예제 #6
0
### ITERATE PROSAIL MODELLING FOR EACH PIXEL IN THE DATA FILE. IT READS THE LAI, CHLORO AND EWT TRAIT COMBINATIONS FROM THE FILE ###
### GENERATES SPECTRA USING PROSAIL. COMPARES WITH THE ACTUAL SPECTRA FROM THE SENTINEL-2 SCENCE USING SPECTRAL ANGLE MAPPER ###
### OPTIONS TO PLOT, PAUSE AND PRINT RESULTS ARE CURRENTLY COMMENTED ###
for irow in range(np.shape(data)[0]):
    rowvars = data.iloc[irow]
    if rowvars['flagsbyfiveall_1'] == 1:
        if rowvars['B8A_1'] > 0.1:
            LAI = rowvars['LAI_1']
            chloro = rowvars['CAB_1'] * rowvars['LAI_1']
            EWT = rowvars['CWC_1'] * rowvars['LAI_1']
            solar_zenith = rowvars['sun_zenith_1']
            solar_azimuth = rowvars['sun_azimuth_1']
            view_zenith = rowvars['view_zenith_mean_1']
            view_azimuth = rowvars['view_azimuth_mean_1']
            specout = pyprosail.run(N, chloro, caroten, brown, EWT, LMA, psoil,
                                    LAI, hot_spot, solar_zenith, solar_azimuth,
                                    view_zenith, view_azimuth, LIDF)
            #                print LAI, chloro, EWT, solar_zenith, solar_azimuth, view_zenith, view_azimuth
            s2out = pd.DataFrame(columns={
                'B2', 'B3', 'B4', 'B5', 'B6', 'B7', 'B8A', 'B11', 'B12'
            })
            s2outt = np.array([[520, 560, 665, 705, 740, 783, 865, 1610, 2190],
                               np.zeros(9)])
            for ib, band in enumerate(bandslist):
                weigthedvalue = 0
                bandname = 'S2A_SR_AV_' + band
                sumvalue = np.sum(s2sens[bandname])
                for ix in np.where(s2sens[bandname] != 0)[0]:
                    iwl = np.where(
                        (specout[:, 0] *
                         1000) == int(s2sens['SR_WL'].iloc[ix]))[0][0]
예제 #7
0
hot_spot = []
LAD_inclination = []
LAD_bimodality = []
s_az = []
s_za = []
v_az = []
v_za = []
nir_v = []
brightness = []

# set the wavelengths to use in calculating nir_v
red_wl = 0.680
nir_wl = 0.800

# set a dummy run of prosail to find the index for each wavelength
spec = pyprosail.run(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
red_band = np.where(spec[:,0] == red_wl)[0][0]
nir_band = np.where(spec[:,0] == nir_wl)[0][0]

# create a function to calculate nir_v
def calc_nir_v(red, nir):
    return nir * (nir - red) / (nir + red)
    
# and some functions to optimize linear and logistic fits for plotting later
def func_sigmoid(x, x0, k, a, c):
    return a / (1 + np.exp(-k * (x - x0))) + c

def func_linear(x, m, b):
    return m * x + b
    
def func_fit(x, y, function):
    s.atmos_profile = AtmosProfile.PredefinedType(atmos_profile[atmos_profile_ind[i]])
    s.aot550 = aot[i]
    geo.solar_a = solar_a[i]
    geo.solar_z = solar_z[i]
    geo.view_a = view_a[i]
    geo.view_z = view_z[i]
    s.geometry = geo
    ground_refl = ground_reflectance[ground_reflectance_ind[i]]
    
    # loop through each veg / wood / soil bundle
    for j in range(n_bundles):
        
        # load prosail and run the canopy model
        LIDF = (LAD_inclination[j], LAD_bimodality[j])
        spectrum = pyprosail.run(N[j], chloro[j], caroten[j],  
                    brown[j], EWT[j], LMA[j], soil_reflectance[j], 
                    LAI[j], hot_spot[j], solar_z_prosail, solar_a_prosail,
                    view_z_prosail, view_a_prosail, LIDF)

        # set the prosail modeled spectrum as ground spectrum in sixs                            
        s.ground_reflectance = ground_refl(spectrum)
    
        # generate the output spectrum
        if target_sensor == 'custom':
            wavelengths, results = run_sixs_params(s, wl, output_name = output_type)
        else:
            wavelengths, results = run_sixs_params(s, output_name = output_type)
    
        # convert output to array for ease of output
        results = np.asarray(results)
        
        # add the modeled spectrum to the output array
예제 #9
0
파일: test.py 프로젝트: tvmathieu/PyProSAIL
import pyprosail

res = pyprosail.run(1.5, 40, 8, 0, 0.01, 0.009, 1, 3, 0.01, 30, 0, 10, 0, pyprosail.Planophile)
print res