population-trend 5.7.1__tar.gz → 5.8.0__tar.gz
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.
- {population_trend-5.7.1 → population_trend-5.8.0}/PKG-INFO +1 -1
- {population_trend-5.7.1 → population_trend-5.8.0}/population_trend/__init__.py +4 -4
- {population_trend-5.7.1 → population_trend-5.8.0}/population_trend/cli.py +52 -23
- population_trend-5.8.0/population_trend/plotter_population_trend_from_cpue.py +44 -0
- {population_trend-5.7.1 → population_trend-5.8.0}/population_trend/population_growth_model.py +20 -24
- {population_trend-5.7.1 → population_trend-5.8.0}/population_trend/regional_lambdas.py +10 -7
- {population_trend-5.7.1 → population_trend-5.8.0}/README.md +0 -0
- {population_trend-5.7.1 → population_trend-5.8.0}/population_trend/calculate_growth_rates.py +0 -0
- {population_trend-5.7.1 → population_trend-5.8.0}/population_trend/filter_data.py +0 -0
- {population_trend-5.7.1 → population_trend-5.8.0}/population_trend/plotter_growth_rate.py +0 -0
- {population_trend-5.7.1 → population_trend-5.8.0}/pyproject.toml +0 -0
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"""A population growth model package"""
|
|
2
2
|
|
|
3
|
-
__version__ = "5.
|
|
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 .
|
|
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
|
|
@@ -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:
|
|
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
|
-
|
|
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(
|
|
76
|
-
Graficador.plot_model(
|
|
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
|
|
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)
|
{population_trend-5.7.1 → population_trend-5.8.0}/population_trend/population_growth_model.py
RENAMED
|
@@ -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
|
|
65
|
+
def plot_smooth(self):
|
|
65
66
|
self.ax.fill_between(
|
|
66
67
|
self.plot_domain,
|
|
67
|
-
|
|
68
|
-
|
|
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
|
-
|
|
75
|
-
|
|
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
|
-
|
|
81
|
-
|
|
81
|
+
self.population_model.min_model,
|
|
82
|
+
self.population_model.max_model,
|
|
82
83
|
color="powderblue",
|
|
83
84
|
)
|
|
84
|
-
number_of_samples = len(
|
|
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
|
-
|
|
89
|
-
|
|
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
|
-
|
|
95
|
-
|
|
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
|
-
|
|
101
|
-
|
|
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
|
|
106
|
+
def plot_model(self):
|
|
106
107
|
plt.plot(
|
|
107
108
|
self.plot_domain,
|
|
108
|
-
|
|
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
|
-
|
|
171
|
-
"
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
|
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 [
|
|
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
|
|
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
|
|
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
|
|
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 = {
|
|
File without changes
|
{population_trend-5.7.1 → population_trend-5.8.0}/population_trend/calculate_growth_rates.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|