inbo / fish-tracking

🐟 Collection of scripts for processing and analysing fish tracking data
3 stars 0 forks source link

Distance not calculated for all station of River Gudena (Denmark) #64

Closed damianooldoni closed 3 years ago

damianooldoni commented 3 years ago

From @PieterjanVerhelst 's comment https://github.com/inbo/fish-tracking/issues/62#issuecomment-721046437:

For the River Gudena the code only calculates distances between some stations

I had to create the line-shapefile myself. For the River Gudena, I added the last part of the river (the original shapefile did not run to the sea)

damianooldoni commented 3 years ago

I am checking this. I found a small bug in function adapt.binarymask(), which is used to extend the raster to include receivers out of the rasterized river by introducing patches.

The error mentioned by @PieterjanVerhelst is generated in this line:

patchCells <- patchCells[sort.list(patchCells[, 2]), ]

If patchCells contains one patch only (see below): image

while if more patches are present: image

So, sorting by second column (sum) in first case is not possible as there is no second column. This seems not arising an error, but has as consequence that patchCells becomes NULL and no extensions are computed.

A easy-to-solve bug.

damianooldoni commented 3 years ago

Now, after solving the bug described above, it seems that extending the binary mask to get all receivers is taking ages. First I thought it was the problem of the bug which is not a bug actually, then I thought it was due to receivers way too far from the river (via mapview(study.area) + mapview(location.receivers)), sometimes 3km far: image @PieterjanVerhelst : I remove this from calculation. However, the problem remains. There is still something wrong in the extension process. I will investigate further.

PieterjanVerhelst commented 3 years ago

@damianooldoni that southern point is indeed 3 km from the Gudena River, but it is in the Lillea river (rivers_id = 22) which is also in the shapefile.

damianooldoni commented 3 years ago

Well, then you have to remove line

gudena <- gudena[gudena$rivers_id == 12,]
PieterjanVerhelst commented 3 years ago

I will subset on both ids instead, otherwise the script will load too many rivers (just to enhance calculation time).

damianooldoni commented 3 years ago

Sure. To do by:

gudena <- gudena[gudena$rivers_id %in% c(12,22),]

Below the result. I recommend you by the way the usage of package mapview and its function mapview() for fast spatial data exploration in RStudio.

image

PieterjanVerhelst commented 3 years ago

Update: when trying to calculate the distance between stations in the River Gudena, I get the following error:

> control.mask(study.area.binary.extended, locations.receivers)
 Show Traceback

 Rerun with Debug
 Error: length(receivers) not equal to length(matched.receivers) 

Note that it has likely nothing to do with the fact that I created a part of the shapefile myself, since the code runs for other rivers in other countries where I did this as well.

The most up to date code and files are in the branch calculate-distances-various-networks.

PieterjanVerhelst commented 3 years ago

Issue solved in #69