rmendels / rerddapXtracto

xtractomactic using rerddap
Other
14 stars 4 forks source link

error rxtracto in example file #12

Closed JM-RG closed 5 years ago

JM-RG commented 5 years ago

Hi Roy,

when just trying to reproduce the example provided:

tagData <- Marlintag38606 xpos <- tagData$lon ypos <- tagData$lat tpos <- tagData$date zpos <- rep(0., length(xpos)) swchlInfo <- rerddap::info('erdSWchla8day') swchl <- rxtracto(swchlInfo, parameter = 'chlorophyll', xcoord = xpos, ycoord = ypos, tcoord = tpos, zcoord = zpos, xlen = .2, ylen = .2)

I get the following error:

Error in if (substr(urlbase, lenURL, lenURL) != "/") { : argument is of length zero

Whit my own data, here summary(tagData) xpos <- tagData$Longitude ypos <- tagData$Latitude tpos <- tagData$Date zpos <- rep(0., length(xpos))

mylist <- list('varname:chla', 'datasetname:8day') searchResult <- searchData(mylist) DT::datatable(searchResult) outInfo <- rerddap::info('erdVH3chla8day') gps1chlR <- rxtracto(outInfo, parameter = 'chla', xcoord = xpos, ycoord = ypos, tcoord = tpos, zcoord = zpos, xlen = .2, ylen = .2)

I get this error: [1] "Requested coordinate names do no match dataset coordinate names" [1] "Requested coordinate names: longitude" "Requested coordinate names: latitude" [3] "Requested coordinate names: altitude" "Requested coordinate names: time"
[1] "Dataset coordinate names: time" "Dataset coordinate names: latitude" [3] "Dataset coordinate names: longitude" Error: Execution halted

Any idea?

I would like to use the package but got stucked just at the start :/

Thanks in advance

JM

rmendels commented 5 years ago

@JM-RG I just ran the output below at home, so I have no advantage of being on our LAN or the like. Given that, I would suggest that you:

  1. Make certain you have the latest version of 'rerddap' and 'rerddapXtracto' installed.

  2. Print out the value of swchlInfo <- rerddap::info('erdSWchla8day') to make certain that this got info

  3. If everything else looks okay, use the 'verbose' option in rxtracto().

> library(rerddapXtracto)
> tagData <- Marlintag38606
> xpos <- tagData$lon
> ypos <- tagData$lat
> tpos <- tagData$date
> zpos <- rep(0., length(xpos))
> swchlInfo <- rerddap::info('erdSWchla8day')
> 
> swchlInfo
<ERDDAP info> erdSWchla8day 
 Base URL: https://upwell.pfeg.noaa.gov/erddap/ 
 Dimensions (range):  
     time: (1997-09-02T00:00:00Z, 2010-12-07T00:00:00Z) 
     altitude: (0.0, 0.0) 
     latitude: (-90.0, 90.0) 
     longitude: (0.0, 360.0) 
 Variables:  
     chlorophyll: 
         Units: mg m-3 
> swchl <- rxtracto(swchlInfo, parameter = 'chlorophyll', xcoord = xpos, ycoord = ypos, tcoord = tpos, zcoord = zpos, xlen = .2, ylen = .2)
Registered S3 methods overwritten by 'httr':
  method                 from  
  as.character.form_file crul  
  print.cache_info       hoardr
> str(swchl)
List of 13
 $ mean chlorophyll  : num [1:152] 0.073 NaN 0.074 0.0653 0.0403 ...
 $ stdev chlorophyll : num [1:152] NA NA 0.00709 0.00768 0.02278 ...
 $ n                 : int [1:152] 1 0 16 4 7 9 4 3 0 6 ...
 $ satellite date    : chr [1:152] "2003-04-19T00:00:00Z" "2003-04-27T00:00:00Z" "2003-04-27T00:00:00Z" "2003-04-27T00:00:00Z" ...
 $ requested lon min : num [1:152] 204 204 204 204 204 ...
 $ requested lon max : num [1:152] 204 204 204 204 204 ...
 $ requested lat min : num [1:152] 19.6 19.7 20.3 20.2 20.2 ...
 $ requested lat max : num [1:152] 19.8 19.9 20.5 20.4 20.4 ...
 $ requested z min   : num [1:152] 0 0 0 0 0 0 0 0 0 0 ...
 $ requested z max   : num [1:152] 0 0 0 0 0 0 0 0 0 0 ...
 $ requested date    : chr [1:152] "2003-04-23" "2003-04-24" "2003-04-30" "2003-05-01" ...
 $ median chlorophyll: num [1:152] 0.073 NA 0.073 0.0645 0.031 ...
 $ mad chlorophyll   : num [1:152] 0 NA 0.00297 0.00741 0.0089 ...
 - attr(*, "row.names")= chr [1:152] "1" "2" "3" "4" ...
 - attr(*, "class")= chr [1:2] "list" "rxtractoTrack"
JM-RG commented 5 years ago

Thanks for replying Roy. I updated all the packages just to be sure, and now the code works well with the Marlin example, but doesn't with my own track. I checked it out and rerddap::info('erdMH1sstd8day')) succesfully retrieves information:

mylist <- list('varname:chl', 'datasetname:8day')
searchResult <- searchData(mylist)
DT::datatable(searchResult)
out <- rerddap::info('erdMH1chla8day')
out
erdMH1chla8day Base URL: https://upwell.pfeg.noaa.gov/erddap/ Dimensions (range): time: (2003-01-05T00:00:00Z, 2019-06-06T00:00:00Z) latitude: (-89.97918, 89.97916) longitude: (-179.9792, 179.9792) Variables: chlorophyll: Units: mg m^-3 ``` summary(tagData) ``` Longitude Latitude Date_Time Date Min. :-16.16 Min. :27.27 Min. :2012-04-16 05:27:03 Min. :2012-04-16 1st Qu.:-16.04 1st Qu.:27.35 1st Qu.:2012-04-16 08:54:34 1st Qu.:2012-04-16 Median :-15.90 Median :27.47 Median :2012-04-16 12:30:02 Median :2012-04-16 Mean :-15.94 Mean :27.48 Mean :2012-04-16 12:44:55 Mean :2012-04-16 3rd Qu.:-15.83 3rd Qu.:27.57 3rd Qu.:2012-04-16 16:10:36 3rd Qu.:2012-04-16 Max. :-15.79 Max. :27.84 Max. :2012-04-16 20:51:59 Max. :2012-04-16 ``` xpos <- tagData$Longitude ypos <- tagData$Latitude tpos <- tagData$Date zpos <- rep(0., length(xpos)) ``` This is the error: `gps1chl <- rxtracto(out, parameter = 'chlorophyll', xcoord = xpos, ycoord = ypos, tcoord = tpos, zcoord = zpos, xlen = .2, ylen = .2, verbose=T)` [1] "Requested coordinate names do no match dataset coordinate names" [1] "Requested coordinate names: longitude" "Requested coordinate names: latitude" [3] "Requested coordinate names: altitude" "Requested coordinate names: time" [1] "Dataset coordinate names: time" "Dataset coordinate names: latitude" [3] "Dataset coordinate names: longitude" Error: Execution halted Thanks again
rmendels commented 5 years ago

One thing is you pass a zcoord value when the dataset does not have a 4th dimension (look at your own print out). Try removing the "zcoord = zpos" and see if the works. If not, please send me the entire script you are running and the first few lines of your dataset.

JM-RG commented 5 years ago

Now it works. I didn't notice this part of the vignette: "the zcoord has to be explicitly given, because ‘erdSWchla8day’ is a 4-D dataset (altitude is a dimension)." So with datasets I'm interested in, without a 4D, zpos is not needed.

Thank u again!