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

Remove science components from framework #46

Merged
merged 26 commits into from
Jul 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
865d524
fix URL for issues/PRs following GH org move
Jun 18, 2021
93ebd92
dissolve components module into root
Jun 18, 2021
1e6bf06
remove science components
Jun 18, 2021
0e860de
update tests to take into account component.py move
Jun 18, 2021
8b6c262
update docs to point to externally hosted science components
Jun 18, 2021
0918668
update tutorial to use externally hosted science components
Jun 21, 2021
1772c58
add API changes related to removing science components
Jun 21, 2021
b07d344
review guide for contributors to reflect externalisation of science c…
Jun 23, 2021
59a4ee6
Merge branch 'dev' into remove-science
Jun 23, 2021
2ba1022
fix attribute error in test for util record
Jun 23, 2021
3772350
adjust keys due to drop in support for short identities in cf
Jun 23, 2021
e76ae74
fix bug due to dataset holding variables not fields anymore
Jun 23, 2021
0957631
review properties in component definition
Jun 29, 2021
b46162b
fix indentation errors/PEP8
Jun 29, 2021
f1d86ea
change API for LSM and flow direction in component definition
Jun 30, 2021
b0b90b2
fix bug following 09576319bc4fe79befc81f6b6703f31332e0157d
Jun 30, 2021
9a9da73
fix bug following f1d86eababfb9940971157a31396926c8cd0d63e
Jun 30, 2021
6c8ed86
reorganise Component display thematically
Jun 30, 2021
fc3709d
update sphinx autocomponent to reflect component attr changes
Jun 30, 2021
ae71159
update component development doc to reflect component attr changes
Jun 30, 2021
ebc02fe
add API change for f1d86eababfb9940971157a31396926c8cd0d63e
Jun 30, 2021
07874f2
update component display following 6c8ed863c15b9f9d1f1dc670c892906694…
Jun 30, 2021
90ec832
update (more) component display following 6c8ed863c15b9f9d1f1dc670c89…
Jun 30, 2021
a108499
deal with special case with empty dictionary
Jul 1, 2021
866d243
use metadata in component display to match class attribute names
Jul 1, 2021
3239d10
remove since added by mistake in 866d243e95aa214f170442092ebed2552876…
Jul 2, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions changelog.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.. default-role:: obj

v0.1.0
------

Expand All @@ -6,30 +8,38 @@ Released on 2021, ???.
.. rubric:: API changes

* add units requirement for component parameters and constants
(`#21 <https://github.com/hydro-jules/cm4twc/issues/21>`_)
(`#21 <https://github.com/cm4twc-org/cm4twc/issues/21>`_)
* move `Component` and its subclasses from subpackage `components` to package root
(`#46 <https://github.com/cm4twc-org/cm4twc/pull/46>`_)
* rename component class attributes `_flow_direction` and `_land_sea_mask` in
component definition to `_requires_flow_direction` and `_requires_land_sea_mask`,
respectively
(`#46 <https://github.com/cm4twc-org/cm4twc/pull/46>`_)
* remove science components (Artemis and RFM) from framework
(`#45 <https://github.com/cm4twc-org/cm4twc/issues/45>`_)

.. rubric:: Bug fixes

* fix dump file update bug due to missing 'divisions' dimension
(`#32 <https://github.com/hydro-jules/cm4twc/issues/32>`_)
(`#32 <https://github.com/cm4twc-org/cm4twc/issues/32>`_)

.. rubric:: Enhancements

* add support for arrays for component parameters
(`#21 <https://github.com/hydro-jules/cm4twc/issues/21>`_)
(`#21 <https://github.com/cm4twc-org/cm4twc/issues/21>`_)
* add support for multiple divisions for component states
(`#39 <https://github.com/hydro-jules/cm4twc/pull/39>`_)
(`#39 <https://github.com/cm4twc-org/cm4twc/pull/39>`_)
* add support for customisable divisions for component states
(`#31 <https://github.com/hydro-jules/cm4twc/issues/31>`_)
(`#31 <https://github.com/cm4twc-org/cm4twc/issues/31>`_)
* add time slice for I/O operations (user customisable)
(`#42 <https://github.com/hydro-jules/cm4twc/pull/42>`_)
(`#42 <https://github.com/cm4twc-org/cm4twc/pull/42>`_)
* cache remapping weights at initialisation
(`#44 <https://github.com/cm4twc-org/cm4twc/pull/44>`_)

