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

dask: Data.uncompress #385

Merged
merged 8 commits into from
Apr 20, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 16 additions & 30 deletions cf/data/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2421,6 +2421,8 @@ def persist(self, inplace=False):

**Examples**

TODODASK

"""
d = _inplace_enabled_define_and_cleanup(self)

Expand Down Expand Up @@ -9042,28 +9044,24 @@ def second(self):
"""
return YMDhms(self, "second")

@daskified(_DASKIFIED_VERBOSE)
@_inplace_enabled(default=False)
def uncompress(self, inplace=False):
"""Uncompress the underlying data.

Compression saves space by identifying and removing unwanted
missing data. Such compression techniques store the data more
efficiently and result in no precision loss.

Whether or not the data is compressed does not alter its
functionality nor external appearance.
"""Uncompress the data.

Data that is already uncompressed will be returned uncompressed.
Only affects data that is compressed by convention, i.e.

The following type of compression are available:
* Ragged arrays for discrete sampling geometries (DSG) and
simple geometry cel definitions.
davidhassell marked this conversation as resolved.
Show resolved Hide resolved

* Ragged arrays for discrete sampling geometries (DSG). Three
different types of ragged array representation are
supported.
* Compression by gathering.

..
* Compression by coordinate subsampling.

* Compression by gathering.
Data that is already uncompressed is returned
unchanged. Whether the data is compressed or not does not
alter its functionality nor external appearance, but may
affect how the data are written to a dataset on disk.

.. versionadded:: 3.0.6

Expand All @@ -9079,7 +9077,7 @@ def uncompress(self, inplace=False):
The uncompressed data, or `None` of the operation was
in-place.

**Examples:**
**Examples**

>>> d.get_compression_type()
'ragged contiguous'
Expand All @@ -9089,20 +9087,8 @@ def uncompress(self, inplace=False):

"""
d = _inplace_enabled_define_and_cleanup(self)

if not d.get_compression_type():
if inplace:
d = None
return d

config = d.partition_configuration(readonly=False)

for partition in d.partitions.matrix.flat:
partition.open(config)
_ = partition.array
partition.close()

d._del_Array(None)
if d.get_compression_type():
d._del_Array(None)

return d

Expand Down
14 changes: 14 additions & 0 deletions cf/test/test_Data.py
Original file line number Diff line number Diff line change
Expand Up @@ -3967,6 +3967,20 @@ def test_Data_tolist(self):
self.assertEqual(e, np.array(x).tolist())
self.assertTrue(d.equals(cf.Data(e)))

def test_Data_uncompress(self):
import cfdm

f = cfdm.read("DSG_timeSeries_contiguous.nc")[0]
a = f.data.array
d = cf.Data(cf.RaggedContiguousArray(source=f.data.source()))

self.assertTrue(d.get_compression_type())
self.assertTrue((d.array == a).all())

self.assertIsNone(d.uncompress(inplace=True))
self.assertFalse(d.get_compression_type())
self.assertTrue((d.array == a).all())

def test_Data_data(self):
for d in [
cf.Data(1),
Expand Down