hugomflavio / actel

Standardised analysis of acoustic telemetry data from fish moving through receiver arrays
https://hugomflavio.github.io/actel-website
26 stars 6 forks source link

Mismatch between release sites reported and locations (multiple issues) #147

Open SimonDedman opened 5 days ago

SimonDedman commented 5 days ago

1. Error mismatch release sites and locations

Error: There is a mismatch between the release sites reported and the release locations for the animals. The following release sites were listed in the biometrics.csv file but are not part of the release sites listed in the spatial.csv file: GNWR Please include the missing release sites in the spatial.csv file.

I changed GNWR in the spatial file from "Hydrophone" to "Release" and now it says it's the same as StJaqs (another site).

This error is related to an earlier warning:

2. Warning deployment station not part of study's stations

Warning: The following station is listed in the deployments but is not part of the study's stations: 'StJaqs'

"StJaqs" %in% unique(deployments$Station.name) # TRUE
"StJaqs" %in% unique(spatial$Station.name) # TRUE
"StJaqs" %in% row.names(distances) # TRUE

Ideally Actel could improve the error message for StJaqs to explain it's due to release/hydrophone in spatial csv. Without that info, the user is left hunting around to try to deduce what's causing this.

Do I need to add a duplicate row for StJaqs and GNWR to be release as well as hydrophone?

Another likely related warning:

3. Warning: receivers not part of study stations

Warning: Detections from receivers 104790, 139044, 484731 are present in the data, but these receivers are not part of the study's stations. Double-check potential errors.

104790: in deployments (GNWR) & GNWR in spatial. 139044 = StJaqs, ditto. 484731 = GNWR also.

So again, could it be these are marked as release sites when they should be receivers?

Another likely related warning:

4. Warning: tag detected on receiver not listed in study area

Warning: Tag 9001-57458 was detected in one or more receivers that are not listed in the study area (receiver(s): 139044, 484731)!

StJaqs & GNWR again.

Probably NOT related but just in case. LMK and I'll make this into a separate issue.

5. Stations not present in distances matrix

Warning: Some stations and/or release sites are not present in the distances matrix. Deactivating speed calculations to avoid function failure. Stations missing: 'St.1', [...], 'St.127

Where is it (not) getting these station names from?

Five Rds files here.

Thanks bud!

hugomflavio commented 8 hours ago

Hi Simon! Thanks for bringing these up.

I see the source of the confusion. Essentially, you have two stations in the same place with the same name; one is a hydrophone station, the other is a release station (in actel terms). actel is not being very helpful by not checking that there is a hydrophone station with the name of the release site stated in the biometrics; in which case it could give a more useful error message (instructing the user to duplicate the line so there's a "hydrophone" and a "release" station).

It would probably also be helpful to call it "release stations" instead of "release sites" in your point 1.

Warning 2 could be improved by saying "study's hydrophone stations" instead of just "study's stations".

Warning 3 could be improved to say that the receivers were deployed at hydrophone stations that are not listed in the spatial input.

For both warnings, it could check if those station names exist as release stations, and provide an extra line with more guidance (essentially telling the user to make two identical stations, one for the hydrophone and another for the release).

Warning 4 is a consequence of the above.

The last is a separate issue. This distances matrix is not correctly formatted for actel. How was it made?

Thanks!

SimonDedman commented 1 hour ago

Cheers for the reply bud. Ongoing fixing attempts:

1/2/3/4

Station log / spatial: GNWR & St Jaques changed to hydrophone. Deep ledge & Jupiter are release only.

Error: The following release sites were listed in the biometrics.csv file but are not part of the release sites listed in the spatial.csv file: GNWR. Please include the missing release sites in the spatial.csv file.

GNWR is in spatial.csv, it's a release site but also a hydrophone. I added another row in spatial.csv to duplicate GNWR and mark it as Release, given the existing row was Hydrophone, and that seemed to solve issue 1.

Kinda: the dupe is then propagated to distances so needs to be removed there and elsewhere.

Error: The 'Station.name' column in the spatial input must not have duplicated values. Stations appearing more than once: GNWR

So: not sure how to proceed. Duplicate station to be both release and hydrophone in spatial.csv fixes the mismatch between release sites and locations, but causes a station.name dupe.

5. Stations not present in distances matrix

This distances matrix is not correctly formatted for actel. How was it made?

install.packages("gbm.auto")
library(gbm.auto)
gbm.auto::gbm.basemap(bounds = c(min(spatial$Longitude),
                                 max(spatial$Longitude),
                                 min(spatial$Latitude),
                                 max(spatial$Latitude)),
                      savedir = file.path(loadloc, "actel", "NOAAcoastlines"),
                      getzip = file.path(loadloc, "actel", "NOAAcoastlines"),
                      extrabounds = FALSE)
# install.packages("gdistance")
base.raster <- actel::shapeToRaster(shape = file.path(loadloc, "actel", "NOAAcoastlines", "CroppedMap", "Crop_Map.shp"),
                                    size = 0.01, # of the raster pixels in metres (or possibly 100km's)
                                    spatial = spatial, # " character string specifying the path to a spatial.csv file or a spatial data frame
                                    coord.x = "Longitude", # names of the columns containing the x and y coordinates
                                    coord.y = "Latitude",
                                    buffer = NULL) # request an expansion of the shapefile limits
t.layer <- actel::transitionLayer(base.raster, directions = 16)
distances <- actel::distancesMatrix(
  t.layer = t.layer,
  starters = spatial,
  targets = spatial,
  coord.x = "Longitude",
  coord.y = "Latitude",
  # id.col = "Station.name",
  actel = FALSE
)
# Colnames & rownames don't match due to Xs, remove GNWR dupe & rename:
duperowremove <- max(which(spatial$Station.name == "GNWR"), na.rm = TRUE)
distances <- distances[-duperowremove,] # remove column
distances <- distances[,-duperowremove] # remove row
colnames(distances) <- unique(spatial$Station.name)
rownames(distances) <- unique(spatial$Station.name)