Skip to content
This repository has been archived by the owner on Dec 20, 2024. It is now read-only.

Commit

Permalink
docs: add docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
JPXKQX committed Dec 18, 2024
1 parent 8a3d478 commit 94f7819
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 7 deletions.
2 changes: 2 additions & 0 deletions docs/graphs/node_coordinates.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ a file:
node_coordinates/zarr_dataset
node_coordinates/npz_file
node_coordinates/icon_mesh
node_coordinates/text_file
node_coordinates/latlon_arrays

or based on other algorithms. A commonn approach is to use an
icosahedron to project the earth's surface, and refine it iteratively to
Expand Down
18 changes: 18 additions & 0 deletions docs/graphs/node_coordinates/latlon_arrays.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#######################################
From latitude & longitude coordinates
#######################################

Nodes can also be created directly using latitude and longitude
coordinates. Below is an example demonstrating how to add these nodes to
a graph:

.. code:: python
from anemoi.graphs.nodes import LatLonNodes
...
lats = np.array([45.0, 45.0, 40.0, 40.0])
lons = np.array([5.0, 10.0, 10.0, 5.0])
graph = LatLonNodes(latitudes=lats, longitudes=lons, name="my_nodes").update_graph(graph)
20 changes: 20 additions & 0 deletions docs/graphs/node_coordinates/text_file.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
################
From .TXT file
################

To define the `node coordinates` based on a TXT file, you can configure
the YAML as follows:

.. code:: yaml
nodes:
data: # name of the nodes
node_builder:
_target_: anemoi.graphs.nodes.TextNodes
dataset: my_file.txt
idx_lon: 0
idx_lat: 1
Here, dataset refers to the path of the TXT file that contains the
latitude and longitude values in the columns specified by `idx_lat` and
`idx_lon`, respectively.
15 changes: 8 additions & 7 deletions src/anemoi/graphs/nodes/builders/from_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ class LatLonNodes(BaseNodeBuilder):
Attributes
----------
latitudes : np.ndarray
The latitude of the nodes.
longitudes : np.ndarray
The longitude of the nodes.
latitudes : list | np.ndarray
The latitude of the nodes, in degrees.
longitudes : list | np.ndarray
The longitude of the nodes, in degrees.
Methods
-------
Expand All @@ -41,8 +41,11 @@ class LatLonNodes(BaseNodeBuilder):
Update the graph with new nodes and attributes.
"""

def __init__(self, latitudes: np.ndarray, longitudes: np.ndarray, name: str) -> None:
def __init__(self, latitudes: list[float] | np.ndarray, longitudes: list[float] | np.ndarray, name: str) -> None:
super().__init__(name)
self.latitudes = latitudes if isinstance(latitudes, np.ndarray) else np.array(latitudes)
self.longitudes = longitudes if isinstance(longitudes, np.ndarray) else np.array(longitudes)

assert len(self.latitudes) == len(
self.longitudes
), f"Lenght of latitudes and longitudes must match but {len(self.latitudes)}!={len(self.longitudes)}."
Expand All @@ -52,8 +55,6 @@ def __init__(self, latitudes: np.ndarray, longitudes: np.ndarray, name: str) ->
assert self.longitudes.ndim == 1 or (
self.longitudes.ndim == 2 and self.longitudes.shape[1] == 1
), "longitudes must have shape (N, ) or (N, 1)."
self.latitudes = latitudes
self.longitudes = longitudes

def get_coordinates(self) -> torch.Tensor:
"""Get the coordinates of the nodes.
Expand Down

0 comments on commit 94f7819

Please sign in to comment.