예제 #1
0
	def test_warp1(self):
		burnArea='burnt_area_verhegghenetal2016_roadless_class4.tif' # in m, small
		refImage='ecozone_stratification_2_emissions_factors_int16_0.tif' # in lat long, very large

		rasterIN=carbEFObj.raster(self.path, burnArea,'exception')
		outType=rasterIN.parameters['dataType']
		refRaster=carbEFObj.raster(self.path, refImage, 'activity')
		refNS=refRaster.parameters['ns']
		refNL=refRaster.parameters['nl']
		refProjection=refRaster.parameters['projection']
		refGeotransform=refRaster.parameters['geotransform']

		warped = carbEFUtil.rasterAlign(self.path, 'warpOut.tif', outType=outType, refNS=refNS, refNL=refNL, refProjection=refProjection, refGeotransform=refGeotransform, rasterIN=rasterIN, resampleType='near')
		self.assertIsNotNone(warped)
예제 #2
0
	def test_parametersValues(self):
		activity = carbEFObj.raster(self.path, self.fname, 'activity')
		ok = True
		for ii in ['ns','nl','nb','dataType','geotransform','projection']:
			test = activity.parameters.get(ii, False)
			if test is None: # if any value set to None, test fails
				ok = False
		self.assertTrue(ok)
예제 #3
0
	def test_parametersExist(self):
		activity = carbEFObj.raster(self.path, self.fname, 'activity')
		ok=True
		for ii in ['ns','nl','nb','dataType','geotransform','projection']:
			test = activity.parameters.get(ii, False)
			if not test: # ok set to False if key not found
				ok = False
		self.assertTrue(ok)
예제 #4
0
def rasterAlign(outPath, outFname, outType, refNS, refNL, refProjection, refGeotransform, rasterIN, resampleType='near'):
	"""lit un objet raster, cree un fichier warped, avec les memes proprietes, 
		puis le transforme en objet raster.
	"""

	# check type:
	if not isinstance(rasterIN, carbEFObj.raster):
		raise("carbEFObj.rasterWarp.__init__: rasterIN must be an instance of raster.")

	ul = carbEFCoord.pixelToMap(0, 0, refGeotransform)
	lr = carbEFCoord.pixelToMap(refNS, refNL, refGeotransform)
	outputBounds = ( min(ul[0], lr[0]), min(ul[1],lr[1]), max(ul[0],lr[0]), max(ul[1],lr[1]) )
	inDatatype = rasterIN.parameters['dataType']
	role = rasterIN.role

	imgToAlign = os.path.join(rasterIN.path, rasterIN.fname)
	aligned = os.path.join(outPath, outFname)

	try:
		if outType is not None:
			print 'Warp casting {} to data type {}'.format(imgToAlign, outType)
			gdal.Warp(aligned, imgToAlign, dstSRS = refProjection, dstNodata = 0,\
					outputBounds = outputBounds, outputBoundsSRS = refProjection,\
					xRes=abs(refGeotransform[1]), yRes=abs(refGeotransform[5]), \
					outputType = outType,\
					resampleAlg = resampleType, format='Gtiff', options=['compress=lzw','bigtiff=YES'])

		else:
			print 'Warp keeps {} original data type as input data type {}'.format(imgToAlign, inDatatype)
			gdal.Warp(aligned, imgToAlign, dstSRS=proj, dstNodata = 0,\
					outputBounds=outputBounds, outputBoundsSRS=refProjection,\
					xRes=abs(refGeotransform[1]), yRes=abs(refGeotransform[5]),\
					resampleAlg=resampleType, format='Gtiff', options=['compress=lzw','bigtiff=YES'])
	except:
		raise("cabEFUtil.rasterAlign: error when warping images")

	alignedRaster = carbEFObj.raster(outPath, outFname, role)

	return alignedRaster
예제 #5
0
	def test_fileToles5(self):
		disag = carbEFObj.raster(self.path, self.fname, 'disaggregation')
		self.assertIsNotNone(disag)
예제 #6
0
	def test_fileRoles4(self):
		exception = carbEFObj.raster(self.path, self.fname, 'exception')
		self.assertIsNotNone(exception)
예제 #7
0
	def test_fileRoles3(self):
		biomass = carbEFObj.raster(self.path, self.fname, 'biomass')
		self.assertIsNotNone(biomass)
예제 #8
0
	def test_fileRoles2(self):
		activity = carbEFObj.raster(self.path, self.fname, 'activity')
		self.assertIsNotNone(activity)