rmendels / rerddapXtracto

xtractomactic using rerddap
Other
14 stars 4 forks source link

Incorrect Number of Dimensions Error #28

Closed kdougg closed 2 years ago

kdougg commented 2 years ago

Hello!

I am trying to download the corresponding environmental variables for my tracking dataset, but when I run my code I get the error: in extract[[1]][xIndex[1]:xIndex[2], yIndex[1]:yIndex[2]] : incorrect number of dimensions

Here is the code that I am using: xpos.21 <- Inter.Breed.f$lon ypos.21 <- Inter.Breed.f$lat tpos.21 <- Inter.Breed.f$DateTime zpos.21 <- rep(0., length(xpos.21))

bath_info <- rerddap::info('etopo180') bath.2021 <- rxtracto(bath_info, parameter = 'altitude', xcoord = xpos.21, ycoord = ypos.21, xlen = .01, ylen = .01, progress_bar = TRUE) Inter.Breed.f$bath <- bath.2021$mean altitude

If you have any insight into what is causing this error I would greatly appreciate it! I have been scouring the internet, but haven't found anything. Thanks so much!

rmendels commented 2 years ago

@kdougg - offhand don't have an answer. I just tested the latest version with the Marlin tag data using Etopo180 and it worked just fine. Can you send me the first couple of rows of Inter.Breed.f so I can try and reproduce the error.

kdougg commented 2 years ago

Hello,

Here are the first few rows of code:

lon | lat | DateTime | dx | dy | dist | dt | R2n |  

47 | -123.0008 | 37.69743 | 2021-06-02 17:00:00 | 0.216537 | 0.008980 | 0.2167231247 | 3600 | 6.071400e-08 |   50 | -122.3927 | 37.70586 | 2021-06-02 20:00:00 | -0.000039 | -0.000130 | 0.0001357240 | 3600 | 3.696326e-01 |   51 | -122.3928 | 37.70573 | 2021-06-02 21:00:00 | -0.107376 | 0.019638 | 0.1091570264 | 3600 | 3.695830e-01 |   54 | -122.4115 | 37.70754 | 2021-06-03 00:00:00 | 0.012970 | 0.000206 | 0.0129716358 | 3600 | 3.471683e-01 |   55 | -122.3985 | 37.70775 | 2021-06-03 01:00:00 | 0.029869 | 0.032257 | 0.0439621566 | 3600 | 3.626226e-01 |   57 | -122.3690 | 37.74005 | 2021-06-03 03:00:00 | 0.000259 | -0.000282 | 0.0003828903 | 3600 | 4.007591e-01 |  

Let me know if you need further information!

Katherine

rmendels commented 2 years ago

@kdougg

Hi Katherine:

Try updating boh 'rerddap' and 'rerddapXtracto' to the latest versions. Otherwise double check that the values in xpos.21 and ypos.21 are what you think they are. The reason I say this is below.

HTH,

-Roy

> xpos <- c(-123.0008,  -122.3927,  -122.3928 )
> ypos <- c(37.69743, 37.70586,  37.70573)
> topoInfo <- rerddap::info('etopo180')
> test <- rxtracto(topoInfo, parameter = 'altitude', xcoord = xpos, ycoord = ypos, xlen = .01, ylen = .01)
> str(test)
List of 13
 $ mean altitude    : num [1:3] -29 10 10
 $ stdev altitude   : num [1:3] NA 16.9 16.9
 $ n                : int [1:3] 1 4 4
 $ satellite date   : logi [1:3] NA NA NA
 $ requested lon min: num [1:3] -123 -122 -122
 $ requested lon max: num [1:3] -123 -122 -122
 $ requested lat min: num [1:3] 37.7 37.7 37.7
 $ requested lat max: num [1:3] 37.7 37.7 37.7
 $ requested z min  : logi [1:3] NA NA NA
 $ requested z max  : logi [1:3] NA NA NA
 $ requested date   : logi [1:3] NA NA NA
 $ median altitude  : num [1:3] -29 3 3
 $ mad altitude     : num [1:3] 0 4.45 4.45
 - attr(*, "row.names")= chr [1:3] "1" "2" "3"
 - attr(*, "class")= chr [1:2] "list" "rxtractoTrack"
kdougg commented 2 years ago

That gives me great hope that I can make this work. I do have updated versions of both 'rerddap' and 'rerddapXtracto', so something must be wrong with the interpolated data. I'll keep trying. Thanks very much!!

rmendels commented 2 years ago

