HI,
I need to add "_var86" to the output file in the code below. How can I achieve it in the code below.
Thanks in advance.
import arcpy, sys
from arcpy import env
from arcpy.sa import *
# Input data source
arcpy.env.workspace = r"C:/Users/Desktop/weekly_avg_project"
arcpy.env.overwriteOutput = True
# Set output folder
OutputFolder = r"C:/Users/Desktop/weekly_avg_project/output"
# Loop through a list of files in the workspace
NCfiles = arcpy.ListFiles("*.nc")
for filename in NCfiles:
print("Processing: " + filename)
inNCfiles = arcpy.env.workspace + "//" + filename
fileroot = filename[0:(len(filename)-3)]
TempLayerFile = "SM_amount"
outRaster = OutputFolder + "//" + fileroot
# Process: Make NetCDF Raster Layer
outfile = arcpy.MakeNetCDFRasterLayer_md(filename, "var86", "lon", "lat", TempLayerFile, "", "", "BY_VALUE")
proj_ras = arcpy.ProjectRaster_management(outfile, "C:/Users/Desktop/weekly_avg_project/project_ras","GEOGCS['GCS_North_American_1983',DATUM['D_North_American_1983',SPHEROID['GRS_1980',6378137.0,298.257222101]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]]", "NEAREST", "0.125 0.125", "NAD_1983_To_WGS_1984_1", "", "GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]]")
# Process: Copy Raster
arcpy.CopyRaster_management(proj_ras, outRaster + ".tif", "", "", "", "NONE", "NONE", "")
Solved! Go to Solution.
I see... the below code may work.
import arcpy, sys
from arcpy import env
from arcpy.sa import *
# Input data source
arcpy.env.workspace = r"C:/Users/Desktop/weekly_avg_project"
arcpy.env.overwriteOutput = True
# Set output folder
OutputFolder = r"C:/Users/Desktop/weekly_avg_project/output"
# Loop through a list of files in the workspace
NCfiles = arcpy.ListFiles("*.nc")
for filename in NCfiles:
print("Processing: " + filename)
inNCfiles = arcpy.env.workspace + "//" + filename
fileroot = filename[:(len(filename)-3)] + '_var86'
#fileroot = filename[:-3] + '_var86' #I think this will work too- and is easier to read
....
...
..
.
Do you need to just rename the output filename? If so, it seems like the output layer is currently the 'TempLayerFile' variable. You can rename that like the code below.
import arcpy, sys
from arcpy import env
from arcpy.sa import *
# Input data source
arcpy.env.workspace = r"C:/Users/Desktop/weekly_avg_project"
arcpy.env.overwriteOutput = True
# Set output folder
OutputFolder = r"C:/Users/Desktop/weekly_avg_project/output"
# Loop through a list of files in the workspace
NCfiles = arcpy.ListFiles("*.nc")
for filename in NCfiles:
print("Processing: " + filename)
inNCfiles = arcpy.env.workspace + "//" + filename
fileroot = filename[0:(len(filename)-3)]
TempLayerFile = "SM_amount_var86"
outRaster = OutputFolder + "//" + fileroot
# Process: Make NetCDF Raster Layer
outfile = arcpy.MakeNetCDFRasterLayer_md(filename, "var86", "lon", "lat", TempLayerFile, "", "", "BY_VALUE")
proj_ras = arcpy.ProjectRaster_management(outfile, "C:/Users/Desktop/weekly_avg_project/project_ras","GEOGCS['GCS_North_American_1983',DATUM['D_North_American_1983',SPHEROID['GRS_1980',6378137.0,298.257222101]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]]", "NEAREST", "0.125 0.125", "NAD_1983_To_WGS_1984_1", "", "GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]]")
# Process: Copy Raster
arcpy.CopyRaster_management(proj_ras, outRaster + ".tif", "", "", "", "NONE", "NONE", "")
No. I need to change the file name for the "outRaster" not the "TempLayerFile"
I need to add "_var86" to the filename which will be the output name for the raster.
I see... the below code may work.
import arcpy, sys
from arcpy import env
from arcpy.sa import *
# Input data source
arcpy.env.workspace = r"C:/Users/Desktop/weekly_avg_project"
arcpy.env.overwriteOutput = True
# Set output folder
OutputFolder = r"C:/Users/Desktop/weekly_avg_project/output"
# Loop through a list of files in the workspace
NCfiles = arcpy.ListFiles("*.nc")
for filename in NCfiles:
print("Processing: " + filename)
inNCfiles = arcpy.env.workspace + "//" + filename
fileroot = filename[:(len(filename)-3)] + '_var86'
#fileroot = filename[:-3] + '_var86' #I think this will work too- and is easier to read
....
...
..
.
Thanks. it worked.