예제 #1
0
def execute_task(in_extentDict):
    #########  Execute Nibble  #####################
    filter_combos = {
        'n4h': ["FOUR", "HALF"],
        'n4m': ["FOUR", "MAJORITY"],
        'n8h': ["EIGHT", "HALF"],
        'n8m': ["EIGHT", "MAJORITY"]
    }
    filter_key = data['core']['filter']

    rg_combos = {'8w': ["EIGHT", "WITHIN"]}
    rg_instance = rg_combos['8w']

    # for count in masks_list:
    cond = "Count < " + str(
        gen.getPixelCount(str(data['global']['res']), int(
            data['core']['mmu'])))
    print 'cond: ', cond

    fc_count = in_extentDict[0]
    # print fc_count
    procExt = in_extentDict[1]
    # print procExt
    XMin = procExt[0]
    YMin = procExt[1]
    XMax = procExt[2]
    YMax = procExt[3]

    #set environments
    arcpy.env.extent = arcpy.Extent(XMin, YMin, XMax, YMax)

    if data['core']['route'] == 'r2':
        raster_filter = MajorityFilter(
            Raster(data['pre']['traj_rfnd']['path']),
            filter_combos[filter_key][0], filter_combos[filter_key][1])
        raster_mtr = Reclassify(raster_filter, "Value",
                                RemapRange(reclassArray), "NODATA")
        raster_rg = RegionGroup(raster_mtr, rg_instance[0], rg_instance[1],
                                "NO_LINK")
        raster_mask = SetNull(raster_rg, 1, cond)
        raster_nbl = arcpy.sa.Nibble(raster_mtr, raster_mask, "DATA_ONLY")

        #clear out the extent for next time
        arcpy.ClearEnvironment("extent")

        outname = "tile_" + str(fc_count) + '.tif'

        outpath = os.path.join("C:/Users/Bougie/Desktop/Gibbs/", r"tiles",
                               outname)

        raster_nbl.save(outpath)
예제 #2
0
def createMMUmaskTiles(prg):
    root_in = 'C:\\Users\\Bougie\\Desktop\\Gibbs\\tiles\\'
    rasterlist = glob.glob(root_in + "*.tif")
    print rasterlist

    for raster in rasterlist:
        print raster

        output = raster.replace('.', '_mask.')
        print output

        # for count in masks_list:
        cond = "Count < " + str(gen.getPixelCount(prg.res, prg.mmu))
        print 'cond: ', cond

        outSetNull = SetNull(raster, 1, cond)

        # Save the output
        outSetNull.save(output)
예제 #3
0
def clipByMMUmask():
    root_in = 'C:\\Users\\Bougie\\Desktop\\Gibbs\\tiles\\'
    rasterlist = glob.glob(root_in + "*.tif")

    for raster in rasterlist:
        print raster

        output = raster.replace('.', '_mask.')
        print output

        # raster = + 'tile_4.tif'
        # print 'raster: ', raster

        # for count in masks_list:
        cond = "Count < " + str(gen.getPixelCount('30', 5))
        print 'cond: ', cond

        outSetNull = SetNull(raster, 1, cond)

        # Save the output
        outSetNull.save(output)
