You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As @hyanwong suggests in #495 (comment) there are very good reasons for having a top-level time_units field in the tree sequence/table collection/file format. One use could be to issue a warning if people are using branch length statistics and using uncalibrated time units, where different branch lengths are not comparable.
I guess the type should be a string. We should probably have a number of "known" values. Two I can think of are
generations_ago
years_ago
uncalibrated
I think the "ago" suffix is necessary, because in principle these could be actual datetime values (we could change the time-travel requirement depending then, if so). Tsinfer (and any other method producing arbitrary-ish time values) should use "uncalibrated". The branch length stats would then issue a warning (in Python) if computed on "uncalibrated" tree sequences.
In terms of how we handle compatibility, I think we have to assume generations_ago if the time_units field isn't present. Otherwise, we would suddenly start issuing confusing warnings to people using existing tree sequences.
How do we deal with time_units that are unknown to the library? Do we
Hard error in C and refuse to create a tree sequence
Raise a warning at load time in Python and treat as "uncalibrated"?
Right - well, if we have time_units then we maybe also want to have spatial_units; and there it's a bit more complicated than just putting meters, so we should design the metadata to accomadate this sort of thing. Maybe 'units' : { 'time' : 'generations, 'space': XXX } or something...
We don't have any actual use within the library for that, though, do we? That's the hurdle for metadata vs data - the library has to do something with it.
Nope - but it's helpful to have more than one example.
However, I do think that time_units is really naturally metadata in the colloquial sense of the word, and so we really might as well put it in metadata, even if the library makes use of it. Won't we save ourselves a bunch of coding hassle (ie changing the kastore format)?
I'm ambivalent about whether time_units is in metadata or is stored more like attributes such as sequence_length. True, we foresee that the library might use it, but it's only to raise an error if it's set to an inappropriate value, so is a relatively minor thing that isn't actually required to enable functionality (merely to disable existing functionality), so I can see Peter's pragmatic argument about saving developer time. OTOH that would be breaking the purity of the existing metadata vs inherent properties scheme, and would require other metadata users to derive metadata schemas from a base format rather than create a schema de-novo, so that places a burden on users rather than developers to do the right thing. 🤷
I think putting it in as metadata it basically rules out us ever using time_units for anything useful, because we'll never be able to access it in the C library if we do. It seems like quite a fundamental thing, to me, so excluding it from the C library forever seems unwise.
In practise, the amount of developer effort to implement this will be basically the same, either way.
I've added this to the C1.0 milestone as we should consider this before we release the supported API.
I think assuming legacy tree-sequences to be gererations-ago isn't quite right as for many that won't be right and could cause confusion/errors. Might it be better to have an unset or legacy value that doesn't raise errors?
Yes, I agree. We should also have "unknown" which is the default value, and keeps the existing behaviour.
Then, I think we should actually error out of C API methods that are related to branch lengths if time_units="uncalibrated" with TSK_ERR_TIME_UNCALIBRATED. We can provide an option to methods like branch stats TSK_FORCE_TIME_UNCALIBRATED, which will suppress this error. Then, it's pretty clear that users are making an informed choice about using uncalibrated time.
It's not clear whether the Python behaviour should be to warn or error - I guess adding the option force_time_uncalibrated to methods isn't too bad?
Just to be clear here, it's only tsinfer that'll (currently) be making these uncalibrated tree sequences, right? And for unknown, we won't error? If so, this sounds good.
I prefer ALLOW_TIME_UNCALIBRATED to FORCE but that's only a minor thing.
Yeah, AFAIK tsinfer is the only thing that makes tree sequences with uncalibrated time, and yes, the default will be to assume "unknown", which will maintain the current behviour. So, we can't break anyone's code.
Great that this is getting sorted. Thanks @benjeffery and @jeromekelleher . One thing: in tsinfer generated tree sequences, do we want to have time_units="uncalibrated" or something like time_units="frequency-of-derived-allele"? I ask because of a silly corner case concerning the tsinfer.SampleData.from_tree_sequence(ts) method. In particular, should we allow historical samples to be set to non-zero times if the generated tree sequence uses frequency of derived allele as the time unit? If we do, we should probably ensure that the ts in this case has units that match the time_units of the tree sequence produced from .from_tree_sequence.
I think it's simpler to just make them uncalibrated in tsinfer @hyanwong - the point here is to make users aware that they shouldn't use the time values for anything in particular. If we were to try saying "frequency-of-derived-allele" we'd have to worry about what to do with times of the ultimate roots and also new nodes introduced by path compression.
We can work around the details in from_tree_sequence in tsinfer.
Yeah, I think you're right. It's just that they are a specific sort of uncalibrated, which might, I suppose, be useful to know (that's what I hit in the case I explained above). But it's such a minor thing that it's hardly worth worrying about.
It's just that they are a specific sort of uncalibrated, which might, I suppose, be useful to know (that's what I hit in the case I explained above).
I agree, but trying to communicate that some times are frequency and some are not would be very tricky. Simpler to just say "times are uncalibrated, and we can change them arbitarily between versions"
Activity
petrelharp commentedon Aug 25, 2021
For a related issue, see bodkan/slendr#61
jeromekelleher commentedon Aug 26, 2021
Related in that you'd like to see top-level info on the spatial coordinate system?
petrelharp commentedon Aug 26, 2021
Right - well, if we have
time_unitsthen we maybe also want to havespatial_units; and there it's a bit more complicated than just puttingmeters, so we should design the metadata to accomadate this sort of thing. Maybe'units' : { 'time' : 'generations, 'space': XXX }or something...jeromekelleher commentedon Aug 26, 2021
We don't have any actual use within the library for that, though, do we? That's the hurdle for metadata vs data - the library has to do something with it.
petrelharp commentedon Aug 26, 2021
Nope - but it's helpful to have more than one example.
However, I do think that
time_unitsis really naturally metadata in the colloquial sense of the word, and so we really might as well put it inmetadata, even if the library makes use of it. Won't we save ourselves a bunch of coding hassle (ie changing the kastore format)?hyanwong commentedon Aug 27, 2021
I'm ambivalent about whether
time_unitsis in metadata or is stored more like attributes such assequence_length. True, we foresee that the library might use it, but it's only to raise an error if it's set to an inappropriate value, so is a relatively minor thing that isn't actually required to enable functionality (merely to disable existing functionality), so I can see Peter's pragmatic argument about saving developer time. OTOH that would be breaking the purity of the existing metadata vs inherent properties scheme, and would require other metadata users to derive metadata schemas from a base format rather than create a schema de-novo, so that places a burden on users rather than developers to do the right thing. 🤷jeromekelleher commentedon Aug 27, 2021
I think putting it in as metadata it basically rules out us ever using
time_unitsfor anything useful, because we'll never be able to access it in the C library if we do. It seems like quite a fundamental thing, to me, so excluding it from the C library forever seems unwise.In practise, the amount of developer effort to implement this will be basically the same, either way.
petrelharp commentedon Aug 27, 2021
Ah, that's right.
benjeffery commentedon Sep 2, 2021
I've added this to the C1.0 milestone as we should consider this before we release the supported API.
I think assuming legacy tree-sequences to be
gererations-agoisn't quite right as for many that won't be right and could cause confusion/errors. Might it be better to have anunsetorlegacyvalue that doesn't raise errors?jeromekelleher commentedon Sep 2, 2021
Yes, I agree. We should also have "unknown" which is the default value, and keeps the existing behaviour.
Then, I think we should actually error out of C API methods that are related to branch lengths if
time_units="uncalibrated"withTSK_ERR_TIME_UNCALIBRATED. We can provide an option to methods like branch statsTSK_FORCE_TIME_UNCALIBRATED, which will suppress this error. Then, it's pretty clear that users are making an informed choice about using uncalibrated time.It's not clear whether the Python behaviour should be to warn or error - I guess adding the option
force_time_uncalibratedto methods isn't too bad?benjeffery commentedon Sep 2, 2021
Yep seems erroring on fixed string(s) and letting everything else through is best.
An error in python, whose message says about the option makes sense to me?
I prefer
ALLOW_TIME_UNCALIBRATEDtoFORCEbut that's only a minor thing.petrelharp commentedon Sep 2, 2021
Just to be clear here, it's only
tsinferthat'll (currently) be making theseuncalibratedtree sequences, right? And forunknown, we won't error? If so, this sounds good.Me, too.
jeromekelleher commentedon Sep 2, 2021
Yeah, AFAIK tsinfer is the only thing that makes tree sequences with uncalibrated time, and yes, the default will be to assume "unknown", which will maintain the current behviour. So, we can't break anyone's code.
Sure, SGTM
hyanwong commentedon Sep 29, 2021
Great that this is getting sorted. Thanks @benjeffery and @jeromekelleher . One thing: in tsinfer generated tree sequences, do we want to have
time_units="uncalibrated"or something liketime_units="frequency-of-derived-allele"? I ask because of a silly corner case concerning thetsinfer.SampleData.from_tree_sequence(ts)method. In particular, should we allow historical samples to be set to non-zero times if the generated tree sequence uses frequency of derived allele as the time unit? If we do, we should probably ensure that thetsin this case has units that match thetime_unitsof the tree sequence produced from.from_tree_sequence.jeromekelleher commentedon Sep 29, 2021
I think it's simpler to just make them
uncalibratedin tsinfer @hyanwong - the point here is to make users aware that they shouldn't use the time values for anything in particular. If we were to try saying"frequency-of-derived-allele"we'd have to worry about what to do with times of the ultimate roots and also new nodes introduced by path compression.We can work around the details in
from_tree_sequencein tsinfer.hyanwong commentedon Sep 29, 2021
Yeah, I think you're right. It's just that they are a specific sort of uncalibrated, which might, I suppose, be useful to know (that's what I hit in the case I explained above). But it's such a minor thing that it's hardly worth worrying about.
jeromekelleher commentedon Sep 29, 2021
I agree, but trying to communicate that some times are frequency and some are not would be very tricky. Simpler to just say "times are uncalibrated, and we can change them arbitarily between versions"