cat-data-tools 1.0.2__tar.gz → 1.2.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.
- {cat_data_tools-1.0.2 → cat_data_tools-1.2.0}/PKG-INFO +1 -1
- {cat_data_tools-1.0.2 → cat_data_tools-1.2.0}/cat_data_tools/__init__.py +1 -1
- {cat_data_tools-1.0.2 → cat_data_tools-1.2.0}/cat_data_tools/build_trap_daily_status.py +1 -1
- {cat_data_tools-1.0.2 → cat_data_tools-1.2.0}/cat_data_tools/cli.py +34 -0
- cat_data_tools-1.2.0/cat_data_tools/detect_status_change.py +30 -0
- cat_data_tools-1.2.0/cat_data_tools/summary_posterior_results.py +44 -0
- cat_data_tools-1.0.2/cat_data_tools/detect_status_change.py +0 -8
- {cat_data_tools-1.0.2 → cat_data_tools-1.2.0}/LICENSE +0 -0
- {cat_data_tools-1.0.2 → cat_data_tools-1.2.0}/README.md +0 -0
- {cat_data_tools-1.0.2 → cat_data_tools-1.2.0}/cat_data_tools/calculate_effort_and_captures.py +0 -0
- {cat_data_tools-1.0.2 → cat_data_tools-1.2.0}/cat_data_tools/filter_data_between_years.py +0 -0
- {cat_data_tools-1.0.2 → cat_data_tools-1.2.0}/cat_data_tools/filter_data_by_month.py +0 -0
- {cat_data_tools-1.0.2 → cat_data_tools-1.2.0}/cat_data_tools/transform_effort_captures.py +0 -0
- {cat_data_tools-1.0.2 → cat_data_tools-1.2.0}/cat_data_tools/trap_status_list.py +0 -0
- {cat_data_tools-1.0.2 → cat_data_tools-1.2.0}/cat_data_tools/update_status_traps.py +0 -0
- {cat_data_tools-1.0.2 → cat_data_tools-1.2.0}/pyproject.toml +0 -0
|
@@ -34,7 +34,7 @@ def fill_trap_daily_status(check_traps_log_df, days_active, unique_trap_identifi
|
|
|
34
34
|
|
|
35
35
|
def activate_traps_for_n_days(df_without_captures, days_active, unique_trap_identificators):
|
|
36
36
|
df_without_captures["Date"] = df_without_captures["Date"].apply(
|
|
37
|
-
lambda x: pd.date_range(start=x, periods=days_active
|
|
37
|
+
lambda x: pd.date_range(start=x, periods=days_active)
|
|
38
38
|
)
|
|
39
39
|
df_exploded = df_without_captures.explode("Date")
|
|
40
40
|
|
|
@@ -7,7 +7,11 @@ from cat_data_tools.build_trap_daily_status import (
|
|
|
7
7
|
_build_trap_daily_status_for_duplicated_positions,
|
|
8
8
|
)
|
|
9
9
|
from cat_data_tools.calculate_effort_and_captures import calculate_effort_and_captures
|
|
10
|
+
from cat_data_tools.detect_status_change import (
|
|
11
|
+
compute_trap_check_log,
|
|
12
|
+
)
|
|
10
13
|
from cat_data_tools.filter_data_between_years import filter_data_between_years
|
|
14
|
+
from cat_data_tools.summary_posterior_results import compute_posterior_summary
|
|
11
15
|
from cat_data_tools.update_status_traps import _update_status_traps
|
|
12
16
|
from cat_data_tools.transform_effort_captures import transform_effort_captures_to_dict
|
|
13
17
|
import cat_data_tools as cdt
|
|
@@ -18,6 +22,24 @@ import typer
|
|
|
18
22
|
app = typer.Typer()
|
|
19
23
|
|
|
20
24
|
|
|
25
|
+
@app.command()
|
|
26
|
+
def write_trap_check_log(
|
|
27
|
+
trap_daily_status_path: str = typer.Option(),
|
|
28
|
+
output_path: str = typer.Option(),
|
|
29
|
+
):
|
|
30
|
+
daily_status_df = pd.read_csv(trap_daily_status_path)
|
|
31
|
+
daily_status_df_renamed = daily_status_df.rename(
|
|
32
|
+
columns={
|
|
33
|
+
"Fecha": "Date",
|
|
34
|
+
"Tipo": "Type",
|
|
35
|
+
"Estado_trampa": "Trap_status",
|
|
36
|
+
"Atrayente": "Bait",
|
|
37
|
+
}
|
|
38
|
+
)
|
|
39
|
+
check_log = compute_trap_check_log(daily_status_df_renamed)
|
|
40
|
+
check_log.to_csv(output_path, index=False, na_rep="NA")
|
|
41
|
+
|
|
42
|
+
|
|
21
43
|
@app.command()
|
|
22
44
|
def write_daily_effort_and_captures_summary_by_zone(
|
|
23
45
|
trap_daily_status_path: str = typer.Option(),
|
|
@@ -58,6 +80,18 @@ def adapt_date_column_name(input_path):
|
|
|
58
80
|
return input_df.rename(columns={"Fecha": "Date"})
|
|
59
81
|
|
|
60
82
|
|
|
83
|
+
@app.command()
|
|
84
|
+
def write_posterior_samples_summary(
|
|
85
|
+
posterior_results_path: str = typer.Option(),
|
|
86
|
+
effort_captures_path: str = typer.Option(),
|
|
87
|
+
output_path: str = typer.Option(),
|
|
88
|
+
):
|
|
89
|
+
posterior_results_df = pd.read_csv(posterior_results_path)
|
|
90
|
+
effort_captures_df = pd.read_csv(effort_captures_path)
|
|
91
|
+
posterior_results_dict = compute_posterior_summary(posterior_results_df, effort_captures_df)
|
|
92
|
+
write_dict_as_json(posterior_results_dict, output_path)
|
|
93
|
+
|
|
94
|
+
|
|
61
95
|
@app.command()
|
|
62
96
|
def write_effort_captures_as_json(
|
|
63
97
|
effort_captures_path: str = typer.Option(), output_path: str = typer.Option()
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
def get_status_change(daily_status_df):
|
|
2
|
+
daily_status_df_copy = daily_status_df.copy().dropna(subset="Trap_status")
|
|
3
|
+
df = daily_status_df_copy.sort_values(by=["ID", "Date"])
|
|
4
|
+
is_status_changed = df["Trap_status"] != df.groupby("ID")["Trap_status"].shift()
|
|
5
|
+
is_trapper_changed = df["Trapper"] != df.groupby("ID")["Trapper"].shift()
|
|
6
|
+
is_type_changed = df["Type"] != df.groupby("ID")["Type"].shift()
|
|
7
|
+
filtered_df = df.loc[is_status_changed | is_trapper_changed | is_type_changed]
|
|
8
|
+
return filtered_df.reset_index(drop=True)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def compute_trap_check_log(daily_status_df):
|
|
12
|
+
daily_status_with_next_status = add_next_status_column(daily_status_df)
|
|
13
|
+
check_log = subsitute_check_traps_status(daily_status_with_next_status)
|
|
14
|
+
return check_log.drop(columns=["next_status"])
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def add_next_status_column(daily_status_df):
|
|
18
|
+
sorted_daily = daily_status_df.sort_values(["ID", "Type", "Trapper", "Date"])
|
|
19
|
+
sorted_daily["next_status"] = sorted_daily.groupby(["ID", "Type", "Trapper"])[
|
|
20
|
+
"Trap_status"
|
|
21
|
+
].shift(-1)
|
|
22
|
+
is_capture = sorted_daily["Trap_status"] == "RX"
|
|
23
|
+
sorted_daily.loc[is_capture, "next_status"] = "X"
|
|
24
|
+
return sorted_daily
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def subsitute_check_traps_status(df):
|
|
28
|
+
checked_traps = df[df.Trap_status.str.startswith("R")]
|
|
29
|
+
checked_traps.Trap_status = checked_traps.next_status
|
|
30
|
+
return checked_traps
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
def compute_posterior_summary(posterior_samples, effort_captures_df):
|
|
2
|
+
summary = {
|
|
3
|
+
"critical_effort": compute_critical_effort(posterior_samples),
|
|
4
|
+
"N0": compute_N0(posterior_samples),
|
|
5
|
+
"r": compute_birth_rate(posterior_samples),
|
|
6
|
+
"q": compute_catchability(posterior_samples),
|
|
7
|
+
"time_series": compute_population_size_time_series(posterior_samples, effort_captures_df),
|
|
8
|
+
}
|
|
9
|
+
return summary
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def compute_population_size_time_series(posterior_samples, effort_captures_df):
|
|
13
|
+
population_size_columns = [
|
|
14
|
+
column for column in posterior_samples.columns if column.startswith("N.")
|
|
15
|
+
]
|
|
16
|
+
population_size = posterior_samples[population_size_columns].median(axis=0)
|
|
17
|
+
birth_rate = compute_birth_rate(posterior_samples)
|
|
18
|
+
births = population_size * birth_rate
|
|
19
|
+
return {
|
|
20
|
+
"population_size": population_size.to_list(),
|
|
21
|
+
"Date": effort_captures_df.Fecha.to_list(),
|
|
22
|
+
"Births": births.to_list(),
|
|
23
|
+
"Captures": effort_captures_df.Capturas.to_list(),
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def compute_critical_effort(posterior_samples):
|
|
28
|
+
posterior_df = posterior_samples.copy()
|
|
29
|
+
r = posterior_df["r"]
|
|
30
|
+
q = posterior_df["q"]
|
|
31
|
+
posterior_df["critical_effort"] = r / q
|
|
32
|
+
return int(posterior_df.critical_effort.quantile(0.9).round(0))
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def compute_N0(posterior_samples):
|
|
36
|
+
return int(posterior_samples.N0.median().round(0))
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def compute_birth_rate(posterior_samples):
|
|
40
|
+
return posterior_samples.r.median()
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def compute_catchability(posterior_samples):
|
|
44
|
+
return posterior_samples.q.median()
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
def get_status_change(daily_status_df):
|
|
2
|
-
daily_status_df_copy = daily_status_df.copy().dropna(subset="Trap_status")
|
|
3
|
-
df = daily_status_df_copy.sort_values(by=["ID", "Date"])
|
|
4
|
-
is_status_changed = df["Trap_status"] != df.groupby("ID")["Trap_status"].shift()
|
|
5
|
-
is_trapper_changed = df["Trapper"] != df.groupby("ID")["Trapper"].shift()
|
|
6
|
-
is_type_changed = df["Type"] != df.groupby("ID")["Type"].shift()
|
|
7
|
-
filtered_df = df.loc[is_status_changed | is_trapper_changed | is_type_changed]
|
|
8
|
-
return filtered_df.reset_index(drop=True)
|
|
File without changes
|
|
File without changes
|
{cat_data_tools-1.0.2 → cat_data_tools-1.2.0}/cat_data_tools/calculate_effort_and_captures.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|