.. rubric:: Documentation

* document 'divisions' for component states in preparation page
(`#35 <https://github.com/hydro-jules/cm4twc/issues/35>`_)
(`#35 <https://github.com/cm4twc-org/cm4twc/issues/35>`_)
* move API reference page to doc tree root
* move science repository page to doc tree root
* add support page
Expand Down
7 changes: 4 additions & 3 deletions cm4twc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
from .time import TimeDomain
from .space import LatLonGrid, RotatedLatLonGrid, BritishNationalGrid
from .data import DataSet
from .components import (surfacelayer, subsurface, openwater,
SurfaceLayerComponent, SubSurfaceComponent,
OpenWaterComponent, DataComponent, NullComponent)
from .component import (
SurfaceLayerComponent, SubSurfaceComponent, OpenWaterComponent,
DataComponent, NullComponent
)
from .settings import atol, rtol, decr, dtype_float
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from datetime import datetime, timedelta
import cftime

from ...time import TimeDomain
from ...settings import dtype_float
from ..time import TimeDomain
from ..settings import dtype_float


# dictionary of supported aggregation methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import cftime
import numpy as np

from ...settings import dtype_float
from ..settings import dtype_float


class State(object):
Expand Down
129 changes: 82 additions & 47 deletions cm4twc/components/component.py → cm4twc/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,22 @@
import cf
from cfunits import Units
from numbers import Number
from copy import deepcopy
import yaml

