-
Notifications
You must be signed in to change notification settings - Fork 23
Read Kerchunk and file-like object datasets #938
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
Changes from 12 commits
7a257fd
9a25a38
4e89b17
3f0ce97
36d7c53
84d7ee6
6a26cd7
932e13e
901a047
2e38c05
25e05ee
38fd977
6a2c0b3
1174168
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| {"version":1,"refs":{"lat\/0":"base64:eF5jYMABDjQwNBwIcmNwCzpwgMHBAQAxqAWx","lat_bnds\/0.0":"base64:eF5jYCAVNMAZYX5+dkDg5xd2AAQcQAAAZ+II3Q==","lon\/0":"base64:eF5jYCAONDxQ2BDwwUPCLCAmOTOvqNQBCgB9ngjU","lon_bnds\/0.0":"base64:eF5jYKAyaACCBw8aGhQUHjzYsKGBwc0tLCwhIS0tJ6egoLi4jMEBFQAA\/noSOQ==","q\/0.0":["example_field_0.nc",17755,100],"q\/0.1":"base64:eF6z7v4lGfX4l4\/QxJO77ufUsaQsrTNvflvm6f88K8x6dlbngZp9PL2\/9\/DdP7LH8ZT9fKbpK0t0\/RVKEhaaSmnnfZy8qXfD5KeucfrtkxbNmLt8U8WGbbvWttkjAQAjCS4Q","q\/1.0":"base64:eF6TzNB+88v69hsGIGCZ2B5Yd\/9nIIgd9lZsR5Z\/3Q4Qm6\/mptye3iw5EFvX\/lxryfQ9rSD2JtPvryfnlbwGseeuW7yxYtHkhfOAwB4K3IEAAKyvI6g=","q\/1.1":"base64:eF6TtLaeY909x5IBCFju3z9yP+fIFhA7zN9fwf+5wgkQm6+3d0Pv7w1lILbu9OlF01cW7QOxN+XlZeR9zJgPYq\/d1DRx0qKFXfOAwB4K3IEAAGAXIr4=","time\/0":"\u0000\u0000\u0000\u0000\u0000\u0000?@",".zgroup":"{\"zarr_format\":2}",".zattrs":"{\"Conventions\":\"CF-1.12\"}","lat\/.zarray":"{\"shape\":[5],\"chunks\":[5],\"dtype\":\"<f8\",\"fill_value\":null,\"order\":\"C\",\"filters\":[{\"id\":\"shuffle\",\"elementsize\":8},{\"id\":\"zlib\",\"level\":4}],\"dimension_separator\":\".\",\"compressor\":null,\"zarr_format\":2}","lat\/.zattrs":"{\"_ARRAY_DIMENSIONS\":[\"lat\"],\"units\":\"degrees_north\",\"standard_name\":\"latitude\",\"bounds\":\"lat_bnds\"}","lat_bnds\/.zarray":"{\"shape\":[5,2],\"chunks\":[5,2],\"dtype\":\"<f8\",\"fill_value\":null,\"order\":\"C\",\"filters\":[{\"id\":\"shuffle\",\"elementsize\":8},{\"id\":\"zlib\",\"level\":4}],\"dimension_separator\":\".\",\"compressor\":null,\"zarr_format\":2}","lat_bnds\/.zattrs":"{\"_ARRAY_DIMENSIONS\":[\"lat\",\"bounds2\"]}","lon\/.zarray":"{\"shape\":[8],\"chunks\":[8],\"dtype\":\"<f8\",\"fill_value\":null,\"order\":\"C\",\"filters\":[{\"id\":\"shuffle\",\"elementsize\":8},{\"id\":\"zlib\",\"level\":4}],\"dimension_separator\":\".\",\"compressor\":null,\"zarr_format\":2}","lon\/.zattrs":"{\"_ARRAY_DIMENSIONS\":[\"lon\"],\"units\":\"degrees_east\",\"standard_name\":\"longitude\",\"bounds\":\"lon_bnds\"}","lon_bnds\/.zarray":"{\"shape\":[8,2],\"chunks\":[8,2],\"dtype\":\"<f8\",\"fill_value\":null,\"order\":\"C\",\"filters\":[{\"id\":\"shuffle\",\"elementsize\":8},{\"id\":\"zlib\",\"level\":4}],\"dimension_separator\":\".\",\"compressor\":null,\"zarr_format\":2}","lon_bnds\/.zattrs":"{\"_ARRAY_DIMENSIONS\":[\"lon\",\"bounds2\"]}","q\/.zarray":"{\"shape\":[5,8],\"chunks\":[3,4],\"dtype\":\"<f8\",\"fill_value\":null,\"order\":\"C\",\"filters\":[{\"id\":\"shuffle\",\"elementsize\":8},{\"id\":\"zlib\",\"level\":4}],\"dimension_separator\":\".\",\"compressor\":null,\"zarr_format\":2}","q\/.zattrs":"{\"_ARRAY_DIMENSIONS\":[\"lat\",\"lon\"],\"project\":\"research\",\"standard_name\":\"specific_humidity\",\"units\":\"1\",\"coordinates\":\"time\",\"cell_methods\":\"area: mean\"}","time\/.zarray":"{\"shape\":[],\"chunks\":[],\"dtype\":\"<f8\",\"fill_value\":null,\"order\":\"C\",\"filters\":null,\"dimension_separator\":\".\",\"compressor\":null,\"zarr_format\":2}","time\/.zattrs":"{\"_ARRAY_DIMENSIONS\":[],\"units\":\"days since 2018-12-01\",\"standard_name\":\"time\"}"}} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| import datetime | ||
| import faulthandler | ||
| import json | ||
| import os | ||
| import unittest | ||
|
|
||
| import fsspec | ||
|
|
||
| faulthandler.enable() # to debug seg faults and timeouts | ||
|
|
||
|
|
||
| import cf | ||
|
|
||
| warnings = False | ||
|
|
||
|
|
||
| kerchunk_file = os.path.join( | ||
| os.path.dirname(os.path.abspath(__file__)), "example_field_0.kerchunk" | ||
| ) | ||
|
|
||
| fs = fsspec.filesystem("reference", fo=kerchunk_file) | ||
| kerchunk_mapper = fs.get_mapper() | ||
|
|
||
|
|
||
| class read_writeTest(unittest.TestCase): | ||
| """Test the reading and writing of field constructs from/to disk.""" | ||
|
|
||
| netcdf = os.path.join( | ||
| os.path.dirname(os.path.abspath(__file__)), "example_field_0.nc" | ||
| ) | ||
| kerchunk = kerchunk_mapper | ||
|
|
||
| def setUp(self): | ||
| """Preparations called immediately before each test method.""" | ||
| # Disable log messages to silence expected warnings | ||
| cf.LOG_LEVEL("DISABLE") | ||
| # Note: to enable all messages for given methods, lines or | ||
| # calls (those without a 'verbose' option to do the same) | ||
| # e.g. to debug them, wrap them (for methods, start-to-end | ||
| # internally) as follows: cf.LOG_LEVEL('DEBUG') | ||
| # | ||
| # < ... test code ... > | ||
| # cf.log_level('DISABLE') | ||
|
|
||
| def test_kerchunk_read(self): | ||
| """Test cf.read with Kerchunk.""" | ||
| f = cf.read(self.netcdf)[0] | ||
|
|
||
| k = cf.read(self.kerchunk, dask_chunks=3) | ||
| self.assertEqual(len(k), 1) | ||
| self.assertTrue(k[0].equals(f)) | ||
| self.assertGreater(k[0].data.npartitions, 1) | ||
|
|
||
| k = cf.read([self.kerchunk, self.kerchunk], dask_chunks=3) | ||
| self.assertEqual(len(k), 2) | ||
| self.assertTrue(k[0].equals(k[-1])) | ||
|
|
||
| k = cf.read([self.kerchunk, self.kerchunk, self.netcdf], dask_chunks=3) | ||
| self.assertEqual(len(k), 3) | ||
| self.assertTrue(k[0].equals(k[-1])) | ||
| self.assertTrue(k[1].equals(k[-1])) | ||
|
|
||
| def test_kerchunk_original_filenames(self): | ||
| """Test original_filenames with Kerchunk.""" | ||
| k = cf.read(self.kerchunk)[0] | ||
| self.assertEqual(k.get_original_filenames(), set()) | ||
|
|
||
| def test_read_dict(self): | ||
| """Test cf.read with an Kerchunk dictionary.""" | ||
| with open(kerchunk_file, "r") as fh: | ||
| d = json.load(fh) | ||
|
|
||
| with self.assertRaises(ValueError): | ||
| cf.read(d) | ||
|
|
||
| fs = fsspec.filesystem("reference", fo=d) | ||
| kerchunk = fs.get_mapper() | ||
| self.assertEqual(len(cf.read(kerchunk)), 1) | ||
|
|
||
| def test_read_bytes(self): | ||
| """Test cf.read with an Kerchunk dictionary.""" | ||
|
davidhassell marked this conversation as resolved.
Outdated
|
||
| with open(kerchunk_file, "r") as fh: | ||
| d = json.load(fh) | ||
|
|
||
| b = json.dumps(d).encode("utf-8") | ||
| with self.assertRaises(ValueError): | ||
| cf.read(b) | ||
|
|
||
| d = json.loads(b) | ||
| fs = fsspec.filesystem("reference", fo=d) | ||
| kerchunk = fs.get_mapper() | ||
| self.assertEqual(len(cf.read(kerchunk)), 1) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| print("Run date:", datetime.datetime.now()) | ||
| cf.environment() | ||
| print("") | ||
| unittest.main(verbosity=2) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| netCDF4==1.7.2 | ||
| netCDF4>=1.7.2 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As discussed offline, we pinned to 1.7.2 only due to #899 so allowing a minimum pin might be unsafe and cause users to hit that issue on install - and the latest version 1.7.4 exhibits different issues. Best leave as-is for now and we can see review on the next release in a few months time.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. discussed offline (again!) and have decided to leave as |
||
| cftime>=1.6.4 | ||
| numpy>=2.0.0 | ||
| cfdm>=1.13.0.0, <1.13.1.0 | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.