Skip to content

Bugfix/metadata utctime error negative subsec #230

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions data/REDEDGE-MX/IMG_0008_1.tif
Git LFS file not shown
3 changes: 3 additions & 0 deletions data/REDEDGE-MX/IMG_0008_2.tif
Git LFS file not shown
3 changes: 3 additions & 0 deletions data/REDEDGE-MX/IMG_0008_3.tif
Git LFS file not shown
3 changes: 3 additions & 0 deletions data/REDEDGE-MX/IMG_0008_4.tif
Git LFS file not shown
3 changes: 3 additions & 0 deletions data/REDEDGE-MX/IMG_0008_5.tif
Git LFS file not shown
3 changes: 2 additions & 1 deletion micasense/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,12 @@ def utc_time(self):
str_time = self.get_item('EXIF:DateTimeOriginal')
if str_time:
utc_time = datetime.strptime(str_time, "%Y:%m:%d %H:%M:%S")
subsec = float(f"0.{self.get_item('EXIF:SubSecTime')}")
subsec = int(self.get_item('EXIF:SubSecTime'))
negative = 1.0
if subsec < 0:
negative = -1.0
subsec *= -1.0
subsec = float(f"0.{int(subsec)}")
subsec *= negative
ms = subsec * 1e3
utc_time += timedelta(milliseconds=ms)
Expand Down
4 changes: 4 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,7 @@ def meta_bad_exposure(rededge_files_dir: Path):
@pytest.fixture()
def meta_altum_dls2(altum_flight_image_name):
return metadata.Metadata(altum_flight_image_name)

@pytest.fixture()
def meta_negative_subsec(rededge_files_dir: Path):
return metadata.Metadata(str(rededge_files_dir / 'IMG_0008_1.tif'))
5 changes: 5 additions & 0 deletions tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ def test_utc_time(meta):
assert utc_time is not None
assert utc_time.strftime('%Y-%m-%d %H:%M:%S.%f') == '2022-04-06 18:50:25.983430'

def test_utc_time_negative_subsec(meta_negative_subsec):
utc_time = meta_negative_subsec.utc_time()
assert utc_time is not None
assert utc_time.strftime('%Y-%m-%d %H:%M:%S.%f') == '2018-07-25 05:53:52.762886'


def test_position(meta):
assert meta.position() == pytest.approx((47.7036143, -122.1414373, 6.728))
Expand Down