Repository navigation
Description
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.
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Projects
- StatusShow more project fields✅ Done
Activity
Sevans711 commentedon Jul 20, 2026
Going through my task list led me back here briefly. Leaving a few quick notes:
dirname, not "path", to more closely match the style of kwargs likefilenameandfilename_or_obj.dirnamekwarg, 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.dylannelson commentedon Jul 20, 2026
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:
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
erogluorhan commentedon Jul 23, 2026
Thanks for the suggestion! We are deferring the path/file handling to the user workflow, and usually what is happening is something like this:
Also,
open_dataset()supports xarray objects, pathlike, etc.That said, let us not consider extra path handling convenience on our end for the time.