1

I am trying to import a ncdf file with 20000 bands (time steps of precipitation) to grass gis using r.in.gdal. My problem is that i dont need all the bands, only a portion of it, e.g : band 1 to band 200, then band 200 to band 400, etc. The only way i can do that is manually put the numbers of the band in module config '[band=integer[,integer,...]] ', e.g band = 1,2,3,4,5... 200.

Is there a way that a i can put for example like in python 'range(1,200)' and get the 200 first bands of the file?.

  • 1
    Sounds like a good case for running your GRASS workflow from a python script. If you want to stay with the terminal, then the Linux bash command: BANDS=seq --separator="," 1 200 will set the varialbe $BANDS to the list of intergers that you need. – Micha Nov 27 '19 at 22:38
  • Hello micha, i put the line in the terminal band=seq --separator="," 1 200 , but dont work. I tried a python script, like "range(1,200)", but dont work either, im very new in python grass gis with python, i am used to work with terminal. Thanks you – Pablo Sanhueza Nov 28 '19 at 3:40
  • Typo: BANDS=$(seq ...). Or use backticks instead of $( and ), but the $( and ) syntax is preferred to bacticks. GIS.SE website doesn't render backticks correctly. – mankoff Dec 13 '19 at 15:25
0

Maybe this will help you get started. From a running grass session, start python (or use the built in python console) and enter this script:

import grass.script as gscript

ncdf_file = "/path/to/your/netcdf/file.nc"
last = 200
band_list = [str(b) for b in range(1, last)]   
gscript.run_command('r.in.gdal', input=ncdf_file, band=band_list, output="ncdf")
gscript.run_command('g.list', type="rast", pattern="ncdf*")
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.