Skip to content

Commit

Permalink
black
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin CO committed Apr 18, 2024
1 parent d5aee78 commit e3b9ada
Show file tree
Hide file tree
Showing 23 changed files with 221 additions and 374 deletions.
34 changes: 6 additions & 28 deletions cocofest/examples/dynamics/reaching_task/make_gaph.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,7 @@

else:
plt.setp(
axs[i][j],
xticks=[0, 0.5, 1, 1.5],
xticklabels=[],
yticks=[0, 75, 150, 225],
yticklabels=[],
axs[i][j], xticks=[0, 0.5, 1, 1.5], xticklabels=[], yticks=[0, 75, 150, 225], yticklabels=[],
)

if i == 0 and j == 0:
Expand Down Expand Up @@ -134,24 +130,14 @@

else:
plt.setp(
axs[2][i],
xticks=[0, 0.5, 1, 1.5],
xticklabels=[0, 0.5, 1, 1.5],
yticks=[-1, 0, 1, 2],
yticklabels=[],
axs[2][i], xticks=[0, 0.5, 1, 1.5], xticklabels=[0, 0.5, 1, 1.5], yticks=[-1, 0, 1, 2], yticklabels=[],
)

axs[2][i].plot(
data_minimize_force["time"],
data_minimize_force["states"]["q"][i],
ms=4,
linewidth=5.0,
data_minimize_force["time"], data_minimize_force["states"]["q"][i], ms=4, linewidth=5.0,
)
axs[2][i].plot(
data_minimize_fatigue["time"],
data_minimize_fatigue["states"]["q"][i],
ms=4,
linewidth=5.0,
data_minimize_fatigue["time"], data_minimize_fatigue["states"]["q"][i], ms=4, linewidth=5.0,
)

# fatigue across time
Expand Down Expand Up @@ -204,19 +190,11 @@
)

axs[2][2].text(
0,
1.15,
f"{'%'}",
transform=axs[2][2].transAxes,
ha="left",
va="top",
fontsize=10,
0, 1.15, f"{'%'}", transform=axs[2][2].transAxes, ha="left", va="top", fontsize=10,
)

plt.setp(
axs[2][2],
xticks=[0, 0.5, 1, 1.5],
xticklabels=[0, 0.5, 1, 1.5],
axs[2][2], xticks=[0, 0.5, 1, 1.5], xticklabels=[0, 0.5, 1, 1.5],
)

# Figure labels
Expand Down
10 changes: 2 additions & 8 deletions cocofest/examples/getting_started/muscle_model_identification.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,7 @@
pulse_intensity_values = [20, 20, 30, 40, 50, 60, 70, 80, 90, 100]
fes_parameters = {"model": DingModelIntensityFrequency(), "n_stim": 10, "pulse_intensity": pulse_intensity_values}
ivp_parameters = {"n_shooting": 10, "final_time": 1, "use_sx": True}
ivp = IvpFes(
fes_parameters,
ivp_parameters,
)
ivp = IvpFes(fes_parameters, ivp_parameters,)

# Integrating the solution
result, time = ivp.integrate()
Expand Down Expand Up @@ -409,10 +406,7 @@

fes_parameters = {"model": identified_model, "n_stim": 10, "pulse_intensity": pulse_intensity_values}
ivp_parameters = {"n_shooting": 10, "final_time": 1, "use_sx": True}
ivp_from_identification = IvpFes(
fes_parameters,
ivp_parameters,
)
ivp_from_identification = IvpFes(fes_parameters, ivp_parameters,)

# Integrating the solution
identified_result, identified_time = ivp_from_identification.integrate()
Expand Down
15 changes: 3 additions & 12 deletions cocofest/examples/getting_started/pulse_mode_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@
fes_parameters = {"model": DingModelFrequencyWithFatigue(), "n_stim": n_stim, "pulse_mode": "Single"}
ivp_parameters = {"n_shooting": ns, "final_time": final_time, "use_sx": True}

