Skip to content

Commit

Permalink
Add windows (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
jvail committed Sep 3, 2023
1 parent 3e4ed26 commit cf7c273
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 80 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

Expand Down
53 changes: 47 additions & 6 deletions notebooks/simple_simulation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"id": "f4e4ddad-ba3d-40c8-9ecc-28740c010452",
"metadata": {
"tags": []
Expand All @@ -60,7 +60,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"id": "89991d0d-2539-478d-8bb5-fe63a9a8095a",
"metadata": {
"tags": []
Expand All @@ -73,7 +73,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"id": "8f50dd49",
"metadata": {
"tags": []
Expand All @@ -86,7 +86,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"id": "b243f0f4-cf7c-4c35-8fa3-a6e894c36e8b",
"metadata": {
"tags": []
Expand All @@ -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()"
]
Expand Down
1 change: 0 additions & 1 deletion vmapplet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
if TYPE_CHECKING:
from pgljupyter import SceneWidget

# from ._cppyy import * # noqa
from .simulation import Simulation
from .options import Options

Expand Down
62 changes: 0 additions & 62 deletions vmapplet/organs/metamer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
51 changes: 42 additions & 9 deletions vmapplet/physics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit cf7c273

Please sign in to comment.