Open keewis opened 9 months ago
Agreed for making dependencies optional.
Regarding third-party index implementations this might be a bit premature a this stage, though. There aren't tons of DGGS (systems, implementations and/or backend libraries) in the wild and it would add some friction if we cannot easily move forward and break the API of the base DGGS index.
Very true, my idea was to redesign with third-party implementations in mind, even if we don't publicly expose the interface (I wouldn't put too much energy into getting that to work, though, just make sure we don't need another refactor). That would make exposing it very easy, but without freezing the API at first.
regarding the DGGS implementations: I believe you're right, though that leaves us with the question of where these should live. @allixender has voiced interest in index implementations backed by dggrid
, would you put these directly in xdggs
or in a separate package?
since there has been an increased interest in third-party index implementations, here's how you'd do it:
xdggs.DGGSInfo
subclass per grid systemxdggs.DGGSIndex
subclass per grid systemregister_dggs("<grid-name>")
For example:
from dataclasses import dataclass
from xdggs import DGGSInfo, DGGSIndex
from xdggs.utils import register_dggs
@dataclass(frozen=True)
class S2Info(DGGSInfo):
level: int
# any additional parameters here
# need to implement `from_dict`, `to_dict`, `cell_ids2geographic`, `geographic2cell_ids`, and `cell_boundaries`
# can make use of `translate_parameters` if multiple conventions exist
...
@register_dggs("s2")
class S2Index(DGGSIndex):
# implement at least `from_variables`, `_replace` and `_repr_inline_`
...
I don't think we need to include this in #75, but at some point we need to add a guide on this to the documentation.
cc @acocac
We currently import all index implementations to create a mapping of registered grid types. However, this currently forces us to require all DGGS support libraries to be installed (
healpy
andh3ronpy
, currently). This is problematic because it means we pull in potentially unused libraries, and in the case ofhealpy
this also means that we cannot test and support windows (sincehealpy
doesn't).In order to avoid the above and to allow third-party index implementations we should think about creating a plugin system.