|
POST
|
Xander Bakker. I am taking one more step to do calculation from all those raster from different subfolder. I am trying to execute this code for the next step calculation but i am getting error, below is code. Please cooperate me. The error code also attached Message File Name Line Position
Traceback
<module> <module2> 53
main <module2> 32
UnboundLocalError: local variable 'ras_APAR' referenced before assignment def main():
import arcpy
import os
arcpy.env.overwriteOutput = True
# Checkout extension
arcpy.CheckOutExtension("Spatial")
arcpy.env.overwriteOutput = True
# Workspace Folder
ws_in_apar = r'D:\MODIS-NDVI-2012\APAR'
ws_in_tscalar = r'D:\MODIS-NDVI-2012\TScalar'
ws_in_wscalar = r'D:\MODIS-NDVI-2012\WScalar'
ws_out_NPP = r'D:\MODIS-NDVI-2012\NPP'
# list "apar" rasters (e.g r001_APAR, r002_APAR so on )
arcpy.env.workspace = ws_in_apar
lst_ras_APAR = arcpy.ListRasters()
print "lst_ras_APAR", lst_ras_APAR
# list "tscalar" rasters (e.g r001_TSCALAR, r002_TSCALAR so on )
arcpy.env.workspace = ws_in_tscalar
lst_ras_TScalar = arcpy.ListRasters()
print "lst_ras_TScalar", lst_ras_TScalar
# list "wscalar" rasters (e.g r001_WSCALAR, r002_WSCALAR so on)
arcpy.env.workspace = ws_in_wscalar
lst_ras_WScalar = arcpy.ListRasters()
print "lst_ras_WScalar", lst_ras_WScalar
for ras_name in lst_ras_APAR:
ras_APAR = arcpy.Raster(os.path.join(ws_in_apar, ras_APAR))
print "ras_apar", ras_apar
for ras_TSCALAR in lst_ras_TSCALAR:
ras_TSCALAR = arcpy.Raster(os.path.join(ws_in_tscalar, ras_TSCALAR))
print "ras_TSCALAR", ras_TSCALAR
for ras_WSCALAR in lst_ras_WSCALAR:
ras_WSCALAR = arcpy.Raster(os.path.join(ws_in_wscalar, ras_WSCALAR))
print "ras_WSCALAR", ras_WSCALAR
# calculate
ras_NPP = (ras_APAR * ras_TSCALAR * ras_WSCALAR * 0.98)
#Process rectricted within mask file : Process will occur only on location that fall within the mask
#else it will be assigned to nodata inthe output
mask="D:\MOD-REF\NDVI\CROP-L-OCT-15.img"
NPP_Mask = ExtractByMask(ras_NPP, mask)
# save raster
ras_num = ras_name[:3]
out_name_NPP = os.path.join(ws_out_NPP, 'r{0}_NPP.TIF'.format(ras_num))
NPP_Mask.save(out_name_NPP)
if __name__ == '__main__':
main()
... View more
08-26-2016
03:10 AM
|
0
|
4
|
1876
|
|
POST
|
Xander Bakker. The expected output for month of October is 1 and we got the same. Through this calculation i am going to do research on monthly temperature effect on vegetation productivity, In India month of October is peak period for vegetation growth therefore October month temperature considering as a optimum temperature (ras_oct) for vegetation growth and its keep constant for all month's calculation. If Temperature more or less from Optimum Temperature than productivity of vegetation also less therefore we kept constant the October month temperature. Month of October the final output of TScalar is 1 and except October month TScalar vary between 0 to 1 because temperature can't meet with optimum temperature . I am very thankful to you for your guidance.
... View more
08-25-2016
09:38 AM
|
1
|
1
|
1876
|
|
POST
|
xander_bakker. Thank you very much for your kind support. Code working perfectly.
... View more
08-25-2016
06:23 AM
|
0
|
3
|
1866
|
|
POST
|
I want to calculate two different peramater using Monthly mean Temp. data using that equation. That Monthly mean Temp data stored in all monthly folder based on different month, for raster1 i want to take mean temp. raster from different month (e.g. JANAURAY : Mean_Temp_001, FEBRUARY: Mean_Temp_002 so on) and raster2 i want to keep constant the raster map of Month of October data (Mean_Temp_010). Later stage, i want to multiply TScalar1 and TScalar2 and save it TScalar folder
... View more
08-25-2016
05:55 AM
|
0
|
5
|
1866
|
|
POST
|
Xander Bakker. I just tried to modify above code for another calculation, But error occurring. Please cooperate me. Below i shown the modified code along with error massage, Message File Name Line Position
Traceback
<module> D:\Arc-GIS-Python-Script\T_SCALAR.py 27
Minus C:\Program Files\ArcGIS\Desktop10.1\arcpy\arcpy\sa\Functions.py 3840
swapper C:\Program Files\ArcGIS\Desktop10.1\arcpy\arcpy\sa\Utils.py 47
wrapper C:\Program Files\ArcGIS\Desktop10.1\arcpy\arcpy\sa\Functions.py 3837
TypeError: expected a raster or layer name import arcpy, os, calendar
from arcpy.sa import *
from arcpy import env
arcpy.env.overwriteOutput = True
arcpy.CheckOutExtension("Spatial")
arcpy.env.parallelProcessingFactor = "100%"
topWorkspace = r'D:\SWAT-WEATHER-DATA2'
ws_out = r'D:\SWAT-WEATHER-DATA2\TScalar' ### Output folder!!!
arcpy.env.workspace = topWorkspace
# Get dict of months and month-number (i.e. January = 001, March = 003 etc.)
months = {calendar.month_name[i].upper(): str(i).zfill(3) for i in range(1, 13)} # Get dict of months and month number (i.e. January = 001, March = 003 etc.)
# Step through list of all folders
for folderPath in arcpy.ListWorkspaces():
baseName = os.path.basename(folderPath).upper()
if baseName in months: # Test that subfolder is a month name
monthNumber = months[baseName] # Get month-number for use in output filename
arcpy.env.workspace = folderPath
# Raster1 take Mean_Temp raster from all month folder(e.g for january: Mean_temp_001.tif) and Raster 2 is constant month of october raster
rasterList1 = arcpy.ListRasters(r'Mean_Temp*.tif')
rasterList2 = arcpy.Raster(r'D:\SWAT-WEATHER-DATA2\OCTOBER\Mean_Temp_010.tif')
### combine list raster into equation
#TScalar1 = 1.1814 / (1 + EXP(0.2 * (rasterList2 - 10- rasterList1)))
TScalar1 = 1.1814 / ((1 + Exp(0.2 * (rasterList2 - 10 - rasterList1))))
#TScalar2 = 1/(1+EXP(0.3*(- rasterList2 - 10 + rasterList1)))
TScalar2 = 1 / (1 + Exp(0.3 * (- rasterList2 - 10 - rasterList1)))
# Multiply TScalar1 and TScalar2
TScalar = (TScalar1 * TScalar2)
#Save the output
outRasterName = os.path.join(ws_out, "T_SCALAR_{}.tif".format(monthNumber))
TScalar.save(outRasterName)
print outRasterName
#print done
print 'done'
... View more
08-25-2016
05:20 AM
|
0
|
7
|
1866
|
|
POST
|
Xander Bakker. This one is very useful step to verify the length of rasterList before calculating mean. Thank you
... View more
08-24-2016
01:27 PM
|
0
|
0
|
1866
|
|
POST
|
Dan_Patterson . I already marked it correct. Thank you
... View more
08-24-2016
01:02 PM
|
0
|
0
|
1866
|
|
POST
|
Xander Bakker . yes i have executed this function before performing cell-statistics to get the list of raster as per your suggestion . Thank you print rasterList
... View more
08-24-2016
12:47 PM
|
0
|
2
|
3507
|
|
POST
|
xander_bakker Thank you. code is working fine. Once again thank you for your kind cooperation.
... View more
08-24-2016
12:39 PM
|
0
|
2
|
1866
|
|
POST
|
Xander Bakker . i have corrected the code, but still error. month folder name in my database is (JANUARY, FEBRUARY ....DECEMBER) import arcpy, os, calendar
from arcpy import env
from arcpy.sa import *
arcpy.CheckOutExtension("Spatial")
arcpy.env.parallelProcessingFactor = "100%"
topWorkspace = r'D:\SWAT-WEATHER-DATA2'
arcpy.env.workspace = topWorkspace
# Get dict of months and month-number (i.e. January = 001, March = 003 etc.)
months = {calendar.month_name[i].upper(): str(i).zfill(3) for i in range(1, 13)} # Get dict of months and month number (i.e. January = 001, March = 003 etc.)
# Step through list of all folders
for folderPath in arcpy.ListWorkspaces():
baseName = os.path.basename(folderPath).upper()
if baseName in months: # Test that subfolder is a month name
monthNumber = months[baseName] # Get month-number for use in output filename
arcpy.env.workspace = folderPath
rasterList1 = arcpy.ListRasters('*Max_Temper.tif')
rasterList2 = arcpy.ListRasters('*Min_Temper.tif')
#Calculate maen
ws_out = (rasterList1 + rasterList2) / 2
outRasterName = os, path.join(ws_out, "Mean_Temp_{}.tif".format(monthNumber))
#print done
print 'done'
... View more
08-24-2016
12:11 PM
|
0
|
17
|
3507
|
|
POST
|
the following error massage i am getting Message File Name Line Position
Traceback
<module> <module1> 20
CellStatistics C:\Program Files\ArcGIS\Desktop10.1\arcpy\arcpy\sa\Functions.py 2817
swapper C:\Program Files\ArcGIS\Desktop10.1\arcpy\arcpy\sa\Utils.py 47
wrapper C:\Program Files\ArcGIS\Desktop10.1\arcpy\arcpy\sa\Functions.py 2813
RuntimeError: ERROR 999998: Unexpected Error.
... View more
08-24-2016
11:35 AM
|
0
|
0
|
3507
|
|
POST
|
I am trying to calculate mean of selected raster chosen from multiple raster. I have multiple raster file in different month folder, i am trying to select only two raster (e.g For JANUARY : 001_Max_Temper.tif, 001_Min_Temper.tif) from different month folder (JANUARY, FEBRUARY....DECEMBER) and calculate the mean of those selected raster and save it as on same month folder (e.g output name, JANUARY: 001_Mean_Temp). I have written a code to do this task but i am getting error massage while i am running this code. Below i have attached my code. import arcpy, os, calendar
from arcpy import env
from arcpy.sa import *
arcpy.CheckOutExtension("Spatial")
arcpy.env.parallelProcessingFactor = "100%"
topWorkspace = r'D:\SWAT-WEATHER-DATA2'
arcpy.env.workspace = topWorkspace
# Get dict of months and month-number (i.e. January = 001, March = 003 etc.)
months = {calendar.month_name[i].upper(): str(i).zfill(3) for i in range(1, 13)} # Get dict of months and month number (i.e. January = 001, March = 003 etc.)
# Step through list of all folders
for folderPath in arcpy.ListWorkspaces():
baseName = os.path.basename(folderPath).upper()
if baseName in months: # Test that subfolder is a month name
monthNumber = months[baseName] # Get month-number for use in output filename
arcpy.env.workspace = folderPath
rasterList = arcpy.ListRasters('*Max_Temper.tif', '*Min_Temper.tif')
# Execute CellStatistics
outCellStatistics = CellStatistics(rasterList, "MEAN", "NODATA")
#Save the output
outRasterName = outCellStatistics, "Mean_Temp_{}.tif".format(monthNumber)
outCellStatistics.save(outRasterName)
#print done
print 'done'
... View more
08-24-2016
11:15 AM
|
0
|
52
|
12992
|
|
POST
|
Xander Bakker. Thank you very much. Code given by you working absolutely correct. Many many thank you for your kind cooperation.
... View more
08-23-2016
10:51 AM
|
0
|
5
|
1612
|
|
POST
|
Xander Bakker. Thanks Upto Vfraction (Line no: 28) whatever i had already i shared with you in my last reply but next stage i don't understanding how to execute those function into code. Below i have attached the reference raster which i am working. Please find it
... View more
08-23-2016
09:33 AM
|
0
|
7
|
1612
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 02-01-2017 09:56 PM | |
| 1 | 01-19-2017 08:03 AM | |
| 1 | 07-31-2017 11:57 AM | |
| 1 | 08-25-2016 09:38 AM | |
| 1 | 08-17-2016 11:13 AM |
| Online Status |
Offline
|
| Date Last Visited |
11-11-2020
02:25 AM
|