Commit cf8a560f authored by Domanski, Marian M.'s avatar Domanski, Marian M.

Merge branch '33-inconsistent-hatching-time-with-silvercarpeggs' into 'master'

Resolve "Inconsistent hatching time with SilverCarpEggs"

Closes #33

See merge request mdomanski/fluegg!28
parents 40f8c405 a79a34c2
......@@ -13,22 +13,21 @@ class CarpEggs(DriftingParticle):
----------
initial_position : numpy.ndarray
Must be an n by 3 array, where n is the number of eggs
simulation_clock : simulation.SimulationClock
Simulation clock
random_numbers : fluegg.random.RandomNumbers, optional
Random number source
characteristic_temperature : float, optional
The default is None
temperature : float, optional
Temperature for computing biological component of carp egg
model. The default is None. If None, the reference
temperature of 22 is used.
"""
_reference_temperature = 22 # degrees Celsius
def __init__(self, initial_position, simulation_clock, random_numbers=None,
characteristic_temperature=None):
temperature=None):
if initial_position.shape[1] == 3 and initial_position.ndim == 2:
self._position = initial_position
......@@ -45,9 +44,9 @@ class CarpEggs(DriftingParticle):
self._reference_density_array = self._init_reference_density_array(
random_numbers)
self._hatching_time = self.hatching_time(characteristic_temperature)
self._hatching_time = self.hatching_time(temperature)
self._gas_bladder_inflation_time = self.gas_bladder_inflation_time(
characteristic_temperature)
temperature)
def _calc_density_std(self, a, b, c):
"""Returns an array of the density standard deviation (kg/m**3)
......@@ -67,13 +66,13 @@ class CarpEggs(DriftingParticle):
@classmethod
def _calc_gas_bladder_inflation_time(cls, tmin2, meanctu_gas_bladder,
characteristic_temperature):
temperature):
if characteristic_temperature is None:
characteristic_temperature = cls._reference_temperature
if temperature is None:
temperature = cls._reference_temperature
# gas bladder inflation time in hours to seconds
return meanctu_gas_bladder/(characteristic_temperature - tmin2) * 3600
return meanctu_gas_bladder/(temperature - tmin2) * 3600
@classmethod
def _calc_hatching_time(cls, a, b, c, temperature=None):
......
......@@ -17,11 +17,11 @@ class SimulationClock:
def __init__(self, time_step_size, total_simulation_time):
if total_simulation_time % time_step_size == 0:
time_array = np.arange(0, total_simulation_time + time_step_size,
time_step_size, dtype=float)
n_steps = total_simulation_time // time_step_size
else:
time_array = np.arange(0, total_simulation_time, time_step_size,
dtype=float)
n_steps = total_simulation_time // time_step_size + 1
time_array = time_step_size*np.arange(0, n_steps+1, dtype=float)
self._time_array = time_array
self._current_time_index = 0
......
......@@ -10,7 +10,6 @@ import pandas as pd
from fluegg.asiancarpeggs import BigheadCarpEggs, GrassCarpEggs, SilverCarpEggs
from fluegg.drift import ConstantDriftingParticle
from fluegg.hydraulics import from_csv
from fluegg.hydraulics import RoughBottomSeriesOfHydraulicCells
from fluegg.resultsrecorder import FullResultsRecorder, QuantileResultsRecorder
from fluegg.simclock import SimulationClock
......@@ -407,15 +406,34 @@ class SimulationParameters:
# Simulation Clock
simulation_clock = SimulationClock(d['time_step'], d['duration'])
# Hydraulic cells (csv vs. hecras)
if d['hydraulic_mode'] == 'csv':
# Hydraulic channel (CSV)
hydraulic_df = pd.read_csv(d['csv_path'], index_col=0)
# Hecras Mode
elif d['hydraulic_mode'] == 'hecras':
with RASProject(d['hecras_path']) as rp:
plan_name = d['hecras_plan']
rp.set_current_plan(plan_name)
profile_name = d['hecras_profile']
temperature = d['hecras_temperature']
hydraulic_df = rp.hydraulic_model_data(
profile_name, temperature)
temperature = hydraulic_df['Temp_C'].mean()
# Drifting Particles
initial_position = np.tile(
np.array([d['x'], d['y'], d['z']]), (d['num_eggs'], 1))
if d['species'] == 'grass':
drift = GrassCarpEggs(initial_position, simulation_clock)
drift = GrassCarpEggs(
initial_position, simulation_clock, temperature=temperature)
elif d['species'] == 'silver':
drift = SilverCarpEggs(initial_position, simulation_clock)
drift = SilverCarpEggs(
initial_position, simulation_clock, temperature=temperature)
elif d['species'] == 'bighead':
drift = BigheadCarpEggs(initial_position, simulation_clock)
drift = BigheadCarpEggs(
initial_position, simulation_clock, temperature=temperature)
# Transporter
transporter_model = init_transporter(
......@@ -424,25 +442,12 @@ class SimulationParameters:
# Simulation
sim = Simulation(drift, transporter_model, simulation_clock)
# Hydraulic cells (csv vs. hecras)
if d['hydraulic_mode'] == 'csv':
# Hydraulic channel (CSV)
hydraulic_cells = from_csv(d['csv_path'])
# Hecras Mode
if d['hydraulic_mode'] == 'hecras':
with RASProject(d['hecras_path']) as rp:
plan_name = d['hecras_plan']
rp.set_current_plan(plan_name)
profile_name = d['hecras_profile']
temperature = d['hecras_temperature']
hydraulic_data_frame = rp.hydraulic_model_data(
profile_name, temperature)
hydraulic_cells = \
RoughBottomSeriesOfHydraulicCells. \
from_data_frame(hydraulic_data_frame,
start_time=d['hecras_start_time'],
simulation_clock=simulation_clock,
simulation=sim)
hydraulic_cells = \
RoughBottomSeriesOfHydraulicCells. \
from_data_frame(hydraulic_df,
start_time=d['hecras_start_time'],
simulation_clock=simulation_clock,
simulation=sim)
# Update sim & transporter with hydraulic cells
sim.set_hydraulic_model(hydraulic_cells)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment