Skip to content

feat: point data #358

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

Merged
merged 35 commits into from
Jun 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
73ef194
add augment feature
b8raoult Dec 2, 2024
0203c88
add augment feature
b8raoult Dec 2, 2024
e0b6cdd
add augment feature
b8raoult Dec 2, 2024
4a439bc
update
b8raoult Dec 2, 2024
57802d9
update
b8raoult Dec 2, 2024
0d75c4f
update
b8raoult Dec 2, 2024
391d917
update complement none
b8raoult Dec 2, 2024
ca3f867
fix shape
b8raoult Dec 2, 2024
99f90d9
Make missing date object lam compatible
OpheliaMiralles Oct 7, 2024
5daa030
Fix bug related to changes in earthkit-data
OpheliaMiralles Dec 5, 2024
1877567
Add ordering of variables
OpheliaMiralles Dec 6, 2024
0f73454
Revert to uncommented + format
OpheliaMiralles Dec 6, 2024
8f8cca0
Remove unlinked code
OpheliaMiralles Dec 6, 2024
dc6a298
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 6, 2024
7789be2
Remove print messages
b8raoult Dec 7, 2024
7960e50
update documentation
b8raoult Dec 7, 2024
24794a0
Fix variables match with source data
OpheliaMiralles Dec 10, 2024
9ce0563
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 10, 2024
532a12a
Comment out some checks
OpheliaMiralles Dec 11, 2024
3816a84
Don't order by default
OpheliaMiralles Jan 6, 2025
294c786
Add statistics
OpheliaMiralles Jan 6, 2025
9411d0b
Stash
OpheliaMiralles Mar 25, 2025
084933e
Merge remote-tracking branch 'origin/main' into comment_out_checks
OpheliaMiralles Mar 26, 2025
b2ab4d7
Comment out check in xarray to support single spatial coord
OpheliaMiralles Mar 26, 2025
651c063
Add spatial interp, fixes to complement
OpheliaMiralles Mar 26, 2025
31bc4ed
Remove unused code
OpheliaMiralles Mar 26, 2025
eb401e4
Clean up
OpheliaMiralles Mar 26, 2025
09584d4
Point data support
OpheliaMiralles Jun 12, 2025
f42695e
Merge remote-tracking branch 'origin/main' into feature/point-data
OpheliaMiralles Jun 12, 2025
d3a1fc9
Add point coord in flavour
OpheliaMiralles Jun 13, 2025
d9ea1a8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 13, 2025
785cb93
Remove core, correct complement md and stats
OpheliaMiralles Jun 17, 2025
c7c3a84
Pre commit hooks
OpheliaMiralles Jun 17, 2025
469c99e
Fix variable ordering in complement
OpheliaMiralles Jun 17, 2025
ea2cca3
Merge branch 'main' into feature/point-data
b8raoult Jun 30, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class Coordinate:
is_member = False
is_x = False
is_y = False
is_point = False

def __init__(self, variable: xr.DataArray) -> None:
"""Initialize the coordinate.
Expand Down Expand Up @@ -390,6 +391,13 @@ def normalise(self, value: Any) -> Any:
return value


class PointCoordinate(Coordinate):
"""Coordinate class for point data."""

is_point = True
mars_names = ("point",)


class LongitudeCoordinate(Coordinate):
"""Coordinate class for longitude."""

Expand Down
18 changes: 18 additions & 0 deletions src/anemoi/datasets/create/sources/xarray_support/flavour.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from .coordinates import LatitudeCoordinate
from .coordinates import LevelCoordinate
from .coordinates import LongitudeCoordinate
from .coordinates import PointCoordinate
from .coordinates import ScalarCoordinate
from .coordinates import StepCoordinate
from .coordinates import TimeCoordinate
Expand Down Expand Up @@ -134,6 +135,10 @@ def _guess(self, coordinate: xr.DataArray, coord: Hashable) -> Coordinate:

d: Optional[Coordinate] = None

d = self._is_point(coordinate, attributes)
if d is not None:
return d

d = self._is_longitude(coordinate, attributes)
if d is not None:
return d
Expand Down Expand Up @@ -392,6 +397,10 @@ def _is_longitude(self, c: xr.DataArray, attributes: CoordinateAttributes) -> Op
"""
pass

