|
7 | 7 |
|
8 | 8 | # Import the python package 'ncpi' |
9 | 9 | import ncpi |
| 10 | +from ncpi import tools |
10 | 11 |
|
11 | 12 | # Import the test module |
12 | 13 | import pytest |
|
32 | 33 | # Methods used to compute the features |
33 | 34 | # all_methods = ['catch22','power_spectrum_parameterization_1'] |
34 | 35 |
|
| 36 | +# Zenodo URL that contains the simulation and empirical test data and ML models for LFP method |
| 37 | +zenodo_URL_test = "https://zenodo.org/api/records/17479326" |
| 38 | + |
35 | 39 | # Get the directory where this test file is located |
36 | 40 | test_dir = os.path.dirname(os.path.abspath(__file__)) |
37 | 41 |
|
| 42 | +# Path to save zenodo test files locally |
| 43 | +zenodo_test_files = os.path.join(test_dir, "..", "data", "zenodo_test_files_LFP") |
| 44 | + |
38 | 45 | # Paths to zenodo simulation files |
39 | | -zenodo_dir_sim = os.path.join(test_dir, "..", "data", "zenodo_test_files_LFP", "zenodo_sim_files") # Dir of GitHub testing downloaded files (set in tests.yml) |
| 46 | +zenodo_dir_sim = os.path.join(zenodo_test_files, "zenodo_sim_files") # Dir of GitHub testing downloaded files (set in tests.yml) |
40 | 47 |
|
41 | 48 | # Paths to zenodo empirical files |
42 | | -zenodo_dir_emp= os.path.join(test_dir, "..", "data", "zenodo_test_files_LFP", "zenodo_emp_files") # Dir of GitHub testing downloaded files (set in tests.yml) |
| 49 | +zenodo_dir_emp= os.path.join(zenodo_test_files, "zenodo_emp_files") # Dir of GitHub testing downloaded files (set in tests.yml) |
43 | 50 |
|
44 | 51 | # ML model used to compute the predictions (MLPRegressor, Ridge or NPE) |
45 | 52 | ML_model = 'MLPRegressor' |
46 | 53 |
|
| 54 | +def download_data_if_needed(): |
| 55 | + """Download test data only when running locally and data is missing""" |
| 56 | + # Skip if running in GitHub Actions |
| 57 | + if os.getenv('GITHUB_ACTIONS'): |
| 58 | + print("Running in CI - assuming test data is cached") |
| 59 | + return |
| 60 | + |
| 61 | + # Download if zenodo sim files data don't exist locally |
| 62 | + if not os.path.exists(zenodo_dir_sim): |
| 63 | + tools.timer("Downloading simulation data for local execution...")( |
| 64 | + tools.download_zenodo_record |
| 65 | + )(zenodo_URL_test, download_dir=zenodo_test_files) |
| 66 | + else: |
| 67 | + print("Zenodo sim and emp test files already exist locally") |
| 68 | + |
| 69 | +# Download the data if it's not already downloaded |
| 70 | +download_data_if_needed() |
| 71 | + |
47 | 72 | def LFP_mean(method): |
48 | 73 | """ |
49 | 74 | Compute only certain data for testing and calculate the average |
@@ -83,3 +108,4 @@ def test_LFP(): |
83 | 108 | # mean_power = LFP_mean('power_spectrum_parameterization_1') |
84 | 109 | # print(f'Is \n{mean_catch} equal or similar to \n-0.8690581451462226?') |
85 | 110 | # print(f'Is \n{mean_power} equal or similar to \n-1.2395402659827317?') |
| 111 | +# print('If no error messages were showed, the tests completed successfully.') |
0 commit comments