accessing netCDF files through a wms/http or other servers

21 views
Skip to first unread message

Geneviev...@csiro.au

unread,
Jan 30, 2013, 6:09:14 PM1/30/13
to tropi...@googlegroups.com

Hi all,

 

I am trying to access .nc and .vrt files stored on an external server. There is access connections through OPENDAP, HTTP Server, WCS, WMS, NetcdfSubset, NCML, UDDC and ISO.

 

However, I am having trouble finding packages that deal with the downloading through R.

 

If anyone has any experience with netcdf files or could point me to a few packages I would greatly appreciate it!

Cheers

Gen

 

 

Genevieve Perkins
Rangelands Biodiversity Technical Officer

CSIRO Ecosystem Sciences
CSIRO

 

Phone: +61 7 4753 8567 | Mobile: 045751 5751 |  Fax: +61 7 4753 8600

geneviev...@csiro.au | www.csiro.au | www.csiro.au/people/Genevieve.Perkins.html

Address: ATSIP Bld 145 James Cook Drive, James Cook University Douglas Campus Qld 4811, Australia

Postal Address: Private Mail Bag, Aitkenvale Qld, 4814, Australia

PLEASE NOTE
The information contained in this email may be confidential or privileged. Any unauthorised use or disclosure is prohibited. If you have received this email in error, please delete it immediately and notify the sender by return email. Thank you. To the extent permitted by law, CSIRO does not represent, warrant and/or guarantee that the integrity of this communication has been maintained or that the communication is free of errors, virus, interception or interference.

Please consider the environment before printing this email.

 

Helga Wiederhecker

unread,
Feb 19, 2013, 6:32:17 PM2/19/13
to tropi...@googlegroups.com
Hope everything is just great with you all!

I wonder if anyone familiar with SDMTools could shed a light on this:

-Learning how to use asc2dataframe/ dataframe2asc function. What is
happening is that I use the function asc2dataframe to produce a
dataframe and when I save the file back to asc, it changes the cell size
and increases one column and one line. I have not performed a single
operation with the file. Is there any clue why it happens?

Thanks,

Helga

Jeremy VanDerWal

unread,
Feb 19, 2013, 9:28:08 PM2/19/13
to tropi...@googlegroups.com
Helga,

could you post the code your are using so that we can identify the issue?

thanks

Jeremy





--
An R group for questions, tips and tricks relevant to spatial ecology and climate change.
All R questions welcome.
--- You received this message because you are subscribed to the Google Groups "Tropical R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tropical-r+unsubscribe@googlegroups.com.
To post to this group, send an email to tropi...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



Helga Wiederhecker

unread,
Feb 19, 2013, 10:39:22 PM2/19/13
to tropi...@googlegroups.com
ooops,

   Sorry for that! Obvious that I needed to send the code to get help.
- The .asc file looks like this

ncols         521
nrows         746
xllcorner     -49.23332651332
yllcorner     -16.641664405353
cellsize      0.0083333337679505
NODATA_value  -9999
2.46603E-6 2.72739E-6 2.75033E-6 2.76176E-.......
 

- the code used was this
setwd("~/PRB/teste asc")
> t=asc2dataframe(file="Acacia_farnesiana2.asc")
working with Acacia_farnesiana2.asc ...
> dataframe2asc(t,filenames="result.asc")

- the output (result.asc) looks like this
ncols         522
nrows         747
xllcorner     -49.23332651332
yllcorner     -16.641664405353
cellsize      0.00833333376794343
NODATA_value  -9999
-9999 -9999 -9999 -9999 -9999


 Thanks


On 20/02/2013 12:28 PM, Jeremy VanDerWal wrote:
Helga,

could you post the code your are using so that we can identify the issue?

thanks

Jeremy
On Wed, Feb 20, 2013 at 9:32 AM, Helga Wiederhecker <helg...@gmail.com> wrote:
Hope everything is just great with you all!

I wonder if anyone familiar with SDMTools could shed a light on this:

 -Learning how to use asc2dataframe/ dataframe2asc function. What is happening is that I use the function asc2dataframe to produce a dataframe and when I save the file back to asc, it changes the cell size and increases one column and one line. I have not performed a single operation with the file. Is there any clue why it happens?

  Thanks,

              Helga


