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

Implementation of UGRID (part 1 of 2) #698

Merged
merged 23 commits into from
Nov 28, 2023
Merged

Conversation

davidhassell
Copy link
Collaborator

@davidhassell davidhassell commented Sep 27, 2023

Fixes #696

Changes

  • Implementation of new constructs
  • Implementation of mesh regridding
  • Implementation of mesh collapsing
  • Refactor to move weights code out of the Field class
  • New Data methods arctan2 and masked_values

New data model constructs that describe meshes

Misc.

Collapse

  • field.py Move weights-related functionality to weights.py
  • weights.py Worker functions for cf.Field.weights that have been refactored out of field.py. Includes new methods for UGRID mesh weights, and bug-fixes the calculation of geometry cell weights.

Regrid

  • regrid.py Extend to allow the regridding of data on UGRID meshes.
  • regridoperator.py New mesh-related attributes; refactored tosparse so that it also works with UGRID meshes.

Data

  • data/data.py New arctan2 and masked_values methods; new masked_value keyword to __init__; Update the calculation of regridded chunksizes to allow for dropped and new axes.
  • data/utils.py New normalize_chunks function to replace the dask one.
  • data/dask_regrid.py Update to allow to the regridded data having more/fewer axes than the source data; Refactor the adjustment of weights to account for missing data.
  • data/collapse/dask_collapse.py Move the checking of weights to compute time, away from definition time in Field.collapse.
  • A whole bunch of changes for representing mesh arrays found in UGRID netCDF files, following the compressed array framework

@davidhassell davidhassell added enhancement New feature or request UGRID Relating to UGRID mesh topologies labels Sep 27, 2023
@davidhassell davidhassell added this to the Next release milestone Nov 6, 2023
commit 0b4e9f1
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Tue Nov 14 11:38:20 2023 +0000

    depency versions

commit 48f543d
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Tue Nov 14 11:37:06 2023 +0000

    cfdm version

commit 31c05be
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Tue Nov 14 11:36:40 2023 +0000

    scipy required

commit 0161159
Merge: 4b87c22 2d53ef6
Author: David Hassell <davidhassell@users.noreply.github.com>
Date:   Tue Nov 14 11:24:47 2023 +0000

    Merge branch 'main' into ugrid-0

commit 4b87c22
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Tue Nov 14 11:07:49 2023 +0000

    UGRIDVER -> 3.16.0

commit 6c18b1e
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Fri Nov 10 13:59:44 2023 +0000

    missing methods in docs rst

commit 6786198
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Fri Nov 10 13:40:02 2023 +0000

    more ugrid tests

commit 09d4335
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Fri Nov 10 13:30:00 2023 +0000

    sparse arrays

commit 48ed306
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Fri Nov 10 12:42:39 2023 +0000

    format

commit 6494aad
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Fri Nov 10 12:39:39 2023 +0000

    cartesian regridding ugrid

commit 4af0948
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Fri Nov 10 12:11:42 2023 +0000

    UGRID ref

commit 01ed055
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Fri Nov 10 12:10:38 2023 +0000

    cfdm version

commit 943664e
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Fri Nov 10 12:09:28 2023 +0000

    mandatory scipy

commit b96ca21
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Fri Nov 10 11:50:21 2023 +0000

    comment

commit 65bfb9e
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Mon Nov 6 13:04:26 2023 +0000

    remove commented code

commit ead7e08
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Mon Nov 6 11:49:28 2023 +0000

    fix ugrid file

commit ab388f9
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Mon Oct 23 19:05:50 2023 +0100

    dev

commit bc68bd7
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Mon Oct 23 10:52:25 2023 +0100

    dev

commit e07bf2d
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Mon Oct 23 10:06:17 2023 +0100

    weights_file

commit cc034ec
Merge: 4b1f7bd 1668e0b
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Mon Oct 23 09:45:25 2023 +0100

    upstream merge

commit 4b1f7bd
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Mon Oct 23 09:42:49 2023 +0100

    dev

commit 3ba860a
Merge: ee3bdac 492d424
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Mon Oct 23 09:10:12 2023 +0100

    dev

commit 492d424
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Thu Oct 19 17:50:22 2023 +0100

    dev

commit ee3bdac
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Thu Oct 19 09:20:16 2023 +0100

    dev

commit 7552ff4
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Wed Oct 11 19:34:54 2023 +0100

    dev

commit c9984eb
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Wed Oct 11 15:38:55 2023 +0100

    dev

commit 4cecab6
Merge: f668a36 70bec02
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Wed Oct 11 14:48:38 2023 +0100

    Merge branch 'main' of github.com:NCAS-CMS/cf-python into ugrid-0