@kdougg If you can't get anywhere, and don't mind me seeing your data, save the Inter.Breed.f dataframe to an .RData file and send me that file. Then I can truly reproduce your code.

kdougg commented 2 years ago

So currently I am running code for bathymetry, SST, chlorophyll a, and wind. Bathymetry and wind are working, but the other 2 only return as NULL. If you have the time to check and see what is wrong, I have attached my code below. Thank you for your help! Inter.Breed.f.csv !

rmendels commented 2 years ago

@kdougg The linked file has the data, I would need to see the code.

kdougg commented 2 years ago

Sorry! Here is the code (github won't let me attach as a R file)

SST

SST_info <- rerddap::info('jplMURSST41') SST.2021 <- rxtracto(SST_info, parameter = 'analysed_sst', xcoord = xpos.21, ycoord = ypos.21, tcoord = tpos.21, xlen = 1, ylen = 1, progress_bar = TRUE) Inter.Breed.f$SST <- Inter.Breed.f$mean analysed_sst Inter.Breed.f$SST

Chlorophyll a

Chla_info <- rerddap::info('erdMWchla14day_LonPM180')

Chla.2021 <- rxtracto(Chla_info, parameter = 'chlorophyll', xcoord = xpos.21, ycoord = ypos.21, tcoord = tpos.21, zcoord = zpos.21, xlen = 1, ylen = 1, progress_bar = TRUE) Inter.Breed.f$chla <- Inter.Breed.f$mean chlorophyll Inter.Breed.f$chla

rmendels commented 2 years ago

@kdougg

See below. If I had to guess, I don't think the times that you are passing are what you think they are, particularly given the break in the field. I left off the time, because both datasets are daily so the time is irrelevant. I would be suspicious of what you are getting from wind, bathymetry is okay because time is to included.

-Roy

> library(rerddapXtracto)
> xpos <- c(-123.0008,  -122.3927,  -122.3928 )
> ypos <- c(37.69743, 37.70586,  37.70573)
> tpos <- c( '2021-06-02', '2021-06-02', '2021-06-02' )
> SST_info <- rerddap::info('jplMURSST41')
> SST.2021 <- rxtracto(SST_info, parameter = 'analysed_sst', xcoord = xpos, ycoord = ypos,
+                      tcoord = tpos, xlen = 1, ylen = 1, progress_bar = TRUE)
 0s 0s  |======================================================| 100%
 0s
> str(SST.2021)
List of 13
 $ mean analysed_sst  : num [1:3] 12.3 13.7 13.7
 $ stdev analysed_sst : num [1:3] 0.846 1.71 1.71
 $ n                  : int [1:3] 8869 3994 3994
 $ satellite date     : chr [1:3] "2021-06-02T09:00:00Z" "2021-06-02T09:00:00Z" "2021-06-02T09:00:00Z"
 $ requested lon min  : num [1:3] -124 -123 -123
 $ requested lon max  : num [1:3] -123 -122 -122
 $ requested lat min  : num [1:3] 37.2 37.2 37.2
 $ requested lat max  : num [1:3] 38.2 38.2 38.2
 $ requested z min    : logi [1:3] NA NA NA
 $ requested z max    : logi [1:3] NA NA NA
 $ requested date     : chr [1:3] "2021-06-02" "2021-06-02" "2021-06-02"
 $ median analysed_sst: num [1:3] 12.4 13 13
 $ mad analysed_sst   : num [1:3] 1.177 0.959 0.959
 - attr(*, "row.names")= chr [1:3] "1" "2" "3"
 - attr(*, "class")= chr [1:2] "list" "rxtractoTrack"
> Chla_info <- rerddap::info('erdMWchla14day_LonPM180')
> zpos <- c(0., 0., 0.)
> Chla.2021 <- rxtracto(Chla_info, parameter = 'chlorophyll', xcoord = xpos, ycoord = ypos,
+                       tcoord = tpos, zcoord = zpos, xlen = 1, ylen = 1, progress_bar = TRUE)
 0s 0s 0s  |======================================================| 100%
 0s
> str(Chla.2021)
List of 13
 $ mean chlorophyll  : num [1:3] 7.82 17.93 17.93
 $ stdev chlorophyll : num [1:3] 16 22.4 22.4
 $ n                 : int [1:3] 5693 2523 2523
 $ satellite date    : chr [1:3] "2021-06-02T00:00:00Z" "2021-06-02T00:00:00Z" "2021-06-02T00:00:00Z"
 $ requested lon min : num [1:3] -124 -123 -123
 $ requested lon max : num [1:3] -123 -122 -122
 $ requested lat min : num [1:3] 37.2 37.2 37.2
 $ requested lat max : num [1:3] 38.2 38.2 38.2
 $ requested z min   : num [1:3] 0 0 0
 $ requested z max   : num [1:3] 0 0 0
 $ requested date    : chr [1:3] "2021-06-02" "2021-06-02" "2021-06-02"
 $ median chlorophyll: num [1:3] 1.67 9.54 9.54
 $ mad chlorophyll   : num [1:3] 1.13 7.05 7.05
 - attr(*, "row.names")= chr [1:3] "1" "2" "3"
 - attr(*, "class")= chr [1:2] "list" "rxtractoTrack"
kdougg commented 2 years ago

Thanks very much for the feedback. I made a new column for just date without time and am running that. Still loading, but it is actually running for SST. Sorry to ask, but can you explain why time should not be included? I thought that the NOAA data would be potentially different depending on the time of day, so I feel a little confused as to why I only include date? Is it because I am only interested in the mean?

kdougg commented 2 years ago

Unfortunately, SST and chlorophyll are still returning NULL even without time.

rmendels commented 2 years ago

@kdougg - The dataset is a daily dataset, so say 2006-02-02 no matter what the time will extract data from the same file. And, the way you have time added (the space in between) likely would not be recognized by rxtracto() nor by ERDDAP. Otherwise, run the examples that I have run above. If those run okay, that means your set up is okay and that the program is working (if not, double check that you really do have the latest versions of both 'rerddap' and 'rerddapXtracto' by re-installing them). If you can run my examples (they are your first three data points), that suggests that the input is not what you think it is. Perhaps the data is being read in as characters, rather than numbers, or the time is being read in as a Posix time, rather than a character string. Also you can run with the verbose option set to TRUE and turn off the progress bar.

kdougg commented 2 years ago

Yesterday the samples were working, but today I am getting a completely new error even though I have not changed any code:

Error: .onLoad failed in loadNamespace() for 'readr', details: call: options() error: Value of SET_STRING_ELT() must be a 'CHARSXP' not a 'NULL'

Have you ever seen this error before? I am getting for both the samples you gave me and my own code.

rmendels commented 2 years ago

@kdougg That error comes from when the program tries to get the coordinate values using 'httr'. There should be code to catch the error before it happens, I will check on that down the line, but that is a side issue. It suggests you are not accessing the ERDDAP service, or again somehow what you think you are passing is not what you are actually passing (do a str() on the dataframe and make certain everything is of the proper type)

I just tried the SST example above, after clearing my 'rerddap' cache. Worked fine. Since I believe you are using the default URL, check you can reach https://upwell.pfeg.noaa.gov/erddap/griddap/jplMURSST41.html

kdougg commented 2 years ago

Since the examples you provided are still giving me the same error as above (error: Value of SET_STRING_ELT() must be a 'CHARSXP' not a 'NULL') I think that something is wrong with my connection to the ERDDAP service. I have also checked str() for my man data frame and cannot see anything wrong there.

I'm sorry, but I am not familiar with how to properly use the NOAA link that you provided?

Sorry for all the questions and no worries if you don't have to respond to this!

rmendels commented 2 years ago

@kdougg Since I can not reproduce this in any way, I am sort of stuck. First, in R can you run the following commands and send me the results:

packageVersion('rerddap')
packageVersion('rerddapXtracto')

Second, below is an URL. Copy and paste it into any browser. It should return a .csv file. Please send me what is dowloaded.

https://upwell.pfeg.noaa.gov/erddap/griddap/jplMURSST41.csv?time[(2021-11-10T09:00:00Z):1:(2021-11-14T09:00:00Z)],latitude[(-37):1:(-34)],longitude[(-140):1:(-134)]

kdougg commented 2 years ago

I completely understand and am sorry for all the questions.

According to R I have 0.7.6 and 1.1.2

Here is the CSV file that came back: jplMURSST41_49d5_08eb_2fd7.csv

rmendels commented 2 years ago

@kdougg That all looks correct. I can only suggest one other thing. I have the file Inter.Breed.f.csv. If you are willing, provide me the complete code where you read in the data, create the data frame, and pass it to 'rxtracto()'. If I can reproduce the error I can put it in the debugger. Particularly since the example I sent is not working, don't know what to tell you.

kdougg commented 2 years ago

I understand. Unfortunately all of my raw data is split into 13 different csv files as it was downloaded from 13 different devices so I don't want to put you through the trouble of going through all that. Thank you for your assistace!