[Qgis-user] Timestep for (Temporal) Mesh/netcdf layers?

Vincent Cloarec vcloarec at gmail.com
Thu Mar 9 06:03:47 PST 2023


Hi Richard,

First, mesh layer time step is not supposed to be constant. Some dataset
could have variable time steps, so there is not ONE time step available for
each mesh layer or dataset group.

If you need one time step, you can deduced if by using one of these ways:
- QgsMeshLayer::datasetMetadata() that will return the metadata of the
dataset, this metadata contains the method time() that will return the time
of the dataset in hours from the reference time
- QgsMeshLayer::datasetRelativeTime() that will return a QgsInteval that is
the time of the dataset from the reference time
- QgsMeshLayer::datasetRelativeTimeInMilliseconds(), same but return in
milliseconds.

By soustraction of two dataset, you will have a time step, and if your data
has constant time step it will be THE time step.
The reference time is not needed in your case but it can be obtained
through the meta data of the dataset group.

Or you can also use your method with the temporalCapabilities that should
give the same results, but it is more related to the data provider, and I
would avoid using it as it could have some issues with dataset group
indexes.

Note that the temporalUnit() of the temporal capabilities is not the unit
of the time returned by the layer, but it the the data provider must
considerer to read the times value. Default is hour for MDAL, but in
certain case, when MDAL can't know the time unit, the user specify this
unit.

Hope this helps.

Regards.

Vincent

Le mer. 8 mars 2023 à 10:42, Richard Duivenvoorde via QGIS-User <
qgis-user at lists.osgeo.org> a écrit :

> Ok, found it. It is in the temporalCapabilities...
>
> So given a loaded netcdf/mesh with time.
> Easiest is the firstTimeStepDuration(i) of
> QgsMeshDataProviderTemporalCapabilities:
>
>   >>> p = iface.activeLayer().dataProvider().temporalCapabilities()
>   >>> p
>   <qgis._core.QgsMeshDataProviderTemporalCapabilities object at
> 0x7fa958267e20>
>   >>> p.timeExtent()
>   <QgsDateTimeRange:[2022-11-07T07:00:00Z, 2022-11-08T06:00:00Z]>
>   >>> p.temporalUnit()
>   <TemporalUnit.Hours: 3>   <<< ?????
>   # datasetTime() Returns the relative time in milliseconds of the dataset
>   >>> p.datasetTime(QgsMeshDatasetIndex(0,0))
>   3600000
>   >>> p.datasetTime(QgsMeshDatasetIndex(0,1))
>   7200000
>   >>> p.datasetTime(QgsMeshDatasetIndex(0,2))
>   10800000
>   # firstTimeStepDuration() Returns the duration of the first time step of
> the dataset group with index \a group
>   # in milliseconds
>   p.firstTimeStepDuration(0)
>   3600000  == 3600 s = 1 hours
>   p.firstTimeStepDuration(0)
>   21600000  == 21600 s == 360 minute == 6 hours
>
> Only strange thing is that the temporalUnit() always returns 'hours',
> while the actual data time is relative in minutes...
>
> Regards,
>
> Richard Duivenvoorde
>
> On 3/8/23 10:46, Richard Duivenvoorde via QGIS-User wrote:
> > Hi,
> >
> > (trying here too, sorry for cross posting)
> >
> > When loading (temporal) Netcdf files (as MeshLayers), the 'timestep'
> > that you see in the Temporal Controller does not change.
> >
> > I had a look at the api, but could not find any indication of knowledge
> > by the QgsMeshLayer of the size of the timesteps of the data.
> >
> > Within netcdf's it is common to define the timesteps as something like:
> > "minutes since 2022-11-27 16:00:00.0Z"
> > then the first set has 0, and then the next one for example 60 for
> > hourly data or 10 for 10-minute data.
> >
> > Question: IS a temporal mesh layer aware of the timesteps used?
> >
> > Or if not: I seem not to be able to inspect the data array of the 'time'
> > dimension. Should/can I?
> >
> > IF so, we could we could deduct from the first 2 or 3 timesteps, the
> > size of the timestep.
> >
> > Anybody a hint or idea?
> >
> > Regards,
> >
> > Richard Duivenvoorde
> >
> > _______________________________________________
> > QGIS-User mailing list
> > QGIS-User at lists.osgeo.org
> > List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
> > Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
>
> _______________________________________________
> QGIS-User mailing list
> QGIS-User at lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20230309/0b69c1d5/attachment.htm>


More information about the QGIS-User mailing list