--
An R group for questions, tips and tricks relevant to spatial ecology and climate change.
All R questions welcome.
--- You received this message because you are subscribed to the Google Groups "Tropical R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tropical-r+...@googlegroups.com.

To post to this group, send an email to tropi...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


--
An R group for questions, tips and tricks relevant to spatial ecology and climate change.
All R questions welcome.
---
You received this message because you are subscribed to the Google Groups "Tropical R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tropical-r+...@googlegroups.com.

Lauren Hodgson

unread,
Feb 20, 2013, 12:58:06 AM2/20/13
to tropi...@googlegroups.com
Reproduced...Jeremy?

setwd('/home/jc148322/tmp/')

> tasc=read.asc('base.asc')
> tasc
Raster map of class "asc":
Cell size:  0.05
Number of rows:  691
Number of columns:  886
Type:  numeric

> t=asc2dataframe(file='base.asc')
> dataframe2asc(t,'out.asc')
> out=read.asc('out.asc')
> out
Raster map of class "asc":
Cell size:  0.05
Number of rows:  675
Number of columns:  819
Type:  numeric

> length(tasc)
[1] 612226
> length(out)
[1] 552825
...losing data

> length(tasc[which(is.finite(tasc))])
[1] 286244
> length(out[which(is.finite(out))])
[1] 286244
...not losing finite data

Lauren Hodgson

unread,
Feb 20, 2013, 1:08:46 AM2/20/13
to tropi...@googlegroups.com
Nevermind!  Not reproduced at all...

dataframe2asc effectively clips out rows/cols in which there are only nodata values.  This is why there are fewer rows and columns in the out.asc, with no loss of actual data.

Helga, can you supply your input ascii?

Helga Wiederhecker

unread,
Feb 20, 2013, 2:07:13 AM2/20/13
to tropi...@googlegroups.com
Hi Lauren,

  Sure! Here it is.
  Actually what happened is the opposite. The out file has one more row and column. I've realised that the included data is -9999 and the change in the cell size difference may have something to do with number precision (numbers of decimal places). However I wonder if there is a way to keep those parameters (ncols, nrows, xllcorner, yllcorner, cellsize) exactly the same to run other analysis. It is always possible to manually adjust the numbers and remove the extra column and row  after transforming it back to .asc but that is what I want to avoid.

Thanks   :-)
Acacia_farnesiana2.asc

Helga Wiederhecker

unread,
Feb 20, 2013, 11:31:34 PM2/20/13
to tropi...@googlegroups.com
Hi Lauren,

  Insisting a little bit... have you had the chance to have another look in the asc2dataframe thing. Is there a suggestion of how I would get the same number of cells and cell size in the output?  I am very curious to understand why it happens.

  Thanks :-)



On 20/02/2013 4:08 PM, Lauren Hodgson wrote:

Lauren Hodgson

unread,
Feb 20, 2013, 11:41:33 PM2/20/13
to tropi...@googlegroups.com
I played with the ascii and the number of rows and columns seem to increase by 1 due to the different cellsize, but I do not know why the cellsize is not the same.  Possibly due to rounding, but that is an as yet unchecked hypothesis.

No actual data values are lost or changed - there is just a row of nodata added to the end.

Helga Wiederhecker

unread,
Feb 20, 2013, 11:44:33 PM2/20/13
to tropi...@googlegroups.com
Thanks for the reply! the mistery continues...Hope I will not have to change that manually in the output...

  Thanks

Lauren Hodgson

unread,
Feb 20, 2013, 11:56:31 PM2/20/13
to tropi...@googlegroups.com
There are alternative (and slower) ways to do it, so you won't have to change them manually... but I know Jeremy was looking into this as well.

This code is different and slower, but might help if you're trying to get work done now:

library(SDMTools)
#a data frame from an ascii
tasc=read.asc('the.asc')
pos = as.data.frame(which(is.finite(tasc),arr.ind=TRUE)) #a positions file with rows and columns and lats and longs of finite values of an ascii
pos$lat = getXYcoords(tasc)$y[pos$col] #extract the longitudes
pos$lon = getXYcoords(tasc)$x[pos$row]; #extract the latitudes
pos$values=extract.data(cbind(pos$lon,pos$lat),tasc)

#a data frame derived from an ascii back to an ascii
copyasc=tasc
copyasc[cbind(pos$row,pos$col)]=pos$values
Reply all
Reply to author
Forward
0 new messages