commit f668a36
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Wed Oct 11 13:36:31 2023 +0100

    dev

commit b185ae4
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Wed Oct 11 13:31:37 2023 +0100

    global UGRID files

commit 68b2b0f
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Wed Oct 11 13:30:56 2023 +0100

    ignore CDL files

commit 0d68338
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Wed Oct 11 08:16:34 2023 +0100

    pre-release

commit 493d0e0
Merge: 5669ae3 af65855
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Tue Oct 10 15:28:36 2023 +0100

    3.15.4 merge

commit 5669ae3
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Tue Oct 10 13:04:58 2023 +0100

    dev

commit 750875e
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Mon Oct 9 21:42:09 2023 +0100

    dev

commit f25b956
Merge: 53ce87b 972cdaa
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Mon Oct 9 21:41:23 2023 +0100

    Merge branch 'main' of github.com:NCAS-CMS/cf-python into ugrid-0

commit 53ce87b
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Mon Oct 9 21:41:02 2023 +0100

    dev

commit 80c19f1
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Fri Oct 6 17:00:27 2023 +0100

    dev

commit 28d624b
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Fri Oct 6 10:09:30 2023 +0100

    dev

commit a0a4771
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Thu Oct 5 23:50:14 2023 +0100

    dev

commit 264780a
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Wed Oct 4 14:17:41 2023 +0100

    dev

commit 3f3f98e
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Sun Oct 1 12:50:55 2023 +0100

    dev

commit 2023f5a
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Sat Sep 30 14:17:26 2023 +0100

    dev

commit 054b272
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Sat Sep 30 12:05:37 2023 +0100

    dev

commit 7ce67d2
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Fri Sep 29 18:29:23 2023 +0100

    dev

commit 5820978
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Thu Sep 28 16:09:17 2023 +0100

    regrid

commit 726223e
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Thu Sep 28 14:52:10 2023 +0100

    geometry spherical polygon weights

commit a7ce7b3
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Wed Sep 27 16:05:30 2023 +0100

    dev

commit 5b8185d
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Wed Sep 27 16:03:08 2023 +0100

    dev

commit 2ebe7b8
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Tue Sep 26 18:51:01 2023 +0100

    dev

commit 075dba9
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Tue Sep 26 16:45:37 2023 +0100

    dev

commit b89b8c2
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Tue Sep 26 09:16:29 2023 +0100

    dev

commit 1afb34a
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Mon Sep 25 19:23:23 2023 +0100

    dev

commit 6009f36
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Mon Sep 25 13:26:13 2023 +0100

    dev

commit 939aba4
Merge: 05c1ed1 2cfc8e6
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Mon Sep 25 10:02:01 2023 +0100

    Merge branch 'main' of github.com:NCAS-CMS/cf-python into ugrid-0

commit 05c1ed1
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Fri Sep 22 18:01:31 2023 +0100

    dev

commit c542050
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Thu Sep 21 10:00:51 2023 +0100

    dev

commit e94cd3d
Merge: 094a60a 88febb7
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Thu Sep 21 08:44:30 2023 +0100

    Merge branch 'main' of github.com:NCAS-CMS/cf-python into ugrid-0

commit 094a60a
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Wed Sep 20 23:06:52 2023 +0100

    dev

commit ebd47b4
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Wed Sep 20 13:44:38 2023 +0100

    dev

commit e9a2d26
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Tue Sep 19 19:34:50 2023 +0100

    dev

commit 6b30280
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Tue Sep 19 17:37:57 2023 +0100

    dev

commit 529b143
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Mon Sep 18 10:40:17 2023 +0100

    dev

commit e11422d
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Sun Sep 17 15:46:42 2023 +0100

    dev

commit 0c84d90
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Sun Sep 17 12:06:45 2023 +0100

    dev

commit dd5df6a
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Thu Sep 14 16:01:33 2023 +0100

    dev

commit 3f0ad2a
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Thu Sep 14 14:09:48 2023 +0100

    dev

commit 26ac71a
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Thu Sep 14 09:33:30 2023 +0100

    dev

commit 25142fa
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Wed Sep 13 23:13:34 2023 +0100

    dev

commit 672cb98
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Wed Sep 13 16:19:33 2023 +0100

    dev

commit c3ad04c
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Wed Sep 13 09:44:12 2023 +0100

    dev

commit 71f31f6
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Thu Sep 7 13:05:30 2023 +0100

    dev

commit 82efa8b
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Wed Sep 6 18:35:01 2023 +0100

    dev

commit 229e383
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Tue Sep 5 19:51:31 2023 +0100

    dev