예제 #4
0
def execute_task(args):
    in_extentDict, data = args
    #########  Execute Nibble  #####################
    filter_combos = {
        'n4h': ["FOUR", "HALF"],
        'n4m': ["FOUR", "MAJORITY"],
        'n8h': ["EIGHT", "HALF"],
        'n8m': ["EIGHT", "MAJORITY"]
    }
    filter_key = data['core']['filter']

    rg_combos = {
        '4w': ["FOUR", "WITHIN"],
        '8w': ["EIGHT", "WITHIN"],
        '4c': ["FOUR", "CROSS"],
        '8c': ["EIGHT", "CROSS"]
    }
    rg_instance = rg_combos[data['core']['rg']]

    # for count in masks_list:
    cond = "Count < " + str(
        gen.getPixelCount(str(data['global']['res']), int(
            data['core']['mmu'])))
    print 'cond: ', cond

    fc_count = in_extentDict[0]
    # print fc_count
    procExt = in_extentDict[1]
    # print procExt
    XMin = procExt[0]
    YMin = procExt[1]
    XMax = procExt[2]
    YMax = procExt[3]

    #set environments
    arcpy.env.extent = arcpy.Extent(XMin, YMin, XMax, YMax)

    if data['core']['route'] == 'r1':
        raster_mtr = Reclassify(Raster(data['pre']['traj_rfnd']['path']),
                                "Value",
                                RemapRange(createReclassifyList(data)),
                                "NODATA")
        raster_filter = MajorityFilter(raster_mtr,
                                       filter_combos[filter_key][0],
                                       filter_combos[filter_key][1])
        raster_rg = RegionGroup(raster_filter, rg_instance[0], rg_instance[1],
                                "NO_LINK")
        raster_mask = SetNull(raster_rg, 1, cond)
        raster_nbl = arcpy.sa.Nibble(raster_filter, raster_mask, "DATA_ONLY")

        #clear out the extent for next time
        arcpy.ClearEnvironment("extent")

        outname = "tile_" + str(fc_count) + '.tif'

        outpath = os.path.join("C:/Users/Bougie/Desktop/Gibbs/", r"tiles",
                               outname)

        raster_nbl.save(outpath)

    elif data['core']['route'] == 'r2':
        raster_filter = MajorityFilter(
            Raster(data['pre']['traj_rfnd']['path']),
            filter_combos[filter_key][0], filter_combos[filter_key][1])
        raster_mtr = Reclassify(raster_filter, "Value",
                                RemapRange(createReclassifyList(data)),
                                "NODATA")
        raster_rg = RegionGroup(raster_mtr, rg_instance[0], rg_instance[1],
                                "NO_LINK")
        raster_mask = SetNull(raster_rg, raster_mtr, cond)
        filled_1 = Con(
            IsNull(raster_mask),
            FocalStatistics(raster_mask, NbrRectangle(3, 3, "CELL"),
                            'MAJORITY'), raster_mask)
        t1 = Con(
            IsNull(filled_1),
            FocalStatistics(filled_1, NbrRectangle(10, 10, "CELL"),
                            'MAJORITY'), filled_1)
        # t2 = Con(IsNull(filled_1),FocalStatistics(filled_1,NbrRectangle(3, 3, "CELL"),'MAJORITY'), filled_1)

        # final = SetNull(path_mtr, filled_2, "VALUE <> 3")
        # raster_mask = SetNull(raster_rg, 1, cond)
        # raster_nbl = arcpy.sa.Nibble(raster_mtr, raster_mask, "DATA_ONLY")

        #clear out the extent for next time
        arcpy.ClearEnvironment("extent")

        outname = "tile_" + str(fc_count) + '.tif'

        outpath = os.path.join("C:/Users/Bougie/Desktop/Gibbs/", r"tiles",
                               outname)

        # raster_shrink.save(outpath)
        t1.save(outpath)

    if data['core']['route'] == 'r3':
        raster_filter = MajorityFilter(
            Raster(data['pre']['traj_rfnd']['path']),
            filter_combos[filter_key][0], filter_combos[filter_key][1])
        raster_rg = RegionGroup(raster_filter, rg_instance[0], rg_instance[1],
                                "NO_LINK")
        raster_mask = SetNull(raster_rg, 1, cond)
        raster_nbl = arcpy.sa.Nibble(raster_filter, raster_mask, "DATA_ONLY")
        raster_mtr = Reclassify(raster_nbl, "Value",
                                RemapRange(createReclassifyList(data)),
                                "NODATA")

        #clear out the extent for next time
        arcpy.ClearEnvironment("extent")

        outname = "tile_" + str(fc_count) + '.tif'

        outpath = os.path.join("C:/Users/Bougie/Desktop/Gibbs/", r"tiles",
                               outname)

        raster_mtr.save(outpath)
