population-trend 5.9.0__py3-none-any.whl → 5.10.0__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.9.0"
3
+ __version__ = "5.10.0"
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,27 +67,6 @@ 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
- )
89
-
90
-
91
70
  def fit_population_model(seasons_series, data_series):
92
71
  parameters = lambda_calculator(seasons_series, data_series)
93
72
  model = power_law(
@@ -98,35 +77,19 @@ def fit_population_model(seasons_series, data_series):
98
77
  return model
99
78
 
100
79
 
101
- class Bootstrap_from_time_series:
80
+ class LambdasBootstrapper(AbstractSeriesBootstrapper):
102
81
  def __init__(self, bootstrap_parametrizer):
103
- self.parameters = bootstrap_parametrizer.parameters
104
- self.lambdas_n0_distribution, _ = self._calculate_distribution_and_interval()
105
- self.season_series = self.parameters["dataframe"]["Temporada"]
106
- self.data_series = self.parameters["dataframe"][self.parameters["column_name"]]
107
- self.lambdas = [lambdas_n0[0] for lambdas_n0 in self.lambdas_n0_distribution]
108
- self.p_values = self.get_p_values()
109
- self.intervals = self.intervals_from_p_values_and_alpha()
110
- self.interval_lambdas = [interval[0] for interval in self.intervals]
111
- self.lambda_latex_interval = self.get_lambda_interval_latex_string()
112
-
113
- def intervals_from_p_values_and_alpha(self):
114
- intervals = calculate_intervals_from_p_values_and_alpha(
115
- self.lambdas_n0_distribution, self.p_values, self.parameters["alpha"]
116
- )
117
- 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()
118
86
 
119
- def get_p_values(self):
120
- p_value_mayor, p_value_menor = calculate_p_values(self.lambdas)
121
- p_values = (p_value_mayor, p_value_menor)
122
- 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
123
90
 
124
91
  def get_distribution(self):
125
- return self.lambdas_n0_distribution
126
-
127
- def _calculate_distribution_and_interval(self):
128
- lambdas_n0_distribution, intervals = bootstrap_from_time_series(**self.parameters)
129
- return lambdas_n0_distribution, intervals
92
+ return self.parameters_distribution
130
93
 
131
94
  def get_inferior_central_and_superior_limit(self):
132
95
  inferior_limit, central, superior_limit = get_bootstrap_deltas(
@@ -134,11 +97,9 @@ class Bootstrap_from_time_series:
134
97
  )
135
98
  return inferior_limit, central, superior_limit
136
99
 
137
- def get_lambda_interval_latex_string(self):
138
- lambda_latex_string = generate_latex_interval_string(
139
- self.interval_lambdas, deltas=False, **{"decimals": 2}
140
- )
141
- return lambda_latex_string
100
+ def fit_population_model(self):
101
+ model = fit_population_model(self.season_series, self.data_series)
102
+ return model
142
103
 
143
104
  def generate_season_interval(self):
144
105
  return "({}-{})".format(
@@ -154,34 +115,19 @@ class Bootstrap_from_time_series:
154
115
  seasons_intervals = calculate_seasons_intervals(monitored_seasons)
155
116
  return ",".join(seasons_intervals)
156
117
 
157
- def fit_population_model(self):
158
- model = fit_population_model(self.season_series, self.data_series)
159
- return model
160
-
161
- def get_intermediate_lambdas(self):
162
- return [
163
- lambda_n0
164
- for lambda_n0 in self.lambdas_n0_distribution
165
- if (lambda_n0[0] > self.intervals[0][0]) and (lambda_n0[0] < self.intervals[2][0])
166
- ]
167
-
168
118
  def save_intervals(self, output_path):
169
- json_dict = {
170
- "intervals": list(self.intervals),
171
- "lambda_latex_interval": self.lambda_latex_interval,
172
- "p-values": self.p_values,
173
- "bootstrap_intermediate_distribution": self.get_intermediate_lambdas(),
174
- }
119
+ json_dict = self.get_parameters_dictionary()
120
+ json_dict["lambda_latex_interval"] = json_dict.pop("main_parameter_latex_interval")
175
121
  with open(output_path, "w") as file:
176
122
  json.dump(json_dict, file)
177
123
 
178
124
 
179
125
  def calculate_growth_rates_table(bootstrap: Bootstrap_from_time_series_parametrizer):
180
- bootstraper = Bootstrap_from_time_series(bootstrap)
126
+ bootstraper = LambdasBootstrapper(bootstrap)
181
127
  df = bootstrap.parameters["dataframe"]
182
128
  model = bootstraper.fit_population_model()
183
129
  inferior_limit, central, superior_limit = bootstraper.get_inferior_central_and_superior_limit()
184
- lambda_latex_string = bootstraper.get_lambda_interval_latex_string()
130
+ lambda_latex_string = bootstraper.lambda_latex_interval
185
131
  bootstrap_distribution = bootstraper.get_distribution()
186
132
  lambdas_distribution = [interval[0] for interval in bootstrap_distribution]
187
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
 
@@ -67,7 +68,8 @@ def plot_population_trend(
67
68
  intervals_path: Annotated[str, typer.Option()],
68
69
  island: Annotated[str, typer.Option()] = "Guadalupe",
69
70
  variable_of_interest: Annotated[str, typer.Option()] = "Maxima_cantidad_nidos",
70
- output_path=None,
71
+ tick_mode: Annotated[str, typer.Option()] = "full",
72
+ output_path: Annotated[str, typer.Option()] = "",
71
73
  ):
72
74
  fit_data = pd.read_csv(data_path)
73
75
  intervals_json = read_json(intervals_path)
@@ -76,7 +78,7 @@ def plot_population_trend(
76
78
  Modelo_Tendencia_Poblacional = Population_Trend_Model(
77
79
  fit_data, intervals_json, variable_of_interest
78
80
  )
79
- Graficador = Plotter_Population_Trend_Model(fit_data, Modelo_Tendencia_Poblacional)
81
+ Graficador = Plotter_Population_Trend_Model(fit_data, Modelo_Tendencia_Poblacional, tick_mode)
80
82
  Graficador.plot_smooth()
81
83
  Graficador.plot_model()
82
84
  Graficador.plot_data()
@@ -130,7 +132,7 @@ def plot_growth_rate(
130
132
  lambdas_intervals_california = read_json(intervals_california)
131
133
  lambdas_intervals_pacific = read_json(intervals_pacific)
132
134
 
133
- plotter = Plotter_Growth_Rate(lambdas_intervals_california, lambdas_intervals_pacific)
135
+ plotter = _Plotter_Growth_Rate(lambdas_intervals_california, lambdas_intervals_pacific)
134
136
  plotter.plot_error_bars()
135
137
  plt.savefig(output_path, transparent=True)
136
138
 
@@ -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
 
@@ -4,6 +4,9 @@ import matplotlib.pyplot as plt
4
4
 
5
5
 
6
6
  class Plotter_Population_Trend_Model_From_CPUE(Plotter_Population_Trend_Model):
7
+ def __init__(self, data, population_model, tick_mode="full"):
8
+ super().__init__(data, population_model, tick_mode)
9
+
7
10
  def set_labels(self):
8
11
  plt.ylabel("CPUE", size=20)
9
12
  plt.xlabel("Seasons", size=20)
@@ -4,12 +4,6 @@ from bootstrapping_tools import power_law, lambda_calculator
4
4
  import matplotlib.pyplot as plt
5
5
 
6
6
 
7
- def normalize_seasons(df):
8
- first_season = int(df.Temporada.min())
9
- last_season = int(df.Temporada.max())
10
- return np.linspace(first_season, last_season, last_season - first_season + 1).astype(int)
11
-
12
-
13
7
  def calculate_model_domain(data):
14
8
  last_value = data.Temporada.max() - data.Temporada.min()
15
9
  return np.linspace(0, last_value, 100)
@@ -52,12 +46,13 @@ class Population_Trend_Model:
52
46
 
53
47
 
54
48
  class Plotter_Population_Trend_Model:
55
- def __init__(self, data, population_model):
49
+ def __init__(self, data, population_model, tick_mode):
56
50
  self.fig, self.ax = geci_plot()
57
51
  self.data = data
58
- self.plot_seasons = self.data["Temporada"][:] - self.data["Temporada"].iloc[0] + 1
59
- self.ticks_text = normalize_seasons(self.data)
60
- self.ticks_positions = ticks_positions_array(self.ticks_text)
52
+ self.tick_mode = tick_mode
53
+ self.ticks_text = self.data.Temporada.values.astype(int)
54
+ self.ticks_positions = ticks_positions_array(self.data)
55
+ self.plot_seasons = self.data.index.values + 1
61
56
  self.plot_domain = np.linspace(self.ticks_positions.min(), self.ticks_positions.max(), 100)
62
57
  self.population_model = population_model
63
58
  self.interest_variable = population_model.interest_variable
@@ -148,14 +143,19 @@ class Plotter_Population_Trend_Model:
148
143
  plt.xlabel("Seasons", size=20)
149
144
 
150
145
  def set_ticks(self):
146
+ self.get_tick_step()
151
147
  plt.xticks(
152
- self.ticks_positions,
153
- self.ticks_text,
148
+ self.ticks_positions[:: self.tick_step],
149
+ self.ticks_text[:: self.tick_step],
154
150
  rotation=90,
155
151
  size=20,
156
152
  )
157
153
  plt.yticks(size=20)
158
154
 
155
+ def get_tick_step(self):
156
+ tick_modes = {"sparse": 2, "full": 1}
157
+ self.tick_step = tick_modes[self.tick_mode]
158
+
159
159
  def draw(self):
160
160
  plt.gcf().subplots_adjust(bottom=0.2)
161
161
  plt.draw()
@@ -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
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: population_trend
3
- Version: 5.9.0
3
+ Version: 5.10.0
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,8 @@ 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
+ License-File: LICENSE
12
+ Requires-Dist: bootstrapping-tools==3.*
12
13
  Requires-Dist: geci-plots
13
14
  Requires-Dist: typer[all]
14
15
 
@@ -0,0 +1,13 @@
1
+ population_trend/__init__.py,sha256=WEnt5bUqsnO-BLEmO9jIKRoHh3tuHj0wyK7FxTP2yuk,317
2
+ population_trend/calculate_growth_rates.py,sha256=qD-a6O17CEhgKo0KmGzVGRpGuKpDQnno16MD3DgjVrk,6003
3
+ population_trend/cli.py,sha256=nSj4noSN7walhWoR02qUiSUx1LNIZsgD0MkeIdb4mI8,5534
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=Ig499pjnUdhkNs4rT71fkAU4j7RpLeqTNKX-JH1Ju_o,1478
7
+ population_trend/population_growth_model.py,sha256=XftOLHs5cigocvU5GpUnwA6yWK-ospr8iSlIa0hEcyU,6003
8
+ population_trend/regional_lambdas.py,sha256=5eCRXf9RWS0c6BG5F-Exico0GNMuUNyexZ0ZJKgOmp4,5274
9
+ population_trend-5.10.0.dist-info/entry_points.txt,sha256=qVw9tnlMx7q2AnksVC2H4oK4ufQrdrbBzSODLH-bcac,61
10
+ population_trend-5.10.0.dist-info/licenses/LICENSE,sha256=hIahDEOTzuHCU5J2nd07LWwkLW7Hko4UFO__ffsvB-8,34523
11
+ population_trend-5.10.0.dist-info/WHEEL,sha256=G2gURzTEtmeR8nrdXUJfNiB3VYVxigPQ-bEQujpNiNs,82
12
+ population_trend-5.10.0.dist-info/METADATA,sha256=OZsrguT89x12gQtmWrQsE7WwZlXywVvcHO0rlZxNz_g,1353
13
+ population_trend-5.10.0.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: flit 3.9.0
2
+ Generator: flit 3.12.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -1,13 +0,0 @@
1
- population_trend/__init__.py,sha256=8PILFcMhthYOWPSs7LL974J3weCz9FMXRRVUCiea2vo,359
2
- population_trend/calculate_growth_rates.py,sha256=FzgAFt2NWc7jZW-v9qG8UCeqfMjyXzp_FT8b5mByNUw,7947
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.9.0.dist-info/entry_points.txt,sha256=qVw9tnlMx7q2AnksVC2H4oK4ufQrdrbBzSODLH-bcac,61
10
- population_trend-5.9.0.dist-info/LICENSE,sha256=hIahDEOTzuHCU5J2nd07LWwkLW7Hko4UFO__ffsvB-8,34523
11
- population_trend-5.9.0.dist-info/WHEEL,sha256=EZbGkh7Ie4PoZfRQ8I0ZuP9VklN_TvcZ6DSE5Uar4z4,81
12
- population_trend-5.9.0.dist-info/METADATA,sha256=EnUbDSSifnPzSAF_PPJn33ZCqMVUsAkE_4Pwcnv59A8,1332
13
- population_trend-5.9.0.dist-info/RECORD,,