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

MAINT: Change name in derived type for obs and sim response #84

Merged
merged 2 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions doc/source/api_reference/principal_methods/model.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ Attributes

Model.setup
Model.mesh
Model.obs_response
Model.response_data
Model.physio_data
Model.atmos_data
Model.opr_parameters
Model.opr_initial_states
Model.sim_response
Model.response
Model.opr_final_states

Simulation
Expand All @@ -49,4 +49,4 @@ Parameters/States
Model.set_opr_parameters
Model.set_opr_initial_states
Model.get_opr_parameters_bounds
Model.get_opr_initial_states_bounds
Model.get_opr_initial_states_bounds
2 changes: 2 additions & 0 deletions f90wrap_utils/py_mod_names
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
"mwd_parameters": "_mwd_parameters",
"mwd_physio_data": "_mwd_physio_data",
"mwd_response": "_mwd_response",
"mwd_response_data": "_mwd_response_data",
"mwd_returns": "_mwd_returns",
"mwd_setup": "_mwd_setup",
"mwd_sparse_matrix": "_mwd_sparse_matrix",
"mwd_u_response_data": "_mwd_u_response_data",
"mw_forward": "_mw_forward",
"mw_optimize": "_mw_optimize",
"mwd_cost": "_mwd_cost",
Expand Down
2 changes: 2 additions & 0 deletions makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ f90: \
obj/mwd_setup.o \
obj/mwd_optimize_options.o \
obj/mwd_mesh.o \
obj/mwd_response_data.o \
obj/mwd_response.o \
obj/mwd_physio_data.o \
obj/mwd_opr_states.o \
Expand All @@ -30,6 +31,7 @@ f90: \
obj/mwd_options.o \
obj/mwd_sparse_matrix.o \
obj/mwd_atmos_data.o \
obj/mwd_u_response_data.o \
obj/mwd_input_data.o \
obj/mw_forward.o \
obj/md_gr_operator.o \
Expand Down
2 changes: 1 addition & 1 deletion smash/core/model/_read_input_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def _read_qobs(setup: SetupDT, mesh: MeshDT, input_data: Input_DataDT):
ind_start_arr = max(0, -start_diff)
ind_end_arr = ind_start_arr + ind_end_dat - ind_start_dat

