|
POST
|
Dan Patterson. Thank you. Now Perfectly its working.
... View more
10-01-2016
02:23 AM
|
1
|
0
|
753
|
|
POST
|
I am trying to add two conditional function (whatever value of raster fall between 0 and 1 range remain same other value replace by 0), so far i have i can put single condition only but i am trying to execute two function. . Below is my conditional statement script line. outRaster = Con(localRaster <0.0, 0, localRaster) Above code only can replace whatever raster value below 0 will replace by 0, but how to add this condition > 0.0 and < 1 remain same and other value replace by 0.
... View more
10-01-2016
02:04 AM
|
0
|
2
|
1469
|
|
POST
|
Dan Patterson. Thank you very much. I have solved the issue as per your suggestion. i replaced it by forward slashes. But why the actual copied path is not working? is there any reason
... View more
10-01-2016
01:47 AM
|
0
|
1
|
787
|
|
POST
|
I am trying to save output raster in out_ws folder path with name r001_EVI, r002_EVI so on... but output raster goes to the main folder (MODIS_SURFACE_RF2012) with such output name rEVI_001_EVI. How to link it with desire location with output name e.g r001_EVI, r002_EVI so on. env.workspace = 'D:\MODIS_SURFACE_RF2012\EVI'
out_ws = 'D:\MODIS_SURFACE_RF2012\EVI1'
rasters = arcpy.ListRasters()
rastersCount = len(rasters)
counter = 0
dek = 1
# compute dekad rasters
while counter < rastersCount:
dekad = []
for i in range(counter,(counter+4)):
print i
dekad.append(rasters[i])
outCellStatistics = CellStatistics(dekad, "MEAN", "NODATA")
outRasterName = out_ws + 'r{:03d}_EVI.tif'.format (dek)
#outRasterName = "00" + str(dek) + ".tif"
outCellStatistics.save(outRasterName)
counter += 4
dek += 1
... View more
10-01-2016
12:27 AM
|
0
|
3
|
1599
|
|
POST
|
Xander Bakker. Thank you very much. I have checked the output as per your suggestion some pixel based calculation. Program generated output are exactly match with pixel wise calculation. Earlier i did with Arc GIS raster calculator. Might be problem with Arc GIS raster calculator output. Hearty gratitude for your valuable guidance.
... View more
09-28-2016
08:03 AM
|
0
|
0
|
450
|
|
POST
|
Xander Bakker. Thank you . I had corrected the equation but problem still persist , updated line below attached ras_EVI = 2.5 * (b02 - b01) / (b02 + (6.0 * b01) - (7.5 * b03) + 1.0)
... View more
09-28-2016
05:44 AM
|
0
|
2
|
450
|
|
POST
|
Xander Bakker, I ran the code, code running successfully. But when I compared the output between from our above program generated and by manually Arc GIS raster calculator generated output of EVI parameter of single time span (A2012001, A2012009, A201217) using Reference raster which i had attached earlier. I am not getting same output from both program. Manually generated output are differ from program generated output. We assumed manually generated output would be correct. kindly give suggestion to resolve the issue . As you mentioned to start a new question for additional question.My humble request you, After this topic we will start new query as a new question. If slow issue make more trouble to you then i will re-post the code as a new question. Sorry for inconvenience cause.
... View more
09-27-2016
05:28 AM
|
0
|
1
|
909
|
|
POST
|
Xander Bakker. Thank you so much. An excellent Code written by you. Code running perfectly. Once again my Hearty gratitude to you. Regarding additional question definitely next time i will start my query as a new question.
... View more
09-26-2016
12:29 AM
|
0
|
3
|
909
|
|
POST
|
Xander Bakker, Hearty gratitude for your guidance, I have written the code as per your suggestions above, But line no 70 shows error massage "SyntaxError: invalid syntax". I tried many times to solve but i could not able to solve. And whatever raster name we mentioned in line no 17 that is only for 3 time span, similarly 8 days interval i have till A2012001, A2012009, A2012017.............A2012361 raster. So All raster name i need to mention? Line no 12 : ws_bands - I have to give folder path where my raster data are stored ? Below is updated code, def main():
import os
import arcpy
# define all your workspaces here
ws_in_mean = r'D:\NPP_GUJARAT\MODIS_DATA\MODIS_NDVI_2012\MASKED_2012C'
ws_out_EVI= r'D:\MODIS_SURFACE_RF2012\EVI'
ws_out_LSWI= r'D:\MODIS_SURFACE_RF2012\LSWI'
ws_out_pscalar = r'D:\MODIS_SURFACE_RF2012\PSCALAR'
# get the list of rasters (bands)
ws_bands = r'D:\NPP_GUJARAT\MODIS_DATA\MODIS_NDVI_2012\MASKED_2012C' # is it correct to give folder path for all bands?
arcpy.env.workspace = ws_bands
lst_ras = arcpy.ListRasters()
# tmp list with bands to show flow (Here i have to mention all raster name?)
lst_ras = ['MOD09A1.MRTWEB.A2012001.005.sur_refl_b01.tif',
'MOD09A1.MRTWEB.A2012001.005.sur_refl_b02.tif',
'MOD09A1.MRTWEB.A2012001.005.sur_refl_b03.tif',
'MOD09A1.MRTWEB.A2012001.005.sur_refl_b04.tif',
'MOD09A1.MRTWEB.A2012001.005.sur_refl_b06.tif',
'MOD09A1.MRTWEB.A2012009.005.sur_refl_b01.tif',
'MOD09A1.MRTWEB.A2012009.005.sur_refl_b02.tif',
'MOD09A1.MRTWEB.A2012009.005.sur_refl_b03.tif',
'MOD09A1.MRTWEB.A2012009.005.sur_refl_b04.tif',
'MOD09A1.MRTWEB.A2012009.005.sur_refl_b06.tif',
'MOD09A1.MRTWEB.A2012017.005.sur_refl_b01.tif',
'MOD09A1.MRTWEB.A2012017.005.sur_refl_b02.tif',
'MOD09A1.MRTWEB.A2012017.005.sur_refl_b03.tif',
'MOD09A1.MRTWEB.A2012017.005.sur_refl_b04.tif',
'MOD09A1.MRTWEB.A2012017.005.sur_refl_b06.tif']
dct = {}
for ras_name in lst_ras:
date_id = ras_name[16:23]
if date_id in dct:
lst_bands = dct[date_id]
lst_bands.append(ras_name)
dct[date_id] = lst_bands
else:
lst_bands = [ras_name]
dct[date_id] = lst_bands
cnt = 0
for date_id, lst_bands in sorted(dct.items()):
cnt += 1
ras_num = "%03d" % (cnt,)
print ras_num, date_id, lst_bands
b01_name = getBand(lst_bands, 1)
b02_name = getBand(lst_bands, 2)
b03_name = getBand(lst_bands, 3)
b04_name = getBand(lst_bands, 4)
b06_name = getBand(lst_bands, 6)
b01 = os.path.join(ws_bands, b01_name)
b02 = os.path.join(ws_bands, b02_name)
b03 = os.path.join(ws_bands, b03_name)
b04 = os.path.join(ws_bands, b04_name)
b06 = os.path.join(ws_bands, b06_name)
if sum([[1,0][i is None] for i in [b01, b02, b03, b04, b06]]) == 5:
# do your calculations with the bands here#
# calculate EVI 2.5 * (band 01 - band 02) / ((band 02 + (6 * band 01) - (7.5 * band 03) + 1)
ras_EVI = 2.5 * (b01 - b02) / ((b02 + (6 * b01) - (7.5 * b03) + 1)
# save the output raster for EVI (for 01, 001_EVI, 009_EVI so on.......for 361, 361 _EVI)
out_name_EVI = os.path.join(ws_out_EVI, 'r{0}_EVI.TIF'.format(ras_num))
ras_EVI.save(out_name_EVI)
# Next calculate LSWI from BAND 2 and band 6
ras_LSWI = (b02 - b06 ) / (b02 + b06)
# save the output raster for LSWI (for 01, 001_LSWI, 009_LSWI so on.......for 361, 361 _LSWI)
out_name_LSWI = os.path.join(ws_out_LSWI, 'r{0}_LSWI.TIF'.format(ras_num))
ras_LSWI.save(out_name_LSWI)
# Whatever raster we get from step 2, we just take each raster from step 2 and execute below euation
ras_pscalar = 1 + ras_LSWI / 2
# save the output raster for pscalar (for 01, 001_PSCALAR, 009_PSCALAR so on.......for 361, 361 _LSWI)
out_name_pscalar = os.path.join(ws_out_pscalar, 'r{0}_PSCALAR.TIF'.format(ras_num))
ras_pscalar.save(out_name_pscalar)
print "Bands found, proceed with calculations..."
pass
def getBand(lst_bands, band_number):
band_id = "b{0}.tif".format("%02d" % (band_number,))
band_found = None
for band in lst_bands:
if band.lower().endswith(band_id):
band_found = band
break
return band_found
if __name__ == '__main__':
main()
... View more
09-23-2016
09:56 AM
|
0
|
8
|
909
|
|
POST
|
Hi Xander, Please kindly Could you help me out, I am totally not understanding that how i can use the logic to take 8 days time spam raster and do calculation for multi-parameters , I am trying to calculate some parameters (parameters mentioned in my code ) using same time span from different band using ArcPy. I have list of raster, raster name like MOD09A1.MRTWEB.A2012001.005.sur_refl_b01.tif MOD09A1.MRTWEB.A2012001.005.sur_refl_b02.tif MOD09A1.MRTWEB.A2012001.005.sur_refl_b03.tif MOD09A1.MRTWEB.A2012001.005.sur_refl_b04.tif MOD09A1.MRTWEB.A2012001.005.sur_refl_b06.tif MOD09A1.MRTWEB.A2012009.005.sur_refl_b01.tif MOD09A1.MRTWEB.A2012009.005.sur_refl_b02.tif MOD09A1.MRTWEB.A2012009.005.sur_refl_b03.tif MOD09A1.MRTWEB.A2012009.005.sur_refl_b04.tif MOD09A1.MRTWEB.A2012009.005.sur_refl_b06.tif MOD09A1.MRTWEB.A2012017.005.sur_refl_b01.tif MOD09A1.MRTWEB.A2012017.005.sur_refl_b02.tif MOD09A1.MRTWEB.A2012017.005.sur_refl_b03.tif MOD09A1.MRTWEB.A2012017.005.sur_refl_b04.tif MOD09A1.MRTWEB.A2012017.005.sur_refl_b06.tif In raster name different bands and 8 days interval time spam is there (e.g. A2012001, A2012009, A2012017……………A2012361) I trying to calculate some parameters for each time spam using different band and will loop same function on all time span (time spam 8 days interval: A2012001, A2012009, A2012017……………A2012361). For instance, whatever raster bands in 2012001 time span , will calculate different parameters , and save it 001_EVI, 001_LSWI, 001_PSCALAR, after calculation program will take 2012009 time span all bands and do same calculation and save it 002_EVI, 002_LSWI, 002_PSCALAR. I have written some code. I think its not enough to do it. And I am not understanding how to loop 8 days interval time span to all raster band. I have attached below, reference raster and raster name list. def main():
import arcpy
from arcpy import env
from arcpy.sa import *
import os
arcpy.env.overwriteOutput = True
# Checkout extension
arcpy.CheckOutExtension("Spatial")
arcpy.env.overwriteOutput = True
ws_in_mean = r'D:\NPP_GUJARAT\MODIS_DATA\MODIS_NDVI_2012\MASKED_2012C'
ws_out_EVI= r'D:\MODIS_SURFACE_RF2012\EVI'
ws_out_LSWI= r'D:\MODIS_SURFACE_RF2012\LSWI'
ws_out_pscalar = r'D:\MODIS_SURFACE_RF2012\PSCALAR'
# list "mean" rasters
arcpy.env.workspace = ws_in_mean
lst_ras_mean = arcpy.ListRasters()
print "lst_ras_mean", lst_ras_mean
for ras_name in lst_ras_mean:
ras_num = ras_name[:3]
ras_mean = arcpy.Raster(os.path.join(ws_in_mean, ras_name))
print "ras_mean", ras_name
# calculate EVI 2.5 * (band 01 - band 02) / ((band 02 + (6 * band 01) - (7.5 * band 03) + 1) (Min Raster Value )
ras_EVI = 2.5 * (b01 - b02) / ((b02 + (6 * b01) - (7.5 * b03) + 1)
# save the output raster for EVI (for 01, 001_EVI, 009_EVI so on.......for 361, 361 _EVI)
out_name_EVI = os.path.join(ws_out_EVI, 'r{0}_EVI.TIF'.format(ras_num))
ras_EVI.save(out_name_EVI)
# Next calculate LSWI from BAND 2 and band 6
ras_LSWI = (b02 - b06 ) / (b02 + b06)
# save the output raster for LSWI (for 01, 001_LSWI, 009_LSWI so on.......for 361, 361 _LSWI)
out_name_LSWI = os.path.join(ws_out_LSWI, 'r{0}_LSWI.TIF'.format(ras_num))
ras_LSWI.save(out_name_LSWI)
# Whatever raster we get from step 2, we just take each raster from step 2 and execute below euation
ras_pscalar = 1 + ras_LSWI / 2
# save the output raster for pscalar (for 01, 001_PSCALAR, 009_PSCALAR so on.......for 361, 361 _LSWI)
out_name_pscalar = os.path.join(ws_out_pscalar, 'r{0}_PSCALAR.TIF'.format(ras_num))
ras_pscalar.save(out_name_pscalar)
if __name__ == '__main__':
main()
... View more
09-21-2016
08:12 AM
|
0
|
1
|
1091
|
|
POST
|
Jake Skinner. I am still stuck to write above code. I am not understanding how to execute 8 days time span loop . Any guidance would be greatly appreciated.
... View more
09-20-2016
08:52 AM
|
0
|
0
|
964
|
|
POST
|
Jake Skinner I am trying to calculate some parameters (parameters mentioned in my code ) using same time span from diferent band using ArcPy. I have list of raster, raster name like MOD09A1.MRTWEB.A2012001.005.sur_refl_b01.tif MOD09A1.MRTWEB.A2012001.005.sur_refl_b02.tif MOD09A1.MRTWEB.A2012001.005.sur_refl_b03.tif MOD09A1.MRTWEB.A2012001.005.sur_refl_b04.tif MOD09A1.MRTWEB.A2012001.005.sur_refl_b06.tif MOD09A1.MRTWEB.A2012009.005.sur_refl_b01.tif MOD09A1.MRTWEB.A2012009.005.sur_refl_b02.tif MOD09A1.MRTWEB.A2012009.005.sur_refl_b03.tif MOD09A1.MRTWEB.A2012009.005.sur_refl_b04.tif MOD09A1.MRTWEB.A2012009.005.sur_refl_b06.tif MOD09A1.MRTWEB.A2012017.005.sur_refl_b01.tif MOD09A1.MRTWEB.A2012017.005.sur_refl_b02.tif MOD09A1.MRTWEB.A2012017.005.sur_refl_b03.tif MOD09A1.MRTWEB.A2012017.005.sur_refl_b04.tif MOD09A1.MRTWEB.A2012017.005.sur_refl_b06.tif In raster name different bands and 8 days interval time spam is there (e.g. A2012001, A2012009, A2012017……………A2012361) I trying to calculate some parameters for each time spam using different band and will loop same function on all time span (time spam 8 days interval: A2012001, A2012009, A2012017……………A2012361). For instance, whatever raster bands in 2012001 time span , will calculate different parameters , and save it 001_EVI, 001_LSWI, 001_PSCALAR, after calculation program will take 2012009 time span all bands and do same calculation and save it 002_EVI, 002_LSWI, 002_PSCALAR. I have written some code. I think its not enough to do it. And I am not understanding how to loop 8 days interval time span to all raster band. I have attached below, reference raster and raster name list. def main():
import arcpy
from arcpy import env
from arcpy.sa import *
import os
arcpy.env.overwriteOutput = True
# Checkout extension
arcpy.CheckOutExtension("Spatial")
arcpy.env.overwriteOutput = True
ws_in_mean = r'D:\NPP_GUJARAT\MODIS_DATA\MODIS_NDVI_2012\MASKED_2012C'
ws_out_EVI= r'D:\MODIS_SURFACE_RF2012\EVI'
ws_out_LSWI= r'D:\MODIS_SURFACE_RF2012\LSWI'
ws_out_pscalar = r'D:\MODIS_SURFACE_RF2012\PSCALAR'
# list "mean" rasters
arcpy.env.workspace = ws_in_mean
lst_ras_mean = arcpy.ListRasters()
print "lst_ras_mean", lst_ras_mean
for ras_name in lst_ras_mean:
ras_num = ras_name[:3]
ras_mean = arcpy.Raster(os.path.join(ws_in_mean, ras_name))
print "ras_mean", ras_name
#Setp:1
# calculate EVI 2.5 * (band 01 - band 02) / ((band 02 + (6 * band 01) - (7.5 * band 03) + 1) (Min Raster Value )
ras_EVI = 2.5 * (b01 - b02) / ((b02 + (6 * b01) - (7.5 * b03) + 1)
# save the output raster for EVI (for 01, 001_EVI, 009_EVI so on.......for 361, 361 _EVI)
out_name_EVI = os.path.join(ws_out_EVI, 'r{0}_EVI.TIF'.format(ras_num))
ras_EVI.save(out_name_EVI)
#Setp:2
# Next calculate LSWI from BAND 2 and band 6
ras_LSWI = (b02 - b01 ) / (b02 + b01)
# save the output raster for LSWI (for 001, 001_LSWI, 009_LSWI so on.......for 361, 361 _LSWI)
out_name_LSWI = os.path.join(ws_out_LSWI, 'r{0}_LSWI.TIF'.format(ras_num))
ras_LSWI.save(out_name_LSWI)
#Setp:3
# Whatever raster we get from step 2, we just take each raster from step 2 and execute below euation
ras_pscalar = 1 + ras_LSWI / 2
# save the output raster for pscalar (for 001, 001_PSCALAR, for 009, 009_PSCALAR so on.......for 361, 361 _LSWI)
out_name_pscalar = os.path.join(ws_out_pscalar, 'r{0}_PSCALAR.TIF'.format(ras_num))
ras_pscalar.save(out_name_pscalar)
if __name__ == '__main__':
main()
... View more
09-17-2016
01:05 AM
|
0
|
1
|
964
|
|
POST
|
i renamed the input name as well as folder name to make it short, but error still persist . PyScripter getting crash Message File Name Line Position
Traceback
__call__ E:\Geo_Softwares\PyScripter\PyScripter\Lib\rpyc.zip\rpyc\core\netref.py 196
syncreq E:\Geo_Softwares\PyScripter\PyScripter\Lib\rpyc.zip\rpyc\core\netref.py 71
sync_request E:\Geo_Softwares\PyScripter\PyScripter\Lib\rpyc.zip\rpyc\core\protocol.py 431
serve E:\Geo_Softwares\PyScripter\PyScripter\Lib\rpyc.zip\rpyc\core\protocol.py 379
_recv E:\Geo_Softwares\PyScripter\PyScripter\Lib\rpyc.zip\rpyc\core\protocol.py 337
recv E:\Geo_Softwares\PyScripter\PyScripter\Lib\rpyc.zip\rpyc\core\channel.py 50
read E:\Geo_Softwares\PyScripter\PyScripter\Lib\rpyc.zip\rpyc\core\stream.py 166
exceptions.EOFError: [Errno 10054] An existing connection was forcibly closed by the remote host
... View more
09-14-2016
12:02 AM
|
0
|
1
|
884
|
|
POST
|
Dan Patterson, I corrected the line by replace line no 4 suggested by you. Now i am getting following error massage. Error massage displaying output raster name can't be more than 13 character. So whats is the possible way to short the output raster name Message File Name Line Position
Traceback
<module> D:\Arc-GIS-Python-Script\NetCDF_RASTER_TIME_SERIES.py 39
CopyRaster C:\Program Files\ArcGIS\Desktop10.1\arcpy\arcpy\management.py 11034
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000472: Name of single band grid cannot have more than 13 characters
Failed to execute (CopyRaster).
... View more
09-13-2016
09:10 PM
|
0
|
1
|
884
|
|
POST
|
Dan , Neil, i extremely sorry for the late reply, here holiday was going on . Problem still persist. by this command i am trying to extract selected time spam images. n[:-12]
... View more
09-13-2016
07:45 PM
|
0
|
3
|
2567
|
| 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
|