Skip to content

Commit

Permalink
add progressbar using tqdm
Browse files Browse the repository at this point in the history
  • Loading branch information
jgriesfeller committed Dec 6, 2023
1 parent 46c15eb commit 08eeb53
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ dependencies = [
"pyaro@git+https://github.com/metno/pyaro",
"requests",
"geocoder",
"tqdm",
]

[project.urls]
Expand Down
29 changes: 16 additions & 13 deletions src/pyaro_readers/aeronetsunreader/AeronetSunTimeseriesReader.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
import csv
from urllib.parse import urlparse

import geocoder
import numpy as np
import requests
from pyaro.timeseries import (
AutoFilterReaderEngine,
Data,
NpStructuredData,
Engine,
Flag,
AutoFilterReaderEngine,
NpStructuredData,
Station,
Engine,
)

import requests, zipfile, io
import geocoder

from urllib.parse import urlparse


# from tqdm import tqdm
from tqdm import tqdm

# default URL
BASE_URL = "https://aeronet.gsfc.nasa.gov/data_push/V3/All_Sites_Times_Daily_Averages_AOD20.zip"
Expand All @@ -24,6 +21,8 @@
DELIMITER = ","
#
NAN_VAL = -999.0
# update progress bar every N lines...
PG_UPDATE_LINES = 100
# main variables to store
LAT_NAME = "Site_Latitude(Degrees)"
LON_NAME = "Site_Longitude(Degrees)"
Expand Down Expand Up @@ -77,8 +76,8 @@ def __init__(

# check if file is a URL
if self.is_valid_url(self._filename):
from urllib.request import urlopen
from io import BytesIO
from urllib.request import urlopen
from zipfile import ZipFile

# try to open as zipfile
Expand All @@ -104,9 +103,12 @@ def __init__(
self._fields = lines.pop(0).strip().split(",")

crd = csv.DictReader(lines, fieldnames=self._fields, **csvreader_kwargs)
bar = tqdm(total=len(lines))
for _ridx, row in enumerate(crd):
# if _ridx % PG_UPDATE_LINES == 0:
bar.update(1)
if row[SITE_NAME] != _laststatstr:
print(f"reading station {row[SITE_NAME]}...")
# print(f"reading station {row[SITE_NAME]}...")
_laststatstr = row[SITE_NAME]
# new station
station = row[SITE_NAME]
Expand Down Expand Up @@ -178,6 +180,7 @@ def __init__(
self._data[variable].append(
value, station, lat, lon, alt, start, end, Flag.VALID, np.nan
)
bar.close()

def _unfiltered_data(self, varname) -> Data:
return self._data[varname]
Expand Down

0 comments on commit 08eeb53

Please sign in to comment.