input_data.obs_response.q[i, ind_start_arr:ind_end_arr] = dat.iloc[
input_data.response_data.q[i, ind_start_arr:ind_end_arr] = dat.iloc[
ind_start_dat:ind_end_dat, 0
]

Expand Down
20 changes: 10 additions & 10 deletions smash/core/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def mesh(self, value):
self._mesh = value

@property
def obs_response(self):
def response_data(self):
"""
Observation response data.

Expand All @@ -173,11 +173,11 @@ def obs_response(self):
TODO: Fill
"""

return self._input_data.obs_response
return self._input_data.response_data

@obs_response.setter
def obs_response(self, value):
self._input_data.obs_response = value
@response_data.setter
def response_data(self, value):
self._input_data.response_data = value

@property
def physio_data(self):
Expand Down Expand Up @@ -244,7 +244,7 @@ def opr_initial_states(self, value):
self._parameters.opr_initial_states = value

@property
def sim_response(self):
def response(self):
"""
Simulated response data.

Expand All @@ -253,11 +253,11 @@ def sim_response(self):
TODO: Fill
"""

return self._output.sim_response
return self._output.response

@sim_response.setter
def sim_response(self, value):
self._output.sim_response = value
@response.setter
def response(self, value):
self._output.response = value

@property
def opr_final_states(self):
Expand Down
4 changes: 2 additions & 2 deletions smash/core/signal_analysis/metrics/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ def metrics(
"""
metric, end_warmup = _standardize_metrics_args(metric, end_warmup, model.setup)

obs = model.obs_response.q[..., end_warmup:]
obs = model.response_data.q[..., end_warmup:]

sim = model.sim_response.q[..., end_warmup:]
sim = model.response.q[..., end_warmup:]

ng = obs.shape[0]

Expand Down
2 changes: 1 addition & 1 deletion smash/core/signal_analysis/prcp_indices/prcp_indices.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def precipitation_indices(

# % Initialise result
prcp_indices = np.zeros(
shape=(len(PRECIPITATION_INDICES), *model.obs_response.q.shape),
shape=(len(PRECIPITATION_INDICES), *model.response_data.q.shape),
dtype=np.float32,
order="F",
)
Expand Down
4 changes: 2 additions & 2 deletions smash/core/signal_analysis/segmentation/_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,12 @@ def _mask_event(
peak_quant: float = PEAK_QUANT,
max_duration: float = MAX_DURATION, # in hour
) -> dict:
mask = np.zeros(model.obs_response.q.shape)
mask = np.zeros(model.response_data.q.shape)
n_event = np.zeros(model.mesh.ng)

for i, catchment in enumerate(model.mesh.code):
prcp = model.atmos_data.mean_prcp[i, :].copy()
qobs = model.obs_response.q[i, :].copy()
qobs = model.response_data.q[i, :].copy()

if (prcp < 0).all() or (qobs < 0).all():
warnings.warn(
Expand Down
4 changes: 3 additions & 1 deletion smash/core/signal_analysis/segmentation/segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ def _hydrograph_segmentation(

for i, catchment in enumerate(instance.mesh.code):
prcp = instance.atmos_data.mean_prcp[i, :].copy()
q = getattr(instance, f"{by}_response").q[i, :].copy()

suffix = "_data" if by == "obs" else ""
q = getattr(instance, f"response{suffix}").q[i, :].copy()

if (prcp < 0).all() or (q < 0).all():
warnings.warn(
Expand Down
6 changes: 4 additions & 2 deletions smash/core/signal_analysis/signatures/signatures.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ def _signatures(
i, :
] # already conversion of instance.atmos_data.mean_prcp[i, :]

q = getattr(instance, f"{domain}_response").q[i, :].copy()
suffix = "_data" if domain == "obs" else ""
q = getattr(instance, f"response{suffix}").q[i, :].copy()

if (prcp < 0).all() or (q < 0).all():
warnings.warn(
Expand Down Expand Up @@ -220,7 +221,8 @@ def _signatures(
)

if len(es) > 0:
q_seg = getattr(instance, f"{by}_response").q[i, :].copy()
suffix = "_data" if by == "obs" else ""
q_seg = getattr(instance, f"response{suffix}").q[i, :].copy()

list_events = _events_grad(
prcp, q_seg, peak_quant, max_duration, instance.setup.dt
Expand Down
2 changes: 1 addition & 1 deletion smash/core/simulation/optimize/optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ def _multiple_optimize(
# % Initialise results
cost = np.zeros(shape=samples.n_sample, dtype=np.float32, order="F")
q = np.zeros(
shape=(*model.obs_response.q.shape, samples.n_sample),
shape=(*model.response_data.q.shape, samples.n_sample),
dtype=np.float32,
order="F",
)
Expand Down
2 changes: 1 addition & 1 deletion smash/core/simulation/run/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ def _multiple_forward_run(
# % Initialise results
cost = np.zeros(shape=samples.n_sample, dtype=np.float32, order="F")
q = np.zeros(
shape=(*model.obs_response.q.shape, samples.n_sample),
shape=(*model.response_data.q.shape, samples.n_sample),
dtype=np.float32,
order="F",
)
Expand Down
1 change: 1 addition & 0 deletions smash/fcore/derived_type/mwd_atmos_data.f90
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
!% ----
!%
!% - Atmos_DataDT
!% Atmospheric data used to force smash and derived quantities.
!%
!% ======================== =======================================
!% `Variables` Description
Expand Down
1 change: 1 addition & 0 deletions smash/fcore/derived_type/mwd_common_options.f90
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
!% ----
!%
!% - Common_OptionsDT
!% Common options passed by user
!%
!% ======================== =======================================
!% `Variables` Description
Expand Down
1 change: 1 addition & 0 deletions smash/fcore/derived_type/mwd_control.f90
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
!% ----
!%
!% - ControlDT
!% Control vector used in optimize and quantities required by the optimizer
!%
!% ========================== =====================================
!% `Variables` Description
Expand Down
1 change: 1 addition & 0 deletions smash/fcore/derived_type/mwd_cost_options.f90
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
!% ----
!%
!% - Cost_OptionsDT
!% Cost options passed by user to define the output cost
!%
!% ======================== =======================================
!% `Variables` Description
Expand Down
15 changes: 12 additions & 3 deletions smash/fcore/derived_type/mwd_input_data.f90
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
!% ----
!%
!% - Input_DataDT
!% Container for all user input data (not only forcing data but all inputs
!% needed to run and/or optimize the model). This data are not meant to be
!% changed at runtime once read.
!%
!% ======================== =======================================
!% `Variables` Description
!% ======================== =======================================
!% ``response_data`` Response_DataDT
!% ``u_response_data`` U_Response_DataDT
!% ``physio_data`` Physio_DataDT
!% ``atmos_data`` Atmos_DataDT
!% ======================== =======================================
Expand All @@ -24,15 +28,18 @@ module mwd_input_data
use md_constant !% only: sp
use mwd_setup !% only: SetupDT
use mwd_mesh !% only: MeshDT
use mwd_response !%: only: ResponseDT, ResponseDT_initialise
use mwd_response_data !%: only: ResponseDataDT, ResponseDataDT_initialise
use mwd_u_response_data !%: only: U_ResponseDataDT, U_ResponseDataDT_initialise
use mwd_physio_data !%: only: Physio_DataDT, Physio_DataDT_initialise
use mwd_atmos_data !%: only: Atmos_DataDT, Atmos_DataDT_initialise

implicit none

type Input_DataDT

type(ResponseDT) :: obs_response
type(Response_DataDT) :: response_data

type(U_Response_DataDT) :: u_response_data

type(Physio_DataDT) :: physio_data

Expand All @@ -50,7 +57,9 @@ subroutine Input_DataDT_initialise(this, setup, mesh)
type(SetupDT), intent(in) :: setup
type(MeshDT), intent(in) :: mesh

call ResponseDT_initialise(this%obs_response, setup, mesh)
call Response_DataDT_initialise(this%response_data, setup, mesh)

call U_Response_DataDT_initialise(this%u_response_data, setup, mesh)

call Physio_DataDT_initialise(this%physio_data, setup, mesh)

Expand Down
1 change: 1 addition & 0 deletions smash/fcore/derived_type/mwd_mesh.f90
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
!% ----
!%
!% - MeshDT
!% Meshing data
!%
!% ======================== =======================================
!% `Variables` Description
Expand Down
2 changes: 2 additions & 0 deletions smash/fcore/derived_type/mwd_opr_parameters.f90
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
!%
!%
!% - Opr_ParametersDT
!% Matrices containting spatialized parameters of hydrological operators.
!% (reservoir max capacity, lag time ...)
!%
!% ========================== =====================================
!% `Variables` Description
Expand Down
2 changes: 2 additions & 0 deletions smash/fcore/derived_type/mwd_opr_states.f90
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
!% ----
!%
!% - Opr_StatesDT
!% Matrices containting spatialized states of hydrological operators.
!% (reservoir level ...) The matrices are updated at each time step.
!%
!% ========================== =====================================
!% `Variables` Description
Expand Down
2 changes: 2 additions & 0 deletions smash/fcore/derived_type/mwd_optimize_options.f90
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
!% ----
!%
!% - Optimize_OptionsDT
!% Optimization options passed by user to define the 'parameters-to-control' mapping,
!% parameters to optimize and optimizer options (factr, pgtol, bounds)
!%
!% ================================== =======================================
!% `Variables` Description
Expand Down
1 change: 1 addition & 0 deletions smash/fcore/derived_type/mwd_options.f90
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
!% ----
!%
!% - OptionsDT
!% Container for all user options (optimize, cost, common)
!%
!% ======================== =======================================
!% `Variables` Description
Expand Down
6 changes: 3 additions & 3 deletions smash/fcore/derived_type/mwd_output.f90
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
!% `Variables` Description
!% ======================== =======================================
!% ``cost`` Value of cost function
!% ``sim_response`` ResponseDT
!% ``response`` ResponseDT
!% ``opr_final_states`` Opr_StatesDT
!% ======================== =======================================
!%
Expand All @@ -31,7 +31,7 @@ module mwd_output

type OutputDT

type(ResponseDT) :: sim_response
type(ResponseDT) :: response
type(Opr_StatesDT) :: opr_final_states
real(sp) :: cost

Expand All @@ -47,7 +47,7 @@ subroutine OutputDT_initialise(this, setup, mesh)
type(SetupDT), intent(in) :: setup
type(MeshDT), intent(in) :: mesh

call ResponseDT_initialise(this%sim_response, setup, mesh)
call ResponseDT_initialise(this%response, setup, mesh)
call Opr_StatesDT_initialise(this%opr_final_states, setup, mesh)

end subroutine OutputDT_initialise
Expand Down
1 change: 1 addition & 0 deletions smash/fcore/derived_type/mwd_parameters.f90
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
!% ----
!%
!% - ParametersDT
!% Container for all parameters. The goal is to keep the control vector and the spatial matrices in sync.
!%
!% ========================== =====================================
!% `Variables` Description
Expand Down
1 change: 1 addition & 0 deletions smash/fcore/derived_type/mwd_physio_data.f90
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
!% ----
!%
!% - Physio_DataDT
!% Physiographic data used to force the regionalization, among other things.
!%
!% ======================== =======================================
!% `Variables` Description
Expand Down
3 changes: 2 additions & 1 deletion smash/fcore/derived_type/mwd_response.f90
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
!% ----
!%
!% - ResponseDT
!% Response simulated by the hydrological model.
!%
!% ======================== =======================================
!% `Variables` Description
!% ======================== =======================================
!% ``q`` Discharge at gauges [m3/s]
!% ``q`` Simulated discharge at gauges [m3/s]
!% ======================== =======================================
!%
!% Subroutine
Expand Down
Loading