diff --git a/extreme_data/edf_data/__init__.py b/extreme_data/edf_data/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/projects/projection_snow_load/main_difference_between_reanalysis_and_simulations.py b/projects/projection_snow_load/main_difference_between_reanalysis_and_simulations.py index c152e7d1fdea027bdb6ae92cbc98d3a00e4045db..40930a83fb70fe985b777758f21cf65b776e9538 100644 --- a/projects/projection_snow_load/main_difference_between_reanalysis_and_simulations.py +++ b/projects/projection_snow_load/main_difference_between_reanalysis_and_simulations.py @@ -6,7 +6,7 @@ from extreme_data.meteo_france_data.scm_models_data.visualization.study_visualiz import matplotlib.pyplot as plt -def test(): +def run_plot(): study = CrocusSnowLoad3Days(altitude=1200) study_visualizer = StudyVisualizer(study) study_visualizer.visualize_max_graphs_poster('Queyras', altitude='noope', snow_abbreviation="ok", color='red') diff --git a/root_utils.py b/root_utils.py index 2305a67c96772d0a0701818902543c438c244b54..8f112131d44455b3a77890948e657620e761b6e2 100644 --- a/root_utils.py +++ b/root_utils.py @@ -1,5 +1,7 @@ import datetime import os.path as op +import subprocess + from cached_property import cached_property VERSION = datetime.datetime.now() @@ -10,6 +12,10 @@ for c in [' ', ':', '-']: NB_CORES = 7 +def terminal_command(command_str): + return subprocess.check_output(command_str.split()).decode("utf-8").split('\n') + + def get_root_path() -> str: return op.dirname(op.abspath(__file__)) diff --git a/run_test_coverage.py b/run_test_coverage.py new file mode 100644 index 0000000000000000000000000000000000000000..620caa4d8c16060dd59e3b46aad23e341b480f74 --- /dev/null +++ b/run_test_coverage.py @@ -0,0 +1,29 @@ +import os.path as op +from root_utils import terminal_command, get_root_path + +""" +To run all my test do: python -m unittest + +Test coverage is only in the professional version of pycharm. +To configure the extent of my coverage: modify the .coveragerc +To run test coverage in the terminal: coverage run -m unittest +Then a hidden file .coverage is create at the root +To create a html file from it do: coverage html +Then open the htlmcov/index.html in your browser +""" + + +def run_test_coverage(): + if op.exists(op.join(get_root_path(), "coverage_html_report")): + terminal_command("rm -r coverage_html_report") + terminal_command("coverage run -m unittest") + + +def display_last_test_coverage(): + terminal_command("coverage html") + terminal_command("firefox coverage_html_report/index.html &") + + +if __name__ == '__main__': + # run_test_coverage() + display_last_test_coverage() diff --git a/spatio_temporal_dataset/coordinates/spatial_coordinates/alps_station_3D_coordinates.py b/spatio_temporal_dataset/coordinates/spatial_coordinates/alps_station_3D_coordinates.py index 8007bfd98a283851e3f062a3dad7f464175ff8d0..c7e405e9c95cc847947896d9ba137670c691342e 100644 --- a/spatio_temporal_dataset/coordinates/spatial_coordinates/alps_station_3D_coordinates.py +++ b/spatio_temporal_dataset/coordinates/spatial_coordinates/alps_station_3D_coordinates.py @@ -23,7 +23,7 @@ class AlpsStation3DCoordinates(AbstractSpatialCoordinates): return super().from_csv(csv_path) @classmethod - def transform_txt_into_csv(cls): + def transform_txt_into_csv(cls, create_csv=True): filepath = op.join(cls.FULL_PATH, 'original data', 'coord-lambert2.txt') station_to_coordinates = {} with open(filepath, 'r') as f: @@ -35,8 +35,9 @@ class AlpsStation3DCoordinates(AbstractSpatialCoordinates): df = pd.DataFrame.from_dict(data=station_to_coordinates, orient='index', columns=[cls.COORDINATE_X, cls.COORDINATE_Y, cls.COORDINATE_Z]) filepath = op.join(cls.FULL_PATH, 'coord-lambert2.csv') - assert not op.exists(filepath) - df.to_csv(filepath) + if create_csv: # pragma: no cover + assert not op.exists(filepath) + df.to_csv(filepath) class AlpsStation3DCoordinatesWithAnisotropy(AlpsStation3DCoordinates): diff --git a/spatio_temporal_dataset/slicer/abstract_slicer.py b/spatio_temporal_dataset/slicer/abstract_slicer.py index cb6d98a5fe4bf6ded551a4424237e6dbc89e228d..e5357d5285cab04e1d4efe8aabe56cec72a15850 100644 --- a/spatio_temporal_dataset/slicer/abstract_slicer.py +++ b/spatio_temporal_dataset/slicer/abstract_slicer.py @@ -46,7 +46,7 @@ class AbstractSlicer(object): for f, name in [(len, 'Total'), (sum, 'train')]: msg += "{}: {} ".format(name, f(s)) msg += ' / ' - if show: + if show: # pragma: no cover print(msg) return msg diff --git a/test/test_spatio_temporal_dataset/test_coordinates.py b/test/test_spatio_temporal_dataset/test_coordinates.py index c589a6069911fb528b409f68c5c5582f64be5290..bd5a883d566eb8f94e3aced52e2e6419029e942f 100644 --- a/test/test_spatio_temporal_dataset/test_coordinates.py +++ b/test/test_spatio_temporal_dataset/test_coordinates.py @@ -31,6 +31,12 @@ from test.test_utils import load_test_spatiotemporal_coordinates, load_test_spat load_test_temporal_coordinates, load_test_1D_and_2D_spatial_coordinates +class TestCoordinatesUtils(unittest.TestCase): + + def test_csv_creation(self): + AlpsStation3DCoordinatesWithAnisotropy.transform_txt_into_csv(create_csv=False) + + class TestSpatialCoordinates(unittest.TestCase): DISPLAY = False diff --git a/test/test_spatio_temporal_dataset/test_slicer.py b/test/test_spatio_temporal_dataset/test_slicer.py index 119f667c62eaa686f73adc0cd8f00454356198b1..716ace5eb13f5f6569334f96126e0711d91163e0 100644 --- a/test/test_spatio_temporal_dataset/test_slicer.py +++ b/test/test_spatio_temporal_dataset/test_slicer.py @@ -46,6 +46,7 @@ class TestSlicerForDataset(unittest.TestCase): assert self.complete_shape is not None for train_split_ratio, data_shape in train_split_ratio_to_observation_shape.items(): for dataset in self.load_datasets(train_split_ratio): + dataset.slicer.summary(show=False) self.assertEqual(self.complete_shape, self.get_shape(dataset, Split.all)) for split in ALL_SPLITS_EXCEPT_ALL: if split in dataset.slicer.splits: