Skip to content
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

concat automagically outer-joins coordinates #1354

Closed
j08lue opened this issue Apr 5, 2017 · 8 comments · Fixed by #3102
Closed

concat automagically outer-joins coordinates #1354

j08lue opened this issue Apr 5, 2017 · 8 comments · Fixed by #3102

Comments

@j08lue
Copy link
Contributor

j08lue commented Apr 5, 2017

I would like to concatenate two netCDF files that have float64 coordinate variables. I thought the coordinate values were the same, but in fact they differ by something in the order of 1e-14.

Using open_mfdataset or concat to merge the datasets, I get a completely different output shape than the two input files have.

This is because concat is somewhere performing an outer join on the coordinates. Now I am wondering where else in my workflows this might happen without my notice...

It would be awesome if there was an option to change this behaviour on concat, open_mfdataset, and auto_combine. I would actually rather make these functions fail if any dimension other than the concatenation dimension differs.

Note: This could also be a special case, because

>>> (ds1.lon == ds2.lon).all()
<xarray.DataArray 'lon' ()>
array(True, dtype=bool)

while

>>> (ds1.lon.values == ds2.lon.values).all()
False

Maybe an interface change could be considered together with that discussed in #1340?

@shoyer
Copy link
Member

shoyer commented Apr 7, 2017

This only happens in concat.

merge, which happens automatically in many operations, e.g., to decide which coordinates propagate, has different behavior: it automatically drops conflicting coordinate values.

Anyways, I agree: we should try to make this more explicit. We might still keep the "magical" version of concat around, but we should certainly expose the fully explicit version as public API.

@shoyer
Copy link
Member

shoyer commented Apr 21, 2017

#1330 will help, in so far as it adds a join='exact' option that can disable automatic alignment. We would just need to make the join argument used internally in align inside xarray.concat part of the public API for concat.

@wqshen
Copy link

wqshen commented Jul 5, 2017

I also have this problem.

I have a list of dataset with all same shaped array at different time, while each have a different coordinate. (Each dataset is centered in the tropical cyclone center, with a same radius width buffer.)

I use xr.concat to concat them along time dimension, this function auto outer-joins coordinates, which makes the final dataset have a larger-shape, but i just want the original dataset shape.

Any solution ?

@darothen
Copy link

darothen commented Jul 5, 2017

@wqshen, a workaround until a more complete modification to align is available would be to explicitly copy/set the coordinate values on your arrays before using xr.concat(). Alternatively, if it's as simple as stacking along a new tailing axis, you could stack via dask/numpy and then construct a new DataArray passing the coordinates explicitly.

@shoyer
Copy link
Member

shoyer commented Jul 5, 2017

I think the right solution here is to relabel the coordinates on each of the datasets that you are concatenating. The alternative behavior here is xarray raising an error in the case of conflicting coordinate labels.

@stale
Copy link

stale bot commented Jun 5, 2019

In order to maintain a list of currently relevant issues, we mark issues as stale after a period of inactivity

If this issue remains relevant, please comment here or remove the stale label; otherwise it will be marked as closed automatically

@stale stale bot added the stale label Jun 5, 2019
@j08lue
Copy link
Contributor Author

j08lue commented Jun 6, 2019

Thanks for reminding me, stalte bot, this is still relevant to me.

I think your proposed solution @shoyer would solve this issue perfectly: expose align's join parameter in the concat function - and please also in open_mfdataset. Would you like a PR for this?

@stale stale bot removed the stale label Jun 6, 2019
@shoyer
Copy link
Member

shoyer commented Jun 6, 2019 via email

dcherian added a commit to dcherian/xarray that referenced this issue Jul 12, 2019
dcherian added a commit to dcherian/xarray that referenced this issue Jul 15, 2019
TomNicholas pushed a commit that referenced this issue Aug 7, 2019
* mfdatset, concat now support the 'join' kwarg.

Closes #1354

* Add whats-new.rst

* Add concat tests

* doc improvements.

* update todo.

* mfdataset tests.

* manual_combine → combine_nested

* Add tests for combine_nested & combine_coords

* Update docstring.

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

Successfully merging a pull request may close this issue.

4 participants