Closed damianooldoni closed 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):
while if more patches are present:
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.
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:
@PieterjanVerhelst : I remove this from calculation.
However, the problem remains. There is still something wrong in the extension process. I will investigate further.
@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.
Well, then you have to remove line
gudena <- gudena[gudena$rivers_id == 12,]
I will subset on both ids instead, otherwise the script will load too many rivers (just to enhance calculation time).
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.
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
.
Issue solved in #69
From @PieterjanVerhelst 's comment https://github.com/inbo/fish-tracking/issues/62#issuecomment-721046437:
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)