def calcRadiance(LMAX, LMIN, QCALMAX, QCALMIN, path, QCAL, band): LMAX = float(LMAX) LMIN = float(LMIN) QCALMAX = float(QCALMAX) QCALMIN = float(QCALMIN) offset = (LMAX - LMIN) / (QCALMAX - QCALMIN) inraster_open = gdal.Open(path + QCAL) inraster_array = inraster_open.GetRasterBand(1).ReadAsArray() radiance = path + 'RadianceB' + str(band) + '.tif' # radiance = path+path[-22:-1]+'_B'+str(band)+'_radiance.tif' inraster_open = None ''' print 'Band'+str(band) print 'LMAX = '+str(LMAX) print 'LMIN = '+str(LMIN) print 'QCALMAX = '+str(QCALMAX) print 'QCALMIN = '+str(QCALMIN) print 'offset = '+str(offset) ''' outraster_array = (offset * (inraster_array - QCALMIN)) + LMIN outraster_array[(inraster_array == 0)] = -9999 #code improvement: is there a better way than the above line to take whatever the nodata value is and use that, vs assuming it's 0? radiance = raster.rasterfile(path + QCAL, radiance, outraster_array, gdal.GDT_Float32, -9999) return radiance
def calcBrightTemp(K1, K2, radiance, path, band): K1 = float(K1) K2 = float(K2) inraster_open = gdal.Open(radiance) inraster_array = inraster_open.GetRasterBand(1).ReadAsArray() filename_pref = os.path.basename(os.path.dirname(path)) BT = path + filename_pref + '_B' + str(band) + '_bt.tif' # BT = path+path[-22:-1]+'_B'+str(band)+'_bt.tif' inraster_open = None # if not inraster_array.all(): # print 'inraster_array empty' # sys.exit is_zero = (inraster_array <= 0) inraster_array[is_zero] = 1 outraster_array = (K2 / (np.log((K1 / inraster_array) + 1))) outraster_array[is_zero] = -9999 outraster_array[(inraster_array == -9999)] = -9999 #code improvement: is there a better way than the above line to take whatever the nodata value is and use that, vs assuming it's -9999? BrightTemp = raster.rasterfile(radiance, BT, outraster_array, gdal.GDT_Float32, -9999) return BrightTemp
def calcReflectance(solarDist, ESUN, solarElevation, radianceRaster, path, scaleFactor): # print 'entering reflectance fn' #Value for solar zenith is 90 degrees minus solar elevation (angle from horizon to the center of the sun) #http://landsathandbook.gsfc.nasa.gov/data_properties/prog_sect6_3.html #note: I'm not sure why the orig. author converts to solarZenith (an extra step) - you #can also keep solarElevation and use sin in the calculation solarZenith = ( (90.0 - (float(solarElevation))) * math.pi) / 180 #Converted from deg to rad (python takes angles in rad) solarDist = float(solarDist) ESUN = float(ESUN) # print radianceRaster radiance_open = gdal.Open(radianceRaster) radiance_array = radiance_open.GetRasterBand(1).ReadAsArray() # reflectance = path + 'ReflecB'+str(band)+'.tif' filename_pref = os.path.basename(os.path.dirname(path)) reflectance = path + filename_pref + '_B' + str(band) + '_refl.tif' radiance_open = None # print 'Band'+str(band) # print 'solarDist = '+str(solarDist) # #print 'solarDistSquared ='+str(math.pow(solarDist, 2)) # print 'ESUN = '+str(ESUN) # print 'solarZenith = '+str(solarZenith) outraster_array = (math.pi * radiance_array * math.pow(solarDist, 2)) / ( ESUN * math.cos(solarZenith)) * scaleFactor outraster_array[(radiance_array == -9999)] = -9999 #code improvement: is there a better way than the above line to take whatever the nodata value is and use that, vs assuming it's -9999? reflectance = raster.rasterfile(radianceRaster, reflectance, outraster_array, gdal.GDT_Float32, -9999) return reflectance
def LS8_calcReflectance(refl_mult, refl_add, solarElevation, path, QCAL): # print 'LS8_calcReflectance entered' # solarElevationRad = ( float(solarElevation) * math.pi ) / 180 #Converted from degr to rad (python takes angles in rad) refl_mult = float(refl_mult) refl_add = float(refl_add) inraster_open = gdal.Open(path + QCAL) inraster_array = inraster_open.GetRasterBand(1).ReadAsArray() filename_pref = os.path.basename(os.path.dirname(path)) reflectance = path + filename_pref + '_B' + str(band) + '_refl.tif' # reflectance = path+path[-22:-1]+'_B'+str(band)+'_refl.tif' inraster_open = None # print 'Band'+str(band) # print 'solarElevation (radians) = '+str(solarElevationRad) # print 'refl_mult = ' + str(refl_mult) # print 'refl_add = ' + str(refl_add) outraster_array = ((refl_mult * inraster_array) + refl_add) / (math.sin(solarElevationRad)) outraster_array[(inraster_array == 0)] = -9999 #code improvement: is there a better way than the above line to take whatever the nodata value is and use that, vs assuming it's -9999? reflectance = raster.rasterfile(path + QCAL, reflectance, outraster_array, gdal.GDT_Float32, -9999) return reflectance
def calcBrightTemp (K1, K2, radiance, path, band): K1 = float(K1) K2 = float(K2) inraster_open = gdal.Open(radiance) inraster_array = inraster_open.GetRasterBand(1).ReadAsArray() filename_pref = os.path.basename(os.path.dirname(path)) BT = path+filename_pref+'_B'+str(band)+'_bt.tif' # BT = path+path[-22:-1]+'_B'+str(band)+'_bt.tif' inraster_open = None # if not inraster_array.all(): # print 'inraster_array empty' # sys.exit is_zero = (inraster_array<=0) inraster_array[is_zero] = 1 outraster_array = (K2 / (np.log((K1/inraster_array) + 1))) outraster_array[is_zero] = -9999 outraster_array[(inraster_array==-9999)] = -9999 #code improvement: is there a better way than the above line to take whatever the nodata value is and use that, vs assuming it's -9999? BrightTemp = raster.rasterfile(radiance, BT, outraster_array, gdal.GDT_Float32, -9999) return BrightTemp
def calcReflectance(solarDist, ESUN, solarElevation, radianceRaster, path, scaleFactor): # print 'entering reflectance fn' #Value for solar zenith is 90 degrees minus solar elevation (angle from horizon to the center of the sun) #http://landsathandbook.gsfc.nasa.gov/data_properties/prog_sect6_3.html #note: I'm not sure why the orig. author converts to solarZenith (an extra step) - you #can also keep solarElevation and use sin in the calculation solarZenith = ((90.0 - (float(solarElevation)))*math.pi)/180 #Converted from deg to rad (python takes angles in rad) solarDist = float(solarDist) ESUN = float(ESUN) # print radianceRaster radiance_open = gdal.Open(radianceRaster) radiance_array = radiance_open.GetRasterBand(1).ReadAsArray() # reflectance = path + 'ReflecB'+str(band)+'.tif' filename_pref = os.path.basename(os.path.dirname(path)) reflectance = path+filename_pref+'_B'+str(band)+'_refl.tif' radiance_open = None # print 'Band'+str(band) # print 'solarDist = '+str(solarDist) # #print 'solarDistSquared ='+str(math.pow(solarDist, 2)) # print 'ESUN = '+str(ESUN) # print 'solarZenith = '+str(solarZenith) outraster_array = (math.pi * radiance_array * math.pow(solarDist, 2)) / (ESUN * math.cos(solarZenith)) * scaleFactor outraster_array[(radiance_array==-9999)] = -9999 #code improvement: is there a better way than the above line to take whatever the nodata value is and use that, vs assuming it's -9999? reflectance = raster.rasterfile(radianceRaster, reflectance, outraster_array, gdal.GDT_Float32, -9999) return reflectance
def calcRadiance (LMAX, LMIN, QCALMAX, QCALMIN, path, QCAL, band): LMAX = float(LMAX) LMIN = float(LMIN) QCALMAX = float(QCALMAX) QCALMIN = float(QCALMIN) offset = (LMAX - LMIN)/(QCALMAX-QCALMIN) inraster_open = gdal.Open(path+QCAL) inraster_array = inraster_open.GetRasterBand(1).ReadAsArray() radiance = path + 'RadianceB'+str(band)+'.tif' # radiance = path+path[-22:-1]+'_B'+str(band)+'_radiance.tif' inraster_open = None ''' print 'Band'+str(band) print 'LMAX = '+str(LMAX) print 'LMIN = '+str(LMIN) print 'QCALMAX = '+str(QCALMAX) print 'QCALMIN = '+str(QCALMIN) print 'offset = '+str(offset) ''' outraster_array = (offset * (inraster_array-QCALMIN)) + LMIN outraster_array[(inraster_array==0)] = -9999 #code improvement: is there a better way than the above line to take whatever the nodata value is and use that, vs assuming it's 0? radiance = raster.rasterfile(path+QCAL, radiance, outraster_array, gdal.GDT_Float32, -9999) return radiance
def LS8_calcReflectance(refl_mult, refl_add, solarElevation, path, QCAL): # print 'LS8_calcReflectance entered' # solarElevationRad = (float(solarElevation)*math.pi)/180 #Converted from degr to rad (python takes angles in rad) refl_mult = float(refl_mult) refl_add = float(refl_add) inraster_open = gdal.Open(path+QCAL) inraster_array = inraster_open.GetRasterBand(1).ReadAsArray() filename_pref = os.path.basename(os.path.dirname(path)) reflectance = path+filename_pref+'_B'+str(band)+'_refl.tif' # reflectance = path+path[-22:-1]+'_B'+str(band)+'_refl.tif' inraster_open = None # print 'Band'+str(band) # print 'solarElevation (radians) = '+str(solarElevationRad) # print 'refl_mult = ' + str(refl_mult) # print 'refl_add = ' + str(refl_add) outraster_array = ((refl_mult * inraster_array) + refl_add) / (math.sin(solarElevationRad)) outraster_array[(inraster_array==0)] = -9999 #code improvement: is there a better way than the above line to take whatever the nodata value is and use that, vs assuming it's -9999? reflectance = raster.rasterfile(path+QCAL, reflectance, outraster_array, gdal.GDT_Float32, -9999) return reflectance
def LS8_calcRadiance (rad_mult, rad_add, path, QCAL, band): rad_mult = float(rad_mult) rad_add = float(rad_add) inraster_open = gdal.Open(path + QCAL) inraster_array = inraster_open.GetRasterBand(1).ReadAsArray() radiance = path + 'RadianceB'+str(band)+'.tif' inraster_open = None outraster_array = ((rad_mult * inraster_array) + rad_add) outraster_array[(inraster_array==0)] = -9999 #code improvement: is there a better way than the above line to take whatever the nodata value is and use that, vs assuming it's 0? radiance = raster.rasterfile(path+QCAL, radiance, outraster_array, gdal.GDT_Float32, -9999) return radiance
def LS8_calcRadiance(rad_mult, rad_add, path, QCAL, band): rad_mult = float(rad_mult) rad_add = float(rad_add) inraster_open = gdal.Open(path + QCAL) inraster_array = inraster_open.GetRasterBand(1).ReadAsArray() radiance = path + 'RadianceB' + str(band) + '.tif' inraster_open = None outraster_array = ((rad_mult * inraster_array) + rad_add) outraster_array[(inraster_array == 0)] = -9999 #code improvement: is there a better way than the above line to take whatever the nodata value is and use that, vs assuming it's 0? radiance = raster.rasterfile(path + QCAL, radiance, outraster_array, gdal.GDT_Float32, -9999) return radiance