population-trend 5.7.1__py3-none-any.whl → 5.8.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,10 @@
1
1
  """A population growth model package"""
2
2
 
3
- __version__ = "5.7.1"
3
+ __version__ = "5.8.0"
4
+ from .calculate_growth_rates import * # noqa
4
5
  from .cli import * # noqa
5
6
  from .filter_data import * # noqa
6
- from .population_growth_model import * # noqa
7
7
  from .plotter_growth_rate import * # noqa
8
- from .calculate_growth_rates import * # noqa
8
+ from .plotter_population_trend_from_cpue import * # noqa
9
+ from .population_growth_model import * # noqa
9
10
  from .regional_lambdas import * # noqa
10
- from bootstrapping_tools import * # noqa
population_trend/cli.py CHANGED
@@ -3,6 +3,9 @@ from population_trend.population_growth_model import (
3
3
  Population_Trend_Model,
4
4
  Plotter_Population_Trend_Model,
5
5
  )
6
+ from population_trend.plotter_population_trend_from_cpue import (
7
+ Plotter_Population_Trend_Model_From_CPUE,
8
+ )
6
9
  from population_trend.calculate_growth_rates import (
7
10
  Bootstrap_from_time_series_parametrizer,
8
11
  Bootstrap_from_time_series,
@@ -15,6 +18,7 @@ from population_trend.regional_lambdas import (
15
18
  from population_trend.plotter_growth_rate import Plotter_Growth_Rate
16
19
 
17
20
  import pandas as pd
21
+ from typing_extensions import Annotated
18
22
  import typer
19
23
  import json
20
24
  import matplotlib.pyplot as plt
@@ -24,12 +28,14 @@ app = typer.Typer(help="Write filtered burrows data by species and island")
24
28
 
25
29
  @app.command(help="Write json with bootstrap intervals")
26
30
  def write_bootstrap_intervals_json(
27
- data_path: str = "data/processed/gumu_guadalupe_burrows.csv",
28
- blocks_length: int = 3,
29
- bootstrap_number: int = 2000,
30
- variable_of_interest: str = "Maxima_cantidad_nidos",
31
- alpha: float = 0.05,
32
- output_path: str = "reports/non-tabular/gumu_guadalupe_boostrap_intervals.json",
31
+ data_path: Annotated[str, typer.Option()] = "data/processed/gumu_guadalupe_burrows.csv",
32
+ blocks_length: Annotated[int, typer.Option()] = 3,
33
+ bootstrap_number: Annotated[int, typer.Option()] = 2000,
34
+ variable_of_interest: Annotated[str, typer.Option()] = "Maxima_cantidad_nidos",
35
+ alpha: Annotated[float, typer.Option()] = 0.05,
36
+ output_path: Annotated[
37
+ str, typer.Option()
38
+ ] = "reports/non-tabular/gumu_guadalupe_boostrap_intervals.json",
33
39
  ):
34
40
  data = pd.read_csv(data_path)
35
41
  parametrizer = Bootstrap_from_time_series_parametrizer(
@@ -45,10 +51,10 @@ def write_bootstrap_intervals_json(
45
51
 
46
52
  @app.command(help="Write csv with ouput-path")
47
53
  def write_burrows_by_species_and_island(
48
- data_path: str = "data/processed/subset_burrows_data.csv",
49
- species: str = "Guadalupe Murrelet",
50
- island: str = "Guadalupe",
51
- output_path: str = "data/processed/gumu_guadalupe_burrows.csv",
54
+ data_path: Annotated[str, typer.Option()] = "data/processed/subset_burrows_data.csv",
55
+ species: Annotated[str, typer.Option()] = "Guadalupe Murrelet",
56
+ island: Annotated[str, typer.Option()] = "Guadalupe",
57
+ output_path: Annotated[str, typer.Option()] = "data/processed/gumu_guadalupe_burrows.csv",
52
58
  ):
53
59
  data = pd.read_csv(data_path)
54
60
  filtered = filter_by_species_and_island(data, species, island)
@@ -57,35 +63,56 @@ def write_burrows_by_species_and_island(
57
63
 
58
64
  @app.command(help="Plot population trend")
59
65
  def plot_population_trend(
60
- data_path: str = "",
61
- intervals_path: str = "",
62
- island: str = "Guadalupe",
63
- variable_of_interest: str = "Maxima_cantidad_nidos",
66
+ data_path: Annotated[str, typer.Option()],
67
+ intervals_path: Annotated[str, typer.Option()],
68
+ island: Annotated[str, typer.Option()] = "Guadalupe",
69
+ variable_of_interest: Annotated[str, typer.Option()] = "Maxima_cantidad_nidos",
64
70
  output_path=None,
65
71
  ):
66
72
  fit_data = pd.read_csv(data_path)
67
- with open(intervals_path, "r") as read_file:
68
- intervals_json = json.load(read_file)
73
+ intervals_json = read_json(intervals_path)
69
74
  lambda_latex = intervals_json["lambda_latex_interval"]
70
75
 
71
76
  Modelo_Tendencia_Poblacional = Population_Trend_Model(
72
77
  fit_data, intervals_json, variable_of_interest
73
78
  )
74
79
  Graficador = Plotter_Population_Trend_Model(fit_data, Modelo_Tendencia_Poblacional)
75
- Graficador.plot_smooth(Modelo_Tendencia_Poblacional)
76
- Graficador.plot_model(Modelo_Tendencia_Poblacional)
80
+ Graficador.plot_smooth()
81
+ Graficador.plot_model()
77
82
  Graficador.plot_data()
78
83
  legend_mpl_object = Graficador.set_legend_location(island)
79
84
  Graficador.plot_growth_rate_interval(legend_mpl_object, lambda_latex)
80
85
  Graficador.savefig(island, output_path)
81
86
 
82
87
 
88
+ @app.command(help="Plot population trend from CPUE")
89
+ def plot_population_trend_from_cpue(
90
+ data_path: Annotated[str, typer.Option()],
91
+ intervals_path: Annotated[str, typer.Option()],
92
+ variable_of_interest: Annotated[str, typer.Option()],
93
+ output_path: Annotated[str, typer.Option()],
94
+ ):
95
+ fit_data = pd.read_csv(data_path)
96
+ intervals_json = read_json(intervals_path)
97
+ lambda_latex = intervals_json["lambda_latex_interval"]
98
+
99
+ Modelo_Tendencia_Poblacional = Population_Trend_Model(
100
+ fit_data, intervals_json, variable_of_interest
101
+ )
102
+ Graficador = Plotter_Population_Trend_Model_From_CPUE(fit_data, Modelo_Tendencia_Poblacional)
103
+ Graficador.plot_smooth()
104
+ Graficador.plot_model()
105
+ Graficador.plot_data()
106
+ Graficador.plot_growth_rate_interval(lambda_latex)
107
+ Graficador.savefig(output_path)
108
+
109
+
83
110
  @app.command(help="Write json with the regional trends")
84
111
  def write_regional_trends(
85
- config_path: str = "data/processed/gumu_guadalupe_burrows.json",
86
- region: str = "",
87
- regional_trend_path: str = "",
88
- alpha: float = 0.05,
112
+ config_path: Annotated[str, typer.Option()] = "data/processed/gumu_guadalupe_burrows.json",
113
+ region: Annotated[str, typer.Option()] = "",
114
+ regional_trend_path: Annotated[str, typer.Option()] = "",
115
+ alpha: Annotated[float, typer.Option()] = 0.05,
89
116
  ):
90
117
  concatenator = Island_Bootstrap_Distribution_Concatenator(config_path)
91
118
  concatenator.set_region(region)
@@ -96,7 +123,9 @@ def write_regional_trends(
96
123
 
97
124
  @app.command()
98
125
  def plot_growth_rate(
99
- intervals_california: str = "", intervals_pacific: str = "", output_path: str = ""
126
+ intervals_california: Annotated[str, typer.Option()],
127
+ intervals_pacific: Annotated[str, typer.Option()],
128
+ output_path: Annotated[str, typer.Option()],
100
129
  ):
101
130
  lambdas_intervals_california = read_json(intervals_california)
102
131
  lambdas_intervals_pacific = read_json(intervals_pacific)
@@ -0,0 +1,44 @@
1
+ from population_trend.population_growth_model import Plotter_Population_Trend_Model
2
+
3
+ import matplotlib.pyplot as plt
4
+
5
+
6
+ class Plotter_Population_Trend_Model_From_CPUE(Plotter_Population_Trend_Model):
7
+ def set_labels(self):
8
+ plt.ylabel("CPUE", size=20)
9
+ plt.xlabel("Seasons", size=20)
10
+
11
+ def plot_data(self):
12
+ plt.plot(
13
+ self.plot_seasons,
14
+ self.data[self.interest_variable],
15
+ "-Dk",
16
+ label="Maximum CPUE",
17
+ )
18
+
19
+ def set_legend_location(
20
+ self,
21
+ ):
22
+ legend_mpl_object = plt.legend(loc="best")
23
+ return legend_mpl_object
24
+
25
+ def plot_growth_rate_interval(self, lambda_interval):
26
+ legend_mpl_object = self.set_legend_location()
27
+ legend_box_positions = legend_mpl_object.get_window_extent()
28
+ self.ax.annotate(
29
+ r"$\lambda =$ {}".format(lambda_interval),
30
+ (legend_box_positions.p0[0], legend_box_positions.p1[1] - 320),
31
+ xycoords="figure pixels",
32
+ fontsize=25,
33
+ color="k",
34
+ alpha=1,
35
+ )
36
+
37
+ def savefig(self, output_path):
38
+ self.set_x_lim()
39
+ self.set_y_lim()
40
+ self.set_labels()
41
+ self.set_ticks()
42
+ self.draw()
43
+ transparent_background = True
44
+ plt.savefig(output_path, dpi=300, transparent=transparent_background)
@@ -59,53 +59,54 @@ class Plotter_Population_Trend_Model:
59
59
  self.ticks_text = normalize_seasons(self.data)
60
60
  self.ticks_positions = ticks_positions_array(self.ticks_text)
61
61
  self.plot_domain = np.linspace(self.ticks_positions.min(), self.ticks_positions.max(), 100)
62
+ self.population_model = population_model
62
63
  self.interest_variable = population_model.interest_variable
63
64
 
64
- def plot_smooth(self, Population_Trend_Model):
65
+ def plot_smooth(self):
65
66
  self.ax.fill_between(
66
67
  self.plot_domain,
67
- Population_Trend_Model.min_model,
68
- Population_Trend_Model.med_model,
68
+ self.population_model.min_model,
69
+ self.population_model.med_model,
69
70
  label="Confidence zone",
70
71
  color="powderblue",
71
72
  )
72
73
  self.ax.fill_between(
73
74
  self.plot_domain,
74
- Population_Trend_Model.med_model,
75
- Population_Trend_Model.max_model,
75
+ self.population_model.med_model,
76
+ self.population_model.max_model,
76
77
  color="powderblue",
77
78
  )
78
79
  self.ax.fill_between(
79
80
  self.plot_domain,
80
- Population_Trend_Model.min_model,
81
- Population_Trend_Model.max_model,
81
+ self.population_model.min_model,
82
+ self.population_model.max_model,
82
83
  color="powderblue",
83
84
  )
84
- number_of_samples = len(Population_Trend_Model.bootstrap_distribution)
85
+ number_of_samples = len(self.population_model.bootstrap_distribution)
85
86
  for i in range(0, number_of_samples - 1, 10):
86
87
  self.ax.fill_between(
87
88
  self.plot_domain,
88
- Population_Trend_Model.intern_model(i),
89
- Population_Trend_Model.med_model,
89
+ self.population_model.intern_model(i),
90
+ self.population_model.med_model,
90
91
  color="powderblue",
91
92
  )
92
93
  self.ax.fill_between(
93
94
  self.plot_domain,
94
- Population_Trend_Model.intern_model(i),
95
- Population_Trend_Model.intern_model(i + 1),
95
+ self.population_model.intern_model(i),
96
+ self.population_model.intern_model(i + 1),
96
97
  color="powderblue",
97
98
  )
98
99
  self.ax.fill_between(
99
100
  self.plot_domain,
100
- Population_Trend_Model.intern_model(i + 1),
101
- Population_Trend_Model.med_model,
101
+ self.population_model.intern_model(i + 1),
102
+ self.population_model.med_model,
102
103
  color="powderblue",
103
104
  )
104
105
 
105
- def plot_model(self, Population_Trend_Model):
106
+ def plot_model(self):
106
107
  plt.plot(
107
108
  self.plot_domain,
108
- Population_Trend_Model.med_model,
109
+ self.population_model.med_model,
109
110
  label="Population growth model",
110
111
  color="b",
111
112
  )
@@ -167,15 +168,10 @@ class Plotter_Population_Trend_Model:
167
168
  self.draw()
168
169
  transparent_background = True
169
170
  if output_path is None:
170
- plt.savefig(
171
- "reports/figures/cormorant_population_trend_{}".format(
172
- islet.replace(" ", "_").lower()
173
- ),
174
- dpi=300,
175
- transparent=transparent_background,
171
+ output_path = "reports/figures/cormorant_population_trend_{}".format(
172
+ islet.replace(" ", "_").lower()
176
173
  )
177
- else:
178
- plt.savefig(output_path, dpi=300, transparent=transparent_background)
174
+ plt.savefig(output_path, dpi=300, transparent=transparent_background)
179
175
 
180
176
  def set_legend_location(self, islet):
181
177
  legend_mpl_object = plt.legend(loc="best")
@@ -81,22 +81,25 @@ class Calculator_Regional_Lambdas_Intervals(Bootstrap_from_time_series):
81
81
  def get_hypotesis_statement(self):
82
82
  rounded_p_values = self._round_p_values()
83
83
  if self.p_values[1] < self.alpha:
84
- return f"La población está decreciendo, $\\lambda$ CI {self.lambda_latex_interval} con una significancia $p =$ {rounded_p_values[1]}"
84
+ return f"La población está decreciendo, $\\lambda$ CI {self.lambda_latex_interval} con una significancia $p {rounded_p_values[1]}$"
85
85
  if self.p_values[0] < self.alpha:
86
- return f"La población está creciendo, $\\lambda$ CI {self.lambda_latex_interval} con una significancia $p =$ {rounded_p_values[0]}"
87
- return f"No podemos concluir si la población está creciendo o decreciendo. El valor $p$ calculado resultó mayor que $\\alpha =$ {self.alpha} para ambas hipótesis nulas. Para $\\lambda>1: p =$ {rounded_p_values[1]}; para $\\lambda<1: p =$ {rounded_p_values[0]}"
86
+ return f"La población está creciendo, $\\lambda$ CI {self.lambda_latex_interval} con una significancia $p {rounded_p_values[0]}$"
87
+ return f"No podemos concluir si la población está creciendo o decreciendo. El valor $p$ calculado resultó mayor que $\\alpha =$ {self.alpha} para ambas hipótesis nulas. Para $\\lambda>1: p {rounded_p_values[1]}$; para $\\lambda<1: p {rounded_p_values[0]}$"
88
88
 
89
89
  def _round_p_values(self):
90
90
  rounded_p_values = np.round(self.p_values, 3)
91
- return [str(p_value)[1:5] if p_value >= 0.001 else "<.001" for p_value in rounded_p_values]
91
+ return [
92
+ "= " + str(p_value)[1:5] if p_value >= 0.001 else "< .001"
93
+ for p_value in rounded_p_values
94
+ ]
92
95
 
93
96
  def get_hypotesis_statement_en(self):
94
97
  rounded_p_values = self._round_p_values()
95
98
  if self.p_values[1] < self.alpha:
96
- return f"The population is decreasing, $\\lambda$ CI {self.lambda_latex_interval} with a significance $p =$ {rounded_p_values[1]}"
99
+ return f"The population is decreasing, $\\lambda$ CI {self.lambda_latex_interval} with a significance $p {rounded_p_values[1]}$"
97
100
  if self.p_values[0] < self.alpha:
98
- return f"The population is increasing, $\\lambda$ CI {self.lambda_latex_interval} with a significance $p =$ {rounded_p_values[0]}"
99
- return f"We can not conclude if the population is increasing or decreasing. The calculated $p$-value is higher than the $\\alpha =$ {self.alpha} for both null hypothesis tests. For $\\lambda>1: p =$ {rounded_p_values[1]}; for $\\lambda<1: p =$ {rounded_p_values[0]}"
101
+ return f"The population is increasing, $\\lambda$ CI {self.lambda_latex_interval} with a significance $p {rounded_p_values[0]}$"
102
+ return f"We can not conclude if the population is increasing or decreasing. The calculated $p$-value is higher than the $\\alpha =$ {self.alpha} for both null hypothesis tests. For $\\lambda>1: p {rounded_p_values[1]}$; for $\\lambda<1: p {rounded_p_values[0]}$"
100
103
 
101
104
  def save_intervals(self, output_path):
102
105
  json_dict = {
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: population_trend
3
- Version: 5.7.1
3
+ Version: 5.8.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
@@ -0,0 +1,13 @@
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,,
@@ -1,12 +0,0 @@
1
- population_trend/__init__.py,sha256=IyhgJZr8vd1wXVG2_f2EB3OVa98kF_r7uhE7Ny5XA34,343
2
- population_trend/calculate_growth_rates.py,sha256=R-H9CSnw1KM9aub849vnxJwEOT7e-Ko6rxi2HoI44i0,7839
3
- population_trend/cli.py,sha256=6J3xeeofSaAh5LEKZOl0sa715THekSzrMtiFd7iZSIA,3965
4
- population_trend/filter_data.py,sha256=D0Y1vztcbbo98af9q7wRhlHfH__bNFI8tnVOdJY6hu0,403
5
- population_trend/plotter_growth_rate.py,sha256=4QWuCB_cKF4yWBzuNvtv1jadrT1GNstQ7cjgWXDL8ag,1174
6
- population_trend/population_growth_model.py,sha256=ShMO9NzU_u5FzscsIzHQCyKelYlEqYZq2261hQzpu50,6148
7
- population_trend/regional_lambdas.py,sha256=3bH2NjVHv0vJozosik8sMVh5S6QpzPtHLS32WJfGdJE,5196
8
- population_trend-5.7.1.dist-info/entry_points.txt,sha256=qVw9tnlMx7q2AnksVC2H4oK4ufQrdrbBzSODLH-bcac,61
9
- population_trend-5.7.1.dist-info/LICENSE,sha256=hIahDEOTzuHCU5J2nd07LWwkLW7Hko4UFO__ffsvB-8,34523
10
- population_trend-5.7.1.dist-info/WHEEL,sha256=EZbGkh7Ie4PoZfRQ8I0ZuP9VklN_TvcZ6DSE5Uar4z4,81
11
- population_trend-5.7.1.dist-info/METADATA,sha256=sZapT8WmF1tSPPL5V2U4EZUJ9zkzn9ZDrnkbvSmHALI,1332
12
- population_trend-5.7.1.dist-info/RECORD,,