AnsweredAssumed Answered

Raster calculation outputs are not matching with manual and ArcPy

Question asked by india123 on Jul 8, 2018
Latest reply on Jul 12, 2018 by india123

Hi Xander Bakker, earlier we had worked on the below code, I just bit modified the code as per my requirement, but the modified code is running but it's not generating the accurate result. I have cross check the output with manual calculation in ArcGIS. Both are different results and the problem with output name also.

Could you please look at the code

 

 

 

def main():
    import arcpy
    import os
    from arcpy import env
    from arcpy.sa import *
    arcpy.env.overwriteOutput = True
    # Checkout extension
    arcpy.CheckOutExtension("Spatial")
    arcpy.env.overwriteOutput = True


    ws_in_apar = r'E:\Test\APAR'
    ws_in_tscalar = r'E:\Test\T_Scalar'
    ws_in_wscalar = r'E:\Test\W_Scalar'
    ws_out_NPP = r'E:\Test\NPP_1982'

    # list "apar" rasters (e.g r001_APAR)
    arcpy.env.workspace = ws_in_apar
    lst_ras_APAR = arcpy.ListRasters()
    print "lst_ras_APAR", lst_ras_APAR

    # list "tscalar" rasters (e.g r012_TSCALAR)
    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)
    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_name))
        print "ras_APAR", ras_APAR

    for ras_name in lst_ras_TSCALAR:
        ras_TSCALAR = arcpy.Raster(os.path.join(ws_in_tscalar, ras_name))
        print "ras_TSCALAR", ras_TSCALAR


    for ras_name in lst_ras_WSCALAR:
        ras_WSCALAR = arcpy.Raster(os.path.join(ws_in_wscalar, ras_name))
        print "ras_WSCALAR", ras_WSCALAR

        # calculate
        ras_NPP = (ras_APAR * ras_TSCALAR * ras_WSCALAR * 0.845)

          
        out_name_NPP = os.path.join(ws_out_NPP, 'r{0}_NPP.TIF'.format(ras_name))
        ras_NPP.save(out_name_NPP)

if __name__ == '__main__':
    main()

Outcomes