diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 73f93eb..9ff2530 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,8 +13,7 @@ jobs: strategy: matrix: - os: ['ubuntu-latest', 'macos-latest'] - # os: ['ubuntu-latest', 'macos-latest', 'windows-latest'] + os: ['ubuntu-latest', 'macos-latest', 'windows-latest'] python-version: ["3.10"] runs-on: ${{ matrix.os }} diff --git a/notebooks/simple_simulation.ipynb b/notebooks/simple_simulation.ipynb index de157dc..00c74d2 100644 --- a/notebooks/simple_simulation.ipynb +++ b/notebooks/simple_simulation.ipynb @@ -46,7 +46,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "id": "f4e4ddad-ba3d-40c8-9ecc-28740c010452", "metadata": { "tags": [] @@ -60,7 +60,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "id": "89991d0d-2539-478d-8bb5-fe63a9a8095a", "metadata": { "tags": [] @@ -73,7 +73,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "id": "8f50dd49", "metadata": { "tags": [] @@ -86,7 +86,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "id": "b243f0f4-cf7c-4c35-8fa3-a6e894c36e8b", "metadata": { "tags": [] @@ -100,12 +100,53 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "id": "64f4118d-93ff-4d43-99ed-f919d820003c", "metadata": { "tags": [] }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "['edge_type',\n", + " 'label',\n", + " '_axial_id',\n", + " 'growth_units',\n", + " 'year',\n", + " 'inflorescence',\n", + " 'number',\n", + " 'closest_apex',\n", + " 'farthest_apex',\n", + " 'sons_nb',\n", + " 'observation',\n", + " 'parent_observation',\n", + " 'parent_unit_id',\n", + " 'parent_fbr_id',\n", + " 'parent_tree_id',\n", + " 'zone',\n", + " 'cumulated_mass',\n", + " 'radius',\n", + " 'offset',\n", + " 'developped',\n", + " 'phyllotactic_angle',\n", + " 'branching_angle',\n", + " 'rigidity',\n", + " 'age',\n", + " 'length',\n", + " 'trunk',\n", + " 'fruit_age',\n", + " 'fruit_mass',\n", + " 'leaf_age',\n", + " 'leaf_mass',\n", + " 'leaf_area']" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "tree.property_names()" ] diff --git a/vmapplet/__init__.py b/vmapplet/__init__.py index 61b0174..7a403d7 100644 --- a/vmapplet/__init__.py +++ b/vmapplet/__init__.py @@ -3,7 +3,6 @@ if TYPE_CHECKING: from pgljupyter import SceneWidget -# from ._cppyy import * # noqa from .simulation import Simulation from .options import Options diff --git a/vmapplet/organs/metamer.py b/vmapplet/organs/metamer.py index 6fb7b1d..00cd6b6 100644 --- a/vmapplet/organs/metamer.py +++ b/vmapplet/organs/metamer.py @@ -10,7 +10,6 @@ second_moment_of_area_annular_section, reaction_wood_target, second_moment_of_area_circle, - second_moment_of_area_circular_section, ) from ..srandom import boolean_event from ..enums import Zone, FruitState, LeafState @@ -519,67 +518,6 @@ def leaf_mass(self): return self.leaf.mass -def reaction_wood_target(up, heading, previous_heading): - r"""Reaction wood target - - The reaction wood is proportional to the change in inclination - over a season (Almeras, 2001). Hypothesis: The reaction wood is - also proportional to the inclination from gravity. - - .. math:: - - P_r = 0.1635 - 0.1778 \theta_s - - where :math:`P_r` is the radial portion of the outermost cambial layer that - become reaction wood and :math:`\theta_s` is the change in inclination of the - internode over the season (i.e., the cahnge in :math:`\vec{H}`, the heading - vector of the HLU frame since the start of the spring. - - In order to also take into account the gravity, The firs term in the equation above - must be multiply by a coefficient that varies with the angle between the internode and - :math:`\vec{u}` a unit vector opposite to :math:`-\vec{g}` - - :param Vector3 up: - :param heading: vector3 - :param previous_heading: vector3 - :returns: reaction_wood (double) - """ - - # multiply by gravity normalised - cos_gh = Vector3(0.0, 0.0, 1.0) * heading - cos_pu = previous_heading * up - cos_ph = previous_heading * heading - - if cos_pu * cos_ph >= 0.0: - try: - inclination = acos(cos_ph / 1.0001) - except Exception: - print("Problem with acos(cos_ph) where cos_ph=%f" % cos_ph) - inclination = 0.0 - else: - try: - inclination = -acos(cos_ph) - except Exception: - tol = 1e-6 - try: - inclination = -acos(cos_ph - tol) - ValueError("try again with tol set %s %s" % (cos_ph, cos_ph - 1.0)) - except Exception: - print("cos+_pu=", cos_pu, " cos_ph=", cos_ph, "cosgh=", cos_gh) - print(cos_ph - 1.0) - raise ValueError("Problem with acos(cos_ph) where cos_ph=%f" % cos_ph) - - percentage = 0.1635 * (1.0 - cos_gh) - 0.1778 * inclination - r = constants.two_pi * percentage - - if r < 0.0: - r = 0.0 - elif r > constants.pi: - r = constants.pi - - return r - - def _clamp_if_near_zero(data, tol=0.0001): if data < tol and data > -tol: return 0 diff --git a/vmapplet/physics.py b/vmapplet/physics.py index a55658f..6c70e4a 100644 --- a/vmapplet/physics.py +++ b/vmapplet/physics.py @@ -32,30 +32,63 @@ def reaction_wood_target(up, heading, previous_heading): + r"""Reaction wood target + + The reaction wood is proportional to the change in inclination + over a season (Almeras, 2001). Hypothesis: The reaction wood is + also proportional to the inclination from gravity. + + .. math:: + + P_r = 0.1635 - 0.1778 \theta_s + + where :math:`P_r` is the radial portion of the outermost cambial layer that + become reaction wood and :math:`\theta_s` is the change in inclination of the + internode over the season (i.e., the cahnge in :math:`\vec{H}`, the heading + vector of the HLU frame since the start of the spring. + + In order to also take into account the gravity, The firs term in the equation above + must be multiply by a coefficient that varies with the angle between the internode and + :math:`\vec{u}` a unit vector opposite to :math:`-\vec{g}` + + :param Vector3 up: + :param heading: vector3 + :param previous_heading: vector3 + :returns: reaction_wood (double) + """ + + # multiply by gravity normalised cos_gh = pgl.Vector3(0.0, 0.0, 1.0) * heading cos_pu = previous_heading * up cos_ph = previous_heading * heading + inclination = 0.0 - inclination = 0 if cos_pu * cos_ph >= 0.0: try: - inclination = acos(cos_ph) + inclination = acos(cos_ph / 1.0001) except Exception: - pass - # print(str(cos_ph)) + print("Problem with acos(cos_ph) where cos_ph=%f" % cos_ph) + inclination = 0.0 else: try: inclination = -acos(cos_ph) except Exception: - pass - # print(str(cos_ph)) + tol = 1e-6 + try: + inclination = -acos(cos_ph - tol) + ValueError("try again with tol set %s %s" % (cos_ph, cos_ph - 1.0)) + except Exception: + print("cos+_pu=", cos_pu, " cos_ph=", cos_ph, "cosgh=", cos_gh) + print(cos_ph - 1.0) + raise ValueError("Problem with acos(cos_ph) where cos_ph=%f" % cos_ph) + percentage = 0.1635 * (1.0 - cos_gh) - 0.1778 * inclination - r = 3.14159 * 2.0 * percentage + r = constants.two_pi * percentage if r < 0.0: r = 0.0 - elif r > 3.14159: - r = 3.141459 + elif r > constants.pi: + r = constants.pi return r