Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]
### Added
- Spanish language support — `Plotter_Population_Trend_Model` and `Plotter_Population_Trend_Model_From_CPUE` now accept a language parameter "english" / "spanish") controlling axis label language.

### Fixed

Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ setup: clean install
tests:
pytest --verbose

tdd_current_test_file = tests/test_cli.py
tdd_current_test_file = tests/test_Population_trend.py
red: format
pytest --verbose $(tdd_current_test_file) \
&& git restore tests/*.py \
Expand All @@ -87,7 +87,7 @@ green: format

refactor: format
pytest --verbose $(tdd_current_test_file) \
&& (git add ${module}/*.py tests/*.py && git commit -m "♻️ Refactor") \
&& (git add ${module}/*.py tests/*.py && git commit -m "♻️ Refactor ${m}") \
|| git restore ${module}/*.py tests/*.py
chmod g+w -R .

4 changes: 2 additions & 2 deletions population_trend/plotter_population_trend_from_cpue.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@


class Plotter_Population_Trend_Model_From_CPUE(Plotter_Population_Trend_Model):
def __init__(self, data, population_model, tick_mode="full"):
super().__init__(data, population_model, tick_mode)
def __init__(self, data, population_model, tick_mode="full", language="english"):
super().__init__(data, population_model, tick_mode, language)

def set_labels(self):
plt.ylabel("CPUE", size=20)
Expand Down
28 changes: 16 additions & 12 deletions population_trend/population_growth_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,14 @@ def max_model(self):


class Plotter_Population_Trend_Model:
def __init__(self, data, population_model, tick_mode):
def __init__(self, data, population_model, tick_mode, language="english"):
self.fig, self.ax = geci_plot()
self.fill_missing_seasons(data)
self.tick_mode = tick_mode
self.language = language
self.seasons_to_plot = self.filled_data.index.values + 1
self.ticks_positions = ticks_positions_array(self.filled_data)
self.plot_domain = np.linspace(self.ticks_positions.min(), self.ticks_positions.max(), 100)
self.domain_plot = np.linspace(self.ticks_positions.min(), self.ticks_positions.max(), 100)
self.population_model = population_model
self.interest_variable = population_model.interest_variable

Expand All @@ -67,48 +68,48 @@ def fill_missing_seasons(self, data):

def plot_smooth(self):
self.ax.fill_between(
self.plot_domain,
self.domain_plot,
self.population_model.min_model,
self.population_model.med_model,
label="Confidence zone",
color="powderblue",
)
self.ax.fill_between(
self.plot_domain,
self.domain_plot,
self.population_model.med_model,
self.population_model.max_model,
color="powderblue",
)
self.ax.fill_between(
self.plot_domain,
self.domain_plot,
self.population_model.min_model,
self.population_model.max_model,
color="powderblue",
)
number_of_samples = len(self.population_model.bootstrap_distribution)
for i in range(0, number_of_samples - 1, 10):
self.ax.fill_between(
self.plot_domain,
self.domain_plot,
self.population_model.intern_model(i),
self.population_model.med_model,
color="powderblue",
)
self.ax.fill_between(
self.plot_domain,
self.domain_plot,
self.population_model.intern_model(i),
self.population_model.intern_model(i + 1),
color="powderblue",
)
self.ax.fill_between(
self.plot_domain,
self.domain_plot,
self.population_model.intern_model(i + 1),
self.population_model.med_model,
color="powderblue",
)

def plot_model(self):
plt.plot(
self.plot_domain,
self.domain_plot,
self.population_model.med_model,
label="Population growth model",
color="b",
Expand Down Expand Up @@ -147,9 +148,12 @@ def set_x_lim(self):
)

def set_labels(self):
labels = {"english": {"ylabel": "Number of breeding pairs", "xlabel": "Seasons"}}
plt.ylabel(labels["english"]["ylabel"], size=20)
plt.xlabel(labels["english"]["xlabel"], size=20)
labels = {
"english": {"ylabel": "Number of breeding pairs", "xlabel": "Seasons"},
"spanish": {"ylabel": "Número de parejas reproductivas", "xlabel": "Temporadas"},
}
self.ax.set_ylabel(labels[self.language]["ylabel"], size=20)
self.ax.set_xlabel(labels[self.language]["xlabel"], size=20)

def set_ticks(self):
self.get_tick_step()
Expand Down
14 changes: 12 additions & 2 deletions tests/test_Population_trend.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ def tests_calculate_upper_limit():


class Tests_Plotter_Population_Trend_Model:

def tests_init_(self):
fig, ax = geci_plot()
assert type(fig) == type(Plotter.fig) # noqa
Expand All @@ -80,12 +79,23 @@ def test_Plotter_plot_data(self):
assert len(Plotter.ax.get_lines()) == expected_one_line

def tests_time_to_model(self):
obtained = Plotter.plot_domain
obtained = Plotter.domain_plot
expected_first_point = 1
assert obtained[0] == expected_first_point
expected_last_point = 4.05
assert obtained[-1] == expected_last_point

def tests_set_labels(self):
Plotter.set_labels()
obtained_labels = [Plotter.ax.get_xlabel(), Plotter.ax.get_ylabel()]
expected_labels = ["Seasons", "Number of breeding pairs"]
assert obtained_labels == expected_labels
Plotter.language = "spanish"
Plotter.set_labels()
obtained_labels = [Plotter.ax.get_xlabel(), Plotter.ax.get_ylabel()]
expected_labels = ["Temporadas", "Número de parejas reproductivas"]
assert obtained_labels == expected_labels

def tests_savefig(self):
islet = "morro"
default_path = f"reports/figures/cormorant_population_trend_{islet}.png"
Expand Down
Loading