Re: [GRASS-user] pb. with netCDF row order

2010-10-27 Thread Nicolas Pérenne
Le lundi 25 octobre 2010 à 19:57 +0200, Nicolas Pérenne a écrit :
> Thanks for the links. I'll try to provide some useful feekback on the
> GDAL Trac, issue #2654 looks pretty close to it indeed. 

Hi again, 

So I went on to have a look at the GDAL Trac, where I didn't understand
everything but realized that the problem appeared to be fixed in version
1.7.2 of GDAL (I was using 1.6.3). 

The UbuntuGIS software deposit which was hinted at on the GDAL download
area: 
https://launchpad.net/~ubuntugis/+archive/ppa/
proved to be a very convenient way to upgrade (among others) GDAL to
version 1.7.2, released 2010/04/23 (many thanks to the UbuntuGIS
project). 

And indeed the "upside down" effect disappeared, in the very same
workflow that I was using before: thanks to the GDAL developpers! 

Eduardo: if you can manage to get GDAL 1.7.2 on your system, you can
drop my script. 

Nicolas




___
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user


Re: [GRASS-user] pb. with netCDF row order

2010-10-27 Thread Eduardo Corbelle Rico
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 ] [-y ] [-z ]
>[-t ] [-m ]
> 
> [ []]
>   -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.750 35.250 34.750 -14.750
> 
> 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.750 35.250 34.750 -14.750
> latN latS lonE lonW:
> 74.750 35.250 34.750 -14.750
> latN latS lonE lonW:
> 74.750 35.250 34.750 -14.750
> latN latS lonE lonW:
> 74.750 35.250 34.750 -14.750
> 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!
> > 
> > 
> 
> 
> 
> 


___
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user


Re: [GRASS-user] pb. with netCDF row order

2010-10-26 Thread Nicolas Pérenne
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 ] [-y ] [-z ]
   [-t ] [-m ]

[ []]
  -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.750 35.250 34.750 -14.750

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.750 35.250 34.750 -14.750
latN latS lonE lonW:
74.750 35.250 34.750 -14.750
latN latS lonE lonW:
74.750 35.250 34.750 -14.750
latN latS lonE lonW:
74.750 35.250 34.750 -14.750
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!
> 
> 




___
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user


Re: [GRASS-user] pb. with netCDF row order

2010-10-26 Thread Eduardo Corbelle Rico
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.corbe...@usc.es
Tel:  +34 982252303 ext. 23292
Fax:  +34 982285926
Web: http://laborate.usc.es

___
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user


Re: [GRASS-user] pb. with netCDF row order

2010-10-25 Thread Nicolas Pérenne
Thanks for the links. I'll try to provide some useful feekback on the
GDAL Trac, issue #2654 looks pretty close to it indeed. 

Le dimanche 24 octobre 2010 à 20:50 +0200, Markus Neteler a écrit :
> 2010/10/24 Nicolas Pérenne :
> > Hi,
> >
> > I am new to GRASS but bought the book (3rd edition) and searched the
> > mail archive before sending in this question. The issue is about reading
> > a netCDF file: I got a "vertical mirror" of "upside down" effect (when I
> > display the imported raster using d.rast)
> 
> Perhaps you are hit by one of these bugs?
> http://trac.osgeo.org/gdal/ticket/2654
> http://trac.osgeo.org/gdal/ticket/2584
> 
> > but when I use an
> > old-fashioned technique (translating to GRASS ASCII, see below) it looks
> > okay.
> 
> Good!
> Perhaps you could add your findings to above ticket(s) as apply
> to help to fix the GDAL-netCDF driver for such cases.
> 
> Markus


___
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user


Re: [GRASS-user] pb. with netCDF row order

2010-10-24 Thread Markus Neteler
2010/10/24 Nicolas Pérenne :
> Hi,
>
> I am new to GRASS but bought the book (3rd edition) and searched the
> mail archive before sending in this question. The issue is about reading
> a netCDF file: I got a "vertical mirror" of "upside down" effect (when I
> display the imported raster using d.rast)

Perhaps you are hit by one of these bugs?
http://trac.osgeo.org/gdal/ticket/2654
http://trac.osgeo.org/gdal/ticket/2584

> but when I use an
> old-fashioned technique (translating to GRASS ASCII, see below) it looks
> okay.

