Skip to content

Improve flexibility of uxarray.open_dataset() #1555

Closed as not planned
Closed as not planned

Description

@Sevans711

Proposed new feature or change:

It would be quite helpful if we could improve flexibillity in uxarray.open_dataset(). In particular, I encounter the following pattern often:

import os
import uxarray as ux
datapath = "path/to/where/data/is/stored"
ds = ux.open_dataset(os.path.join(datapath, 'grid.nc'), os.path.join(datapath, 'data.nc'))

I would love to instead be able to do something like:

import uxarray as ux
datapath = "path/to/where/data/is/stored"
ds = ux.open_dataset('grid.nc', 'data.nc', path=datapath)

(Is path a good name for that kwarg?)

Even better, for a simple case where the file names really are just 'grid.nc' and 'data.nc', it would be awesome to do:

import uxarray as ux
datapath = "path/to/where/data/is/stored"
ds = ux.open_dataset(datapath)

We can't always support opening based on a folder, but I think there are a few unambiguous and somewhat common cases where we could support it, and it would be very convenient. Those cases seem to be:

  • (1) the folder contains files with exactly the names 'grid.nc' and 'data.nc', regardless of any other files in the folder --> open_dataset(datapath) == open_dataset('grid.nc', 'data.nc', path=datapath).
  • (2) the folder contains only two files with supported extensions (e.g. two .nc files, and no files ending in .exo, .g, .nc4, .cpg, .dbf, …), and they differ only in that one says 'grid' and the other says 'data', e.g. 'gradient_data_subset.nc' and 'gradient_grid_subset.nc'. --> open_dataset(datapath) uses those two files.
  • (3) the folder contains only one supported data file (e.g. one .nc file) and one .ug file --> open_dataset(datapath) == open_dataset(theugfile, thedatafile, path=datapath)

I believe the downside of slightly more complexity in the open_dataset signature and docstring would be outweighed by the upside of making uxarray easier to set up and use, especially initially for new users or in new analysis pipelines.

Tangentially related to #1479.

Activity

  1. added
    new feature
    improvement
    on Jul 9, 2026
  2. Sevans711 commented on Jul 20, 2026

    @Sevans711
    CollaboratorAuthor

    Going through my task list led me back here briefly. Leaving a few quick notes:

    1. Maybe a better name for the new proposed kwarg would be dirname, not "path", to more closely match the style of kwargs like filename and filename_or_obj.
    2. Clarifying: while the changes proposed here do touch a central part of uxarray api, they would still be fully backwards-compatible; all existing working code would continue to work, this just provides more options.
    3. Maybe easiest to make two separate PRs, one to add dirname kwarg, and a different one for the "auto-infer file names if the path is a directory and file names can be inferred unambiguously" part of this feature request? I think the latter might require a bit more discussion than the former.
    4. This feature is probably low priority, but it would also probably be fast to implement and not require too much knowledge of the code, so it may be a decent first issue? It also requires a small amount of touching the docs. Pinging @dylannelson and @erogluorhan for your consideration.
  3. dylannelson commented on Jul 20, 2026

    @dylannelson
    Member

    I feel like the 1st and 3rd representations would make sense, and the 2nd seems like it may not be needed if the 3rd is implemented

    The only thing I'm wondering about is if you'd have to fundamentally change how the function handles only 1 unnamed variable inputs for the 3rd option. Right now it looks like if you only supply 1 unnamed arg, it assumes its a grid file, but you'd have to add functionality for checking if its a path or a file, and handling it different ways depending on the circumstance. I haven't tested many file types before so I can't say for certain how difficult that may be, but if there's already a lot of variety of inputs and formats, it may be easier to give this 1 folder/arg route a specific name like:

    ds = ux.open_dataset(datapath, folder = True)

    than to make a large catch all function that can handle any folder/file input as a single arg

    Just some thoughts, no strong suggestions either way. Also still getting to learn the details so I may be wrong in some assumptions

  4. moved this from 📚 Backlog to 📝 To-Do in UXarray Developmenton Jul 21, 2026
  5. moved this from 📝 To-Do to 📚 Backlog in UXarray Developmenton Jul 21, 2026
  6. erogluorhan commented on Jul 23, 2026

    @erogluorhan
    Member

    Thanks for the suggestion! We are deferring the path/file handling to the user workflow, and usually what is happening is something like this:

    path = "path/to/where/data/is/stored"
    grid_file = path + "grid.nc"
    data_file = path + "data.nc"
    
    ds = ux.open_dataset(grid_file, data_file)
    

    Also, open_dataset() supports xarray objects, pathlike, etc.

    That said, let us not consider extra path handling convenience on our end for the time.

  7. moved this from 📚 Backlog to ✅ Done in UXarray Developmenton Jul 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    improvementnew feature

    Fields

    Priority

    None yet

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions