Skip to content

Commit

Permalink
example: Setup input and output args for pytest
Browse files Browse the repository at this point in the history
.github/workflows: Added ubi8-weekly.yml
  • Loading branch information
e10harvey committed Aug 20, 2024
1 parent a6f42bc commit 8828d9a
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ubi8-nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ jobs:
with:
path: OpenCSP

- name: pytest-cov
- name: pytest-cov (OpenCSP/example)
working-directory: OpenCSP/example
run: |
python3 -m pip install -r ../requirements.txt
export PYTHONPATH=$PWD/../
pytest --color=yes -rs -vv --cov=. --cov-report term --cov-config=.coveragerc
- name: Pip Upgrade pytest-cov
- name: Pip Upgrade pytest-cov (OpenCSP/example)
working-directory: OpenCSP/example
run: |
python3 -m pip install -U -r ../requirements.txt
Expand Down
43 changes: 43 additions & 0 deletions .github/workflows/ubi8-weekly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: github-UBI8-WEEKLY

# Runs every Sunday at midnight
on:
workflow_dispatch:
schedule:
- cron: '00 00 * * 0'

permissions:
contents: none

# Cancels any in progress 'workflow' associated with this PR
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
ubi8-weekly:
runs-on: [opencsp-latest-ubi8]
permissions:
packages: read
contents: read

steps:
- name: checkout
uses: actions/checkout@v4
with:
path: OpenCSP

- name: pytest-cov (OpenCSP/example - scene_reconstruction)
working-directory: OpenCSP/example
run: |
python3 -m pip install -r ../requirements.txt
export PYTHONPATH=$PWD/../
pytest \
--color=yes \
-rs \
-vv \
--cov=. --cov-report term \
--cov-config=.coveragerc \
--dir-input=/box_data/scene_reconstruction/data_measurement/ \
--dir-output=/box_data/scene_reconstruction/data_calculation/ \
scene_reconstruction/example_scene_reconstruction.py
2 changes: 1 addition & 1 deletion .github/workflows/ubi8.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
with:
path: OpenCSP

- name: pytest-cov
- name: pytest-cov (OpenCSP/opencsp)
working-directory: OpenCSP/opencsp
run: |
python3 -m pip install -r ../requirements.txt
Expand Down
19 changes: 19 additions & 0 deletions example/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import pytest


#
# Ensure pytest adds root directory to the system path.
#
def pytest_addoption(parser):
parser.addoption('--dir-input', action='store', default='', help='Base directory with data input')
parser.addoption('--dir-output', action='store', default='', help='Base directory where output will be written')


@pytest.fixture
def dir_input_fixture(request):
return request.config.getoption('--dir-input')


@pytest.fixture
def dir_output_fixture(request):
return request.config.getoption('--dir-output')
25 changes: 15 additions & 10 deletions example/scene_reconstruction/example_scene_reconstruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@
import opencsp.common.lib.tool.log_tools as lt


def scene_reconstruction(save_dir):
def scene_reconstruction(dir_output, dir_input):
"""Example script that reconstructs the XYZ locations of Aruco markers in a scene."""
# Define input directory
dir_input = join(opencsp_code_dir(), 'app/scene_reconstruction/test/data/data_measurement')

# Load components
camera = Camera.load_from_hdf(join(dir_input, 'camera.h5'))
Expand All @@ -38,22 +36,29 @@ def scene_reconstruction(save_dir):
cal_scene_recon.align_points(marker_ids, alignment_values)

# Save points as CSV
cal_scene_recon.save_data_as_csv(join(save_dir, 'point_locations.csv'))
cal_scene_recon.save_data_as_csv(join(dir_output, 'point_locations.csv'))

# Save calibrtion figures
for fig in cal_scene_recon.figures:
fig.savefig(join(save_dir, fig.get_label() + '.png'))
fig.savefig(join(dir_output, fig.get_label() + '.png'))


def example_driver(dir_output_fixture, dir_input_fixture):

dir_input = join(opencsp_code_dir(), 'app/scene_reconstruction/test/data/data_measurement')
dir_output = join(dirname(__file__), 'data/output/scene_reconstruction')
if dir_input_fixture:
dir_input = dir_input_fixture
if dir_output_fixture:
dir_output = dir_input_fixture

def example_driver():
# Define output directory
save_path = join(dirname(__file__), 'data/output/scene_reconstruction')
ft.create_directories_if_necessary(save_path)
ft.create_directories_if_necessary(dir_input)

# Set up logger
lt.logger(join(save_path, 'log.txt'), lt.log.INFO)
lt.logger(join(dir_output, 'log.txt'), lt.log.INFO)

scene_reconstruction(save_path)
scene_reconstruction(dir_output, dir_input)


if __name__ == '__main__':
Expand Down

0 comments on commit 8828d9a

Please sign in to comment.