html_url,issue_url,id,node_id,user,created_at,updated_at,author_association,body,reactions,performed_via_github_app,issue https://github.com/pydata/xarray/issues/6310#issuecomment-1069096876,https://api.github.com/repos/pydata/xarray/issues/6310,1069096876,IC_kwDOAMm_X84_uR-s,57705593,2022-03-16T12:55:28Z,2022-03-16T12:55:28Z,CONTRIBUTOR,"Yes, I tested this locally, and here is the PR for that suggestion: #6366","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,1154014066 https://github.com/pydata/xarray/issues/6310#issuecomment-1069089232,https://api.github.com/repos/pydata/xarray/issues/6310,1069089232,IC_kwDOAMm_X84_uQHQ,57705593,2022-03-16T12:46:33Z,2022-03-16T12:46:33Z,CONTRIBUTOR,"No, in this case `""coordinates"" in encoding` will resolve to `False`, so that's not the problematic step. I think the problem is that the author of line 773 assumed that `pop_to` would return the value of `attrs['coordinates']` if `encoding['coordinates']` is not set. That is wrong and the line should be fixed to look like this instead: ```python coords_str = pop_to(encoding, attrs, ""coordinates"") or attrs.get(""coordinates"") ```","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,1154014066 https://github.com/pydata/xarray/issues/6310#issuecomment-1069073130,https://api.github.com/repos/pydata/xarray/issues/6310,1069073130,IC_kwDOAMm_X84_uMLq,57705593,2022-03-16T12:27:14Z,2022-03-16T12:27:14Z,CONTRIBUTOR,"@DWesl Thanks for digging into the details of the CF! I read your post in the sense that solution (1) is the one to choose. I have one more question though before we close this: When setting `""coordinates""` as a variable attribute instead of as an `encoding`, the value of that variable attribute is overwritten when writing to a NetCDF file, see this example: ```python import xarray as xr ds = xr.Dataset( {""values"": ('time', [0.0, 0.1])}, coords={ 'time': ('time', [0, 1]), 'lat': ('time', [5, 4]), 'lon': ('time', [10, 12]) }) ds['values'].attrs['coordinates'] = ""time lon lat"" ds.to_netcdf(""test.nc"") ``` ```shell $ ncdump -h test.nc netcdf test { dimensions: time = 2 ; variables: double values(time) ; values:_FillValue = NaN ; values:coordinates = ""lon lat"" ; int64 time(time) ; int64 lat(time) ; int64 lon(time) ; } ``` Is this intended, and if so, what is the reason?","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,1154014066 https://github.com/pydata/xarray/issues/6310#issuecomment-1068869457,https://api.github.com/repos/pydata/xarray/issues/6310,1068869457,IC_kwDOAMm_X84_tadR,57705593,2022-03-16T08:39:02Z,2022-03-16T08:40:08Z,CONTRIBUTOR,"Hey @dcherian, Thanks for your consideration! I just started to create a new branch with my suggested changes, but then I noticed that setting the `coordinates` attribute to include non-auxiliary dimensions by default will let a lot of unit tests fail. That made me think about this again: In fact, always setting the coordinates attribute is permissible according to the conventions. However, most users will probably be confused about the clutter and we might run into some discussions about this in the future. In my original post, the example can easily be fixed to reflect the coordinate attributes in the conventions (https://cfconventions.org/cf-conventions/cf-conventions.html#_single_trajectory) by enforcing the attribute value in the `encoding`: ```python import xarray as xr ds = xr.Dataset( {""values"": ('time', [0.0, 0.1])}, coords={ 'time': ('time', [0, 1]), 'lat': ('time', [5, 4]), 'lon': ('time', [10, 12]) }) ds['values'].encoding['coordinates'] = ""time lon lat"" ds.to_netcdf(""test.nc"") ``` ```shell $ ncdump -h test.nc netcdf test { dimensions: time = 2 ; variables: double values(time) ; values:_FillValue = NaN ; values:coordinates = ""time lon lat"" ; int64 time(time) ; int64 lat(time) ; int64 lon(time) ; } ``` From here, there are several ways to proceed: 1. Stick to the current logic which might be non-conformal with the CF conventions in case of ""Discrete Sampling Geometries"". However, users can manually fix this by setting the `coordinates` in `encoding`. 2. Enforce to always list all non-auxiliary coordinates in the variable attribute, which is conformal with the conventions, but generates a lot of clutter. 3. Implement a logic to recognize cases where a dataset is a ""Discrete Sampling Geometry"" and only then list the non-auxiliary coordinates in the variable attribute. This is a bit tricky, and I don't have the time to implement this, I'm afraid. I actually suggest to choose solution (1) and close this issue as ""won't fix"". What do you think?","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,1154014066 https://github.com/pydata/xarray/issues/6310#issuecomment-1054195542,https://api.github.com/repos/pydata/xarray/issues/6310,1054195542,IC_kwDOAMm_X84-1b9W,57705593,2022-02-28T12:13:46Z,2022-02-28T12:33:07Z,CONTRIBUTOR,"If you are interested in a fix, I would modify the following section: https://github.com/pydata/xarray/blob/613a8fda4f07181fbc41d6ff2296fec3726fd351/xarray/conventions.py#L726-L744 The `variable_coordinates` should be initialized for each variable `v` with the names in `v.dims`. Currently, the dimension names are explicitly excluded. So it seems to me like this behavior has originally been implemented on purpose because the main use of the `coordinates` attribute according to the CF convention is to list the auxiliary coordinates. However, the conventions also say: ""Note that it is permissible, but optional, to list coordinate variables as well as auxiliary coordinate variables in the coordinates attribute."" (https://cfconventions.org/cf-conventions/cf-conventions.html#coordinate-system) So, this issue is about including the non-auxiliary coordinates by default because it's permissible in general, and it is even required for so-called ""Discrete Sampling Geometries"".","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,1154014066