Hi,
Following on from a netCDF file generated several raster and then built a mosaic dataset, finally need to add time for each raster that form the mosaic.
Create the following code but I added the last time all previous raster.
I need each raster has its respective time. (the problem is in the last part of the code)
Can you help?
thank you very much
Gualberto
Following on from a netCDF file generated several raster and then built a mosaic dataset, finally need to add time for each raster that form the mosaic.
Create the following code but I added the last time all previous raster.
I need each raster has its respective time. (the problem is in the last part of the code)
Can you help?
thank you very much
Gualberto
Code:
import arcpy
import glob, os
import time
from time import localtime, strftime
tic = time.clock()
#*********** PRINCIPALES VARIABLES *************
prefijo = "sde.SDE."
Nommosaico = "test"
variable = "pslv"
outLoc = "Database Connections/Coneccion local SDE.sde/"
inNetCDF = "C:/IIE_Datos/Prediccion/Ejemplomosaico/MMOUT_DOMAIN1.nc"
ESTADOS_shp = "C:\\IIE_Datos\\Prediccion\\Ejemplomosaico\\Mapa república Mexicana\\ESTADOS.shp"
Coneccion_local_SDE_sde = "Database Connections\\Coneccion local SDE.sde"
# Process: Create Mosaic Dataset
arcpy.CreateMosaicDataset_management(outLoc, Nommosaico, "PROJCS['Lambert_Conformal_Conic',GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Lambert_Conformal_Conic'],PARAMETER['False_Easting',0.0],PARAMETER['False_Northing',-27.0],PARAMETER['Central_Meridian',-124.17],PARAMETER['Standard_Parallel_1',0.0],PARAMETER['Standard_Parallel_2',0.0],PARAMETER['Scale_Factor',1.0],PARAMETER['Latitude_Of_Origin',0.0],UNIT['Kilometer',1000.0]];-20037.7 -30225.3 149134210447.956;1 1;1 1;0.000001;2;2;IsHighPrecision", "", "")
# Process: Add Field
arcpy.AddField_management(outLoc + Nommosaico, "tiempo", "DATE", "", "", "", "T", "NULLABLE", "NON_REQUIRED", "")
nc_FP = arcpy.NetCDFFileProperties(inNetCDF)
nc_Dim = nc_FP.getDimensions()
test = outLoc + '/*'
r = glob.glob(test)
list = []
for i in r:
os.remove(i)
for dimension in nc_Dim:
top = nc_FP.getDimensionSize(dimension)
for i in range(0, top):
if dimension == "time":
dimension_values = nc_FP.getDimensionValue(dimension, i)
daat = "time '"+str(dimension_values)+ "'"
print daat
nowFile = str(i)
testt = dimension_values.replace("/","").replace(":","").replace(".","").replace("'","").replace(' ','')
print testt
rast = "time" + nowFile
#print rast
# Convierte todos los tiempos del NETCDF A LAYER
arcpy.MakeNetCDFRasterLayer_md(inNetCDF, variable, "lon", "lat", testt, "", daat, "BY_VALUE")
#CONVIERTE LAS LAYER A RASTER Y LOS GUARDA EN EL DIRECTORIO INDICADO
arcpy.CopyRaster_management(testt, outLoc + rast, "", "", "-3,402823e+038", "NONE", "NONE", "", "NONE", "NONE")
# Local variables:
Build_Raster_Pyramids = "true"
Calculate_Statistics = "true"
# Process: Add Rasters To Mosaic Dataset
arcpy.AddRastersToMosaicDataset_management(outLoc + Nommosaico, "Raster Dataset", outLoc + rast, "UPDATE_CELL_SIZES", "NO_BOUNDARY", "NO_OVERVIEWS", "", "0", "1500", "", "", "SUBFOLDERS", "ALLOW_DUPLICATES", Build_Raster_Pyramids, Calculate_Statistics, "NO_THUMBNAILS", "")
fech = str(dimension_values)
vv = time.strftime(fech)
# CREA UNA LISTA DE TODOS LOS RASTER CREADOS, PARA DESPUES UNIRLOS EN UNO SOLO
list.append(vv)
updateRows = arcpy.UpdateCursor(outLoc + Nommosaico)
for updateRow in updateRows:
updateRow.tiempo = vv
updateRows.updateRow(updateRow)
del updateRow, updateRows
#print list
toc = time.clock()
print toc - tic