Running Focal Stats on specific values in Python?

Running Focal Stats on specific values in Python?

I'm a beginning programmer.

I'm trying to recreate a raster calculator operation using python scripts but am having a hard time getting it to run properly.

I want to : check a raster for null or 0 values and use focal statistics to patch holes only on those values. In ArcGis 10.3 my raster calculation looks like this and works fine:

Con( IsNull(Rasterin.tif),FocalStatistics(Rasterin.tif,NbrRectangle(5,5"Cell"), "MEAN")Rasterin.tif)

In Python I have tried to approaches to try to recreate this.

I've tried a while statement to find these values but it does the entire raster instead of patching only the values I want ( in this case 0 so the cursors can find it in the raster table:

cursor = arcpy.da.SearchCursor("BadRaster.tif",['Value']) neighborhood = NbrRectangle(5, 5, "CELL") while True: try: for row in cursor: for value in row: if value == 0: print 'Patching… ' outFocalStatistics = FocalStatistics("BadRaster.tif", neighborhood, "MINIMUM","") print 'Saving stats… '"PatchedRaster.tif") print 'Checking… ' break break except: break print "Finished Patching" del cursor

And I've tried using it with map algebra :

neighborhood = NbrRectangle(5, 5, "CELL") con = Con(("BadRaster.tif" < 1,0,0),FocalStatistics("BadRaster.tif", neighborhood, "MEAN","")),"PatchedRaster.tif")

Your last attempt with map algebra is almost there. Try:

from import * arcpy.CheckOutExtension('spatial') #not required if run from within ArcMap with Spatial Analyst already enabled neighborhood = NbrRectangle(5, 5, "CELL") in_raster = Raster("BadRaster.tif") out_raster = Con(IsNull(in_raster), FocalStatistics(in_raster, neighborhood, "MEAN",""), in_raster)"PatchedRaster.tif")

Chemotherapy-induced ileal crypt apoptosis and the ileal microbiome shape immunosurveillance and prognosis of proximal colon cancer

The prognosis of colon cancer (CC) is dictated by tumor-infiltrating lymphocytes, including follicular helper T (TFH) cells and the efficacy of chemotherapy-induced immune responses. It remains unclear whether gut microbes contribute to the elicitation of TFH cell-driven responses. Here, we show that the ileal microbiota dictates tolerogenic versus immunogenic cell death of ileal intestinal epithelial cells (IECs) and the accumulation of TFH cells in patients with CC and mice. Suppression of IEC apoptosis led to compromised chemotherapy-induced immunosurveillance against CC in mice. Protective immune responses against CC were associated with residence of Bacteroides fragilis and Erysipelotrichaceae in the ileum. In the presence of these commensals, apoptotic ileal IECs elicited PD-1 + TFH cells in an interleukin-1R1- and interleukin-12-dependent manner. The ileal microbiome governed the efficacy of chemotherapy and PD-1 blockade in CC independently of microsatellite instability. These findings demonstrate that immunogenic ileal apoptosis contributes to the prognosis of chemotherapy-treated CC.