|
POST
|
Dan Patterson, @Lan Murray, Xander Bakker i have tried using below command , but wont understand how to complete this code, and i want to take all 12 rasters in time series NetCDF file. Please guide on same # Import system modules
import arcpy
from arcpy import env
# Set environment settings
env.workspace = r"D:\NPP_GUJARAT_NEW\MODIS_BKU_DATA"
# Set local variables
inRaster = r"D:\NPP_GUJARAT_NEW\MODIS_BKU_DATA\NPP_2012A"
outNetCDFFile = r"D:\NPP_GUJARAT_NEW\MODIS_BKU_DATA\NC_FILE"
rasters = arcpy.ListRasters("*.tif")
for filename in rasters:
variable = "NPP"
units = "gcsqm"
XDimension = "x"
YDimension = "y"
bandDimension = ""
# Process: RasterToNetCDF
arcpy.RasterToNetCDF_md(filename, outNetCDFFile, variable, units,XDimension, YDimension, bandDimension)
... View more
01-21-2017
12:35 AM
|
0
|
0
|
4752
|
|
POST
|
Dan_Patterson, I am trying to find the solution, following by above comments but its not solved yet.
... View more
01-21-2017
12:25 AM
|
0
|
4
|
2809
|
|
POST
|
Dan Patterson Xander Bakker, Thank you very much all of you. I have updated my code, still problem persist, and and my raster name , r001_NPP.tif, r002_NPP.tif ........... r012_NPP.tif , and i checked one raster to converted in NetCDF using Arc GIS tool, i got perfect output from there, but i want to convert by the script , i have many of raster to convert. # Import system modules
import arcpy
from arcpy import env
# Set environment settings
env.workspace = r"D:\NPP_GUJARAT_NEW\MODIS_BKU_DATA"
# Set local variables
inRaster = r"D:\NPP_GUJARAT_NEW\MODIS_BKU_DATA\NPP_2012A"
outNetCDFFile = r"D:\NPP_GUJARAT_NEW\MODIS_BKU_DATA\NC_FILE\nppnetcdf.nc"
variable = "NPP"
units = "gcsqm"
XDimension = "x"
YDimension = "y"
bandDimension = ""
# Process: RasterToNetCDF
arcpy.RasterToNetCDF_md(inRaster, outNetCDFFile, variable, units,
XDimension, YDimension, bandDimension)
... View more
01-19-2017
08:03 AM
|
1
|
3
|
4752
|
|
POST
|
Xander Bakker, I have posted one of my problem, Please cooperate with us to solve the issues.
... View more
01-19-2017
02:04 AM
|
0
|
0
|
4752
|
|
POST
|
Dan Patterson, Thank you. I have updated my code by the add of r comment. and my raster file in .tif format. but unfortunately i am getting the error massage, below is error code, can you please explain, why i have to add .gdb and is it possible to run without gdb file ? Message File Name Line Position
Traceback
<module> <module1> 19
RasterToNetCDF C:\Program Files\ArcGIS\Desktop10.3\ArcPy\arcpy\md.py 253
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000840: The value is not a Raster Layer.
ERROR 000840: The value is not a Raster Catalog.
Failed to execute (RasterToNetCDF).
... View more
01-19-2017
12:19 AM
|
0
|
3
|
4752
|
|
POST
|
Dear all, I have multiples raster files, i am trying to convert it in NetCDF file using Arcpy script . below script i am using for conversion. While i ran the below script , i am getting the error, Below i have attached my raster file also, which i trying to convert in NetCDF format. Error Code ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000840: The value is not a Raster Layer.
ERROR 000840: The value is not a Raster Catalog.
Failed to execute (RasterToNetCDF). Below script i am using for conversion of raster to NetCDF. import arcpy
from arcpy import env
# Set environment settings
env.workspace = "D:\2012A"
# Set local variables
inRaster = "D:\2012A"
outNetCDFFile = "D:\2012A/nppnetcdf.nc"
variable = "NPP"
units = "gCSqm"
XDimension = "x"
YDimension = "y"
bandDimension = ""
# Process: RasterToNetCDF
arcpy.RasterToNetCDF_md(inRaster, outNetCDFFile, variable, units,
XDimension, YDimension, bandDimension)
... View more
01-18-2017
10:24 PM
|
0
|
24
|
11030
|
|
POST
|
Dan Patterson, Thank you very much. Exactly you hit the source of error. Sorry for Xander Bakker Sorry for the inconvenience. Main reason for error is: 1. During script writing, i followed the wrong equation (Snapshot) which is published by co-research author. 2. During Arc GIS raster calculator i followed the right equation which is published by main research author. I figured out the error with the snapshot equation after Dan Patterson pointed the minus and plus difference. And i checked the main research paper also from where co-author has taken the equation. And which equation i used in Arc GIS raster calculator and Excel sheet that is correct, that's why i was continuous getting the wrong result. Now i am getting the accurate result from both of programs. Once again thank you very much to all.
... View more
11-25-2016
09:53 PM
|
0
|
0
|
913
|
|
POST
|
Xander Bakker I am running into a problem of the mathematical expression in raster calculation. Earlier we had worked for writing the below code. According to existing mathematical function in the script, if raster cell value will be Earlier we had worked for writing the below code. According to existing mathematical function in the script, if the raster cell value (Mean raster in script ) will be increase or cross the threshold value (23 mentioned in script) , output raster cell should be decreased . But with this code, I am getting reverse output which is not desirable. I have checked the same mathematical equation in Arc GIS raster calculator and Excel also, both results are same. But Output generated from below script is not matching with Excel and Arc GIS raster calculator's result . Kindly provide your guidance to solve the issue . Below I have attached the link for raster data, which I am working on. Due to size limit here, I just uploaded on dropbox. I am using Arc GIS 10.3 and script running on PyScripter In below equation Topt = 23 which is constant value (in our script) and T = Monthly mean raster data which is changed monthly. Data link : Dropbox - TEST_TSCALAR1.rar Script copied from Arc GIS raster result : arcpy.gp.RasterCalculator_sa("""(1.185 / (1 + Exp(0.2 * (23 - 10 - "Mean_Temp_010.tif"))) / (1 + Exp(0.3 * ( - 23 - 10 + "Mean_Temp_010.tif")))) * 0.99""", "D:/NPP_GUJARAT/WEATHER_DATA/2012/T_SCALAR_2012C/T_SCALAR_010A.tif") ArcPy Script, import arcpy, os, calendar
from arcpy.sa import *
from arcpy import env
arcpy.env.overwriteOutput = True
arcpy.CheckOutExtension("Spatial")
topWorkspace = r'D:\TEST_TSCALAR'
ws_out = r'D:\TEST_TSCALAR\T_SCALAR_OUT' ### 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)}
# 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')
print rasterList1
for ras_name in rasterList1:
ras_mean = arcpy.Raster(os.path.join(folderPath, ras_name))
# I devided the above equation into two part
# TScalar2 (Exp = exponential)
ras_scal2 = 1.1814 / (1 + Exp(0.2 * (23 - 10 - ras_mean)))
# TScalar3
ras_scal3 = (1 + Exp(0.3 * (- 23 - 10 - ras_mean)))
# Multiply TScalar1 and TScalar2
ras_scal = 0.99 * (ras_scal2 / ras_scal3)
# Save the output
outRasterName = os.path.join(ws_out, "T_SCALAR_{}.tif".format(monthNumber))
#print outRasterName
ras_scal.save(outRasterName)
#print done
print 'done'
... View more
11-25-2016
07:19 AM
|
0
|
2
|
1498
|
|
POST
|
Xander Bakker, Thank you very much for your kind cooperation. your script working absolutely correct. I will readjust the search RadiusVariable accordingly. Really i learned a totally new thing from you about the importance of RadiusVariable. Earlier i just kept RadiusVariable as a default value.
... View more
11-24-2016
08:51 AM
|
0
|
1
|
1739
|
|
POST
|
Xander Bakker, Thank you. I ran the script by replacing ("r*_mean.shp"). Still i am getting error. Traceback (most recent call last):
File "<module1>", line 27, in <module>
File "C:\Program Files\ArcGIS\Desktop10.3\ArcPy\arcpy\sa\Functions.py", line 2467, in Idw
in_barrier_polyline_features)
File "C:\Program Files\ArcGIS\Desktop10.3\ArcPy\arcpy\sa\Utils.py", line 53, in swapper
result = wrapper(*args, **kwargs)
File "C:\Program Files\ArcGIS\Desktop10.3\ArcPy\arcpy\sa\Functions.py", line 2459, in Wrapper
in_barrier_polyline_features)
File "C:\Program Files\ArcGIS\Desktop10.3\ArcPy\arcpy\geoprocessing\_base.py", line 504, in <lambda>
return lambda *args: val(*gp_fixargs(args, True))
RuntimeError: Object: Error in executing tool Line no 20, i have followed the Arc GIS default value. searchRadius = RadiusVariable(10, 150000)
... View more
11-24-2016
04:17 AM
|
0
|
3
|
1739
|
|
POST
|
Dan , i have added the print statement but nothing file showing during program execution, i have posted below my full code with print statement. thank you
... View more
11-23-2016
11:11 PM
|
0
|
0
|
2287
|
|
POST
|
Xander Bakker , Thank you very much. Yes, you are absolutely correct. i have generated that point from raster data, actually i want to downscale the raster data to meet the spatial resolution with base map . Thats why i am trying to apply interpolation method. But from Kriging method we getting error, possibly error due to downscaling cell size, I am thinking to apply linear interpolation IDW method, though i have modified that code according to IDW interpolation, but the problem is same with the script, neither error nor output. Below is updated script for IDW import arcpy
from arcpy import env
from arcpy.sa import *
arcpy.env.parallelProcessingFactor = "100%"
arcpy.env.overwriteOutput = True
# Check out the ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")
env.workspace = r"D:\NPP_Test\KRIGING\Test_Points"
points = arcpy.ListFeatureClasses("r*_mean", "POINT")
print points
out_folder = r"D:\NPP_Test\KRIGING\OUTPUT_RAS"
zFields = ["GRID_CODE"]
cellSize = 0.002298707671
power = 2
searchRadius = RadiusVariable(10, 150000)
#Mask region of interest
mask="D:\NPP_Test\KRIGING\MASK_FILE\GUJARAT-STATE_NEW.shp"
# Execute IDW
for fc in points:
print fc
outIDW = Idw(fc, zField, cellSize, power, searchRadius)
# Execute Mask
IDWMASk = ExtractByMask(outIDW, mask)
#Save output raster to output workspace
tifname = fc[:4] # captures "r001" for output tiff name
print tifname
# Save output, except Solar Radiation raster
IDW_OUT= os.path.join(out_folder, 'r{0}.tif'.format(tifname))
IDWMASk.save(IDW_OUT)
#print done
print 'done'
... View more
11-23-2016
11:08 PM
|
0
|
6
|
2287
|
|
POST
|
Xander Bakker, I have modified this code from your early code which was multiple Z fields and one feature class. I have tried hard to fix the issue suggested by many of people but unfortunately I am still stuck yet. Kindly cooperate with us to solve the issue. Thank you
... View more
11-23-2016
01:41 AM
|
0
|
9
|
2287
|
|
POST
|
Dan, I have added the print statements, but not any files shows while running the script.
... View more
11-23-2016
12:42 AM
|
0
|
2
|
2287
|
|
POST
|
Hi, Curis, Thank you. I have updated my code according to you. and i did bit changes in line no 37. Below is my updated script, this script neither producing any error nor output. Also I have attached sample input file, which i trying to interpolate. Plase find the sample attached file for reference import arcpy
import os
from arcpy import env
from arcpy.sa import *
arcpy.env.overwriteOutput = True
# Check out the ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")
zField = "GRID_CODE" # field in each input point fc
#Kriging Veriable
cellSize = 0.05
lagSize = 0.5780481172534
majorRange = 6
partialSill = 3.304292110
nugget = 0.002701348
kRadius = RadiusFixed(20000, 1)
# get list of point fcs
env.workspace = r"D:\NPP_Test\KRIGING\Test_Points"
points = arcpy.ListFeatureClasses("r*mean", "POINT")
# where to save output
out_folder = r"D:\NPP_Test\KRIGING\OUTPUT_RAS"
#Mask region of interest
mask = r"D:\NPP_Test\KRIGING\MASK_FILE\GUJARAT-STATE_NEW.shp"
for fc in points:
kModelUniversalObj = KrigingModelUniversal("LINEARDRIFT", lagSize, majorRange, partialSill, nugget)
OutKriging = Kriging(fc, zField, kModelUniversalObj, cellSize, kRadius)
KrigMask = ExtractByMask(OutKriging, mask)
#Save output raster to output workspace
tifname = fc[:4] # captures "r001" for output tiff name
Krigout = os.path.join(out_folder, 'r{0}.tif'.format(tifname))
KrigMask.save(Krigout)
... View more
11-22-2016
11:40 PM
|
0
|
4
|
2287
|
| 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
|