Skip to content

Commit

Permalink
Merge pull request #10401 from gem/timezone
Browse files Browse the repository at this point in the history
Import `timezonefinder` at runtime as it was before
  • Loading branch information
ptormene authored Mar 3, 2025
2 parents a7d28cb + f5b94c3 commit 2989adb
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion openquake/hazardlib/shakemap/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import pandas as pd
from datetime import datetime
from zoneinfo import ZoneInfo
from timezonefinder import TimezoneFinder
from shapely.geometry import Polygon
import numpy

Expand Down Expand Up @@ -243,6 +242,16 @@ def utc_to_local_time(utc_timestamp, lon, lat):
"""
Convert a timestamp '%Y-%m-%dT%H:%M:%S.%fZ' into a datetime object
"""
try:
# NOTE: mandatory dependency for ARISTOTLE
from timezonefinder import TimezoneFinder
except ImportError:
raise ImportError(
'The python package "timezonefinder" is not installed. It is'
' required in order to convert the UTC time to the local time of'
' the event. You can install it from'
' https://wheelhouse.openquake.org/v3/linux/ choosing the one'
' corresponding to the installed python version.')
tf = TimezoneFinder()
timezone_str = tf.timezone_at(lng=lon, lat=lat)
if timezone_str is None:
Expand Down

0 comments on commit 2989adb

Please sign in to comment.