Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Use case] Multi-individual spatial interaction #2

Closed
comtes opened this issue Sep 30, 2019 · 12 comments
Closed

[Use case] Multi-individual spatial interaction #2

comtes opened this issue Sep 30, 2019 · 12 comments
Labels
spatsoc Related to the package 'spatsoc' use-case Use cases wildlifeDI Related to the package 'wildlifeDI'

Comments

@comtes
Copy link

comtes commented Sep 30, 2019

Use case:
Assuming two individuals with concomitant tracking data. The 'function' would calculate the distance and the azimuth between the relocation of both individuals for each shared timestamp.

Requirements:
spatial coordinates (x,y) as geographic coordinates with projection information
a time (t) as POSIXt object
information that identifies individuals (e.g. animal) for each location

Input:
One sftraj with at least two individual ID with matching timestamps

Output:
two new fields in the sftraj object: distance between the two individual and azimuth between the two individuals

Additional information:

@basille basille added the use-case Use cases label Oct 1, 2019
@basille
Copy link
Member

basille commented Oct 1, 2019

Thanks for this contribution too Sebastien! This one will not make it into sftraj, as it would be beyond the scope of the package. However, we want to make sure sftraj allows this. From what I understand, in your scenario, you have several individuals in the same sftraj, so you would need basically ways to extract spatio-temporal coordinates and this individual detail at the same time — which will be basic accessors from sftraj.

On a side note, you would want also a third column giving the individual identity in case there are more than two in one single objects… It would also be nice to be able to work over several trajectory objects (like one sftraj object per individual), and be sure that it can also work in 3 dimensions…

@basille basille closed this as completed Oct 1, 2019
@jedalong
Copy link

jedalong commented Oct 4, 2019

we are working on tools that I think address this issue (or partly thereof) in the package wildlifeDI (which currently uses adehabitat ltraj objects)

@robitalec
Copy link

spatsoc provides two functions that could help here: group_times for grouping relocations temporally based off some temporal threshold (since relocations rarely share the exact same timestamp) and edge_dist for calculating the distance between all individuals (can be > 2) within timegroups. No support for azimuth at this time though.

@basille basille added wildlifeDI Related to the package 'wildlifeDI' spatsoc Related to the package 'spatsoc' labels Oct 4, 2019
@basille
Copy link
Member

basille commented Oct 4, 2019

@jedalong and @robitalec, are there specific requirements for the tools offered by your respective packages? Would you rely on sftraj for the data part?

@jedalong
Copy link

jedalong commented Oct 4, 2019

Currently use ltraj, would migrate if it creates efficiencies. A key basic feature is the ability to include multiple individuals in a single sftraj object that can be easily subset (but I think you probably had that).

@basille
Copy link
Member

basille commented Oct 4, 2019

It is indeed planned, but does not hurt to repeat it! In the proposal, we have:

Nesting is an essential part of the data model, as it allows any relevant boundaries of a trajectory, such as the individual level, the year, or a journey (movement from home to work and from work to shopping), and any nested combination of those. The package tidyr provides a function nest, which allows to nest columns inside a data frame, and will be used to easily switch from one level to another (e.g. from an individual representation to an individual-year representation).

So that would be one possibility… which still has to be defined properly (I will probably open a use case just for this).

@robitalec
Copy link

@basille, spatsoc works with data.table, so the geometries are expected as two columns (lat, lon) along with a datetime column. We then loop through (with data.table's by argument) the data by timegroup chunk and calculate distance between individuals. sftraj could be used for the data but I would worry about sacrifices in terms of speed, losing out on data.table's efficient grouped calculations.

I agree though, the handling of multiple individuals in one object is key.

@basille
Copy link
Member

basille commented Oct 4, 2019

Thanks for these details @robitalec. Does spatsoc work with data.table for performance reasons only, or were there other reasons as well? Would you have very large datasets that you could share with us so we can test on our end?

@robitalec
Copy link

We used data.table because it's my personal preference when working with tabular data, it's really efficient and when paired with functions like fread, it can easily import large CSVs (and other text formats). Our relocation data is normally received and stored as CSVs so it felt like a natural tool to use. Advantages include: easily working with many individuals, simple chunking by season, subpopulation or other groups, efficient. Disadvantages: requires all data prep (datetimes, reprojected coordinates) and data cleaning/checking to be ad hoc (and in the spatsoc context - up to the user). The structure and integrated checks of a track-specific package would help here.

I definitely agree with the comments in #6 about anticipating larger (and not strictly wildlife) datasets and performance being a priority. spatsoc's core functions: group_times and group_pts are inherently point-based and would not benefit from trajectories being stored as a line, but having both storage options with conversion between seems like a good option, albeit more work!

Unfortunately I don't currently have any large datasets I can share. The example data in spatsoc shows our expected data structure, but is only ~14K rows.

@basille
Copy link
Member

basille commented Oct 8, 2019

Our largest dataset here is >1M locations, but I'm sure we can find substantially larger ones. We can also fake them for test purposes…

As for data.table, thanks for this information! So we have:

  • Reading performance when importing data files → not covered by sftraj
  • Easy manipulation

I see there are efforts to make sf and data.table truly compatible, but I think this goes behind the scope of sftraj. As long as we rely properly on sf, then whatever sf can use should work for sftraj too.

@birderboone
Copy link
Member

I'm re-opening some of these use-cases so theyre easier to find as people submit new ones.

@basille
Copy link
Member

basille commented Jun 3, 2022

Closing this issue now that sftrack is developed and on CRAN.

@basille basille closed this as completed Jun 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
spatsoc Related to the package 'spatsoc' use-case Use cases wildlifeDI Related to the package 'wildlifeDI'
Projects
None yet
Development

No branches or pull requests

5 participants