@abstractmethod
def _is_point(self, c: xr.DataArray, attributes: CoordinateAttributes) -> Optional[PointCoordinate]:
pass

@abstractmethod
def _is_latitude(self, c: xr.DataArray, attributes: CoordinateAttributes) -> Optional[LatitudeCoordinate]:
"""Checks if the coordinate is a latitude.
Expand Down Expand Up @@ -550,6 +559,15 @@ def __init__(self, ds: xr.Dataset) -> None:
"""
super().__init__(ds)

def _is_point(self, c: xr.DataArray, attributes: CoordinateAttributes) -> Optional[PointCoordinate]:
if attributes.standard_name in ["cell", "station", "poi", "point"]:
return PointCoordinate(c)

if attributes.name in ["cell", "station", "poi", "point"]: # WeatherBench
return PointCoordinate(c)

return None

def _is_longitude(self, c: xr.DataArray, attributes: CoordinateAttributes) -> Optional[LongitudeCoordinate]:
"""Checks if the coordinate is a longitude.

Expand Down
8 changes: 6 additions & 2 deletions src/anemoi/datasets/create/sources/xarray_support/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,12 @@ def __init__(

self.time = time

self.shape = tuple(len(c.variable) for c in coordinates if c.is_dim and not c.scalar and not c.is_grid)
self.names = {c.variable.name: c for c in coordinates if c.is_dim and not c.scalar and not c.is_grid}
self.shape = tuple(
len(c.variable) for c in coordinates if c.is_dim and not c.scalar and not c.is_grid and not c.is_point
)
self.names = {
c.variable.name: c for c in coordinates if c.is_dim and not c.scalar and not c.is_grid and not c.is_point
}
self.by_name = {c.variable.name: c for c in coordinates}

# We need that alias for the time dimension
Expand Down
15 changes: 10 additions & 5 deletions src/anemoi/datasets/data/complement.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,11 @@ def variables(self) -> List[str]:

@property
def statistics(self) -> Dict[str, NDArray[Any]]:
"""Returns the statistics of the complemented dataset."""
index = [self._source.name_to_index[v] for v in self._variables]
return {k: v[index] for k, v in self._source.statistics.items()}
datasets = [self._source, self._target]
return {
k: [d.statistics[k][d.name_to_index[i]] for d in datasets for i in d.variables if i in self.variables]
for k in datasets[0].statistics
}

def statistics_tendencies(self, delta: Optional[datetime.timedelta] = None) -> Dict[str, NDArray[Any]]:
index = [self._source.name_to_index[v] for v in self._variables]
Expand All @@ -120,7 +122,9 @@ def shape(self) -> Shape:
@property
def variables_metadata(self) -> Dict[str, Any]:
"""Returns the metadata of the variables to be added to the target dataset."""
return {k: v for k, v in self._source.variables_metadata.items() if k in self._variables}
all_meta = self._source.variables_metadata.items().copy()
all_meta.update(self._target.variables_metadata.items())
return {k: v for k, v in all_meta.items() if k in self._variables}

def check_same_variables(self, d1: Dataset, d2: Dataset) -> None:
"""Checks if the variables in two datasets are the same.
Expand Down Expand Up @@ -331,5 +335,6 @@ def complement_factory(args: Tuple, kwargs: dict) -> Dataset:
}[interpolation]

complement = Class(target=target, source=source)._subset(**kwargs)
joined = _open_dataset([target, complement])

return _open_dataset([target, complement], reorder=source.variables)
return _open_dataset(joined, reorder=sorted(joined.variables))
Loading