cat-data-tools 1.1.0__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cat_data_tools
3
- Version: 1.1.0
3
+ Version: 1.2.0
4
4
  Summary: A Python module to process cats data
5
5
  Home-page: https://github.com/IslasGECI/cat_data_tools
6
6
  Author: Ciencia de Datos • GECI
@@ -1,6 +1,6 @@
1
1
  """A Python module to process cats data"""
2
2
 
3
- __version__ = "1.1.0"
3
+ __version__ = "1.2.0"
4
4
  from .cli import * # noqa
5
5
  from .filter_data_between_years import * # noqa
6
6
  from .filter_data_by_month import * # noqa
@@ -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, freq="D")
37
+ lambda x: pd.date_range(start=x, periods=days_active)
38
38
  )
39
39
  df_exploded = df_without_captures.explode("Date")
40
40
 
@@ -11,6 +11,7 @@ from cat_data_tools.detect_status_change import (
11
11
  compute_trap_check_log,
12
12
  )
13
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
14
15
  from cat_data_tools.update_status_traps import _update_status_traps
15
16
  from cat_data_tools.transform_effort_captures import transform_effort_captures_to_dict
16
17
  import cat_data_tools as cdt
@@ -79,6 +80,18 @@ def adapt_date_column_name(input_path):
79
80
  return input_df.rename(columns={"Fecha": "Date"})
80
81
 
81
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
+
82
95
  @app.command()
83
96
  def write_effort_captures_as_json(
84
97
  effort_captures_path: str = typer.Option(), output_path: str = typer.Option()
@@ -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()
File without changes
File without changes