-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for anemoi-datasets #383
Merged
Merged
Changes from 18 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
720fe7d
Add suport for anemoi-datasets
sandorkertesz 7bc0772
Add suport for anemoi-datasets
sandorkertesz e80e8b9
Add suport for anemoi-datasets
sandorkertesz baefc8e
Add suport for anemoi-datasets
sandorkertesz 6303c90
Merge branch 'develop' into feature/anemoi
sandorkertesz 04df73d
Merge branch 'develop' into feature/anemoi
sandorkertesz a1791e8
Merge from develop
sandorkertesz 2d1617c
Add suport for anemoi-datasets
sandorkertesz 88f6113
Add suport for anemoi-datasets
sandorkertesz a222790
Add suport for anemoi-datasets
sandorkertesz 8f8f9eb
Add suport for anemoi-datasets
sandorkertesz 9b21e5c
Add suport for anemoi-datasets
sandorkertesz c94f37d
Add suport for anemoi-datasets
sandorkertesz afb5e79
Add suport for anemoi-datasets
sandorkertesz feed652
Add suport for anemoi-datasets
sandorkertesz ee21223
Add suport for anemoi-datasets
sandorkertesz 40dca0d
Add suport for anemoi-datasets
sandorkertesz 2b49ff7
Add test for remapping
sandorkertesz ce06623
Fix netcdf field memory usage
sandorkertesz 9ce7828
Fix netcdf field memory usage
sandorkertesz 11c1170
Add support for anemoi-datasets
sandorkertesz 8e12525
Add support for anemoi-datasets
sandorkertesz c7f2d21
Add test for cube
sandorkertesz 290ef68
Set eathkit-geo version
sandorkertesz 5339d23
Disable opendap notebook in tests
sandorkertesz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,16 +13,20 @@ | |
LOG = logging.getLogger(__name__) | ||
|
||
|
||
class Remapping: | ||
class Remapping(dict): | ||
# inherit from dict to make it serialisable | ||
|
||
def __init__(self, remapping): | ||
self.remapping = {} | ||
super().__init__(remapping) | ||
|
||
self.lists = {} | ||
for k, v in remapping.items(): | ||
m = re.split(r"\{([^}]*)\}", v) | ||
self.remapping[k] = m | ||
if isinstance(v, str): | ||
v = re.split(r"\{([^}]*)\}", v) | ||
self.lists[k] = v | ||
|
||
def __call__(self, func): | ||
if self.remapping is None or not self.remapping: | ||
if not self: | ||
return func | ||
|
||
class CustomJoiner: | ||
|
@@ -43,9 +47,12 @@ def wrapped(name, **kwargs): | |
return wrapped | ||
|
||
def substitute(self, name, joiner, **kwargs): | ||
if name in self.remapping: | ||
if name in self.lists: | ||
if callable(self.lists[name]): | ||
return self.lists[name]() | ||
|
||
lst = [] | ||
for i, bit in enumerate(self.remapping[name]): | ||
for i, bit in enumerate(self.lists[name]): | ||
if i % 2: | ||
p = joiner.format_name(bit, **kwargs) | ||
if p is not None: | ||
|
@@ -58,19 +65,61 @@ def substitute(self, name, joiner, **kwargs): | |
return joiner.format_name(name, **kwargs) | ||
|
||
def as_dict(self): | ||
return self.remapping | ||
return dict(self) | ||
|
||
|
||
def build_remapping(mapping): | ||
def _build_remapping(mapping): | ||
if mapping is None: | ||
return Remapping({}) | ||
|
||
if isinstance(mapping, dict): | ||
if not isinstance(mapping, Remapping) and isinstance(mapping, dict): | ||
return Remapping(mapping) | ||
|
||
return mapping | ||
|
||
|
||
class Patch(dict): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be nice to have a little description of what Patch is for |
||
# inherit from dict to make it serialisable | ||
|
||
def __init__(self, proc, name, patch): | ||
self.proc = proc | ||
self.name = name | ||
|
||
if isinstance(patch, dict): | ||
self.patch = lambda x: patch.get(x, x) | ||
elif isinstance(patch, (int, bool, float, str)) or patch is None: | ||
self.patch = lambda x: patch | ||
else: | ||
assert callable(patch) | ||
self.patch = patch | ||
|
||
# For JSON, we simply forward to the remapping | ||
super().__init__(proc.as_dict()) | ||
|
||
def __call__(self, func): | ||
next = self.proc(func) | ||
|
||
def wrapped(name, **kwargs): | ||
result = next(name, **kwargs) | ||
if name == self.name: | ||
result = self.patch(result) | ||
return result | ||
|
||
return wrapped | ||
# assert False, (name, self.proc, self.name, self.patch) | ||
|
||
def as_dict(self): | ||
return dict(self) | ||
|
||
|
||
def build_remapping(mapping, patches=None): | ||
result = _build_remapping(mapping) | ||
if patches: | ||
for k, v in patches.items(): | ||
result = Patch(result, k, v) | ||
return result | ||
|
||
|
||
def normalize_order_by(*args, **kwargs): | ||
_kwargs = {} | ||
for a in args: | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It feels a little strange to return a str rather than a datetime here. Could the client (anemoi-datasets) not perform the conversion to string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This requires further discussion.