2
« on: December 11, 2017, 11:45:32 PM »
Hi,
I am having a few problems with the below script. I am processing Multi-spectral data and an RGB data set of the same paddock. I run the project with one chunk (the first) as the multi-spectral and another chunk as RGB (as the second).
Once I get to the export stage of the script in the RGB section it always defaults to the multi-spectral chunk and exports it, in the script I have this doc.chunk = doc.chunks[1]
to change the chunk to the second in the project.
I am running this script as part of a workflow and I have tried running the script on both chunks and just on the multispec (in the workflow). But it seams to always seems to do the same thing.
Any help would be appreciated
chunk = PhotoScan.app.document.chunk
doc = PhotoScan.app.document
doc.chunk = doc.chunks[0]
#Mosaic Blend
chunk.buildOrthomosaic(surface=PhotoScan.ModelData, blending=PhotoScan.MosaicBlending, color_correction=False, projection=chunk.crs)
multispec = "multispec"
RGB = "RGB"
#NDVI Band
chunk.raster_transform.formula = ["(B4-B2)/(B4+B2)"]
chunk.raster_transform.calibrateRange()
chunk.raster_transform.enabled = True
chunk.exportOrthomosaic("/path/to/dir//SQM/" + multispec + "_NDVI_ortho_mosaic_blend.tif", image_format = PhotoScan.ImageFormatTIFF, raster_transform = PhotoScan.RasterTransformValue, write_world=True, write_alpha=False, tiff_big=False, white_background=True)
# Normalize Green band
chunk.raster_transform.formula = ["(B1)"]
chunk.raster_transform.calibrateRange()
greenMax = chunk.raster_transform.range[1]
chunk.raster_transform.formula = ["(B1)/(" + str(greenMax) + ")"]
chunk.raster_transform.calibrateRange()
chunk.exportOrthomosaic("/path/to/dir//SQM/" + multispec + "_Green_ortho_mosaic_blend.tif", image_format = PhotoScan.ImageFormatTIFF, raster_transform = PhotoScan.RasterTransformValue, write_world=True, write_alpha=False, tiff_big=False, white_background=True)
# Normalize Red band
chunk.raster_transform.formula = ["(B2)"]
chunk.raster_transform.calibrateRange()
redMax = chunk.raster_transform.range[1]
chunk.raster_transform.formula = ["(B2)/(" + str(redMax) + ")"]
chunk.raster_transform.calibrateRange()
chunk.exportOrthomosaic("/path/to/dir//SQM/" + multispec + "_Red_ortho_mosaic_blend.tif", image_format = PhotoScan.ImageFormatTIFF, raster_transform = PhotoScan.RasterTransformValue, write_world=True, write_alpha=False, tiff_big=False, white_background=True)
# Normalize Red Edge band
chunk.raster_transform.formula = ["(B3)"]
chunk.raster_transform.calibrateRange()
rededgeMax = chunk.raster_transform.range[1]
chunk.raster_transform.formula = ["(B3)/(" + str(rededgeMax) + ")"]
chunk.raster_transform.calibrateRange()
chunk.exportOrthomosaic("/path/to/dir//SQM/" + multispec + "_Rededge_ortho_mosaic_blend.tif", image_format = PhotoScan.ImageFormatTIFF, raster_transform = PhotoScan.RasterTransformValue, write_world=True, write_alpha=False, tiff_big=False, white_background=True)
# Normalize NIR band
chunk.raster_transform.formula = ["(B4)"]
chunk.raster_transform.calibrateRange()
NIRMax = chunk.raster_transform.range[1]
chunk.raster_transform.formula = ["(B4)/(" + str(NIRMax) + ")"]
chunk.raster_transform.calibrateRange()
chunk.exportOrthomosaic("/path/to/dir//SQM/" + multispec + "_NIR_ortho_mosaic_blend.tif", image_format = PhotoScan.ImageFormatTIFF, raster_transform = PhotoScan.RasterTransformValue, write_world=True, write_alpha=False, tiff_big=False, white_background=True)
# Compute normalized WDVI (Green)
chunk.raster_transform.formula = ["(B4)"]
chunk.raster_transform.calibrateRange()
nirMax = chunk.raster_transform.range[1]
chunk.raster_transform.reset()
chunk.raster_transform.formula = ["(B4 / (" + str(nirMax) + ")) - (1.5 * (B1 / " + str(greenMax) + "))"]
chunk.raster_transform.calibrateRange()
chunk.exportOrthomosaic("/path/to/dir//SQM/" + multispec + "_WDVI_Green_ortho_mosaic_blend.tif", image_format = PhotoScan.ImageFormatTIFF, raster_transform = PhotoScan.RasterTransformValue, write_world=True, write_alpha=False, tiff_big=False, white_background=True)
#Average Blend
doc.chunk = doc.chunks[0]
chunk.buildOrthomosaic(surface=PhotoScan.ModelData, blending=PhotoScan.AverageBlending, color_correction=False, projection=chunk.crs)
#NDVI Band
chunk.raster_transform.formula = ["(B4-B2)/(B4+B2)"]
chunk.raster_transform.calibrateRange()
chunk.raster_transform.enabled = True
chunk.exportOrthomosaic("/path/to/dir//SQM/" + multispec + "_NDVI_ortho_average_blend.tif", image_format = PhotoScan.ImageFormatTIFF, raster_transform = PhotoScan.RasterTransformValue, write_world=True, write_alpha=False, tiff_big=False, white_background=True)
# Normalize Green band
chunk.raster_transform.formula = ["(B1)"]
chunk.raster_transform.calibrateRange()
greenMax = chunk.raster_transform.range[1]
chunk.raster_transform.formula = ["(B1)/(" + str(greenMax) + ")"]
chunk.raster_transform.calibrateRange()
chunk.exportOrthomosaic("/path/to/dir//SQM/" + multispec + "_Green_ortho_average_blend.tif", image_format = PhotoScan.ImageFormatTIFF, raster_transform = PhotoScan.RasterTransformValue, write_world=True, write_alpha=False, tiff_big=False, white_background=True)
# Normalize Red band
chunk.raster_transform.formula = ["(B2)"]
chunk.raster_transform.calibrateRange()
redMax = chunk.raster_transform.range[1]
chunk.raster_transform.formula = ["(B2)/(" + str(redMax) + ")"]
chunk.raster_transform.calibrateRange()
chunk.exportOrthomosaic("/path/to/dir//SQM/" + multispec + "_Red_ortho_average_blend.tif", image_format = PhotoScan.ImageFormatTIFF, raster_transform = PhotoScan.RasterTransformValue, write_world=True, write_alpha=False, tiff_big=False, white_background=True)
# Normalize Red Edge band
chunk.raster_transform.formula = ["(B3)"]
chunk.raster_transform.calibrateRange()
rededgeMax = chunk.raster_transform.range[1]
chunk.raster_transform.formula = ["(B3)/(" + str(rededgeMax) + ")"]
chunk.raster_transform.calibrateRange()
chunk.exportOrthomosaic("/path/to/dir//SQM/" + multispec + "_Rededge_ortho_average_blend.tif", image_format = PhotoScan.ImageFormatTIFF, raster_transform = PhotoScan.RasterTransformValue, write_world=True, write_alpha=False, tiff_big=False, white_background=True)
# Normalize NIR band
chunk.raster_transform.formula = ["(B4)"]
chunk.raster_transform.calibrateRange()
NIRMax = chunk.raster_transform.range[1]
chunk.raster_transform.formula = ["(B4)/(" + str(NIRMax) + ")"]
chunk.raster_transform.calibrateRange()
chunk.exportOrthomosaic("/path/to/dir//SQM/" + multispec + "_NIR_ortho_average_blend.tif", image_format = PhotoScan.ImageFormatTIFF, raster_transform = PhotoScan.RasterTransformValue, write_world=True, write_alpha=False, tiff_big=False, white_background=True)
# Compute normalized WDVI (Green)
chunk.raster_transform.formula = ["(B4)"]
chunk.raster_transform.calibrateRange()
nirMax = chunk.raster_transform.range[1]
chunk.raster_transform.reset()
chunk.raster_transform.formula = ["(B4 / (" + str(nirMax) + ")) - (1.5 * (B1 / " + str(greenMax) + "))"]
chunk.raster_transform.calibrateRange()
chunk.exportOrthomosaic("/path/to/dir//SQM/" + multispec + "_WDVI_Green_ortho_average_blend.tif", image_format = PhotoScan.ImageFormatTIFF, raster_transform = PhotoScan.RasterTransformValue, write_world=True, write_alpha=False, tiff_big=False, white_background=True)
#DEM
chunk.exportDem("/path/to/dir//DSM/" + multispec + "_SQM_DSM_ortho.tif", image_format = PhotoScan.ImageFormatTIFF, write_world=True, tiff_big=False)
chunk.exportReport("/path/to/dir//Report/" + multispec + "_SQM_report.pdf")
#RGB
doc.chunk = doc.chunks[1]
chunk.raster_transform.reset()
#Mosaic Blend
chunk.buildOrthomosaic(surface=PhotoScan.ModelData, blending=PhotoScan.MosaicBlending, color_correction=False, projection=chunk.crs)
# RGB
chunk.exportOrthomosaic("/path/to/dir//RGB/" + RGB + "_RGB_ortho_mosaic_blend.tif", image_format = PhotoScan.ImageFormatTIFF, write_world=True, write_alpha=False, tiff_big=False, white_background=True)
chunk.raster_transform.reset()
#Average Blend
chunk.buildOrthomosaic(surface=PhotoScan.ModelData, blending=PhotoScan.AverageBlending, color_correction=False, projection=chunk.crs)
# RGB
chunk.exportOrthomosaic("/path/to/dir//RGB/" + RGB + "_RGB_ortho_average_blend.tif", image_format = PhotoScan.ImageFormatTIFF, write_world=True, write_alpha=False, tiff_big=False, white_background=True)
#DEM
chunk.exportDem("/path/to/dir//DSM/" + RGB + "_RGB_DSM_ortho.tif", image_format = PhotoScan.ImageFormatTIFF, write_world=True, tiff_big=False)
chunk.exportReport("/path/to/dir//Report/" + RGB + "_RGB_report.pdf")