Quantcast
Channel: Active questions tagged raster-calculator - Geographic Information Systems Stack Exchange
Viewing all articles
Browse latest Browse all 190

Calculate the mean of files generated from gdal.Translate

$
0
0

I created several velocity maps from .nc files through gdal.Translate. Each .nc file is organized in several bands, I am only interested in 1: velocities. gdal.Translate allows me to select only the velocities and cut them to my area of interest.

I would like to calculate the velocities' mean on a specific time-period, and for that I intended to open on Python my cut files (.vrt). However, when I open them in Python they are all "NoneType", while when I open them in QGIS I can see the velocities.

To calculate the means, my idea was to use:

myarray = np.array(ds.ReadAsArray())

Where ds is my cut velocity map. Then in a loop, I stack the myarray in a 3D matrix, and calculate the mean over the time axis.

Do you know if there is a better way to do it? Also, why do I have only NoneType files? I am new to gdal, and I am surprised QGIS can recognize my cut velocities maps while Python sees only a NoneType. I could calculate the mean through Raster Calculator in QGIS, but I want to automatize this task.

Ps: this is how I open my .nc file, cut and select the velocities only:

ds = gdal.Open("NETCDF:{0}:{1}".format(netcdf_name, layer_name))gdal.Translate('output/'+ Name +'.vrt', ds, projWin = [-3353315, 380000, -3257001, 260460])

Viewing all articles
Browse latest Browse all 190

Trending Articles