From cb624c11586234152fb51361e155cbd1dd1e1568 Mon Sep 17 00:00:00 2001 From: forestbat Date: Sun, 18 Feb 2024 15:48:17 +0800 Subject: [PATCH] use tzfpy to alternative timezonefinder, reduce memory cost and download time cost. --- hydrodataset/caravan.py | 6 +++--- hydrodataset/hydro_dataset.py | 4 +++- requirements.txt | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/hydrodataset/caravan.py b/hydrodataset/caravan.py index ad1ff21..6fbc54a 100644 --- a/hydrodataset/caravan.py +++ b/hydrodataset/caravan.py @@ -11,7 +11,7 @@ from urllib.request import urlopen import pandas as pd import numpy as np -from timezonefinder import TimezoneFinder +from tzfpy import get_tz from hydroutils import hydro_file from hydrodataset import CACHE_DIR, HydroDataset @@ -748,7 +748,7 @@ def _check_data(self, regions): _data.set_index(["date"]) ) the_ncfile_data.attrs = attrs - tf = TimezoneFinder() + # tf = TimezoneFinder() site_meta_file = os.path.join( self.data_source_description["ATTR_DIR"], region, @@ -763,7 +763,7 @@ def _check_data(self, regions): lon = df_metadata.loc[ df_metadata.index == gage_id, "gauge_lon" ].values[0] - the_ncfile_data.attrs["Timezone"] = tf.timezone_at(lat=lat, lng=lon) + the_ncfile_data.attrs["Timezone"] = get_tz(lat=lat, lng=lon) the_ncfile = os.path.join( os.path.dirname(file_path), f"{gage_id}.nc" ) diff --git a/hydrodataset/hydro_dataset.py b/hydrodataset/hydro_dataset.py index 9fa0df4..2166b0f 100644 --- a/hydrodataset/hydro_dataset.py +++ b/hydrodataset/hydro_dataset.py @@ -7,10 +7,12 @@ FilePath: \hydrodataset\hydrodataset\hydro_dataset.py Copyright (c) 2021-2022 Wenyu Ouyang. All rights reserved. """ -from pathlib import Path from abc import ABC +from pathlib import Path from typing import Union + import numpy as np + from hydrodataset import ROOT_DIR diff --git a/requirements.txt b/requirements.txt index 1a7fbbe..276e919 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,6 +7,6 @@ scipy pint pint-pandas pint-xarray -timezonefinder[numba] +tzfpy async-retriever -hydroutils \ No newline at end of file +hydroutils