population-trend 5.8.0__py3-none-any.whl → 5.9.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,9 @@
1
1
  """A population growth model package"""
2
2
 
3
- __version__ = "5.8.0"
3
+ __version__ = "5.9.1"
4
4
  from .calculate_growth_rates import * # noqa
5
5
  from .cli import * # noqa
6
6
  from .filter_data import * # noqa
7
- from .plotter_growth_rate import * # noqa
8
7
  from .plotter_population_trend_from_cpue import * # noqa
9
8
  from .population_growth_model import * # noqa
10
9
  from .regional_lambdas import * # noqa
@@ -1,11 +1,11 @@
1
1
  from bootstrapping_tools import (
2
2
  bootstrap_from_time_series,
3
- calculate_intervals_from_p_values_and_alpha,
4
3
  calculate_p_values,
5
- generate_latex_interval_string,
6
4
  get_bootstrap_deltas,
7
5
  lambda_calculator,
8
6
  power_law,
7
+ AbstractSeriesBootstrapper,
8
+ Bootstrap_from_time_series_parametrizer,
9
9
  )
10
10
  from matplotlib.ticker import MaxNLocator
11
11
 
@@ -67,56 +67,29 @@ def calculate_percent_diff_in_seasons(cantidad_nidos, model):
67
67
  return porcentaje_cambio
68
68
 
69
69
 
70
- class Bootstrap_from_time_series_parametrizer:
71
- def __init__(self, blocks_length=3, N=2000, column_name="Maxima_cantidad_nidos", alpha=0.05):
72
- self.parameters = dict(
73
- dataframe=None,
74
- column_name=column_name,
75
- N=N,
76
- return_distribution=True,
77
- blocks_length=blocks_length,
78
- alpha=alpha,
79
- )
80
-
81
- def set_data(self, data):
82
- self.parameters["dataframe"] = data
83
-
84
-
85
- Bootstrap = dict(
86
- default=Bootstrap_from_time_series_parametrizer(),
87
- testing=Bootstrap_from_time_series_parametrizer(blocks_length=2, N=100),
88
- )
70
+ def fit_population_model(seasons_series, data_series):
71
+ parameters = lambda_calculator(seasons_series, data_series)
72
+ model = power_law(
73
+ seasons_series - seasons_series.iloc[0],
74
+ parameters[0],
75
+ parameters[1],
76
+ )
77
+ return model
89
78
 
90
79
 
91
- class Bootstrap_from_time_series:
80
+ class LambdasBootstrapper(AbstractSeriesBootstrapper):
92
81
  def __init__(self, bootstrap_parametrizer):
93
- self.parameters = bootstrap_parametrizer.parameters
94
- self.lambdas_n0_distribution, _ = self._calculate_distribution_and_interval()
95
- self.season_series = self.parameters["dataframe"]["Temporada"]
96
- self.data_series = self.parameters["dataframe"][self.parameters["column_name"]]
97
- self.lambdas = [lambdas_n0[0] for lambdas_n0 in self.lambdas_n0_distribution]
98
- self.p_values = self.get_p_values()
99
- self.intervals = self.intervals_from_p_values_and_alpha()
100
- self.interval_lambdas = [interval[0] for interval in self.intervals]
101
- self.lambda_latex_interval = self.get_lambda_interval_latex_string()
102
-
103
- def intervals_from_p_values_and_alpha(self):
104
- intervals = calculate_intervals_from_p_values_and_alpha(
105
- self.lambdas_n0_distribution, self.p_values, self.parameters["alpha"]
106
- )
107
- return intervals
82
+ self.bootstrap_config = bootstrap_parametrizer.parameters
83
+ self.data_series = self.bootstrap_config["dataframe"][self.bootstrap_config["column_name"]]
84
+ self.season_series = self.bootstrap_config["dataframe"]["Temporada"]
85
+ self.parameters_distribution, _ = self.get_parameters_distribution()
108
86
 
109
- def get_p_values(self):
110
- p_value_mayor, p_value_menor = calculate_p_values(self.lambdas)
111
- p_values = (p_value_mayor, p_value_menor)
112
- return p_values
87
+ def get_parameters_distribution(self):
88
+ lambdas_n0_distribution, intervals = bootstrap_from_time_series(**self.bootstrap_config)
89
+ return lambdas_n0_distribution, intervals
113
90
 
114
91
  def get_distribution(self):
115
- return self.lambdas_n0_distribution
116
-
117
- def _calculate_distribution_and_interval(self):
118
- lambdas_n0_distribution, intervals = bootstrap_from_time_series(**self.parameters)
119
- return lambdas_n0_distribution, intervals
92
+ return self.parameters_distribution
120
93
 
