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

Interpolation or retrieval does not work at subsecond level #69

Open
valeriu-balaban opened this issue Aug 27, 2024 · 5 comments
Open
Assignees
Labels
bug Something isn't working

Comments

@valeriu-balaban
Copy link

When trying to extract the value from TGeomPointSeq using the value_at_timestamp method, and the timestamp provided has a non-zero microseconds part, the microseconds would not be considered for interpolation or retrieval.

To Reproduce
Let tgps be equal to TGeomPointSeq([POINT(295.9722900390625 654.239990234375)@2024-05-07 14:47:07-07, POINT(343.66021728515625 633.1279296875)@2024-05-07 14:47:07.1001-07, POINT(419.7856750488281 599.8984985351562)@2024-05-07 14:47:07.2002-07, POINT(483.23553466796875 565.5811767578125)@2024-05-07 14:47:07.3003-07, POINT(547.3091430664062 539.0184326171875)@2024-05-07 14:47:07.4004-07, POINT(607.9834594726562 513.4208374023438)@2024-05-07 14:47:07.5005-07, POINT(662.676513671875 490.9242858886719)@2024-05-07 14:47:07.6006-07, POINT(714.170654296875 475.9928894042969)@2024-05-07 14:47:07.7007-07, POINT(764.0394897460938 462.255126953125)@2024-05-07 14:47:07.8008-07, POINT(807.018310546875 448.92486572265625)@2024-05-07 14:47:07.9009-07, POINT(846.0618896484375 436.96124267578125)@2024-05-07 14:47:08.001-07]), then calling tgps.value_at_timestamp(datetime.datetime(2024, 5, 7, 14, 47, 7, 400400)) would return <POINT (295.972 654.24)> (the first point in the sequence) instead of the expected <POINT (547.30 539.01)> (the value of the 5th instant in the sequence).

Desktop (please complete the following information):

  • OS: macOS
  • Architecture: x64
  • Environment: conda
  • Version 1.1.4
@valeriu-balaban valeriu-balaban added the bug Something isn't working label Aug 27, 2024
@Diviloper Diviloper self-assigned this Aug 28, 2024
@Diviloper
Copy link
Member

This was an issue in the pymeos_cffi library. It should be fixed in the new 1.1.2 version (MobilityDB/PyMEOS-CFFI@7f4afb4).
Can you update it and try again to confirm it works now as expected?
I'll close the issue afterwards.

@valeriu-balaban
Copy link
Author

Many thanks for the quick reply.

I updated the cffi package. There were no errors on Linux, but on MacOS, there was a compilation error during installation. I will create a separate issue for that on the cffi repo.

Now, when running the code below, it throws an error:

import datetime

import pymeos
import pymeos_cffi

pymeos.pymeos_initialize()

print(pymeos_cffi.__version__)

t = pymeos.TGeomPointSeq(
  "[POINT(295.9722900390625 654.239990234375)@2024-05-07 14:47:07-07, POINT(343.66021728515625 633.1279296875)@2024-05-07 14:47:07.1001-07, POINT(419.7856750488281 599.8984985351562)@2024-05-07 14:47:07.2002-07, POINT(483.23553466796875 565.5811767578125)@2024-05-07 14:47:07.3003-07, POINT(547.3091430664062 539.0184326171875)@2024-05-07 14:47:07.4004-07, POINT(607.9834594726562 513.4208374023438)@2024-05-07 14:47:07.5005-07, POINT(662.676513671875 490.9242858886719)@2024-05-07 14:47:07.6006-07, POINT(714.170654296875 475.9928894042969)@2024-05-07 14:47:07.7007-07, POINT(764.0394897460938 462.255126953125)@2024-05-07 14:47:07.8008-07, POINT(807.018310546875 448.92486572265625)@2024-05-07 14:47:07.9009-07, POINT(846.0618896484375 436.96124267578125)@2024-05-07 14:47:08.001-07]"
)

t.value_at_timestamp(datetime.datetime(2024, 5, 7, 14, 47, 7, 400400))

I get the following output

1.1.2
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
 print(pymeos_cffi.__version__)
 t = pymeos.TGeomPointSeq(
   "[POINT(295.9722900390625 654.239990234375)@2024-05-07 14:47:07-07, POINT(343.66021728515625 633.1279296875)@2024-05-07 14:47:07.1001-07, POINT(419.7856750488281 599.8984985351562)@2024-05-07 14:47:07.2002-07, POINT(483.23553466796875 565.5811767578125)@2024-05-07 14:47:07.3003-07, POINT(547.3091430664062 539.0184326171875)@2024-05-07 14:47:07.4004-07, POINT(607.9834594726562 513.4208374023438)@2024-05-07 14:47:07.5005-07, POINT(662.676513671875 490.9242858886719)@2024-05-07 14:47:07.6006-07, POINT(714.170654296875 475.9928894042969)@2024-05-07 14:47:07.7007-07, POINT(764.0394897460938 462.255126953125)@2024-05-07 14:47:07.8008-07, POINT(807.018310546875 448.92486572265625)@2024-05-07 14:47:07.9009-07, POINT(846.0618896484375 436.96124267578125)@2024-05-07 14:47:08.001-07]"
) )
--->  t.value_at_timestamp(datetime.datetime(2024, 5, 7, 14, 47, 7, 400400))

File ~/study-venv/lib/python3.10/site-packages/pymeos/main/tpoint.py:227, in TPoint.value_at_timestamp(self, timestamp, precision)
 def value_at_timestamp(self, timestamp: datetime, precision: int = 15) -> shp.Point:
     """
   Returns the value of the temporal point at the given timestamp.
   (...)
        tpoint_value_at_timestamp
     """
     return gserialized_to_shapely_point(
         tpoint_value_at_timestamptz(
             self._inner, datetime_to_timestamptz(timestamp), True
         )[0],
         precision,
     )

TypeError: 'NoneType' object is not subscriptable

@Diviloper
Copy link
Member

I think there are two separate issues here. One is that it crashes when the function returns None. I I'll fix this as soon as I can.
However, in this case, the intention was to use a timestamp in the sequence, so it shouldn't be returning a None. It's probably due to the timezones. Can you try removing the timezone from the sequence input, or adding it to the used timestamp and see if it still crashes?

Many thanks!

@valeriu-balaban
Copy link
Author

Yes, many thanks. It now interpolates at the subsecond level.

import datetime
import pymeos

pymeos.pymeos_initialize()


t = pymeos.TGeomPointSeq(
  "[POINT(295.9722900390625 654.239990234375)@2024-05-07 14:47:07-07, POINT(343.66021728515625 633.1279296875)@2024-05-07 14:47:07.1001-07]"
)

print(t.value_at_timestamp(t.timestamps()[0] + datetime.timedelta(seconds=0.05)))

prints POINT (319.7924335186298 643.6945054457261) as expected.

@Diviloper
Copy link
Member

Great!
I'll leave the issue open until I fix the None bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants