Skip to content

Commit

Permalink
Add parameters to UxDataArray.to_dataset() (#783)
Browse files Browse the repository at this point in the history
* add parameters to UxDataArray.to_dataset

* update docstirng
  • Loading branch information
philipc2 authored May 14, 2024
1 parent e7d0972 commit 682127e
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions uxarray/core/dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import xarray as xr
import numpy as np

from typing import TYPE_CHECKING, Optional, Union
from typing import TYPE_CHECKING, Optional, Union, Hashable

from uxarray.grid import Grid
import uxarray.core.dataset
Expand Down Expand Up @@ -245,11 +245,35 @@ def to_polycollection(
f"({self.uxgrid.n_face}."
)

def to_dataset(self) -> UxDataset:
"""Converts a ``UxDataArray`` into a ``UxDataset`` with a single data
variable."""
xrds = super().to_dataset()
return uxarray.core.dataset.UxDataset(xrds, uxgrid=self.uxgrid)
def to_dataset(
self,
dim: Hashable = None,
*,
name: Hashable = None,
promote_attrs: bool = False,
) -> UxDataset:
"""Convert a UxDataArray to a UxDataset.
Parameters
----------
dim : Hashable, optional
Name of the dimension on this array along which to split this array
into separate variables. If not provided, this array is converted
into a Dataset of one variable.
name : Hashable, optional
Name to substitute for this array's name. Only valid if ``dim`` is
not provided.
promote_attrs : bool, default: False
Set to True to shallow copy attrs of UxDataArray to returned UxDataset.
Returns
-------
uxds: UxDataSet
"""
xrds = super().to_dataset(dim=dim, name=name, promote_attrs=promote_attrs)
uxds = uxarray.core.dataset.UxDataset(xrds, uxgrid=self.uxgrid)

return uxds

def nearest_neighbor_remap(
self,
Expand Down

0 comments on commit 682127e

Please sign in to comment.