dugtoni

Extracting Pixel Data

Discussion created by dugtoni on Aug 7, 2012
Latest reply on Aug 13, 2012 by dugtoni
Hey Everyone,

I am working on a script right now that extracts climate data for one particular pixel over a period of time.  I have written a script which works, but I feel like there is a much faster and efficient way to go about it.  Right now I have a script which downloads a NetCDF file, creates a numpy 2d array, converts this array to a raster, then I create a point which is fed x and y coordinates, and the raster is then clipped by this point so that I am left with the pixel in the raster that this point falls within.  I feel like an easier way to do this is if I could specify the xy coordinate of the pixel of interest, and then simply read this pixel value from the numpy array.  This way I wouldn't be creating a numpy array for entire climate dataset (the entire United States) and then converting this huge dataset to a raster.  I would be very grateful if anyone knows how to do this.  Thanks!

Here is a bit of my code where I create the point which is used to clip the climate raster to my pixel of interest:

def ClipPix(output,pixelX,pixelY):
    arcpy.CreateFolder_management(output,'/clipped climate rasters')
    pointFC= arcpy.CreateFeatureclass_management(output, "Point.shp", "POINT")
    inPoint = arcpy.CreateObject("Point")
    inPoint.X = float(pixelX)
    inPoint.Y = float(pixelY)
    cursor= arcpy.InsertCursor(pointFC)
    feature= cursor.newRow()
    feature.shape= inPoint
    cursor.insertRow(feature)
    del cursor
    arcpy.env.workspace= output+'/climate rasters'
    ClimRasters= arcpy.ListRasters()
    for ClimRaster in ClimRasters:
        arcpy.Clip_management(output+'/climate rasters/'+ClimRaster, "", output+"/clipped climate rasters/"+ClimRaster, pointFC, "", "ClippingGeometry")

Outcomes