Skip to content

Commit

Permalink
rename some Pastas Types
Browse files Browse the repository at this point in the history
- rename Array_Like to ArrayLike
- rename Tminmax to TimestampType
  • Loading branch information
martinvonk committed Jan 9, 2023
1 parent 7c9e1e8 commit d04bd68
Show file tree
Hide file tree
Showing 16 changed files with 356 additions and 247 deletions.
81 changes: 51 additions & 30 deletions pastas/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

# Type Hinting
from typing import Union, Optional, Tuple, List
from pastas.typing import StressModel, Solver, Tminmax, Array_Like
from pastas.typing import StressModel, Solver, TimestampType, ArrayLike
from pastas.typing import NoiseModel as NoiseModelType
from pastas.typing import TimeSeries as TimeSeriesType
from pastas.typing import Model as ModelType
Expand Down Expand Up @@ -304,7 +304,8 @@ def del_noisemodel(self) -> None:
self.noisemodel = None
self.parameters = self.get_init_parameters(initial=False)

def simulate(self, p: Optional[Array_Like] = None, tmin: Optional[Tminmax] = None, tmax: Optional[Tminmax] = None, freq: Optional[str] = None, warmup: Optional[float] = None,
def simulate(self, p: Optional[ArrayLike] = None, tmin: Optional[TimestampType] = None,
tmax: Optional[TimestampType] = None, freq: Optional[str] = None, warmup: Optional[float] = None,
return_warmup: bool = False) -> Series:
"""Method to simulate the time series model.
Expand Down Expand Up @@ -395,7 +396,9 @@ def simulate(self, p: Optional[Array_Like] = None, tmin: Optional[Tminmax] = Non
sim.name = 'Simulation'
return sim

def residuals(self, p: Optional[Array_Like] = None, tmin: Optional[Tminmax] = None, tmax: Optional[Tminmax] = None, freq: Optional[str] = None, warmup: Optional[float] = None) -> Series:
def residuals(
self, p: Optional[ArrayLike] = None, tmin: Optional[TimestampType] = None, tmax: Optional[TimestampType] = None,
freq: Optional[str] = None, warmup: Optional[float] = None) -> Series:
"""Method to calculate the residual series.
Parameters
Expand Down Expand Up @@ -464,7 +467,9 @@ def residuals(self, p: Optional[Array_Like] = None, tmin: Optional[Tminmax] = No
res.name = "Residuals"
return res

def noise(self, p: Optional[Array_Like] = None, tmin: Optional[Tminmax] = None, tmax: Optional[Tminmax] = None, freq: Optional[str] = None, warmup: Optional[float] = None) -> Series:
def noise(
self, p: Optional[ArrayLike] = None, tmin: Optional[TimestampType] = None, tmax: Optional[TimestampType] = None,
freq: Optional[str] = None, warmup: Optional[float] = None) -> Series:
"""Method to simulate the noise when a noisemodel is present.
Parameters
Expand Down Expand Up @@ -521,7 +526,9 @@ def noise(self, p: Optional[Array_Like] = None, tmin: Optional[Tminmax] = None,
noise = self.noisemodel.simulate(res, p)
return noise

def noise_weights(self, p: Optional[list] = None, tmin: Optional[Tminmax] = None, tmax: Optional[Tminmax] = None, freq: Optional[str] = None, warmup: Optional[float] = None) -> Array_Like:
def noise_weights(
self, p: Optional[list] = None, tmin: Optional[TimestampType] = None, tmax: Optional[TimestampType] = None,
freq: Optional[str] = None, warmup: Optional[float] = None) -> ArrayLike:
"""Internal method to calculate the noise weights."""
# Get parameters if none are provided
if p is None:
Expand All @@ -535,8 +542,9 @@ def noise_weights(self, p: Optional[list] = None, tmin: Optional[Tminmax] = None

return weights

def observations(self, tmin: Optional[Tminmax] = None, tmax: Optional[Tminmax] = None, freq: Optional[str] = None,
update_observations: bool = False) -> Series:
def observations(
self, tmin: Optional[TimestampType] = None, tmax: Optional[TimestampType] = None, freq: Optional[str] = None,
update_observations: bool = False) -> Series:
"""Method that returns the observations series used for calibration.
Parameters
Expand Down Expand Up @@ -597,8 +605,10 @@ def observations(self, tmin: Optional[Tminmax] = None, tmax: Optional[Tminmax] =
oseries_calib = self.oseries_calib
return oseries_calib

def initialize(self, tmin: Optional[Tminmax] = None, tmax: Optional[Tminmax] = None, freq: Optional[str] = None, warmup: Optional[float] = None,
noise: Optional[bool] = None, weights: Optional[Series] = None, initial: bool = True, fit_constant: bool = True) -> None:
def initialize(
self, tmin: Optional[TimestampType] = None, tmax: Optional[TimestampType] = None, freq: Optional[str] = None,
warmup: Optional[float] = None, noise: Optional[bool] = None, weights: Optional[Series] = None, initial:
bool = True, fit_constant: bool = True) -> None:
"""Method to initialize the model.
This method is called by the solve-method, but can also be
Expand Down Expand Up @@ -652,9 +662,10 @@ def initialize(self, tmin: Optional[Tminmax] = None, tmax: Optional[Tminmax] = N
self.parameters.loc["constant_d", "initial"] = 0.0
self.normalize_residuals = True

def solve(self, tmin: Optional[Tminmax] = None, tmax: Optional[Tminmax] = None, freq: Optional[str] = None, warmup: Optional[float] = None, noise: bool = True,
solver: Optional[Solver] = None, report: bool = True, initial: bool = True, weights: Optional[Series] = None,
fit_constant: bool = True, **kwargs) -> None:
def solve(
self, tmin: Optional[TimestampType] = None, tmax: Optional[TimestampType] = None, freq: Optional[str] = None,
warmup: Optional[float] = None, noise: bool = True, solver: Optional[Solver] = None, report: bool = True,
initial: bool = True, weights: Optional[Series] = None, fit_constant: bool = True, **kwargs) -> None:
"""Method to solve the time series model.
Parameters
Expand Down Expand Up @@ -755,8 +766,9 @@ def solve(self, tmin: Optional[Tminmax] = None, tmax: Optional[Tminmax] = None,
output = None
print(self.fit_report(output=output))

def set_parameter(self, name: str, initial: Optional[float] = None, vary: Optional[bool] = None, pmin: Optional[float] = None,
pmax: Optional[float] = None, optimal: Optional[float] = None, move_bounds: bool = False) -> None:
def set_parameter(
self, name: str, initial: Optional[float] = None, vary: Optional[bool] = None, pmin: Optional[float] = None,
pmax: Optional[float] = None, optimal: Optional[float] = None, move_bounds: bool = False) -> None:
"""Method to change the parameter properties.
Parameters
Expand Down Expand Up @@ -911,7 +923,8 @@ def _get_sim_index(self, tmin: Timestamp, tmax: Timestamp, freq: str, warmup: Ti
sim_index = self.sim_index
return sim_index

def get_tmin(self, tmin: Optional[Tminmax] = None, use_oseries: bool = True, use_stresses: bool = False) -> Timestamp:
def get_tmin(
self, tmin: Optional[TimestampType] = None, use_oseries: bool = True, use_stresses: bool = False) -> Timestamp:
"""Method that checks and returns valid values for tmin.
Parameters
Expand Down Expand Up @@ -969,7 +982,8 @@ def get_tmin(self, tmin: Optional[Tminmax] = None, use_oseries: bool = True, use

return tmin

def get_tmax(self, tmax: Optional[Tminmax] = None, use_oseries: bool = True, use_stresses: bool = False) -> Timestamp:
def get_tmax(
self, tmax: Optional[TimestampType] = None, use_oseries: bool = True, use_stresses: bool = False) -> Timestamp:
"""Method that checks and returns valid values for tmax.
Parameters
Expand Down Expand Up @@ -1070,7 +1084,7 @@ def get_init_parameters(self, noise: Optional[bool] = None, initial: bool = True

return parameters

def get_parameters(self, name: Optional[str] = None) -> Array_Like:
def get_parameters(self, name: Optional[str] = None) -> ArrayLike:
"""Method to obtain the parameters needed for calculation.
This method is used by the simulation, residuals and the noise
Expand Down Expand Up @@ -1127,9 +1141,10 @@ def get_stressmodel_settings(self, name: str) -> Union[dict, None]:
return settings

@get_stressmodel
def get_contribution(self, name: str, tmin: Optional[Tminmax] = None, tmax: Optional[Tminmax] = None, freq: Optional[str] = None,
warmup: Optional[float] = None, istress: Optional[int] = None, return_warmup: bool = False,
p: Optional[Array_Like] = None) -> Series:
def get_contribution(
self, name: str, tmin: Optional[TimestampType] = None, tmax: Optional[TimestampType] = None,
freq: Optional[str] = None, warmup: Optional[float] = None, istress: Optional[int] = None,
return_warmup: bool = False, p: Optional[ArrayLike] = None) -> Series:
"""Method to get the contribution of a stressmodel.
Parameters
Expand Down Expand Up @@ -1231,7 +1246,8 @@ def get_contributions(self, split: bool = True, **kwargs) -> List[Series]:
contribs.append(contrib)
return contribs

def get_transform_contribution(self, tmin: Optional[Tminmax] = None, tmax: Optional[Tminmax] = None) -> Series:
def get_transform_contribution(
self, tmin: Optional[TimestampType] = None, tmax: Optional[TimestampType] = None) -> Series:
"""Method to get the contribution of a transform.
Parameters
Expand All @@ -1255,8 +1271,9 @@ def get_transform_contribution(self, tmin: Optional[Tminmax] = None, tmax: Optio
sim_org = ml.simulate(tmin=tmin, tmax=tmax)
return sim - sim_org

def get_output_series(self, tmin: Optional[Tminmax] = None, tmax: Optional[Tminmax] = None, add_contributions: bool = True,
split: bool = True) -> DataFrame:
def get_output_series(
self, tmin: Optional[TimestampType] = None, tmax: Optional[TimestampType] = None, add_contributions: bool = True,
split: bool = True) -> DataFrame:
"""Method to get all the modeled output time series from the Model.
Parameters
Expand Down Expand Up @@ -1307,8 +1324,9 @@ def get_output_series(self, tmin: Optional[Tminmax] = None, tmax: Optional[Tminm
df = concat(df, axis=1)
return df

def _get_response(self, block_or_step: str, name: str, p: Optional[Array_Like] = None, dt: Optional[float] = None, add_0: bool = False,
**kwargs) -> Series:
def _get_response(
self, block_or_step: str, name: str, p: Optional[ArrayLike] = None, dt: Optional[float] = None, add_0:
bool = False, **kwargs) -> Series:
"""Internal method to compute the block and step response.
Parameters
Expand Down Expand Up @@ -1363,7 +1381,8 @@ def _get_response(self, block_or_step: str, name: str, p: Optional[Array_Like] =
return response

@get_stressmodel
def get_block_response(self, name: str, p: Optional[Array_Like] = None, add_0: bool = False, dt: Optional[float] = None, **kwargs) -> Series:
def get_block_response(self, name: str, p: Optional[ArrayLike] = None, add_0: bool = False, dt: Optional[float] = None, **
kwargs) -> Series:
"""Method to obtain the block response for a stressmodel.
The optimal parameters are used when available, initial otherwise.
Expand Down Expand Up @@ -1392,7 +1411,8 @@ def get_block_response(self, name: str, p: Optional[Array_Like] = None, add_0: b
p=p, add_0=add_0, **kwargs)

@get_stressmodel
def get_step_response(self, name, p: Optional[Array_Like] = None, add_0: bool = False, dt: Optional[float] = None, **kwargs) -> Series:
def get_step_response(
self, name, p: Optional[ArrayLike] = None, add_0: bool = False, dt: Optional[float] = None, **kwargs) -> Series:
"""Method to obtain the step response for a stressmodel.
The optimal parameters are used when available, initial otherwise.
Expand Down Expand Up @@ -1420,7 +1440,7 @@ def get_step_response(self, name, p: Optional[Array_Like] = None, add_0: bool =
p=p, add_0=add_0, **kwargs)

@get_stressmodel
def get_response_tmax(self, name: str, p: Array_Like = None, cutoff: float = 0.999) -> float:
def get_response_tmax(self, name: str, p: ArrayLike = None, cutoff: float = 0.999) -> float:
"""Method to get the tmax used for the response function.
Parameters
Expand Down Expand Up @@ -1457,8 +1477,9 @@ def get_response_tmax(self, name: str, p: Array_Like = None, cutoff: float = 0.9
return tmax

@get_stressmodel
def get_stress(self, name: str, tmin: Optional[Tminmax] = None, tmax: Optional[Tminmax] = None, freq: Optional[str] = None, warmup: Optional[float] = None,
istress: Optional[int] = None, return_warmup: bool = False, p: Optional[Array_Like] = None) -> Union[Series, List[Series]]:
def get_stress(self, name: str, tmin: Optional[TimestampType] = None, tmax: Optional[TimestampType] = None,
freq: Optional[str] = None, warmup: Optional[float] = None, istress: Optional[int] = None,
return_warmup: bool = False, p: Optional[ArrayLike] = None) -> Union[Series, List[Series]]:
"""Method to obtain the stress(es) from the stressmodel.
Parameters
Expand Down

0 comments on commit d04bd68

Please sign in to comment.