Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Griesfeller committed Oct 1, 2024
1 parent c231676 commit d564d7c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
25 changes: 21 additions & 4 deletions src/pyaro_readers/actrisebas/ActrisEbasReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
logger = logging.getLogger(__name__)

# default API URL base
# BASE_API_URL = "https://prod-actris-md.nilu.no/Vocabulary/categories"
BASE_API_URL = "https://dev-actris-md.nilu.no/"
# BASE_API_URL = "https://prod-actris-md.nilu.no/"
# base URL to query for data for a certain variable
VAR_QUERY_URL = f"{BASE_API_URL}metadata/content/"
# basename of definitions.toml which connects the pyaerocom variable names with the ACTRIS variable names
Expand Down Expand Up @@ -181,9 +181,19 @@ def __init__(
retries = Retry(connect=5, read=2, redirect=5)
http = PoolManager(retries=retries)
response = http.request("GET", query_url)
json_resp_tmp = json.loads(response.data.decode("utf-8"))
json_resp.extend(json_resp_tmp)
page_no += 1
if len(response.data) > 0:
try:
json_resp_tmp = json.loads(
response.data.decode("utf-8")
)
except json.decoder.JSONDecodeError:
json_resp_tmp = json.loads(response.data)

json_resp.extend(json_resp_tmp)
page_no += 1
else:
json_resp_tmp = ""
continue

self._metadata[_pyaro_var][_actris_var] = json_resp
self._urls_to_dl[_actris_var] = self.extract_urls(
Expand Down Expand Up @@ -401,6 +411,7 @@ def extract_urls(
LOCATION_NAME_KEY
]
if site_name in sites_to_exclude:
logger.info(f"site {site_name} excluded due to exclusion filter")
continue
if site_name in sites_to_read or len(sites_to_read) == 0:
if site_name not in urls_to_dl:
Expand All @@ -415,11 +426,17 @@ def extract_urls(
distribution_data[DISTRIBUTION_PROTOCOL_KEY]
!= DISTRIBUTION_PROTOCOL_NAME
):
logger.info(
f"skipping site: {site_name} / proto: {distribution_data[DISTRIBUTION_PROTOCOL_KEY]}"
)
continue
else:
urls_to_dl[site_name].append(
distribution_data[DISTRIBUTION_URL_KEY]
)
logger.info(
f"site: {site_name} / proto: {distribution_data[DISTRIBUTION_PROTOCOL_KEY]} included in URL list"
)
break
return urls_to_dl

Expand Down
3 changes: 2 additions & 1 deletion src/pyaro_readers/actrisebas/definitions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ ebas_matrix = ["air"]
standard_names = ["mass_concentration_of_ozone_in_air"]

[variables.vmro3]
actris_variable = ["ozone amount fraction"]
#actris_variable = ["ozone amount fraction"]
actris_variable = ["ozone mass concentration"]
actris_matrix = ["gas phase"]
ebas_component = ["ozone"]
ebas_matrix = ["air"]
Expand Down
4 changes: 2 additions & 2 deletions tests/test_ActrisEbasReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class TestActrisEbasTimeSeriesReader(unittest.TestCase):
# vars_to_read = ["aerosol particle sulphate mass concentration"]
vars_to_read = ["aerosol particle elemental carbon mass concentration"]
# pyaerocom_vars_to_read = ["conco3"]
# pyaerocom_vars_to_read = ["vmro3"]
pyaerocom_vars_to_read = ["concso4t"]
pyaerocom_vars_to_read = ["vmro3"]
# pyaerocom_vars_to_read = ["concso4t"]

def test_api_online(self, url=TEST_URL):
try:
Expand Down

0 comments on commit d564d7c

Please sign in to comment.