121
94
  def get_inferior_central_and_superior_limit(self):
122
95
  inferior_limit, central, superior_limit = get_bootstrap_deltas(
@@ -124,11 +97,9 @@ class Bootstrap_from_time_series:
124
97
  )
125
98
  return inferior_limit, central, superior_limit
126
99
 
127
- def get_lambda_interval_latex_string(self):
128
- lambda_latex_string = generate_latex_interval_string(
129
- self.interval_lambdas, deltas=False, **{"decimals": 2}
130
- )
131
- return lambda_latex_string
100
+ def fit_population_model(self):
101
+ model = fit_population_model(self.season_series, self.data_series)
102
+ return model
132
103
 
133
104
  def generate_season_interval(self):
134
105
  return "({}-{})".format(
@@ -144,39 +115,19 @@ class Bootstrap_from_time_series:
144
115
  seasons_intervals = calculate_seasons_intervals(monitored_seasons)
145
116
  return ",".join(seasons_intervals)
146
117
 
147
- def fit_population_model(self):
148
- parameters = lambda_calculator(self.season_series, self.data_series)
149
- model = power_law(
150
- self.season_series - self.season_series.iloc[0],
151
- parameters[0],
152
- parameters[1],
153
- )
154
- return model
155
-
156
- def get_intermediate_lambdas(self):
157
- return [
158
- lambda_n0
159
- for lambda_n0 in self.lambdas_n0_distribution
160
- if (lambda_n0[0] > self.intervals[0][0]) and (lambda_n0[0] < self.intervals[2][0])
161
- ]
162
-
163
118
  def save_intervals(self, output_path):
164
- json_dict = {
165
- "intervals": list(self.intervals),
166
- "lambda_latex_interval": self.lambda_latex_interval,
167
- "p-values": self.p_values,
168
- "bootstrap_intermediate_distribution": self.get_intermediate_lambdas(),
169
- }
119
+ json_dict = self.get_parameters_dictionary()
120
+ json_dict["lambda_latex_interval"] = json_dict.pop("main_parameter_latex_interval")
170
121
  with open(output_path, "w") as file:
171
122
  json.dump(json_dict, file)
172
123
 
173
124
 
174
125
  def calculate_growth_rates_table(bootstrap: Bootstrap_from_time_series_parametrizer):
175
- bootstraper = Bootstrap_from_time_series(bootstrap)
126
+ bootstraper = LambdasBootstrapper(bootstrap)
176
127
  df = bootstrap.parameters["dataframe"]
177
128
  model = bootstraper.fit_population_model()
178
129
  inferior_limit, central, superior_limit = bootstraper.get_inferior_central_and_superior_limit()
179
- lambda_latex_string = bootstraper.get_lambda_interval_latex_string()
130
+ lambda_latex_string = bootstraper.lambda_latex_interval
180
131
  bootstrap_distribution = bootstraper.get_distribution()
181
132
  lambdas_distribution = [interval[0] for interval in bootstrap_distribution]
182
133
  p_value_mayor, p_value_menor = calculate_p_values(lambdas_distribution)
population_trend/cli.py CHANGED
@@ -7,15 +7,16 @@ from population_trend.plotter_population_trend_from_cpue import (
7
7
  Plotter_Population_Trend_Model_From_CPUE,
8
8
  )
9
9
  from population_trend.calculate_growth_rates import (
10
- Bootstrap_from_time_series_parametrizer,
11
- Bootstrap_from_time_series,
10
+ LambdasBootstrapper,
12
11
  )
13
12
  from population_trend.regional_lambdas import (
14
13
  Island_Bootstrap_Distribution_Concatenator,
15
14
  Calculator_Regional_Lambdas_Intervals,
16
15
  )
17
16
 
18
- from population_trend.plotter_growth_rate import Plotter_Growth_Rate
17
+ from population_trend.plotter_growth_rate import _Plotter_Growth_Rate
18
+ from bootstrapping_tools import Bootstrap_from_time_series_parametrizer
19
+
19
20
 
20
21
  import pandas as pd
21
22
  from typing_extensions import Annotated
@@ -45,7 +46,7 @@ def write_bootstrap_intervals_json(
45
46
  alpha=alpha,
46
47
  )
47
48
  parametrizer.set_data(data)
48
- bootstrap = Bootstrap_from_time_series(parametrizer)
49
+ bootstrap = LambdasBootstrapper(parametrizer)
49
50
  bootstrap.save_intervals(output_path)
50
51
 
51
52
 
@@ -130,7 +131,7 @@ def plot_growth_rate(
130
131
  lambdas_intervals_california = read_json(intervals_california)
131
132
  lambdas_intervals_pacific = read_json(intervals_pacific)
132
133
 
133
- plotter = Plotter_Growth_Rate(lambdas_intervals_california, lambdas_intervals_pacific)
134
+ plotter = _Plotter_Growth_Rate(lambdas_intervals_california, lambdas_intervals_pacific)
134
135
  plotter.plot_error_bars()
135
136
  plt.savefig(output_path, transparent=True)
136
137
 
@@ -2,7 +2,7 @@ import geci_plots as gp
2
2
  import matplotlib.pyplot as plt
3
3
 
4
4
 
5
- class Plotter_Growth_Rate:
5
+ class _Plotter_Growth_Rate:
6
6
  def __init__(self, lambdas_dict, lambdas_dict_2):
7
7
  self.interval = [lambdas_dict["intervals"], lambdas_dict_2["intervals"]]
8
8
 
@@ -1,9 +1,9 @@
1
1
  import numpy as np
2
2
  import json
3
3
 
4
- from bootstrapping_tools import calculate_intervals_from_p_values_and_alpha
4
+ from bootstrapping_tools import calculate_intervals_from_p_values_and_alpha, calculate_p_values
5
5
 
6
- from population_trend.calculate_growth_rates import Bootstrap_from_time_series
6
+ from population_trend.calculate_growth_rates import LambdasBootstrapper
7
7
 
8
8
 
9
9
  class Island_Bootstrap_Distribution_Concatenator:
@@ -54,24 +54,31 @@ class Island_Bootstrap_Distribution_Concatenator:
54
54
  return lambdas_distribution
55
55
 
56
56
 
57
- class Calculator_Regional_Lambdas_Intervals(Bootstrap_from_time_series):
57
+ class Calculator_Regional_Lambdas_Intervals(LambdasBootstrapper):
58
58
  def __init__(self, regional_lambdas, alpha):
59
59
  self.lambdas = regional_lambdas
60
- self.p_values = self.get_p_values()
61
60
  self.alpha = alpha
62
- self.intervals = self.intervals_from_p_values_and_alpha()
63
- self.interval_lambdas = [interval for interval in self.intervals]
64
- self.lambda_latex_interval = self.get_lambda_interval_latex_string()
65
61
  self.hypothesis_test_statement_latex = self.get_hypotesis_statement()
66
62
  self.hypothesis_test_statement_latex_en = self.get_hypotesis_statement_en()
67
63
 
68
- def intervals_from_p_values_and_alpha(self):
64
+ @property
65
+ def p_values(self):
66
+ p_value_mayor, p_value_menor = calculate_p_values(self.lambdas)
67
+ p_values = (p_value_mayor, p_value_menor)
68
+ return p_values
69
+
70
+ @property
71
+ def intervals(self):
69
72
  intervals = calculate_intervals_from_p_values_and_alpha(
70
73
  self.lambdas, self.p_values, self.alpha
71
74
  )
72
75
  return intervals
73
76
 
74
- def get_intermediate_lambdas(self):
77
+ @property
78
+ def interval_lambdas(self):
79
+ return [interval for interval in self.intervals]
80
+
81
+ def get_lambdas_inside_confidence_interval(self):
75
82
  return [
76
83
  lambdas
77
84
  for lambdas in self.lambdas
@@ -106,7 +113,7 @@ class Calculator_Regional_Lambdas_Intervals(Bootstrap_from_time_series):
106
113
  "intervals": list(self.intervals),
107
114
  "lambda_latex_interval": self.lambda_latex_interval,
108
115
  "p-values": self.p_values,
109
- "bootstrap_intermediate_distribution": self.get_intermediate_lambdas(),
116
+ "bootstrap_intermediate_distribution": self.get_lambdas_inside_confidence_interval(),
110
117
  "hypothesis_test_statement_latex_sp": self.hypothesis_test_statement_latex,
111
118
  "hypothesis_test_statement_latex_en": self.hypothesis_test_statement_latex_en,
112
119
  }
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: population_trend
3
- Version: 5.8.0
3
+ Version: 5.9.1
4
4
  Summary: A population growth model package
5
5
  Home-page: https://github.com/IslasGECI/population_trend
6
6
  Author: Ciencia de Datos • GECI
@@ -8,7 +8,7 @@ Author-email: ciencia.datos@islas.org.mx
8
8
  Requires-Python: >=3.9
9
9
  Description-Content-Type: text/markdown
10
10
  Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
11
- Requires-Dist: bootstrapping-tools==3.0.0
11
+ Requires-Dist: bootstrapping-tools==3.*
12
12
  Requires-Dist: geci-plots
13
13
  Requires-Dist: typer[all]
14
14
 
@@ -0,0 +1,13 @@
1
+ population_trend/__init__.py,sha256=IKO9fZhfnavlCZgtkAkXVvIOV4zIie7auj4Ec9IjSNk,316
2
+ population_trend/calculate_growth_rates.py,sha256=qD-a6O17CEhgKo0KmGzVGRpGuKpDQnno16MD3DgjVrk,6003
3
+ population_trend/cli.py,sha256=wsAYBTBpegnvom_UCQqTyDgdE6OqraZ68EjcfXO3lJg,5435
4
+ population_trend/filter_data.py,sha256=D0Y1vztcbbo98af9q7wRhlHfH__bNFI8tnVOdJY6hu0,403
5
+ population_trend/plotter_growth_rate.py,sha256=jWMETGAahYNedyGJmxEzvjJdSNSPDsrpGlXrGIgDLQQ,1175
6
+ population_trend/plotter_population_trend_from_cpue.py,sha256=US8h948Mtb9AQpDYfvt1c-35i2if9HxqcOp1q_R-rio,1351
7
+ population_trend/population_growth_model.py,sha256=LWgMyEJqHY9M5Xuv9nVFSfX5_X61tXCBS2n-kvY8pNk,6002
8
+ population_trend/regional_lambdas.py,sha256=5eCRXf9RWS0c6BG5F-Exico0GNMuUNyexZ0ZJKgOmp4,5274
9
+ population_trend-5.9.1.dist-info/entry_points.txt,sha256=qVw9tnlMx7q2AnksVC2H4oK4ufQrdrbBzSODLH-bcac,61
10
+ population_trend-5.9.1.dist-info/LICENSE,sha256=hIahDEOTzuHCU5J2nd07LWwkLW7Hko4UFO__ffsvB-8,34523
11
+ population_trend-5.9.1.dist-info/WHEEL,sha256=EZbGkh7Ie4PoZfRQ8I0ZuP9VklN_TvcZ6DSE5Uar4z4,81
12
+ population_trend-5.9.1.dist-info/METADATA,sha256=vs5I3SAYU6Kvv3PS8_otOxkwFKTCMiBJtm7WhDWA6u0,1330
13
+ population_trend-5.9.1.dist-info/RECORD,,
@@ -1,13 +0,0 @@
1
- population_trend/__init__.py,sha256=iBaG8DzqD9h_KXj7_qkuklIXGS26PnRNoHsKb9I_0uI,359
2
- population_trend/calculate_growth_rates.py,sha256=R-H9CSnw1KM9aub849vnxJwEOT7e-Ko6rxi2HoI44i0,7839
3
- population_trend/cli.py,sha256=KfIeLpr4uHHIeFMAfyjV_iKAdAVwXzVK4EglVQz8HcY,5419
4
- population_trend/filter_data.py,sha256=D0Y1vztcbbo98af9q7wRhlHfH__bNFI8tnVOdJY6hu0,403
5
- population_trend/plotter_growth_rate.py,sha256=4QWuCB_cKF4yWBzuNvtv1jadrT1GNstQ7cjgWXDL8ag,1174
6
- population_trend/plotter_population_trend_from_cpue.py,sha256=US8h948Mtb9AQpDYfvt1c-35i2if9HxqcOp1q_R-rio,1351
7
- population_trend/population_growth_model.py,sha256=LWgMyEJqHY9M5Xuv9nVFSfX5_X61tXCBS2n-kvY8pNk,6002
8
- population_trend/regional_lambdas.py,sha256=Hk1BWWqHjqf9zYarjt1Y7VNebeFmlX3xFpUFaMVdeoI,5222
9
- population_trend-5.8.0.dist-info/entry_points.txt,sha256=qVw9tnlMx7q2AnksVC2H4oK4ufQrdrbBzSODLH-bcac,61
10
- population_trend-5.8.0.dist-info/LICENSE,sha256=hIahDEOTzuHCU5J2nd07LWwkLW7Hko4UFO__ffsvB-8,34523
11
- population_trend-5.8.0.dist-info/WHEEL,sha256=EZbGkh7Ie4PoZfRQ8I0ZuP9VklN_TvcZ6DSE5Uar4z4,81
12
- population_trend-5.8.0.dist-info/METADATA,sha256=uciylDLjHZGvKjwEpBC2Ku1ztuUW0ve4nJ6-_Q_d4M4,1332
13
- population_trend-5.8.0.dist-info/RECORD,,