-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
7a257fd
Merge branch 'ugrid-write' of github.com:davidhassell/cf-python
davidhassell 9a25a38
Merge branch 'main' of github.com:NCAS-CMS/cf-python
davidhassell 4e89b17
Merge branch 'main' of github.com:NCAS-CMS/cf-python
davidhassell 3f0ce97
dev
davidhassell 36d7c53
Merge branch 'main' of github.com:NCAS-CMS/cf-python
davidhassell 84d7ee6
main merge
davidhassell 6a26cd7
dev
davidhassell 932e13e
pp
davidhassell 901a047
fix netCDF4 pin
davidhassell 2e38c05
Merge branch 'main' into kerchunk-read
davidhassell 25e05ee
Merge branch 'main' of github.com:NCAS-CMS/cf-python
davidhassell 38fd977
Merge branch 'main' into kerchunk-read
davidhassell 6a2c0b3
Update docs/source/installation.rst
davidhassell 1174168
Typos
davidhassell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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\"}"}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 a Kerchunk raw bytes representation.""" | ||
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| netCDF4==1.7.2 | ||
| netCDF4>=1.7.2 | ||
| cftime>=1.6.4 | ||
| numpy>=2.0.0 | ||
| cfdm>=1.13.0.0, <1.13.1.0 | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
discussed offline (again!) and have decided to leave as
netCDF4>=1.7.2for now :)