from ._utils.states import (State, create_states_dump, update_states_dump,
load_states_dump)
from ._utils.records import (StateRecord, OutwardRecord, OutputRecord,
RecordStream)
from ..time import TimeDomain
from .. import space
from ..space import SpaceDomain, Grid
from ..data import (
from ._utils.state import (
State, create_states_dump, update_states_dump, load_states_dump
)
from ._utils.record import (
StateRecord, OutwardRecord, OutputRecord, RecordStream
)
from .time import TimeDomain
from . import space
from .space import SpaceDomain, Grid
from .data import (
DataSet, Variable, StaticVariable, ClimatologicVariable, DynamicVariable
)
from ..settings import dtype_float, array_order
from .settings import dtype_float, array_order


class MetaComponent(abc.ABCMeta):
Expand All @@ -33,72 +37,103 @@ class MetaComponent(abc.ABCMeta):
_states_info = None
_outputs_info = None
_solver_history = None
_land_sea_mask = None
_flow_direction = None
_requires_land_sea_mask = None
_requires_flow_direction = None

@property
def category(cls):
return cls._category

@property
def inwards_info(cls):
return cls._inwards_info
return deepcopy(cls._inwards_info)

@property
def outwards_info(cls):
return cls._outwards_info
return deepcopy(cls._outwards_info)

@property
def inputs_info(cls):
return cls._inputs_info
def inwards_metadata(cls):
if cls._inwards_info:
return yaml.dump(cls._inwards_info)

@property
def parameters_info(cls):
return cls._parameters_info
def outwards_metadata(cls):
if cls._outwards_info:
return yaml.dump(cls._outwards_info)

@property
def constants_info(cls):
return cls._constants_info
def inputs_metadata(cls):
if cls._inputs_info:
return yaml.dump(cls._inputs_info)

@property
def states_info(cls):
return cls._states_info
def parameters_metadata(cls):
if cls._parameters_info:
return yaml.dump(cls._parameters_info)

@property
def outputs_info(cls):
return cls._outputs_info
def constants_metadata(cls):
if cls._constants_info:
return yaml.dump(cls._constants_info)

@property
def solver_history(cls):
return cls._solver_history
def states_metadata(cls):
if cls._states_info:
return yaml.dump(cls._states_info)

@property
def flow_direction(cls):
return cls._flow_direction
def outputs_metadata(cls):
if cls._outputs_info:
return yaml.dump(cls._outputs_info)

@property
def land_sea_mask(cls):
return cls._land_sea_mask
def solver_history(cls):
return cls._solver_history

def requires_flow_direction(cls):
return cls._requires_flow_direction

def requires_land_sea_mask(cls):
return cls._requires_land_sea_mask

def __str__(cls):
info = [
info_a = [
"\n".join(
([" {}:".format(t.replace('_', ' '))]
([" {}:".format(t.replace('_info', ' metadata'))]
+ [" {} [{}]".format(n, info['units'])
for n, info in getattr(cls, '_' + t).items()])
)
for t in ['inwards_info', 'outwards_info', 'inputs_info',
'parameters_info', 'constants_info', 'outputs_info',
'states_info']
if getattr(cls, t)
for t in ['inwards_info', 'inputs_info']
if getattr(cls, '_' + t)
]

info_b = [
"\n".join(
([" {}:".format(t.replace('_info', ' metadata'))]
+ [" {} [{}]".format(n, info['units'])
for n, info in getattr(cls, '_' + t).items()])
)
for t in ['parameters_info', 'constants_info', 'states_info',
'outwards_info', 'outputs_info']
if getattr(cls, '_' + t)
]

return "\n".join(
["{}(".format(cls.__name__)]
+ [" category: {}".format(getattr(cls, '_category'))]
+ info
+ [" solver history: {}".format(getattr(cls, '_solver_history'))]
+ [" land sea mask: {}".format(getattr(cls, '_land_sea_mask'))]
+ [" flow direction: {}".format(getattr(cls, '_flow_direction'))]
+ info_a
+ [
" requires land sea mask: {}".format(
getattr(cls, '_requires_land_sea_mask')
)
]
+ [
" requires flow direction: {}".format(
getattr(cls, '_requires_flow_direction')
)
]
+ info_b
+ [")"]
)

Expand All @@ -116,8 +151,8 @@ class Component(metaclass=MetaComponent):
_states_info = {}
_outputs_info = {}
_solver_history = 1
_land_sea_mask = False
_flow_direction = False
_requires_land_sea_mask = False
_requires_flow_direction = False

def __init__(self, saving_directory, timedomain, spacedomain,
dataset=None, parameters=None, constants=None, records=None,
Expand Down Expand Up @@ -544,7 +579,7 @@ def _check_spacedomain(self, spacedomain):
"for spacedomain".format(Grid.__name__)
)

if self._land_sea_mask:
if self._requires_land_sea_mask:
if spacedomain.land_sea_mask is None:
raise RuntimeError(
"'land_sea_mask' must be set in {} of {} "
Expand All @@ -553,7 +588,7 @@ def _check_spacedomain(self, spacedomain):
self.__class__.__name__)
)

if self._flow_direction:
if self._requires_flow_direction:
if spacedomain.flow_direction is None:
raise RuntimeError(
"'flow_direction' must be set in {} of {} "
Expand Down Expand Up @@ -840,12 +875,12 @@ def category(self):
@property
def inwards_info(self):
"""Return the incoming information expected by the `Component`."""
return self._inwards_info
return deepcopy(self._inwards_info)

@property
def outwards_info(self):
"""Return the outgoing information provided by the `Component`."""
return self._outwards_info
return deepcopy(self._outwards_info)

@classmethod
def from_config(cls, cfg):
Expand Down Expand Up @@ -899,7 +934,7 @@ def to_config(self):
# create a new file for it
filename = sep.join(
[self.saving_directory,
'_'.join([self.identifier, self.category, name])
'_'.join([self.identifier, self._category, name])
+ ".nc"]
)
cf.write(original, filename)
Expand All @@ -921,7 +956,7 @@ def to_config(self):
# create a new file for it
filename = sep.join(
[self.saving_directory,
'_'.join([self.identifier, self.category, name])
'_'.join([self.identifier, self._category, name])
+ ".nc"]
)
cf.write(original, filename)
Expand Down
4 changes: 0 additions & 4 deletions cm4twc/components/__init__.py

This file was deleted.

Empty file.
3 changes: 0 additions & 3 deletions cm4twc/components/openwater/__init__.py

This file was deleted.

Loading