POST
|
This worked for me, for southern hemisphere (negative lat and lon). It is necessary to set the environmental options before running the script. import numpy as np
import arcpy
from arcpy.sa import *
from arcpy import env as E
#Create variables from environment
latmin = E.extent.YMin
latmax = E.extent.YMax
lonmin = E.extent.XMin
lonmax = E.extent.XMax
cellsize = float(E.cellSize)
lowerleft = arcpy.Point(lonmin, latmin)
#Generating inverse meshgrid for latitude grid
lat1 = np.arange(float(-latmax), float(-latmin), float(cellsize))
lon1 = np.arange(float(-lonmax), float(-lonmin), float(cellsize))
lon1, lat1 = np.meshgrid(lon1, lat1)
lat = arcpy.NumPyArrayToRaster(-lat1, lowerleft, float(cellsize), float(cellsize))
#Generating meshgrid for longitude grid
lat2 = np.arange(float(latmin), float(latmax), float(cellsize))
lon2 = np.arange(float(lonmin), float(lonmax), float(cellsize))
lon2, lat2 = np.meshgrid(lon2, lat2)
lon = arcpy.NumPyArrayToRaster(lon2, lowerleft, float(cellsize), float(cellsize))
... View more
09-25-2018
12:23 PM
|
0
|
0
|
1738
|
POST
|
Thank you all! The final code is: import numpy as np
import arcpy
arcpy.CheckOutExtension("Spatial")
arcpy.env.overwriteOutput = True
wksp = "D:\Vianna\Dados\Raster\Clima\ETP"
arcpy.env.workspace = wksp
lat = arcpy.Raster("D:\Vianna\Dados\Raster\Topografia\latit.tif")
lon = arcpy.Raster("D:\Vianna\Dados\Raster\Topografia\longit.tif")
alt = arcpy.Raster("D:\Vianna\Dados\Raster\Topografia\mde_sc_90.tif")
tbl = "D:\Vianna\Dados\Raster\Clima\Raster_Clima.gdb\TB_EQUAC_ETP"
arr = arcpy.da.TableToNumPyArray(tbl, "*")
eqs = arr['DS_EQUAC']
filenames = ["{}{}{}{}".format(*i) for i in arr[['SG_PREFIX', 'SG_SUFIX', 'SG_PERIO', 'SG_FORMA']]]
a = arr['VL_A']
b = arr['VL_B']
c = arr['VL_C']
d = arr['VL_D']
for i in range(len(filenames)):
print(filenames[i])
eq = a[i] + b[i] * lat + c[i] * lon + d[i] * alt
eq.save(filenames[i])
... View more
09-18-2018
10:16 AM
|
1
|
0
|
5088
|
POST
|
All I need is: eq[0] -> save as filenames[0] eq[1] -> save as filenames[1] eq[2] -> save as filenames[2] ....
... View more
09-18-2018
09:31 AM
|
0
|
2
|
1457
|
POST
|
Sorry, I think I´m not clear about my issue. My english in not good. I want to run "n" regression equations using lat, lon, and alt as input (a+lat*b + lon*c+alt*d). lat, lon and alt are rasters (tif), georreferenced and with the same pixel size. a, b, c and d are the coeficients of the regression equations. The coefficients are in a table were each line will generate an raster output. Each output have lat, lon and alt as inputs and each field (VL_A, VL_B, VL_C and VL_D) have the coefficients. The inputs lat, lon and alt doesn't change, only the coefficients changes. I need to loop the inputs trhough the lines just to change the coefficients. For each line of the table, I will have an output. I don't need to create lat and lon arrays because they are rasters: Lat Lon Alt
... View more
09-18-2018
08:03 AM
|
0
|
0
|
1457
|
POST
|
The script is now ok. I´m running it using lat, lon and alt inputs as rasters (tif). The line 28 (eq) is running ok and generating the output raster in scratch workspace. eq = [a[i] + b[i] * lat + c[i] * lon + d[i] * alt for i in range(len(a))]
eq
[D:\Vianna\Projetos\Vitivinicultura\APTX\MCA\MCA.gdb\plus_48988a4b_b545_4542_a1a6_2033bd3fdf61_70285720,
D:\Vianna\Projetos\Vitivinicultura\APTX\MCA\MCA.gdb\plus_83029179_cc6b_4cff_9083_01c3a6d2b97a_70285720,
D:\Vianna\Projetos\Vitivinicultura\APTX\MCA\MCA.gdb\plus_7c292bb1_3754_43d7_8e61_75ba5011864e_70285720,
D:\Vianna\Projetos\Vitivinicultura\APTX\MCA\MCA.gdb\plus_7d559a2b_32f6_4526_8e42_9909cc8959f7_70285720,
D:\Vianna\Projetos\Vitivinicultura\APTX\MCA\MCA.gdb\plus_bcc6da9d_3189_489a_9151_0dcbd3315338_70285720,
D:\Vianna\Projetos\Vitivinicultura\APTX\MCA\MCA.gdb\plus_331494a3_5e1d_493f_8fd1_78f11f674f4d_70285720,
D:\Vianna\Projetos\Vitivinicultura\APTX\MCA\MCA.gdb\plus_c81ada51_8de1_47e0_a299_f30e15ab984c_70285720,
D:\Vianna\Projetos\Vitivinicultura\APTX\MCA\MCA.gdb\plus_056e14b0_2764_40bd_855f_f993f623fd08_70285720,
D:\Vianna\Projetos\Vitivinicultura\APTX\MCA\MCA.gdb\plus_35056ba8_41ba_4e19_a036_e7b430f1ece5_70285720,
D:\Vianna\Projetos\Vitivinicultura\APTX\MCA\MCA.gdb\plus_beb5dc22_f5cc_4e9a_9c46_063826a82a1a_70285720,
D:\Vianna\Projetos\Vitivinicultura\APTX\MCA\MCA.gdb\plus_55a08d44_9db9_446d_aa61_94db00b56cec_70285720,
D:\Vianna\Projetos\Vitivinicultura\APTX\MCA\MCA.gdb\plus_92a899db_de84_4e92_a942_71bba78a429e_70285720,
D:\Vianna\Projetos\Vitivinicultura\APTX\MCA\MCA.gdb\plus_dc217a38_13a4_453c_ae0a_1f5efe4703bd_70285720]
However I don´t know how to record the output files as tif in the defined workspace (line 6). I think the save command in line 29 is wrong. import numpy as np
import arcpy
arcpy.CheckOutExtension("Spatial")
arcpy.env.overwriteOutput = True
wksp = "D:\Vianna\Dados\Raster\Clima\ETP"
arcpy.env.workspace = wksp
lat = arcpy.Raster("D:\Vianna\Dados\Raster\Topografia\latit.tif")
lon = arcpy.Raster("D:\Vianna\Dados\Raster\Topografia\longit.tif")
alt = arcpy.Raster("D:\Vianna\Dados\Raster\Topografia\mde_sc_90.tif")
tbl = "D:\Vianna\Dados\Raster\Clima\Raster_Clima.gdb\TB_EQUAC_ETP"
arr = arcpy.da.TableToNumPyArray(tbl, "*")
eqs = arr['DS_EQUAC']
filenames = ["{}{}{}{}".format(*i) for i in arr[['SG_PREFIX', 'SG_SUFIX', 'SG_PERIO', 'SG_FORMA']]]
a = arr['VL_A']
b = arr['VL_B']
c = arr['VL_C']
d = arr['VL_D']
#eq = [a + b*lat + c*lon + d*alt for i in range(len(a))]
#outname = "D:\\Vianna\\Dados\\Raster\\Clima\\ETP\\{}".format(eq[2])
#fns.save(fns)
for filename in filenames:
print(filename)
# A bit more memory friendly alternative to arrs
eq = [a[i] + b[i] * lat + c[i] * lon + d[i] * alt for i in range(len(a))]
eq.save(eq)
etp_m01.tif
Traceback (most recent call last):
File "<string>", line 29, in <module>
AttributeError: 'list' object has no attribute 'save'
... View more
09-18-2018
07:11 AM
|
0
|
6
|
1652
|
POST
|
Thank you, Hakon! The size of text fields seems to be the problem! I re-imported the xlsx table (as csv) and re-sized the text fields to 255 and solved the array problem. However the equation (arrs) is not running: import numpy as np
import arcpy
arcpy.CheckOutExtension("spatial")
arcpy.env.overwriteOutput = True
lat = np.arange(-29.373511, -25.928348, 0.000871310821466946, 'float')
lon = np.arange(-53.915588, -48.273851, 0.000871310821466947, 'float')
lon, lat = np.meshgrid(lon, lat)
alt = r"D:\Vianna\Dados\Raster\Topografia\mde_sc_90.tif"
tbl = r"D:\Vianna\Dados\Raster\Clima\Raster_Clima.gdb\TB_EQUAC_ETP"
fields=['SG_PREFIX','SG_SUFIX','SG_PERIO','SG_FORMA','VL_A','VL_B','VL_C','VL_D']
arr = arcpy.da.TableToNumPyArray(tbl, fields, skip_nulls=True)
arr
array([('etp', '_', 'm01', '.tif', 7.5685, 1.61406, -3.39528, -0.03605),
('etp', '_', 'm02', '.tif', 66.3169, 2.0214 , -2.07062, -0.03056),
('etp', '_', 'm03', '.tif', 123.8896, 2.44179, -1.03483, -0.02871),
('etp', '_', 'm04', '.tif', 178.6612, 2.52436, 0.6756 , -0.01879),
('etp', '_', 'm05', '.tif', 152.986 , 1.48649, 1.1555 , -0.012 ),
('etp', '_', 'm06', '.tif', 126.2742, 1.22244, 1.07461, -0.00638),
('etp', '_', 'm07', '.tif', 107.1097, 1.69144, 0.45795, -0.00522),
('etp', '_', 'm08', '.tif', 78.4072, 2.02199, -0.45745, -0.00556),
('etp', '_', 'm09', '.tif', 40.4517, 1.63276, -1.21244, -0.00851),
('etp', '_', 'm10', '.tif', 43.7457, 2.8771 , -2.2587 , -0.01466),
('etp', '_', 'm11', '.tif', 19.1544, 2.43133, -2.86775, -0.02095),
('etp', '_', 'm12', '.tif', 1.5875, 2.37287, -3.70006, -0.0303 ),
('etp', '_', 'anual', '.tif', 834.3966, 24.28193, -15.89816, -0.22546)],
dtype=[('SG_PREFIX', '<U255'), ('SG_SUFIX', '<U255'), ('SG_PERIO', '<U255'), ('SG_FORMA', '<U255'), ('VL_A', '<f8'), ('VL_B', '<f8'), ('VL_C', '<f8'), ('VL_D', '<f8')])
fns = ["{}{}{}{}".format(*i) for i in arr[['SG_PREFIX', 'SG_SUFIX', 'SG_PERIO', 'SG_FORMA']]]
a = arr['VL_A']
b = arr['VL_B']
c = arr['VL_C']
d = arr['VL_D']
arrs = [a[i] + b[i]*lat + c[i]*lon + d[i]*alt for i in range(len(a))]
LL = arcpy.Point(lon[0,0], lat[-1,0]) # magical slicing
outname = "D:\\Temp\\{}".format(fns[2])
outraster = arcpy.NumPyArrayToRaster(arrs[2], LL, 1., 1.) # last 2 terms are cell size
outraster = arcpy.sa.ExtractByMask(outraster, alt)
outraster.save(outname)
Traceback (most recent call last):
File "<string>", line 6, in <module>
File "<string>", line 6, in <listcomp>
TypeError: 'numpy.float64' object cannot be interpreted as an integer
fns
['etp_m01.tif', 'etp_m02.tif', 'etp_m03.tif', 'etp_m04.tif', 'etp_m05.tif', 'etp_m06.tif', 'etp_m07.tif', 'etp_m08.tif', 'etp_m09.tif', 'etp_m10.tif', 'etp_m11.tif', 'etp_m12.tif', 'etp_anual.tif']
a
array([ 7.5685, 66.3169, 123.8896, 178.6612, 152.986 , 126.2742,
107.1097, 78.4072, 40.4517, 43.7457, 19.1544, 1.5875,
834.3966])
arrs
Traceback (most recent call last):
File "<string>", line 1, in <module>
NameError: name 'arrs' is not defined
arrs = [a[i] + b[i]*lat + c[i]*lon + d[i]*alt for i in range(len(a))]
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "<string>", line 1, in <listcomp>
TypeError: 'numpy.float64' object cannot be interpreted as an integer
... View more
09-17-2018
05:07 AM
|
0
|
8
|
1652
|
POST
|
Thank you, Dan! Unfortunatly the Tech Support could not help me. Congratulations for your blog! Best regards!
... View more
09-13-2018
05:30 AM
|
0
|
0
|
1845
|
POST
|
The same problem.... With "*" and with: import numpy as np
import arcpy
arcpy.CheckOutExtension("spatial")
arcpy.env.overwriteOutput = True
lat = np.arange(-29.373511, -25.928348, 0.000871310821466946, 'float')
lon = np.arange(-53.915588, -48.273851, 0.000871310821466947, 'float')
lon, lat = np.meshgrid(lon, lat)
alt = r"D:\Vianna\Dados\Raster\Topografia\mde_sc_90.tif"
tbl = r"D:\Vianna\Dados\Raster\Clima\Raster_Clima.gdb\TB_EQUAC_ETP"
fields=['SG_PREFIX','SG_SUFIX','SG_PERIO','SG_FORMA','VL_A','VL_B','VL_C','VL_D']
arr = arcpy.da.TableToNumPyArray(tbl, fields, skip_nulls=True)
... View more
09-12-2018
11:34 AM
|
0
|
21
|
1845
|
POST
|
I'd re-installed the ArcGis Pro 2.1.3 and the geodatabase path is "D:\Vianna\Dados\Raster\Clima\Raster_Clima.gdb". It still crashing whe running: arr = arcpy.da.TableToNumPyArray(tbl, "*"). I also tried to export the table as .txt to D:\Temp and used: tbl = r"D:\Temp\TB_EQUAC_ETP.txt"
arr = arcpy.da.TableToNumPyArray(tbl, "*") This also crashes python.
... View more
09-12-2018
11:14 AM
|
0
|
1
|
1845
|
POST
|
dir(arcpy.da) ['Describe', 'Domain', 'Editor', 'ExtendTable', 'FeatureClassToNumPyArray', 'InsertCursor', 'ListDomains', 'ListFieldConflictFilters', 'ListReplicas', 'ListSubtypes', 'ListVersions', 'NumPyArrayToFeatureClass', 'NumPyArrayToTable', 'Replica', 'SearchCursor', 'TableToNumPyArray', 'UpdateCursor', 'Version', 'Walk', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '_internal_eq', '_internal_sd', '_internal_vb']
... View more
09-06-2018
12:40 PM
|
0
|
3
|
1845
|
POST
|
I thank you all, but unfortunatly it still doesn´t working here. I follwed the code step by step, I re-imported the excel table to geodatabase and the line "arr = arcpy.da.TableToNumPyArray(tbl, "*")" still closing Python. import numpy as np
import arcpy
lat = np.arange(-29.373511, -25.928348, 0.000871310821466946, 'float')
lat
array([-29.373511 , -29.37263969, -29.37176838, ..., -25.93009063,
-25.92921932, -25.92834801])
lon = np.arange(-53.915588, -48.273851, 0.000871310821466947, 'float')
lon
array([-53.915588 , -53.91471669, -53.91384538, ..., -48.27646436,
-48.27559305, -48.27472174])
lon, lat = np.meshgrid(lon, lat)
lat
array([[-29.373511 , -29.373511 , -29.373511 , ..., -29.373511 ,
-29.373511 , -29.373511 ],
[-29.37263969, -29.37263969, -29.37263969, ..., -29.37263969,
-29.37263969, -29.37263969],
[-29.37176838, -29.37176838, -29.37176838, ..., -29.37176838,
-29.37176838, -29.37176838],
...,
[-25.93009063, -25.93009063, -25.93009063, ..., -25.93009063,
-25.93009063, -25.93009063],
[-25.92921932, -25.92921932, -25.92921932, ..., -25.92921932,
-25.92921932, -25.92921932],
[-25.92834801, -25.92834801, -25.92834801, ..., -25.92834801,
-25.92834801, -25.92834801]])
lon
array([[-53.915588 , -53.91471669, -53.91384538, ..., -48.27646436,
-48.27559305, -48.27472174],
[-53.915588 , -53.91471669, -53.91384538, ..., -48.27646436,
-48.27559305, -48.27472174],
[-53.915588 , -53.91471669, -53.91384538, ..., -48.27646436,
-48.27559305, -48.27472174],
...,
[-53.915588 , -53.91471669, -53.91384538, ..., -48.27646436,
-48.27559305, -48.27472174],
[-53.915588 , -53.91471669, -53.91384538, ..., -48.27646436,
-48.27559305, -48.27472174],
[-53.915588 , -53.91471669, -53.91384538, ..., -48.27646436,
-48.27559305, -48.27472174]])
alt = r"D:\Vianna\Dados\Raster\Topografia\mde_sc_90.tif"
tbl = r"D:\Vianna\Dados\Raster\Clima\Raster_Clima.gdb\TB_EQUAC_ETP"
alt
'D:\\Vianna\\Dados\\Raster\\Topografia\\mde_sc_90.tif'
tbl
'D:\\Vianna\\Dados\\Raster\\Clima\\Raster_Clima.gdb\\TB_EQUAC_ETP'
arr = arcpy.da.TableToNumPyArray(tbl, "*")
eqs = arr['DS_EQUAC']
fns = ["{}{}{}{}".format(*i) for i in arr[['SG_PREFIX', 'SG_SUFIX', 'SG_PERIO', 'SG_FORMA']]]
a = arr['VL_A']
b = arr['VL_B']
c = arr['VL_C']
d = arr['VL_D']
arrs = [a[i] + b[i]*lat + c[i]*lon + d[i]*alt for i in range(len(a))]
LL = arcpy.Point(lon[0,0], lat[-1,0]) # magical slicing
outname = "D:\\Temp\\{}".format(fns[2])
outraster = arcpy.NumPyArrayToRaster(arrs[2], LL, 1., 1.) # last 2 terms are cell size
outraster.save(outname)
... View more
09-06-2018
11:53 AM
|
0
|
5
|
3631
|
POST
|
I also did it. And the table is in the file geodatabase. However when I run the line 14, the Python crashes. I´ve tried to run from ArcGis Pro and from prompt. Did you try to run the script with attached data? I dont know if the problem is in the script or is the file geodatabase.
... View more
09-06-2018
10:16 AM
|
0
|
1
|
3631
|
POST
|
The line below closes the ArcGisPro arr = arcpy.da.TableToNumPyArray(tbl, "*")
... View more
09-05-2018
11:07 AM
|
0
|
0
|
3631
|
POST
|
This is what I need: Follow a data sample. import arcpy
arcpy.CheckOutExtension("Spatial")
arcpy.env.overwriteOutput = True
env.workspace = r"D:\Vianna\Dados\Raster\Clima" #Folder with raster datasets. This line is not working...
#Input raster datasets of the same masked area and same spatial reference
lat = r"D:\Vianna\Dados\Raster\Topografia\latit.tif" #Input lat raster
lon = r"D:\Vianna\Dados\Raster\Topografia\longit.tif" #Input lon raster
alt = r"D:\Vianna\Dados\Raster\Topografia\mde_sc_90.tif" # Input dem raster
tbl = r"D:\Vianna\Dados\Raster\Clima\Raster_Clima.gdb\TB_EQUAC_ETP"
arr = arcpy.da.TableToNumPyArray(tbl, "*")#This line close the ArcGis Pro
eqs = arr['DS_EQUAC']
fns = ["{}{}{}{}".format(*i) for i in arr[['SG_PREFIX', 'SG_SUFIX', 'SG_PERIO', 'SG_FORMA']]]
a = arr['VL_A']
b = arr['VL_B']
c = arr['VL_C']
d = arr['VL_D']
eq = [a[i] + b[i]*lat + c[i]*lon + d[i]*alt for i in range(len(a))] #This is the equation I need
#How to run this equation and write outputs named as "fns"?
... View more
09-05-2018
10:41 AM
|
0
|
5
|
3631
|
POST
|
I need to run 252 equations to calculate freeze probability using lat, lon, and altitude as raster inputs, multiplied by a, b, c and d regression coeficients. The equations are in format a+b*lat+c*lon+d*alt. The equations are in an Excel spreedsheet (attached) and I need to write them in a python script. The lat, lon and lat raster datasets are in the same folder and the output tif files have a standardized name (also in the Excel file). Thank you!
... View more
09-03-2018
01:23 PM
|
1
|
35
|
9202
|
Title | Kudos | Posted |
---|---|---|
1 | 09-18-2018 10:16 AM | |
1 | 06-19-2018 01:10 PM | |
1 | 09-03-2018 01:23 PM | |
1 | 06-14-2018 12:07 PM | |
1 | 06-14-2018 05:38 AM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|