commit 4250b11
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Tue Sep 5 19:37:51 2023 +0100

    upstream merge

commit 2c70d98
Merge: 87ffa9b ed9e4c8
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Tue Sep 5 19:37:30 2023 +0100

    Merge branch 'main' of github.com:NCAS-CMS/cf-python into ugrid-0

commit 87ffa9b
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Fri Aug 25 14:54:01 2023 +0100

    dev

commit e0d89c3
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Fri Aug 25 10:51:18 2023 +0100

    dev

commit bff67d9
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Thu Aug 24 22:35:51 2023 +0100

    dev

commit 5bd3c5b
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Thu Aug 24 15:13:17 2023 +0100

    dev

commit bc279f2
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Wed Aug 23 18:31:14 2023 +0100

    dev

commit 354b662
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Wed Aug 23 15:56:22 2023 +0100

    dev

commit 4aef6c7
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Wed Aug 23 10:03:56 2023 +0100

    dev

commit 0e368b8
Author: David Hassell <david.hassell@ncas.ac.uk>
Date:   Tue Aug 22 17:23:42 2023 +0100

    dev
Copy link
Member

@sadielbartholomew sadielbartholomew left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

About half-way through (by file number total) eyeballing the code changes. Here are the (minor) comments so far. Functionality review TODO.

Changelog.rst Outdated Show resolved Hide resolved
cf/test/create_test_files_2.py Outdated Show resolved Hide resolved
cf/docstring/docstring.py Outdated Show resolved Hide resolved
cf/cellconnectivity.py Outdated Show resolved Hide resolved
cf/data/array/boundsfromnodesarray.py Outdated Show resolved Hide resolved
cf/data/array/mixin/compressedarraymixin.py Outdated Show resolved Hide resolved
cf/data/collapse/dask_collapse.py Outdated Show resolved Hide resolved
cf/data/collapse/dask_collapse.py Outdated Show resolved Hide resolved
cf/data/collapse/dask_collapse.py Outdated Show resolved Hide resolved
cf/data/collapse/dask_collapse.py Outdated Show resolved Hide resolved
davidhassell and others added 4 commits November 21, 2023 11:15
Co-authored-by: Sadie L. Bartholomew <sadie.bartholomew@ncas.ac.uk>
Co-authored-by: Sadie L. Bartholomew <sadie.bartholomew@ncas.ac.uk>
Co-authored-by: Sadie L. Bartholomew <sadie.bartholomew@ncas.ac.uk>
Co-authored-by: Sadie L. Bartholomew <sadie.bartholomew@ncas.ac.uk>
@davidhassell davidhassell changed the title WIP: Implementation of UGRID (part 1 of 2) Implementation of UGRID (part 1 of 2) Nov 21, 2023
@davidhassell davidhassell linked an issue Nov 22, 2023 that may be closed by this pull request
Copy link
Member

@sadielbartholomew sadielbartholomew left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More minor comments, including those below. I am mostly done with the functional review and eyeballing the code, but still need to look over the regrid and weights modules. I'll submit my final review on Monday.


  1. Some new methods are missing from the API reference at present:
