diff --git a/CHANGELOG.md b/CHANGELOG.md index b19eb53..5abe5d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/Makefile b/Makefile index c86d84d..87af6c7 100644 --- a/Makefile +++ b/Makefile @@ -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 \ @@ -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 . diff --git a/population_trend/plotter_population_trend_from_cpue.py b/population_trend/plotter_population_trend_from_cpue.py index aa5b66f..0303865 100644 --- a/population_trend/plotter_population_trend_from_cpue.py +++ b/population_trend/plotter_population_trend_from_cpue.py @@ -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) diff --git a/population_trend/population_growth_model.py b/population_trend/population_growth_model.py index fc6df94..e1e76d0 100644 --- a/population_trend/population_growth_model.py +++ b/population_trend/population_growth_model.py @@ -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 @@ -67,20 +68,20 @@ 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", @@ -88,19 +89,19 @@ def plot_smooth(self): 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", @@ -108,7 +109,7 @@ def plot_smooth(self): def plot_model(self): plt.plot( - self.plot_domain, + self.domain_plot, self.population_model.med_model, label="Population growth model", color="b", @@ -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() diff --git a/tests/test_Population_trend.py b/tests/test_Population_trend.py index f4f0734..dae38cc 100644 --- a/tests/test_Population_trend.py +++ b/tests/test_Population_trend.py @@ -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 @@ -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"