Good!
Perhaps you could add your findings to above ticket(s) as apply
to help to fix the GDAL-netCDF driver for such cases.

Markus
___
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user


[GRASS-user] pb. with netCDF row order

2010-10-24 Thread Nicolas Pérenne
Hi, 

I am new to GRASS but bought the book (3rd edition) and searched the
mail archive before sending in this question. The issue is about reading
a netCDF file: I got a "vertical mirror" of "upside down" effect (when I
display the imported raster using d.rast) but when I use an
old-fashioned technique (translating to GRASS ASCII, see below) it looks
okay. 

The netCDF file itself is fine when viewed using, e.g., Ferret
(http://ferret.pmel.noaa.gov/Ferret/). The outputs of ncdump and
gdalinfo are provided at the end of this mail. 

The best procedure would be to follow
http://lists.osgeo.org/pipermail/grass-user/2010-September/057799.html
and thus either use r.in.gdal directly: 
grass>r.in.gdal -o NETCDF:"r2.nc":xe out=xe2
(in a WGS84 LOCATION) or after a gdal_translate: 
grass>gdal_translate -a_srs EPSG:4326 NETCDF:"r2.nc":h0 h02.tiff
grass>r.in.gdal h02.tiff out=h02

But when I view the resulting raster, h02, it is flipped "upside
down" (as if the latitude was increasing "downward"). 

Thus so far I need to rely on a script which is actually a follow-up of
this (old) thread: 
http://lists.osgeo.org/pipermail/grass-user/2002-December/008022.html
I have attached the script I use to this mail, in case somebody finds it
useful (you also need awk and nco); it is only an ersatz though, and I
would like to know what I can do to import my netCDF file directly into
GRASS (without a temporary GRASS ASCII file). 

Are there metadata I should add to the netCDF file to get r.in.gdal
happy? Does r.in.gdal need a particular row order in the netCDF file
(such as j index increasing southward)? 

That was a long one! 
Hope it was more or less clear. 

Nicolas

PS the system I am working with: 
bash>uname -a
Linux Herminet1 2.6.32-25-generic #45-Ubuntu SMP Sat Oct 16 19:48:22 UTC
2010 i686 GNU/Linux
bash>gdalinfo --version
GDAL 1.6.3, released 2009/11/19
bash>grass -v
GRASS GIS 6.4.0RC5+39438

#
bash> ncdump -h r2.nc
netcdf r2 {
dimensions:
longitude = 133 ;
latitude = 64 ;
time = UNLIMITED ; // (14 currently)
variables:
double longitude(longitude) ;
longitude:units = "degrees_east" ;
double latitude(latitude) ;
latitude:units = "degrees_north" ;
double time(time) ;
time:units = "seconds since 1900-1-1" ;
float h0(latitude, longitude) ;
h0:units = "m" ;
h0:missing_value = -999.f ;
float xe(time, latitude, longitude) ;
xe:units = "m" ;
xe:missing_value = -999.f ;
float u(time, latitude, longitude) ;
u:units = "m/s" ;
u:missing_value = -999.f ;
float v(time, latitude, longitude) ;
v:units = "m/s" ;
v:missing_value = -999.f ;
// global attributes:
:Conventions = "COARDS" ;
}

bash> gdalinfo r2.nc 
Driver: netCDF/Network Common Data Format
Files: r2.nc
Size is 512, 512
Coordinate System is `'
Metadata:
  NC_GLOBAL#Conventions=COARDS
Subdatasets:
  SUBDATASET_1_NAME=NETCDF:"r2.nc":h0
  SUBDATASET_1_DESC=[64x133] h0 (32-bit floating-point)
  SUBDATASET_2_NAME=NETCDF:"r2.nc":xe
  SUBDATASET_2_DESC=[14x64x133] xe (32-bit floating-point)
  SUBDATASET_3_NAME=NETCDF:"r2.nc":u
  SUBDATASET_3_DESC=[14x64x133] u (32-bit floating-point)
  SUBDATASET_4_NAME=NETCDF:"r2.nc":v
  SUBDATASET_4_DESC=[14x64x133] v (32-bit floating-point)
Corner Coordinates:
Upper Left  (0.0,0.0)
Lower Left  (0.0,  512.0)
Upper Right (  512.0,0.0)
Lower Right (  512.0,  512.0)
Center  (  256.0,  256.0)


nc2grass.sh
Description: application/shellscript
___
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user