Skip to content
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

move registry to utils #6

Merged
merged 1 commit into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions dev/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@
# granted to it by virtue of its status as an intergovernmental organisation
# nor does it submit to any jurisdiction.

from anemoi.transform.filters import filter_factory
from anemoi.transform.sources import source_factory
from anemoi.transform.workflows import workflow_factory
from anemoi.transform.filters import filter_registry
from anemoi.transform.sources import source_registry
from anemoi.transform.workflows import workflow_registry

################

mars = source_factory(
"mars",
)
mars = source_registry.create("mars")

r = dict(
param=["u", "v", "t", "q"],
Expand All @@ -31,22 +29,22 @@

################

uv_2_ddff = filter_factory("uv_2_ddff")
uv_2_ddff = filter_registry.create("uv_2_ddff")

data = uv_2_ddff.forward(data)
for f in data:
print(f)


ddff_2_uv = filter_factory("ddff_2_uv")
ddff_2_uv = filter_registry.create("ddff_2_uv")
data = ddff_2_uv.forward(data)
for f in data:
print(f)


################

pipeline = workflow_factory("pipeline", filters=[mars, uv_2_ddff, ddff_2_uv])
pipeline = workflow_registry.create("pipeline", filters=[mars, uv_2_ddff, ddff_2_uv])
for f in pipeline(r):
print(f)

Expand Down
16 changes: 2 additions & 14 deletions src/anemoi/transform/filters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,6 @@
# nor does it submit to any jurisdiction.


from ..registry import Registry
from anemoi.utils.registry import Registry

registry = Registry(__name__)


def register_filter(name, maker):
registry.register(name, maker)


def lookup_filter(name):
return registry.lookup(name)


def filter_factory(name, *args, **kwargs):
return lookup_filter(name)(*args, **kwargs)
filter_registry = Registry(__name__)
6 changes: 3 additions & 3 deletions src/anemoi/transform/filters/uv_to_ddff.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from earthkit.meteo.wind.array import polar_to_xy
from earthkit.meteo.wind.array import xy_to_polar

from . import register_filter
from . import filter_registry
from .base import SimpleFilter


Expand Down Expand Up @@ -80,5 +80,5 @@ def backward_transform(self, speed, direction):
yield self.new_field_from_numpy(v, template=direction, param=self.v_component)


register_filter("uv_2_ddff", WindComponents)
register_filter("ddff_2_uv", WindComponents.reversed)
filter_registry.register("uv_2_ddff", WindComponents)
filter_registry.register("ddff_2_uv", WindComponents.reversed)
75 changes: 0 additions & 75 deletions src/anemoi/transform/registry.py

This file was deleted.

16 changes: 2 additions & 14 deletions src/anemoi/transform/sources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,6 @@
# nor does it submit to any jurisdiction.


from ..registry import Registry
from anemoi.utils.registry import Registry

registry = Registry(__name__)


def register_source(name, maker):
registry.register(name, maker)


def lookup_source(name):
return registry.lookup(name)


def source_factory(name, *args, **kwargs):
return lookup_source(name)(*args, **kwargs)
source_registry = Registry(__name__)
5 changes: 3 additions & 2 deletions src/anemoi/transform/sources/mars.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
import earthkit.data as ekd

from ..source import Source
from . import register_source
from . import source_registry


@source_registry.register("mars")
class Mars(Source):
"""A demo source"""

Expand All @@ -37,4 +38,4 @@ def forward(self, data):
return Input(data)


register_source("mars", Mars)
source_registry.register("mars", Mars)
4 changes: 2 additions & 2 deletions src/anemoi/transform/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ def reversed(cls, *args, **kwargs):
return ReversedTransform(cls(*args, **kwargs))

def __or__(self, other):
from .workflows import workflow_factory
from .workflows import workflow_registry

return workflow_factory("pipeline", filters=[self, other])
return workflow_registry.create("pipeline", filters=[self, other])


class ReversedTransform(Transform):
Expand Down
16 changes: 2 additions & 14 deletions src/anemoi/transform/workflows/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,6 @@
# granted to it by virtue of its status as an intergovernmental organisation
# nor does it submit to any jurisdiction.

from ..registry import Registry
from anemoi.utils.registry import Registry

registry = Registry(__name__)


def register_workflow(name, maker):
registry.register(name, maker)


def lookup_workflow(name):
return registry.lookup(name)


def workflow_factory(name, *args, **kwargs):
return lookup_workflow(name)(*args, **kwargs)
workflow_registry = Registry(__name__)
4 changes: 2 additions & 2 deletions src/anemoi/transform/workflows/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


from ..workflow import Workflow
from . import register_workflow
from . import workflow_registry


class Pipeline(Workflow):
Expand All @@ -29,4 +29,4 @@ def backward(self, data):
return data


register_workflow("pipeline", Pipeline)
workflow_registry.register("pipeline", Pipeline)
Loading