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

Fix #48942 add 1 timestep to AnimationRange #49283

Closed

Conversation

rduivenvoorde
Copy link
Contributor

@rduivenvoorde rduivenvoorde commented Jul 8, 2022

Description

This small change will Fix #48942

The TemporalController does not take the last step into account, when loading Mesh layers.

This zip:

123steps.zip

contains 3 netcdf's (ugrid) with 1, 2 and 3 (day) timesteps to test.

WIthout this commit, you will not be able to see the last timestep, without changing the Animation range.

Note that we do the same (add one timestep to the range) for Vector temporal properties:
https://github.com/qgis/QGIS/blob/master/src/core/vector/qgsvectorlayertemporalproperties.cpp#L74

@github-actions github-actions bot added this to the 3.28.0 milestone Jul 8, 2022
@rduivenvoorde rduivenvoorde added Mesh Related to general mesh layer handling (not specific data formats) Temporal Temporal filtering or animation Bug Either a bug report, or a bug fix. Let's hope for the latter! labels Jul 8, 2022
@@ -132,7 +132,8 @@ QgsDateTimeRange QgsMeshDataProviderTemporalCapabilities::timeExtent( const QDat
if ( !times.isEmpty() )
{
durationSinceFirst += times.first();
durationSinceLast += times.last();
// adding one timestep (length as: times.last() - times.beforeLast)), to be sure we have enough steps
durationSinceLast += times.last() + ( times.last() - times[times.length() - 2] );
Copy link
Contributor Author

@rduivenvoorde rduivenvoorde Jul 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that having data with just 1 timestep, the 'times' here will be empty, so you will only enter this if when length is at least 2 so times[times.length() - 2] is safe.

@rduivenvoorde
Copy link
Contributor Author

@PeterPetrik @vcloarec can you maybe guide me a little to fix the test, if you have time? Obviously after this commit, the resulting temporal extents are changed (as I add one timestep), but I'm unclear which parts of the test test_temporal() I can change (I'm not so familiar with this "datasetIndexClosestFromRelativeTime etc" kind of options:
https://github.com/qgis/QGIS/blob/master/tests/src/core/testqgsmeshlayer.cpp#L1950

The crux of this commit: because the temporal controller is working with 'range'-filter, with an INcluding start and an EXcluding end (of the filter range), the last timestep in a Mesh is never shown in the Temporal controller, because the extent calculated earlier was UNTILL the last timestep (after the reference time).
(easily testable with included mini meshes, but also with the meshes from the mdal test data, see #48942)

Sorry if I'm not clear enough...

@vcloarec
Copy link
Member

Hi Richard,
Just a quick comment before I look deeper, but not sure it the good place to change the time extent. If you change here, you alter the real time extent of the mesh layer.
Maybe it is better to change the extent where where this time extent is required to be changed, that is at the temporal controller widget level.

@rduivenvoorde
Copy link
Contributor Author

rduivenvoorde commented Jul 12, 2022

@vcloarec yes, maybe you are right.

Another (in this case working option) is to add +1 in the TemporalNavigationObject in the 'totalFrameCount()' member:
https://github.com/qgis/QGIS/blob/master/src/core/qgstemporalnavigationobject.cpp#L322
so make it ( +1 added)

return static_cast< long long >( std::ceil( totalAnimationLength.seconds() / mFrameDuration.seconds() ) + 1);

That will always add an 'extra' timestep (in case of other temporal datasets also I think)

@nyalldawson do you have an opinion in this? Both options 'work'.

Crux here: in a netcdf (mesh in general?) you define a 'period since' timestep, so say:

  • you define as 'time array: 'years since 1-1-2000'
  • then the first data array in it is for say: 1-1-2000 (time = 0)
  • the second for 1-1-2001 (time value = 1)
  • etc
    Current QGIS will create a controller, starting on 1-1-2000 and ending on 1-1-2002
    But because the end is NOT inclusive, the last timestep isn't shown/visible.

@vcloarec though there is an argument that the stepcount in the meshprovider is off by one...
For example, have a look at one of the dataset:
https://github.com/lutraconsulting/MDAL/blob/master/tests/data/netcdf/indonesia_nc4.nc
using ncdump you see:

...
time:units = "hours since 1900-01-01 00:00:0.0" ;
...
 time = 1008072, 1008096, 1008120, 1008144, 1008168, 1008192, 1008216, 
    1008240, 1008264, 1008288, 1008312, 1008336, 1008360, 1008384, 1008408, 
    1008432, 1008456, 1008480, 1008504, 1008528, 1008552, 1008576, 1008600, 
    1008624, 1008648, 1008672, 1008696, 1008720, 1008744, 1008768, 1008792 ;

There I count 31(!) datasets/timesteps, while if you load this in QGIS, the controller just shows 30(!).

@github-actions
Copy link

The QGIS project highly values your contribution and would love to see this work merged! Unfortunately this PR has not had any activity in the last 14 days and is being automatically marked as "stale". If you think this pull request should be merged, please check

  • that all unit tests are passing

  • that all comments by reviewers have been addressed

  • that there is enough information for reviewers, in particular

    • link to any issues which this pull request fixes

    • add a description of workflows which this pull request fixes

    • add screenshots if applicable

  • that you have written unit tests where possible
    In case you should have any uncertainty, please leave a comment and we will be happy to help you proceed with this pull request.
    If there is no further activity on this pull request, it will be closed in a week.

@github-actions github-actions bot added the stale Uh oh! Seems this work is abandoned, and the PR is about to close. label Jul 27, 2022
@PeterPetrik
Copy link
Contributor

Hmm, this is strange, I would assume it would pick the last step. If you open a similar example in the vector layer, does it show the last step?

@rduivenvoorde
Copy link
Contributor Author

@PeterPetrik there has been a time (pre 2021) when the temporal filter took both limits into account (INcluding both start en end limit). At that time the mdal filter worked correctly.

Working with measurements with time ranges, I've put a lot of effort to change this, so (the default option) is to include the start limit (of the filter range) and to exclude the end limit (for more discussion see the lengthy conversation of this issue: #38468 and PR #40989 (and the followups of that one).

Argh!! Vector is behaving the same (see the project + data below):

time.zip

It has all to do with the fact that data with just one timestamp column (instantaneous data), in which the event has zero-length (in time), the last step is in that case never shown...
See the tests and comments here for all possible ways:
https://github.com/qgis/QGIS/blob/master/tests/src/python/test_qgsvectorlayertemporalproperties.py#L181
Note that the Temporal controller filter is behaving as it should.
It is just that the Temporal Controller Widget does not give enough frames for the data...

Which would be an argument to add always one extra timestep in totalFrameCount:
https://github.com/qgis/QGIS/blob/master/src/core/qgstemporalnavigationobject.cpp#L313
@nyalldawson what you think?

@PeterPetrik
Copy link
Contributor

Fixing the widget is what @vcloarec suggested too, it should behave the same for vector & mesh, so in case there are more frames we could take the last one too.... Could you make such PR to discuss that implementation instead of this one?

@github-actions github-actions bot removed the stale Uh oh! Seems this work is abandoned, and the PR is about to close. label Aug 2, 2022
@rduivenvoorde
Copy link
Contributor Author

@PeterPetrik yes, will do, closing this one. Sorry for the fuzz...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Mesh Related to general mesh layer handling (not specific data formats) Temporal Temporal filtering or animation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Temporal Controller is missing last time step of NetCDF (or all meshes?)
3 participants