$ ./check_docs_api_coverage 
Method cf.Field.del_mesh_id not in docs/source/class/cf.Field.rst
Method cf.Field.get_mesh_id not in docs/source/class/cf.Field.rst
Method cf.Field.has_mesh_id not in docs/source/class/cf.Field.rst
Method cf.Field.set_mesh_id not in docs/source/class/cf.Field.rst
Method cf.Domain.del_mesh_id not in docs/source/class/cf.Domain.rst
Method cf.Domain.get_mesh_id not in docs/source/class/cf.Domain.rst
Method cf.Domain.has_mesh_id not in docs/source/class/cf.Domain.rst
Method cf.Domain.set_mesh_id not in docs/source/class/cf.Domain.rst
Traceback (most recent call last):
  File "docs/source/check_docs_api_coverage.py", line 77, in <module>
    raise ValueError(
ValueError: Found 8 undocumented methods and 0 missing .rst files
  1. There are some of my old commented-out references to arctan2 still floating about. We should remove them to tidy whilst we are finally adding our Dask-enabled arctan2:
$ pwd
/home/sadie/cf-python/cf
$ git grep "AT2"
data/data.py:    # `arctan2`, AT2 seealso
mixin/propertiesdata.py:    # `arctan2`, AT2 seealso
mixin/propertiesdata.py:    # `arctan2`, AT2 seealso
mixin/propertiesdatabounds.py:    # `arctan2`, AT2 seealso
mixin/propertiesdatabounds.py:    # `arctan2`, AT2 seealso

cf/test/test_weights.py Outdated Show resolved Hide resolved
cf/test/test_weights.py Outdated Show resolved Hide resolved
cf/test/test_weights.py Outdated Show resolved Hide resolved
cf/regrid/regridoperator.py Outdated Show resolved Hide resolved
cf/domaintopology.py Outdated Show resolved Hide resolved
cf/field.py Outdated Show resolved Hide resolved
cf/field.py Outdated Show resolved Hide resolved
cf/field.py Outdated Show resolved Hide resolved
cf/data/dask_regrid.py Outdated Show resolved Hide resolved
cf/data/data.py Show resolved Hide resolved
davidhassell and others added 5 commits November 27, 2023 08:26
Co-authored-by: Sadie L. Bartholomew <sadie.bartholomew@ncas.ac.uk>
Co-authored-by: Sadie L. Bartholomew <sadie.bartholomew@ncas.ac.uk>
Co-authored-by: Sadie L. Bartholomew <sadie.bartholomew@ncas.ac.uk>
@davidhassell
Copy link
Collaborator Author

davidhassell commented Nov 27, 2023

  1. Some new methods are missing from the API reference at present:

Ah yes, that's deliberate, as noted in NCAS-CMS/cfdm#272 (comment):
The new recording of a "mesh_id" (netcdfready.py, fielddomain.py, field.py) is forward looking to the time when we write these things out (see NCAS-CMS/cfdm#271). However, it's possible that when it comes to it we find that we don't need it. As a result it is deliberate that, for now, the various X_mesh_id methods remain undocumented in cfdm/docs/

2.There are some of my old commented-out references to arctan2 still floating about

71c6e93

@sadielbartholomew
Copy link
Member

sadielbartholomew commented Nov 27, 2023

Some new methods are missing from the API reference at present:

Ah yes, that's deliberate, as noted in NCAS-CMS/cfdm#272 (comment):
The new recording of a "mesh_id" (netcdfready.py, fielddomain.py, field.py) is forward looking to the time when we write these things out (see NCAS-CMS/cfdm#271). However, it's possible that when it comes to it we find that we don't need it. As a result it is deliberate that, for now, the various X_mesh_id methods remain undocumented in cfdm/docs/

Aha, apologies I do remember that from reviewing the cfdm PR but it slipped my mind here. All good, in that context.

RE (2), thanks for removing the old refs. Also all good now.

About to finish the review...

Copy link
Member

@sadielbartholomew sadielbartholomew left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving my final batch of minor comments, as usual mostly inevitable typos appearing across lots of new text.

Overall, I am happy, so please merge once you have considered the batch of comments here. I've done a sanity check at this stage after some new post-review commits and everything works as it should, but am happy to do another later before we merge if you wish.

cf/regrid/regrid.py Outdated Show resolved Hide resolved
cf/regrid/regrid.py Show resolved Hide resolved
cf/regrid/regrid.py Show resolved Hide resolved
cf/regrid/regrid.py Outdated Show resolved Hide resolved
cf/regrid/regrid.py Outdated Show resolved Hide resolved
cf/weights.py Outdated Show resolved Hide resolved
cf/weights.py Outdated Show resolved Hide resolved
cf/weights.py Outdated Show resolved Hide resolved
cf/weights.py Outdated Show resolved Hide resolved
cf/weights.py Outdated Show resolved Hide resolved
davidhassell and others added 3 commits November 28, 2023 08:32
Co-authored-by: Sadie L. Bartholomew <sadie.bartholomew@ncas.ac.uk>
Co-authored-by: Sadie L. Bartholomew <sadie.bartholomew@ncas.ac.uk>
Co-authored-by: Sadie L. Bartholomew <sadie.bartholomew@ncas.ac.uk>
davidhassell and others added 7 commits November 28, 2023 08:47
Co-authored-by: Sadie L. Bartholomew <sadie.bartholomew@ncas.ac.uk>
Co-authored-by: Sadie L. Bartholomew <sadie.bartholomew@ncas.ac.uk>
Copy link
Member

@sadielbartholomew sadielbartholomew left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All feedback addressed really well, thanks. I have just pulled down the latest state of the PR and run the test suite locally, with all passes. As far as I am concerned, this is all ready to merge so please do the honours if you agree!

@davidhassell
Copy link
Collaborator Author

Great - thanks again for your reviewing!

@davidhassell davidhassell merged commit f6406ee into NCAS-CMS:main Nov 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request netCDF read Relating to reading netCDF datasets UGRID Relating to UGRID mesh topologies
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implementation of UGRID (part 1 of 2) UGRID support?
2 participants