POST
|
Thanks for your insight, Peter! I appreciate it! It is hard to say without seeing the images. Source raters are raw. No orthorectification either pre-generated or on-the-fly. I had shrink in build footprints at 0. I ended up checking some raters out with reclassify and raster calculator (IsNull). All nodata values are where I would expect them to be. Once I calculated stats it looks like the footprints automatically excluded the nodata parts. So I just didn't run build footprints.
... View more
08-31-2018
01:54 PM
|
1
|
0
|
501
|
POST
|
I'm trying to use build footprints so null values don't appear in my mosaic dataset. However the result after running build footprints cuts areas that are not null. My rasters are 8bit with YCbCr JPEG compression. How do I find out if something is wrong with my rasters?
Before running Build Footprints
After running Build Footprints
... View more
08-29-2018
02:01 PM
|
0
|
2
|
623
|
POST
|
Thank you for all the time you have put in to help me, Dan. Thank you! When I did this: arrayA = arrayA * x arrayC = arrayB + arrayA where x multiplies the entire arrayA instead of going through cell by cell I could not get x to loop beyond 2. So I wanted to use a smaller section of the original array to post as a sample to test. But I didn't understand that trying to get a smaller section was still going through an array cell by cell. I don't want to go through an array cell by cell. But nothing else was working. Why does the code only work when going cell by cell.
... View more
01-10-2017
10:51 AM
|
0
|
0
|
427
|
POST
|
Hi Dan, I have changed my code to include: a[i:j] = v1
b[i:j] = v2 This is the error I get: Traceback (most recent call last):
File "C:\PyTest\petCode.py", line 19, in <module>
a = v1
ValueError: could not broadcast input array from shape (0,6318) into shape (0,6)
Here is the code: import arcpy
import numpy
inRasCgcm = arcpy.Raster("C:/PyTest/testResult.gdb/petCRsClip")
inRasNorm = arcpy.Raster("C:/PyTest/testResult.gdb/petNRsClip")
inArrayCgcm = arcpy.RasterToNumPyArray(inRasCgcm)
inArrayNorm = arcpy.RasterToNumPyArray(inRasNorm)
a = numpy.zeros(4*6).reshape(4, 6)
b = numpy.zeros(4*6).reshape(4, 6)
c = numpy.zeros(4*6).reshape(4, 6)
for i in range (5):
for j in range (7):
v1 = inArrayCgcm[i:j]
v2 = inArrayNorm[i:j]
a[i:j] = v1
b[i:j] = v2
print("array a \n{} \n array b \n{}".format(a, b))
for x in range (1, 4):
c = a * x
c = c + b
print ("array c \n{}".format(c))
newRas = arcpy.NumPyArrayToRaster(c, x_cell_size = 1)
newRas.save("C:/PyTest/testResult.gdb/Year%d" %x) I thought I would test using a 4*6 clip of the the original (5400, 6318) raster starting from the top left corner in order to see if I can resolve that previous error.
... View more
01-10-2017
09:09 AM
|
0
|
2
|
427
|
POST
|
Hi Dan, I don't quite understand when you say print is not a function? Do you mean never do this: print myArray Instead always do this: print("this is my array\n{}".format(myarray)) If so what is wrong with doing this: print myArray This is my cleaned up code: import arcpy
import numpy
inRasCgcm = arcpy.Raster("C:/PyTest/testResult.gdb/petCRsClip")
inRasNorm = arcpy.Raster("C:/PyTest/testResult.gdb/petNRsClip")
inArrayCgcm = arcpy.RasterToNumPyArray(inRasCgcm)
inArrayNorm = arcpy.RasterToNumPyArray(inRasNorm)
a = numpy.zeros(4*6).reshape(4, 6)
b = numpy.zeros(4*6).reshape(4, 6)
c = numpy.zeros(4*6).reshape(4, 6)
for i in range (5):
for j in range (7):
v1 = inArrayCgcm[i:j]
v2 = inArrayNorm[i:j]
a = v1
b = v2
print("array a \n{} \n array b \n{}".format(a, b))
for x in range (1, 4):
c = a * x
c = c + b
print ("array c \n{}".format(c))
newRas = arcpy.NumPyArrayToRaster(c, x_cell_size = 1)
newRas.save("C:/PyTest/testResult.gdb/Year%d" %x)
Why is does the resulting raster look like a thin line of pixels instead of a 4*6 shaped raster? Does this bit of code read a 4*6 area of the original raster starting from the top left or just the first 24 cells? for i in range (5):
for j in range (7):
v1 = inArrayCgcm[i:j]
v2 = inArrayNorm[i:j]
a = v1
b = v2 Since I used this bit of code, does this mean my rasters have a different cell size than the original rasters? newRas = arcpy.NumPyArrayToRaster(c, x_cell_size = 1)
... View more
01-08-2017
03:51 PM
|
0
|
4
|
427
|
POST
|
Thank you Dan! That was very instructive. I now have a very small sample of the data: array a
[[ 2.50291276 2.50291276 2.50291276 ..., 2.20816231 2.20816231
2.20816231]
[ 2.50291276 2.50291276 2.50291276 ..., 2.20816231 2.20816231
2.20816231]]
array b
[[ 453.25619507 453.25619507 453.25619507 ..., 411.51553345
411.51553345 411.51553345]
[ 453.25619507 453.25619507 453.25619507 ..., 411.51553345
411.51553345 411.51553345]]
array c
[[ 455.75909424 455.75909424 455.75909424 ..., 413.72369385
413.72369385 413.72369385]
[ 455.75909424 455.75909424 455.75909424 ..., 413.72369385
413.72369385 413.72369385]]
array c
[[ 458.26202393 458.26202393 458.26202393 ..., 415.93185425
415.93185425 415.93185425]
[ 458.26202393 458.26202393 458.26202393 ..., 415.93185425
415.93185425 415.93185425]]
array c
[[ 460.7649231 460.7649231 460.7649231 ..., 418.14001465
418.14001465 418.14001465]
[ 460.7649231 460.7649231 460.7649231 ..., 418.14001465
418.14001465 418.14001465]] I'm not sure how to make the entire array print, but here's the code: import arcpy
import numpy
inRasCgcm = arcpy.Raster("C:/PyTest/testResult.gdb/petCRsClip")
inRasNorm = arcpy.Raster("C:/PyTest/testResult.gdb/petNRsClip")
lowerLeft = arcpy.Point(inRasNorm.extent.XMin,inRasNorm.extent.YMin)
cellSize = inRasNorm.meanCellWidth
inArrayCgcm = arcpy.RasterToNumPyArray(inRasCgcm)
inArrayNorm = arcpy.RasterToNumPyArray(inRasNorm)
a = numpy.zeros(4*6).reshape(4, 6)
b = numpy.zeros(4*6).reshape(4, 6)
c = numpy.zeros(4*6).reshape(4, 6)
for i in range (5):
for j in range (7):
v1 = inArrayCgcm[i:j]
v2 = inArrayNorm[i:j]
a = v1
b = v2
print("array a \n{} \n array b \n{}".format(a, b))
for x in range (1, 4):
c = a * x
c = c + b
print "array c \n"
print c
It definitely lets me loop through more than 2 iterations. Should I try saving it back to a raster to see what is causing me to get that error: Traceback (most recent call last):
File "C:\PyTest\petCode.py", line 19, in <module>
newRasPET = arcpy.NumPyArrayToRaster(outArrayPE, lowerLeft, cellSize)
File "C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcPy\arcpy\__init__.py", line 2292, in NumPyArrayToRaster
return _NumPyArrayToRaster(*args, **kwargs)
TypeError: Cannot create raster for numpy array.
... View more
01-06-2017
03:49 PM
|
0
|
6
|
427
|
POST
|
Hi Dan I'm not good with python yet. I was trying this code to post a sample, but it gave me this error. I think it's something simple that I'm not understanding with python. Error: Traceback (most recent call last):
File "C:\PyTest\petCode.py", line 23, in <module>
a = v1
IndexError: index 6 is out of bounds for axis 0 with size 6 Code: import arcpy
import numpy
inRasCgcm = arcpy.Raster("C:/PyTest/testResult.gdb/petCRsClip")
inRasNorm = arcpy.Raster("C:/PyTest/testResult.gdb/petNRsClip")
lowerLeft = arcpy.Point(inRasNorm.extent.XMin,inRasNorm.extent.YMin)
cellSize = inRasNorm.meanCellWidth
inArrayCgcm = arcpy.RasterToNumPyArray(inRasCgcm)
inArrayNorm = arcpy.RasterToNumPyArray(inRasNorm)
#outArrayPE = numpy.zeros_like(inArrayNorm)
a = numpy.zeros(4*6).reshape(4, 6)
b = numpy.zeros(4*6).reshape(4, 6)
for i in range (5):
for j in range (7):
v1 = inArrayCgcm[i, j]
v2 = inArrayNorm[i, j]
a[i][j] = v1
b[i][j] = v2
print "array a \n"
print a
print "array b \n"
print b
... View more
01-05-2017
06:56 PM
|
0
|
8
|
495
|
POST
|
Hi Dan, Thank you so much for all your help. I changed to shorter file names, but I am getting the same error. Error: Traceback (most recent call last):
File "C:\PyTest\petCode.py", line 19, in <module>
newRasPET = arcpy.NumPyArrayToRaster(outArrayPE, lowerLeft, cellSize)
File "C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcPy\arcpy\__init__.py", line 2292, in NumPyArrayToRaster
return _NumPyArrayToRaster(*args, **kwargs)
TypeError: Cannot create raster for numpy array. The code now makes it 2 iterations with correct raster values thank you for showing me the zeros_like() to properly initialize an array. Latest code: import arcpy
import numpy
inRasCgcm = arcpy.Raster("C:/PyTest/testResult.gdb/petCRsClip")
inRasNorm = arcpy.Raster("C:/PyTest/testResult.gdb/petNRsClip")
lowerLeft = arcpy.Point(inRasNorm.extent.XMin,inRasNorm.extent.YMin)
cellSize = inRasNorm.meanCellWidth
inArrayCgcm = arcpy.RasterToNumPyArray(inRasCgcm)
inArrayNorm = arcpy.RasterToNumPyArray(inRasNorm)
outArrayPE = numpy.zeros_like(inArrayNorm)
for x in range (1, 4):
inArrayCgcm = inArrayCgcm * x
outArrayPE = inArrayNorm + inArrayCgcm
newRasPET = arcpy.NumPyArrayToRaster(outArrayPE, lowerLeft, cellSize)
newRasPET.save("C:/PyTest/testResult.gdb/petR{}Year".format(x)) The structure of my array and saving location should be okay if I can make it to 2 iterations correctly shouldn't it?
... View more
01-04-2017
12:38 PM
|
0
|
10
|
495
|
POST
|
But the last version of my code crashes, gives me this error, and is still only correct on the first iteration: Traceback (most recent call last):
File "C:\VegModel\PETyearlyChange.py", line 20, in <module>
newRasPET = arcpy.NumPyArrayToRaster(outArrayPET, lowerLeft, cellSize)
File "C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcPy\arcpy\__init__.py", line 2292, in NumPyArrayToRaster
return _NumPyArrayToRaster(*args, **kwargs)
TypeError: Cannot create raster for numpy array.
... View more
01-03-2017
04:00 PM
|
0
|
1
|
495
|
POST
|
Hi Dan, Thank you for all your help. I see this code as NOT go through the array cell by cell. It is doing exactly what you are showing above. I AM multiplying the entire array inArrayPETcgcm by the constant x. If inArrayPETcgcm was array A like you have above. Then array A would have: array dimensions (ndim) = 2 array shape (shape) = (5400, 6318) Loop x just goes from 1 to 50 as the constants that get multiplied to the entire array. import arcpy
import numpy
inRasPETcgcm = arcpy.Raster("C:/VegModel/CCSSRawData.gdb/petCgcmRS100Clip")
inRasPETnorm = arcpy.Raster("C:/VegModel/CCSSRawData.gdb/petNormRS100Clip")
lowerLeft = arcpy.Point(inRasPETnorm.extent.XMin,inRasPETnorm.extent.YMin)
cellSize = inRasPETnorm.meanCellWidth
inArrayPETcgcm = arcpy.RasterToNumPyArray(inRasPETcgcm)
inArrayPETnorm = arcpy.RasterToNumPyArray(inRasPETnorm)
for x in range (1, 51):
inArrayPETcgcm = inArrayPETcgcm * x
outArrayPET = inArrayPETnorm + inArrayPETcgcm
newRasPET = arcpy.NumPyArrayToRaster(outArrayPET, lowerLeft, cellSize)
newRasPET.save("C:/VegModel/Revise.gdb/pet100ReviseYear%dB" %x) How are you reading this code as going through the array cell by cell? I'm honestly so confused? If I am wrong please let me know.
... View more
01-03-2017
02:34 PM
|
0
|
3
|
495
|
POST
|
Hi Dan, I know going through an array cell by cell is very inefficient. So the first code I tried did not got through my array cell by cell. The first code I tried looked like this: import arcpy
import numpy
inRasPETcgcm = arcpy.Raster("C:/VegModel/CCSSRawData.gdb/petCgcmRS100Clip")
inRasPETnorm = arcpy.Raster("C:/VegModel/CCSSRawData.gdb/petNormRS100Clip")
lowerLeft = arcpy.Point(inRasPETnorm.extent.XMin,inRasPETnorm.extent.YMin)
cellSize = inRasPETnorm.meanCellWidth
inArrayPETcgcm = arcpy.RasterToNumPyArray(inRasPETcgcm)
inArrayPETnorm = arcpy.RasterToNumPyArray(inRasPETnorm)
for x in range (1, 51):
inArrayPETcgcm = inArrayPETcgcm * x
outArrayPET = inArrayPETnorm + inArrayPETcgcm
newRasPET = arcpy.NumPyArrayToRaster(outArrayPET, lowerLeft, cellSize)
newRasPET.save("C:/VegModel/Revise.gdb/pet100ReviseYear%dB" %x) This code would also give me the incorrect values after the first iteration, and it would crash after only 2 iterations giving me an error like this: Traceback (most recent call last):
File "C:\VegModel\PETyearlyChange.py", line 20, in <module>
newRasPET = arcpy.NumPyArrayToRaster(outArrayPET, lowerLeft, cellSize)
File "C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcPy\arcpy\__init__.py", line 2292, in NumPyArrayToRaster
return _NumPyArrayToRaster(*args, **kwargs)
TypeError: Cannot create raster for numpy array. I don't know how to fix this error. Are my arrays to big to fit into RAM? Do I have to clear or release the memory after each iteration? Do I need to go multiprocessing? I will try to subsample my arrays and return with the results.
... View more
01-03-2017
10:17 AM
|
0
|
5
|
495
|
POST
|
I'm not sure what you mean when you say running calculation on the array. I'm trying to do exactly what your code is showing. Each array contains floats and have the following: array dimensions (ndim) = 2 array shape (shape) = (5400, 6318) I actually don't want my array C (outArrayPET) to be a clone of inarrayPETnorm I didn't know how to initialize it. I'll try doing what you have with: c = np.zeros_like(b) Also could you explain what the + 2 is for in line 5 of your code: b = np.arange(rows*cols).reshape(rows, cols) + 2 I ran this code again with print statements: import arcpy
import numpy
inRasPETcgcm = arcpy.Raster("C:/VegModel/CCSSRawData.gdb/petCgcmRS100Clip")
inRasPETnorm = arcpy.Raster("C:/VegModel/CCSSRawData.gdb/petNormRS100Clip")
lowerLeft = arcpy.Point(inRasPETnorm.extent.XMin,inRasPETnorm.extent.YMin)
cellSize = inRasPETnorm.meanCellWidth
inArrayPETcgcm = arcpy.RasterToNumPyArray(inRasPETcgcm)
inArrayPETnorm = arcpy.RasterToNumPyArray(inRasPETnorm)
outArrayPET = inArrayPETnorm
for x in range (1, 3):
for i in range(0, 2):
for j in range(0, 2):
value1 = inArrayPETcgcm[i, j]
value2 = inArrayPETnorm[i, j]
print "value1 before calculation is: "
print value1
print "value2 is before calculation: "
print value2
value1 = value1 * x
print "value1 after multiplication is: "
print value1
value3 = value1 + value2
print "value3 after addition is: "
print value3
outArrayPET[i, j] = value3
newRasPET = arcpy.NumPyArrayToRaster(outArrayPET, lowerLeft, cellSize)
newRasPET.save("C:/VegModel/Revise.gdb/pet100ReviseYear%dB" %x)
value2 has somehow changed in the second iteration (the bottom 4 groups) of the x loop. The output gave me the following: value1 before calculation is:
2.50291
value2 is before calculation:
453.256
value1 after multiplication is:
2.50291275978
value3 after addition is:
455.759107828
value1 before calculation is:
2.50291
value2 is before calculation:
453.256
value1 after multiplication is:
2.50291275978
value3 after addition is:
455.759107828
value1 before calculation is:
2.50291
value2 is before calculation:
453.256
value1 after multiplication is:
2.50291275978
value3 after addition is:
455.759107828
value1 before calculation is:
2.50291
value2 is before calculation:
453.256
value1 after multiplication is:
2.50291275978
value3 after addition is:
455.759107828
value1 before calculation is:
2.50291
value2 is before calculation:
455.759
value1 after multiplication is:
5.00582551956
value3 after addition is:
460.764919758
value1 before calculation is:
2.50291
value2 is before calculation:
455.759
value1 after multiplication is:
5.00582551956
value3 after addition is:
460.764919758
value1 before calculation is:
2.50291
value2 is before calculation:
455.759
value1 after multiplication is:
5.00582551956
value3 after addition is:
460.764919758
value1 before calculation is:
2.50291
value2 is before calculation:
455.759
value1 after multiplication is:
5.00582551956
value3 after addition is:
460.764919758
I have no clue where the value2 of 455.759 is coming from in the second iteration of the x loop
... View more
01-02-2017
09:46 PM
|
0
|
0
|
1158
|
POST
|
Hi Dan, I want the file saved after the i loop is completed or after each iteration of the x loop. The intent is that I have raster A and B. I need to multiple 1, 2, 3, ... 48, 49, 50 to raster A and add the result to raster B. I have outlined what I have tried below. The initial code I tried is this: import arcpy
import numpy
inRasPETcgcm = arcpy.Raster("C:/VegModel/CCSSRawData.gdb/petCgcmRS100Clip")
inRasPETnorm = arcpy.Raster("C:/VegModel/CCSSRawData.gdb/petNormRS100Clip")
lowerLeft = arcpy.Point(inRasPETnorm.extent.XMin,inRasPETnorm.extent.YMin)
cellSize = inRasPETnorm.meanCellWidth
inArrayPETcgcm = arcpy.RasterToNumPyArray(inRasPETcgcm)
inArrayPETnorm = arcpy.RasterToNumPyArray(inRasPETnorm)
for x in range (1, 51):
inArrayPETcgcm = inArrayPETcgcm * x
outArrayPET = inArrayPETnorm + inArrayPETcgcm
newRasPET = arcpy.NumPyArrayToRaster(outArrayPET, lowerLeft, cellSize)
newRasPET.save("C:/VegModel/Revise.gdb/pet100ReviseYear%dB" %x)
But that code crashes after 2 iterations and give an error message like this: Traceback (most recent call last):
File "C:\VegModel\PETyearlyChange.py", line 20, in <module>
newRasPET = arcpy.NumPyArrayToRaster(outArrayPET, lowerLeft, cellSize)
File "C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcPy\arcpy\__init__.py", line 2292, in NumPyArrayToRaster
return _NumPyArrayToRaster(*args, **kwargs)
TypeError: Cannot create raster for numpy array. Plus, of the 2 rasters that got saved before crashing only the raster in the first iteration is correct. So then I tried code that looks like this: import arcpy
import numpy
inRasPETcgcm = arcpy.Raster("C:/VegModel/CCSSRawData.gdb/petCgcmRS100Clip")
inRasPETnorm = arcpy.Raster("C:/VegModel/CCSSRawData.gdb/petNormRS100Clip")
lowerLeft = arcpy.Point(inRasPETnorm.extent.XMin,inRasPETnorm.extent.YMin)
cellSize = inRasPETnorm.meanCellWidth
inArrayPETcgcm = arcpy.RasterToNumPyArray(inRasPETcgcm)
inArrayPETnorm = arcpy.RasterToNumPyArray(inRasPETnorm)
rasHeight, rasWidth = inArrayPETnorm.shape
outArrayPET = inArrayPETnorm
for x in range (1, 51):
for i in range(0, 2):
for j in range(0, 2):
value1 = inArrayPETcgcm[i, j]
value2 = inArrayPETnorm[i, j]
value1 = value1 * x
value3 = value1 + value2
outArrayPET[i, j] = value3
newRasPET = arcpy.NumPyArrayToRaster(outArrayPET, lowerLeft, cellSize)
newRasPET.save("C:/VegModel/Revise.gdb/pet100ReviseYear%dB" %x)
This code is able to make it to 50 without crashing. It also doesn't use Decimal. But again, only the raster from the first iteration is correct.
... View more
01-02-2017
05:50 PM
|
0
|
0
|
1158
|
POST
|
Hi Dan, Thank you, I understand what you are staying about not needing the Decimal module. However, I have run it without the using Decimal and I am still only getting a correct raster on the first iteration of the loop at line 27. I want to save each iteration to a new file after the outer most for loop at line 27. If I indent it more doesn't it mean I'll be saving each iteration to a new file on the inner nested for loops?
... View more
01-02-2017
10:35 AM
|
0
|
1
|
1158
|
POST
|
Hi Dan, Thank you for the tip. I did try it also without using the Decimal module, which works fine. However, my problem is that I am only getting a correct raster result in the first loop through at line 27. All subsequent iterations gives me the wrong values in the rasters, which I have checked by using the identify tool and picking random values to do the math. I should also mention that my actual raster is something like 6000 by 3000. I'm pretty sure arcpy can handle the math of multiplication (line 41) and addition (line 45), but I have no idea why only the first iteration give a correct result. Is it a memory problem? Or do I need to clear the values after each iteration?
... View more
01-01-2017
10:01 PM
|
0
|
3
|
1158
|
Title | Kudos | Posted |
---|---|---|
1 | 08-31-2018 01:54 PM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:24 AM
|