예제 #5
0
def execute_task(args):
	in_extentDict, data, traj_list = args

	filter_combos = {'n4h':["FOUR", "HALF"],'n4m':["FOUR", "MAJORITY"],'n8h':["EIGHT", "HALF"],'n8m':["EIGHT", "MAJORITY"]}
	filter_key = data['core']['filter']

	rg_combos = {'4w':["FOUR", "WITHIN"], '8w':["EIGHT", "WITHIN"], '4c':["FOUR", "CROSS"], '8c':["EIGHT", "CROSS"]}
	rg_instance = rg_combos[data['core']['rg']]

	# for count in masks_list:
	cond = "Count < " + str(gen.getPixelCount(str(data['global']['res']), int(data['core']['mmu'])))
	print 'cond: ',cond


	fc_count = in_extentDict[0]
	# print fc_count
	procExt = in_extentDict[1]
	# print procExt
	XMin = procExt[0]
	YMin = procExt[1]
	XMax = procExt[2]
	YMax = procExt[3]

	#set environments
	arcpy.env.extent = arcpy.Extent(XMin, YMin, XMax, YMax)

	cdl=Raster('C:\\Users\\Bougie\\Desktop\\Gibbs\\data\\usxp\\ancillary\\raster\\cdl.gdb\\cdl30_2012')
	

	if data['core']['route'] == 'r1':
		raster_yxc = Reclassify(Raster(data['pre']['traj_rfnd']['path']), "Value", RemapRange(traj_list), "NODATA")
		raster_filter = MajorityFilter(raster_yxc, filter_combos[filter_key][0], filter_combos[filter_key][1])
		raster_rg = RegionGroup(raster_filter, rg_instance[0], rg_instance[1],"NO_LINK")
		raster_mask = SetNull(raster_rg, 1, cond)
		raster_nbl = arcpy.sa.Nibble(raster_filter, raster_mask, "DATA_ONLY")

		#clear out the extent for next time
		arcpy.ClearEnvironment("extent")

		outname = "tile_" + str(fc_count) +'.tif'

		outpath = os.path.join("C:/Users/Bougie/Desktop/Gibbs/data/", r"tiles", outname)

		raster_nbl.save(outpath)


	elif data['core']['route'] == 'r2':
		##perform a majority filter on the refined trajectory 
		raster_filter = MajorityFilter(Raster(data['pre']['traj_rfnd']['path']), filter_combos[filter_key][0], filter_combos[filter_key][1])
		
        ####reclassify the filtered raster to the MTR labels
		raster_yxc = Reclassify(raster_filter, "Value", RemapRange(traj_list), "NODATA")
		raster_filter=None

		### perform region group on the raster_yxc to get the number of pixels for each region
		raster_rg = RegionGroup(raster_yxc, rg_instance[0], rg_instance[1], "NO_LINK")
		
		### set null the regions that are less than the mmu treshold
		raster_mask = SetNull(raster_rg, raster_yxc, cond)
		raster_yxc=None
		raster_rg=None

		### fill in the regions that were below the mmu threshold.  Perform these in series starting small (taking advantage of spatial autocorelation) and expanding out to get 
		### past the equilibrium sink of a certain kernel size
		filled_1 = Con(IsNull(raster_mask),FocalStatistics(raster_mask,NbrRectangle(3, 3, "CELL"),'MAJORITY'), raster_mask)
		raster_mask=None
		filled_2 = Con(IsNull(filled_1),FocalStatistics(filled_1,NbrRectangle(5, 5, "CELL"),'MAJORITY'), filled_1)
		filled_1=None
		filled_3 = Con(IsNull(filled_2),FocalStatistics(filled_2,NbrRectangle(10, 10, "CELL"),'MAJORITY'), filled_2)
		filled_2=None
		filled_4 = Con(IsNull(filled_3),FocalStatistics(filled_3,NbrRectangle(20, 20, "CELL"),'MAJORITY'), filled_3)
		filled_3=None

		##### trim of the patches that have expanded past the cdl map boundaries  #####################
		cond = "Value = 0"
		raster_mask = SetNull(cdl, filled_4, cond)
		filled_4=None


        ##### create a tiff file from the raster object  #######################################
		#clear out the extent for next time
		arcpy.ClearEnvironment("extent")

		outname = "tile_" + str(fc_count) +'.tif'

		outpath = os.path.join("C:/Users/Bougie/Desktop/Gibbs/data/", r"tiles", outname)

		raster_mask.save(outpath)
        raster_mask=None