Skip to content

Coordinates operations #10314

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

Open
11 tasks
keewis opened this issue May 13, 2025 · 1 comment
Open
11 tasks

Coordinates operations #10314

keewis opened this issue May 13, 2025 · 1 comment

Comments

@keewis
Copy link
Collaborator

keewis commented May 13, 2025

What is your issue?

At the moment, the Coordinates objects are not as useful as I'd like them to be, so in this issue I'd like to collect all the methods it should support. Some of these already exist, but listing them again helps with defining a coherent API:

  • coordinate variables
    • assignment of new coordinates (from Variable / DataArray / Coordinates / any array): Coordinates.assign()
    • deletion of coordinates (similar to Dataset.drop_vars): only via del coords["x"] but a Coordinates.drop_vars() might be welcome I guess
    • renaming coordinates: no specific method yet, Coordinates.rename_vars()?
    • renaming dimensions on coordinates: no specific method yet, Coordinates.rename_dims()?
  • indexes
  • combination
    • merging (also using |)

cc @benbovy, @scottyhq

@keewis
Copy link
Collaborator Author

keewis commented May 13, 2025

Some examples of how I'd imagine to use these:

Coordinates:

# assigning variables
time = xr.DataArray(..., dims="time")
coords.assign(lat=xr.Variable("lat", lat), lon=("lon", lon), time=time)
# dropping variables (and their associated indexes)
coords.drop_coords(["lat", "lon"])
# renaming variables
coords.rename_coords({"lat": "latitude", "lon": "longitude"})
# renaming dims
coords.rename_dims({"lat": "latitude"})

Indexes:

# assign an existing index
coords.assign_indexes([index1, index2])
# drop indexes (without dropping the associated variables)
coords.drop_indexes([Frozen(["lon", "lat"]), "time"])
# create new index
coords.create_indexes({Frozen(["lon", "lat"]): (CustomIndex, {"option1": "value1", ...})})

Combination:

# merging two `Coordinates` objects
coords1.merge(coords2)
# or
coords1 | coords2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant