def model(info, inputs, outputs, otherargs): """ create image stack and statistics from bands """ np.seterr(all='ignore') nullValue = otherargs.coverNull if qvf.stage(outputs.image) in ['djl']: index = 0 if qvf.stage(outputs.image) in ['djm']: index = 1 if qvf.stage(outputs.image) in ['djn']: index = 2 stack = np.array([img[index] for img in inputs.images]) maskedstack = ma.masked_array(stack,stack==0) percentile5 = np.ma.apply_along_axis(mstats.scoreatpercentile,0,maskedstack,5) percentile95 = np.ma.apply_along_axis(mstats.scoreatpercentile,0,maskedstack,95) outputs.bare=np.array([percentile5,percentile95],dtype=np.uint8)
def applyMasks(processedList): """ Do masking of output - create generic model to be used for all seasonal products. Uses cloud and shadow masks to mask image. Uses RSC derived masks if available and fmask if not. """ cloudList = [] shadowList = [] sceneList =[] maskImageList = [] processedListClipped = [] for scene in processedList: processedListClipped.append(qvf.changestage(scene, 'tmp')) if not os.path.exists(qvf.changestage(scene, 'tmp')): fMaskCloudImage = qvf.changestage(scene, 'dgr') fMaskShadowImage = qvf.changestage(scene, 'dgs') if qv.existsonfilestore(fMaskCloudImage): cloudMaskImage = fMaskCloudImage if qv.existsonfilestore(fMaskShadowImage): shadowMaskImage = fMaskShadowImage if qv.existsonfilestore(cloudMaskImage) and qv.existsonfilestore(shadowMaskImage) and qv.existsonfilestore(scene): cloudList.append(cloudMaskImage) shadowList.append(shadowMaskImage) sceneList.append(scene) maskImageList.append([scene,cloudMaskImage,shadowMaskImage]) if len(maskImageList)!=0: recallList(cloudList, qvf.stage(cloudList[0])) recallList(shadowList, qvf.stage(shadowList[0])) recallList(sceneList, qvf.stage(sceneList[0])) print 'Applying masks...' controls = applier.ApplierControls() controls.setStatsIgnore(0) for (image1,image2,image3) in maskImageList: tmpscene = qvf.changestage(image1, 'tmp') print tmpscene if not os.path.exists(tmpscene) and os.path.exists(image1) and os.path.exists(image2): infiles = applier.FilenameAssociations() infiles.image1 = image1 infiles.image2 = image2 infiles.image3 = image3 outfiles = applier.FilenameAssociations() outfiles.outimage = tmpscene if not os.path.exists(outfiles.outimage): applier.apply(createMaskedImage, infiles, outfiles, controls=controls) if os.path.exists(outfiles.outimage): os.remove(image1) os.remove(image2) os.remove(image3) return processedListClipped