Skip to content

Commit

Permalink
Fix #199. (#200)
Browse files Browse the repository at this point in the history
* Fix #199. Written datasets should no longer include empty coords.

* Fix bug in coordinate selection.

* Update HISTORY.rst
  • Loading branch information
JSKenyon committed Apr 12, 2022
1 parent 8c6af89 commit b317b04
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 20 deletions.
1 change: 1 addition & 0 deletions HISTORY.rst
Expand Up @@ -4,6 +4,7 @@ History

X.Y.Z (YYYY-MM-DD)
------------------
* Fix #199 - do not create spurious fields in zarr writes. (:pr:`200`)
* Improve fix for #172 - error out more reliably. (:pr:`198`)
* Fix #172 - error out when missing datavars should be written. (:pr:`197`)
* Fix #195 - allow non-standard columns to be tiled. (:pr:`196`)
Expand Down
25 changes: 6 additions & 19 deletions daskms/experimental/utils.py
Expand Up @@ -83,27 +83,14 @@ def select_vars_and_coords(dataset, columns):
f"columns: {column_set}. Some or all of these "
f"are not present on the datasets. Aborting.")

data_cols = column_set & data_var_names
coord_cols = column_set & coord_names
data_sel = column_set & data_var_names
coord_sel = column_set & coord_names

for c in coord_cols:
coord_cols.union(*(d for d in coords[c].dims))
for dv in data_sel:
coord_sel = coord_sel.union(*data_vars[dv].coords.keys())

ret_data_vars = {}

for c in data_cols:
ret_data_vars[c] = v = data_vars[c]
coord_cols.union(*(d for d in v.dims))

ret_coords = {}

for c in coord_cols:
try:
v = coords[c]
except KeyError:
continue
else:
ret_coords[c] = v
ret_data_vars = {col: data_vars[col] for col in data_sel}
ret_coords = {c: coords[c] for c in coord_sel}

return ret_data_vars, ret_coords

Expand Down
6 changes: 5 additions & 1 deletion daskms/experimental/zarr/__init__.py
Expand Up @@ -201,7 +201,8 @@ def xds_to_zarr(xds, store, columns=None):
Path to store the data
columns : list of str or str or None
Columns to store. `None` or `"ALL"` stores all columns on each dataset.
Otherwise, a list of columns should be supplied.
Otherwise, a list of columns should be supplied. All coordinates
associated with a specified column will be written automatically.
Returns
-------
Expand Down Expand Up @@ -234,6 +235,9 @@ def xds_to_zarr(xds, store, columns=None):

data_vars, coords = select_vars_and_coords(ds, columns)

# Create a new ds which is consistent with what we want to write.
ds = Dataset(data_vars, coords=coords, attrs=ds.attrs)

group = prepare_zarr_group(di, ds, store)

data_vars = dict(_gen_writes(data_vars, ds.chunks, group))
Expand Down

0 comments on commit b317b04

Please sign in to comment.