CWorthy-ocean / C-Star

C-Star is a python package for setting up and running ocean model simulations, with a particular focus on marine carbon dioxide removal (mCDR) applications.
https://c-star.readthedocs.io
10 stars 4 forks source link

Refactor `Case.from_blueprint/persist` to use new methods `Component.to/from_dict` #103

Closed dafyddstephenson closed 2 weeks ago

dafyddstephenson commented 1 month ago

Currently, Case.from_blueprint constructs a Case by first constructing every Component, by first constructing every fundamental object. This leads to a lot of ugly logic for deciding what to do, like:

https://github.com/CWorthy-ocean/C-Star/blob/bfac303efa5ff76f98f76c61f42245b6d4e00004/cstar/case.py#L437-L458

Instead, Component should have a from_dict method that is called from Case.from_blueprint, removing the need for most of this sort of code. Following #102 , Case can simply choose the Component subclass from component_type, then hand-off all future work to that Component subclass.

This also applies to Case.persist / Component.to_dict, though that example is mercifully less messy.