ivp = IvpFes(
fes_parameters,
ivp_parameters,
)
ivp = IvpFes(fes_parameters, ivp_parameters,)

result_single, time_single = ivp.integrate()
force_single = result_single["F"][0]
Expand All @@ -37,10 +34,7 @@
final_time = 1
fes_parameters = {"model": DingModelFrequencyWithFatigue(), "n_stim": n_stim, "pulse_mode": "Doublet"}
ivp_parameters = {"n_shooting": ns, "final_time": final_time, "use_sx": True}
ivp = IvpFes(
fes_parameters,
ivp_parameters,
)
ivp = IvpFes(fes_parameters, ivp_parameters,)

result_doublet, time_doublet = ivp.integrate()
force_doublet = result_doublet["F"][0]
Expand All @@ -53,10 +47,7 @@
n_stim = 30
fes_parameters = {"model": DingModelFrequencyWithFatigue(), "n_stim": n_stim, "pulse_mode": "Triplet"}
ivp_parameters = {"n_shooting": 10, "final_time": 1, "use_sx": True}
ivp = IvpFes(
fes_parameters,
ivp_parameters,
)
ivp = IvpFes(fes_parameters, ivp_parameters,)

result_triplet, time_triplet = ivp.integrate()
force_triplet = result_triplet["F"][0]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@

# --- Creating the simulated data to identify on --- #
# Building the Initial Value Problem
ivp = IvpFes(
fes_parameters,
ivp_parameters,
)
ivp = IvpFes(fes_parameters, ivp_parameters,)

# Integrating the solution
result, time = ivp.integrate()
Expand Down Expand Up @@ -94,10 +91,7 @@
"extend_last_phase": extra_phase_time,
"use_sx": True,
}
ivp_from_identification = IvpFes(
fes_parameters,
ivp_parameters,
)
ivp_from_identification = IvpFes(fes_parameters, ivp_parameters,)

# Integrating the solution
identified_result, identified_time = ivp_from_identification.integrate()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@

# --- Creating the simulated data to identify on --- #
# Building the Initial Value Problem
ivp = IvpFes(
fes_parameters,
ivp_parameters,
)
ivp = IvpFes(fes_parameters, ivp_parameters,)

# Integrating the solution
result, time = ivp.integrate()
Expand Down Expand Up @@ -97,10 +94,7 @@
"extend_last_phase": extra_phase_time,
"use_sx": True,
}
ivp_from_identification = IvpFes(
fes_parameters,
ivp_parameters,
)
ivp_from_identification = IvpFes(fes_parameters, ivp_parameters,)

# Integrating the solution
identified_result, identified_time = ivp_from_identification.integrate()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@

# --- Creating the simulated data to identify on --- #
# Building the Initial Value Problem
ivp = IvpFes(
fes_parameters,
ivp_parameters,
)
ivp = IvpFes(fes_parameters, ivp_parameters,)

# Integrating the solution
result, time = ivp.integrate()
Expand Down Expand Up @@ -99,10 +96,7 @@
"extend_last_phase": extra_phase_time,
}

ivp_from_identification = IvpFes(
fes_parameters,
ivp_parameters,
)
ivp_from_identification = IvpFes(fes_parameters, ivp_parameters,)

# Integrating the solution
identified_result, identified_time = ivp_from_identification.integrate()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@
"pulse_mode": mode,
}
ivp_parameters = {"n_shooting": temp_node_shooting, "final_time": 1, "use_sx": True}
ivp = IvpFes(
fes_parameters=fes_parameters,
ivp_parameters=ivp_parameters,
)
ivp = IvpFes(fes_parameters=fes_parameters, ivp_parameters=ivp_parameters,)
ocp_end_time = time.time()

for k in range(repetition):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,7 @@
color="black",
)

