Skip to content

Commit

Permalink
test with tmp diretory
Browse files Browse the repository at this point in the history
  • Loading branch information
Laura Cabayol-Garcia committed Sep 30, 2024
1 parent 78adc37 commit 187102f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
16 changes: 11 additions & 5 deletions .github/workflows/python-tests.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# .github/workflows/python-tests.yml

name: LaCE automated testing

on:
push:
branches: '*'
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -24,22 +26,26 @@ jobs:
pip install fdasrsf
pip install setuptools
pip install pytest wheel pytest-cov
- name: Install lace
run: pip install -e .

- name: Create temporary directory
run: mkdir -p temp/plots # Create a temporary directory for plots

- name: Run tests
timeout-minutes: 30
run: |
pytest tests/test_lace.py
pytest tests/plot_mpg.py
pytest tests/test_lace.py
pytest tests/plot_mpg.py -- --output_dir temp/plots # Pass the temp directory as an argument
- name: Archive generated plots
uses: actions/upload-artifact@v4
with:
name: validation-figures
path: data/validation_figures/Gadget/*.png
path: temp/plots/*.png # Upload all generated PNG files from the temp directory

- name: List generated plots
run: |
echo "Files in the validation_figures directory:"
ls data/validation_figures/Gadget/
echo "Files in the temporary plots directory:"
ls temp/plots/
24 changes: 8 additions & 16 deletions tests/plot_mpg.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,29 @@
from lace.utils.plotting_functions import plot_p1d_vs_emulator


def test():
def test(output_dir='data/validation_figures/Gadget/'):
"""
Function to plot emulated P1D using specified archive (Nyx or Gadget).
Parameters:
archive (str): Archive to use for data ('Nyx' or 'Gadget')
output_dir (str): Directory to save plots.
"""
archive_name = 'Gadget'
# Get the base directory of the lace module
repo = os.path.dirname(lace.__path__[0]) + "/"

# Define the parameters for the emulator specific to Gadget
emu_params = ['Delta2_p', 'n_p', 'mF', 'sigT_Mpc', 'gamma', 'kF_Mpc']
training_set='Cabayol23'
emulator_label='Cabayol23+'
training_set = 'Cabayol23'
emulator_label = 'Cabayol23+'
model_path = f'{repo}data/NNmodels/Cabayol23+/Cabayol23+_drop_sim'

# Initialize a GadgetArchive instance for postprocessing data
archive = gadget_archive.GadgetArchive(postproc="Cabayol23")

# Directory for saving plots
save_dir = f'{repo}data/validation_figures/{archive_name}/'
# Create the directory if it does not exist
os.makedirs(save_dir, exist_ok=True)
# Create the output directory if it does not exist
os.makedirs(output_dir, exist_ok=True)

#for ii, sim in enumerate(archive.list_sim):
for ii, sim in enumerate(['mpg_1','mpg_central']):

for ii, sim in enumerate(['mpg_1', 'mpg_central']):
if sim == 'mpg_central':
model_path_central = f'{repo}data/NNmodels/Cabayol23+/Cabayol23+.pt'

Expand All @@ -70,10 +65,7 @@ def test():
testing_data = [d for d in testing_data if d['val_scaling'] == 1]

# Plot and save the emulated P1D
save_path = f'{save_dir}{sim}.png'
save_path = f'{output_dir}{sim}.png' # Save plots to the specified output directory
plot_p1d_vs_emulator(testing_data, emulator, save_path=save_path)

return

# Call the function to execute the test
test()

0 comments on commit 187102f

Please sign in to comment.