Skip to content

Commit

Permalink
updated domain search in tables (#157)
Browse files Browse the repository at this point in the history
* updated domain search in tables

* update domain idents

* update index search

* Update whats_new.rst
  • Loading branch information
larsbuntemeyer authored Jul 17, 2023
1 parent 265d085 commit 36bfb50
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
36 changes: 26 additions & 10 deletions cordex/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,35 @@
from .utils import get_tempfile


def _locate_domain_id(domain_id, tables):
"""Locate domain_id in domain table trying different indexes."""
indexes = ["short_name", "domain_id", "CORDEX_domain"]
def _locate_domain_id(domain_id, table):
"""Locate domain_id in domain table trying different indexes.
tables = tables.replace(np.nan, None)
First, it is assumed that domain_id can be found in the tables index.
If it is not found in the index, a number of different colums are
tried as index (``short_name``, ``domain_id``, ``CORDEX_domain``).
for i in indexes:
if domain_id in tables.reset_index()[i].values:
return (
tables.reset_index().set_index(i).loc[[domain_id]].reset_index().iloc[0]
)
"""

indexes = [table.index.name]
# additional indexes to try
indexes.extend(["short_name", "domain_id", "CORDEX_domain"])
# removed duplicates
indexes = list(dict.fromkeys(indexes))

return tables.replace(np.nan, None).loc[domain_id]
table = table.replace(np.nan, None)

for i in indexes:
if i in table.reset_index().columns:
if domain_id in table.reset_index()[i].values:
return (
table.reset_index()
.set_index(i)
.loc[[domain_id]]
.reset_index()
.iloc[0]
)

return table.replace(np.nan, None).loc[domain_id]


def domain_names(table_name=None):
Expand Down
8 changes: 8 additions & 0 deletions docs/whats_new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
What's New
==========

v0.6.2 (Unreleased)
-------------------

Internal Changes
~~~~~~~~~~~~~~~~

- Support for searching indexes in alternative domain tables (:pull:`157`).

v0.6.1 (17 July 2023)
---------------------

Expand Down

0 comments on commit 36bfb50

Please sign in to comment.