[GRASS-user] pb. with netCDF row order

Nicolas,

I've been struggling with the issue of row order in netCDF files and
your post came perfect for me. Thank you very much for it.

I still have a problem that surely you or anyone in the list would find
trivial: the file I'm trying to convert

(downloadable in the Prudence project:
http://prudence.dmi.dk/data/seasonal/KNMI/t2m.mean.KNMI.HA2.nc.gz )

has four time bands, which I can't write separately into different ascii
files.

I'm using the script as...

./nc2grass-0001.bin t2m.mean.KNMI.HA2.nc t2m 1 100 1 80 > t2m.txt

...and the four time (seasonal) bands came together in the same ascii
line.

Should I use any additional argument with the script to be able to get
four separate ascii files?

Thanks a lot!

--
Dr. Eduardo Corbelle Rico

Associate Researcher
Research Group 1934-TeBio - Land Lab.
Dept. Agric. & Forest Engineering
University of Santiago de Compostela (SPAIN)

e-mail: eduardo.corbelle@usc.es
Tel: +34 982252303 ext. 23292
Fax: +34 982285926
Web: http://laborate.usc.es

Hi Eduardo,

I have downloaded your file and indeed as you guessed there is a way to
select the time index, and possibly also a level (altitude or depth)
index. It goes through optional positional arguments which are not
documented (sorry), because one has to guess that 'l' stands for the
time index and 'k' for the level one:

bash> nc2grass.sh -h
Usage: nc2grass.sh [-h]
       nc2grass.sh [-x <axis name>] [-y <axis name>] [-z <axis name>]
                   [-t <axis name>] [-m <missing value>]
                   <netCDF file> <variable> <imin> <imax> <jmin> <jmax>
[<l> [<k>]]
  -h: help
  -x: axis name in input file. Default: longitude
  -y: axis name in input file. Default: latitude
  -z: axis name in input file. Default: z
  -t: axis name in input file. Default: time
  -m: missing value code in output header. Default: -9.99e+02

Actually in your case 'ncdump -h' shows that the missing value flag is
1.e+30f and you can tell GRASS about it using the -m option; my
experience is that you have to provide this flag with the very same
formatting given to awk in the script, that is "+1.00e+30" (check out
the default value).

To get the first time index in your file:
nc2grass.sh -m +1.00e+30 t2m.mean.KNMI.HA2.nc t2m 1 100 1 80 1 > \
t2m_l1.txt
latN latS lonE lonW:
74.7500000 35.2500000 34.7500000 -14.7500000

Or you can automate the extraction like this:

bash> for l in 1 2 3 4; do

nc2grass.sh -m +1.00e+30 t2m.mean.KNMI.HA2.nc t2m 1 100 1 80 $l > \

t2m_l$l.txt

done

latN latS lonE lonW:
74.7500000 35.2500000 34.7500000 -14.7500000
latN latS lonE lonW:
74.7500000 35.2500000 34.7500000 -14.7500000
latN latS lonE lonW:
74.7500000 35.2500000 34.7500000 -14.7500000
latN latS lonE lonW:
74.7500000 35.2500000 34.7500000 -14.7500000
bash> ls
t2m_l1.txt t2m_l2.txt t2m_l3.txt t2m_l4.txt t2m.mean.KNMI.HA2.nc

One potential shortcoming of the script though is that you may provide a
time index, or a time index and a level index, but not a level index
alone... a fix could be to provide 'k' and 'l' as options instead of
positional arguments.

Hope it helps.

Le mardi 26 octobre 2010 à 12:48 +0200, Eduardo Corbelle Rico a écrit :

Nicolas,

I've been struggling with the issue of row order in netCDF files and
your post came perfect for me. Thank you very much for it.

I still have a problem that surely you or anyone in the list would find
trivial: the file I'm trying to convert

(downloadable in the Prudence project:
http://prudence.dmi.dk/data/seasonal/KNMI/t2m.mean.KNMI.HA2.nc.gz )

has four time bands, which I can't write separately into different ascii
files.

I'm using the script as...

./nc2grass-0001.bin t2m.mean.KNMI.HA2.nc t2m 1 100 1 80 > t2m.txt

...and the four time (seasonal) bands came together in the same ascii
line.

Should I use any additional argument with the script to be able to get
four separate ascii files?

Thanks a lot!

Hi Nicolas,

it works perfectly now. Thanks a lot again.

Eduardo

O Mar, 26-10-2010 ás 22:39 +0200, Nicolas Pérenne escribiu:

Hi Eduardo,

I have downloaded your file and indeed as you guessed there is a way to
select the time index, and possibly also a level (altitude or depth)
index. It goes through optional positional arguments which are not
documented (sorry), because one has to guess that 'l' stands for the
time index and 'k' for the level one:

bash> nc2grass.sh -h
Usage: nc2grass.sh [-h]
       nc2grass.sh [-x <axis name>] [-y <axis name>] [-z <axis name>]
                   [-t <axis name>] [-m <missing value>]
                   <netCDF file> <variable> <imin> <imax> <jmin> <jmax>
[<l> [<k>]]
  -h: help
  -x: axis name in input file. Default: longitude
  -y: axis name in input file. Default: latitude
  -z: axis name in input file. Default: z
  -t: axis name in input file. Default: time
  -m: missing value code in output header. Default: -9.99e+02

Actually in your case 'ncdump -h' shows that the missing value flag is
1.e+30f and you can tell GRASS about it using the -m option; my
experience is that you have to provide this flag with the very same
formatting given to awk in the script, that is "+1.00e+30" (check out
the default value).

To get the first time index in your file:
nc2grass.sh -m +1.00e+30 t2m.mean.KNMI.HA2.nc t2m 1 100 1 80 1 > \
t2m_l1.txt
latN latS lonE lonW:
74.7500000 35.2500000 34.7500000 -14.7500000

Or you can automate the extraction like this:

bash> for l in 1 2 3 4; do
>nc2grass.sh -m +1.00e+30 t2m.mean.KNMI.HA2.nc t2m 1 100 1 80 $l > \
t2m_l$l.txt
>done
latN latS lonE lonW:
74.7500000 35.2500000 34.7500000 -14.7500000
latN latS lonE lonW:
74.7500000 35.2500000 34.7500000 -14.7500000
latN latS lonE lonW:
74.7500000 35.2500000 34.7500000 -14.7500000
latN latS lonE lonW:
74.7500000 35.2500000 34.7500000 -14.7500000
bash> ls
t2m_l1.txt t2m_l2.txt t2m_l3.txt t2m_l4.txt t2m.mean.KNMI.HA2.nc

One potential shortcoming of the script though is that you may provide a
time index, or a time index and a level index, but not a level index
alone... a fix could be to provide 'k' and 'l' as options instead of
positional arguments.

Hope it helps.

Le mardi 26 octobre 2010 à 12:48 +0200, Eduardo Corbelle Rico a écrit :
> Nicolas,
>
> I've been struggling with the issue of row order in netCDF files and
> your post came perfect for me. Thank you very much for it.
>
> I still have a problem that surely you or anyone in the list would find
> trivial: the file I'm trying to convert
>
> (downloadable in the Prudence project:
> http://prudence.dmi.dk/data/seasonal/KNMI/t2m.mean.KNMI.HA2.nc.gz )
>
> has four time bands, which I can't write separately into different ascii
> files.
>
> I'm using the script as...
>
> ./nc2grass-0001.bin t2m.mean.KNMI.HA2.nc t2m 1 100 1 80 > t2m.txt
>
> ...and the four time (seasonal) bands came together in the same ascii
> line.
>
> Should I use any additional argument with the script to be able to get
> four separate ascii files?
>
> Thanks a lot!
>
>