Skip to content

Commit 16b5c83

Browse files
authored
feat: fix repeat dates (#458)
## Description <!-- What issue or task does this change relate to? --> ## What problem does this change solve? <!-- Describe if it's a bugfix, new feature, doc update, or breaking change --> ## What issue or task does this change relate to? <!-- link to Issue Number --> ## Additional notes ## <!-- Include any additional information, caveats, or considerations that the reviewer should be aware of. --> ***As a contributor to the Anemoi framework, please ensure that your changes include unit tests, updates to any affected dependencies and documentation, and have been tested in a parallel setting (i.e., with multiple GPUs). As a reviewer, you are also responsible for verifying these aspects and requesting changes if they are not adequately addressed. For guidelines about those please refer to https://anemoi.readthedocs.io/en/latest/*** By opening this pull request, I affirm that all authors agree to the [Contributor License Agreement.](https://github.com/ecmwf/codex/blob/main/Legal/contributor_license_agreement.md)
1 parent d6ed174 commit 16b5c83

File tree

1 file changed

+0
-116
lines changed

1 file changed

+0
-116
lines changed

src/anemoi/datasets/create/input/repeated_dates.py

Lines changed: 0 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,9 @@
1414
from typing import Any
1515

1616
import numpy as np
17-
from anemoi.transform.fields import new_field_with_valid_datetime
18-
from anemoi.transform.fields import new_fieldlist_from_list
1917
from anemoi.utils.dates import as_datetime
2018
from anemoi.utils.dates import frequency_to_timedelta
2119

22-
from .action import Action
23-
from .action import action_factory
24-
from .join import JoinResult
25-
from .result.field import Result
26-
from .trace import trace_select
27-
2820
LOG = logging.getLogger(__name__)
2921

3022

@@ -276,111 +268,3 @@ def transform(self, group_of_dates: Any) -> tuple[Any, Any]:
276268
group_of_dates,
277269
)
278270
]
279-
280-
281-
class DateMapperResult(Result):
282-
"""A Result implementation that updates the valid datetime of the datasource."""
283-
284-
def __init__(
285-
self,
286-
context: Any,
287-
action_path: list[str],
288-
group_of_dates: Any,
289-
source_result: Any,
290-
mapper: DateMapper,
291-
original_group_of_dates: Any,
292-
) -> None:
293-
"""Initialize DateMapperResult.
294-
295-
Parameters
296-
----------
297-
context : Any
298-
The context.
299-
action_path : list of str
300-
The action path.
301-
group_of_dates : Any
302-
The group of dates.
303-
source_result : Any
304-
The source result.
305-
mapper : DateMapper
306-
The date mapper.
307-
original_group_of_dates : Any
308-
The original group of dates.
309-
"""
310-
super().__init__(context, action_path, group_of_dates)
311-
312-
self.source_results: Any = source_result
313-
self.mapper: DateMapper = mapper
314-
self.original_group_of_dates: Any = original_group_of_dates
315-
316-
@property
317-
def datasource(self) -> Any:
318-
"""Get the datasource with updated valid datetime."""
319-
result: list = []
320-
321-
for field in self.source_results.datasource:
322-
for date in self.original_group_of_dates:
323-
result.append(new_field_with_valid_datetime(field, date))
324-
325-
if not result:
326-
raise ValueError("repeated_dates: no input data found")
327-
328-
return new_fieldlist_from_list(result)
329-
330-
331-
class RepeatedDatesAction(Action):
332-
"""An Action implementation that selects and transforms a group of dates."""
333-
334-
def __init__(self, context: Any, action_path: list[str], source: Any, mode: str, **kwargs: Any) -> None:
335-
"""Initialize RepeatedDatesAction.
336-
337-
Args:
338-
context (Any): The context.
339-
action_path (List[str]): The action path.
340-
source (Any): The data source.
341-
mode (str): The mode for date mapping.
342-
**kwargs (Any): Additional arguments.
343-
"""
344-
super().__init__(context, action_path, source, mode, **kwargs)
345-
346-
self.source: Any = action_factory(source, context, action_path + ["source"])
347-
self.mapper: DateMapper = DateMapper.from_mode(mode, self.source, kwargs)
348-
self.mode = mode
349-
self.kwargs = kwargs
350-
351-
@trace_select
352-
def select(self, group_of_dates: Any) -> JoinResult:
353-
"""Select and transform the group of dates.
354-
355-
Args:
356-
group_of_dates (Any): The group of dates to select.
357-
358-
Returns
359-
-------
360-
JoinResult
361-
The result of the join operation.
362-
"""
363-
results: list = []
364-
for one_date_group, many_dates_group in self.mapper.transform(group_of_dates):
365-
results.append(
366-
DateMapperResult(
367-
self.context,
368-
self.action_path,
369-
one_date_group,
370-
self.source.select(one_date_group),
371-
self.mapper,
372-
many_dates_group,
373-
)
374-
)
375-
376-
return JoinResult(self.context, self.action_path, group_of_dates, results)
377-
378-
def __repr__(self) -> str:
379-
"""Get the string representation of the action.
380-
381-
Returns
382-
-------
383-
str
384-
The string representation.
385-
"""
386-
return f"MultiDateMatchAction({self.source}, {self.mapper})"

0 commit comments

Comments
 (0)