cbar1 = fig.colorbar(
im1,
ax=axs,
extend="min",
ticks=[1e-12, 1e-10, 1e-8, 1e-6, 1e-4, 1e-2, 1, max_error],
cmap=cmap,
)
cbar1 = fig.colorbar(im1, ax=axs, extend="min", ticks=[1e-12, 1e-10, 1e-8, 1e-6, 1e-4, 1e-2, 1, max_error], cmap=cmap,)
cbar1.set_label(label="Force absolute error (N)", size=25, fontname="Times New Roman")

cbar1.ax.set_yticklabels(
Expand Down
1 change: 0 additions & 1 deletion cocofest/identification/identification_abstract_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@


class ParameterIdentification(ABC):

@abstractmethod
def _set_default_values(self, model):
"""
Expand Down
25 changes: 6 additions & 19 deletions cocofest/integration/ivp_fes.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ class IvpFes:
"""

def __init__(
self,
fes_parameters: dict = None,
ivp_parameters: dict = None,
self, fes_parameters: dict = None, ivp_parameters: dict = None,
):
"""
Enables the creation of an ivp problem
Expand Down Expand Up @@ -92,8 +90,7 @@ def __init__(
)

parameters_init.add(
key="pulse_apparition_time",
initial_guess=np.array(self.pulse_apparition_time),
key="pulse_apparition_time", initial_guess=np.array(self.pulse_apparition_time),
)

parameters.add(
Expand Down Expand Up @@ -431,9 +428,7 @@ def build_initial_guess_from_ocp(self, ocp):

@classmethod
def from_frequency_and_final_time(
cls,
fes_parameters: dict = None,
ivp_parameters: dict = None,
cls, fes_parameters: dict = None, ivp_parameters: dict = None,
):
"""
Enables the creation of an ivp problem from final time and frequency information instead of the stimulation
Expand Down Expand Up @@ -469,16 +464,11 @@ def from_frequency_and_final_time(
"The number of stimulation needs to be integer within the final time t, set round down "
"to True or set final_time * frequency to make the result an integer."
)
return cls(
fes_parameters,
ivp_parameters,
)
return cls(fes_parameters, ivp_parameters,)

@classmethod
def from_frequency_and_n_stim(
cls,
fes_parameters: dict = None,
ivp_parameters: dict = None,
cls, fes_parameters: dict = None, ivp_parameters: dict = None,
):
"""
Enables the creation of an ivp problem from stimulation number and frequency information instead of the final
Expand All @@ -502,7 +492,4 @@ def from_frequency_and_n_stim(
raise ValueError("Frequency must be an int")

Check warning on line 492 in cocofest/integration/ivp_fes.py

View check run for this annotation

Codecov / codecov/patch

cocofest/integration/ivp_fes.py#L492

Added line #L492 was not covered by tests

ivp_parameters["final_time"] = n_stim / frequency
return cls(
fes_parameters,
ivp_parameters,
)
return cls(fes_parameters, ivp_parameters,)
5 changes: 1 addition & 4 deletions cocofest/models/ding2003.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ class DingModelFrequency(FesModel):
"""

def __init__(
self,
model_name: str = "ding2003",
muscle_name: str = None,
sum_stim_truncation: int = None,
self, model_name: str = "ding2003", muscle_name: str = None, sum_stim_truncation: int = None,
):
super().__init__()
self._model_name = model_name
Expand Down
5 changes: 1 addition & 4 deletions cocofest/models/ding2003_with_fatigue.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ class DingModelFrequencyWithFatigue(DingModelFrequency):
"""

def __init__(
self,
model_name: str = "ding2003_with_fatigue",
muscle_name: str = None,
sum_stim_truncation: int = None,
self, model_name: str = "ding2003_with_fatigue", muscle_name: str = None, sum_stim_truncation: int = None,
):
super().__init__(model_name=model_name, muscle_name=muscle_name, sum_stim_truncation=sum_stim_truncation)
self._with_fatigue = True
Expand Down
1 change: 0 additions & 1 deletion cocofest/models/fes_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class FesModel(ABC):

@abstractmethod
def set_a_rest(self, model, a_rest: MX | float):
"""
Expand Down
Loading

0 comments on commit e3b9ada

Please sign in to comment.