Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
bhilbert4 committed Feb 19, 2024
1 parent ce649ff commit c44b090
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 8 deletions.
53 changes: 53 additions & 0 deletions jwql/tests/test_data_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
# Skip testing this module if on Github Actions
ON_GITHUB_ACTIONS = '/home/runner' in os.path.expanduser('~') or '/Users/runner' in os.path.expanduser('~')
from jwql.website.apps.jwql import data_containers
from jwql.website.apps.jwql.models import RootFileInfo
from jwql.tests.resources import (
MockSessionFileAnomaly, MockSessionGroupAnomaly,
MockGetRequest, MockPostRequest)
Expand Down Expand Up @@ -127,6 +128,58 @@ def test_get_acknowledgements():
assert len(acknowledgements) > 0


@pytest.mark.skipif(ON_GITHUB_ACTIONS, reason='Requires access to django models.')
def test_get_additional_exposure_info():
"""Tests ``get_additional_exposure_info`` function."""
# Test an exposure-level case
group_root = 'jw01068002001_02102_00008'
image_info = data_containers.get_image_info(group_root)
root_file_info = RootFileInfo.objects.filter(root_name__startswith=group_root)
basic, additional = data_containers.get_additional_exposure_info(root_file_info, image_info)
expected_basic = {'exp_type': 'NRC_IMAGE',
'category': 'COM',
'visit_status': 'SUCCESSFUL',
'subarray': 'SUB320',
'pupil': 'CLEAR'}
# We can only test a subset of the keys in additional, since things like the pipeline version,
# crds context, etc can change over time.
expected_additional = {'READPATT': 'RAPID',
'TITLE': 'NIRCam Subarray-Mode Commissioning, CAR NIRCam-019',
'NGROUPS': 10,
'PI_NAME': 'Hilbert, Bryan',
'NINTS': 10,
'TARGNAME': 'GP2-JMAG14-STAR-OFFSET',
'EXPTIME': 106.904,
'EXPSTART': 59714.6163261875}
for key in expected_basic:
assert basic[key] == expected_basic[key]
for key in expected_additional:
assert additional[key] == expected_additional[key]

# Test an image-level case
file_root = 'jw01022016001_03101_00001_nrs1'
image_info = data_containers.get_image_info(file_root)
root_file_info = RootFileInfo.objects.get(root_name=file_root)
basic, additional = data_containers.get_additional_exposure_info(root_file_info, image_info)
expected_basic = {'exp_type': 'NRS_IFU',
'category': 'COM',
'visit_status': 'SUCCESSFUL',
'subarray': 'FULL',
'filter': 'F100LP',
'grating': 'G140H'}
expected_additional = {'READPATT': 'NRSRAPID',
'TITLE': 'CAR FGS-017 Straylight for Moving Targets (All SIs)',
'NGROUPS': 13,
'PI_NAME': 'Stansberry, John A.',
'NINTS': 2,
'TARGNAME': 'JUPITER',
'EXPTIME': 279.156,
'EXPSTART': 59764.77659749352}
assert basic == expected_basic
for key in expected_additional:
assert additional[key] == expected_additional[key]


@pytest.mark.skipif(ON_GITHUB_ACTIONS, reason='Requires access to central storage.')
def test_get_all_proposals():
"""Tests the ``get_all_proposals`` function."""
Expand Down
15 changes: 7 additions & 8 deletions jwql/website/apps/jwql/data_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,8 @@ def get_additional_exposure_info(root_file_infos, image_info):
Parameters
----------
root_file_infos : jwql.models.RootFileInfo or django.db.models.query.QuerySet
RootFileInfo for a particular file base name, or a list of RootFileInfos for
root_file_infos : jwql.website.apps.jwql.models.RootFileInfo or django.db.models.query.QuerySet
RootFileInfo for a particular file base name, or a QuerySet of RootFileInfos for
an exposure base name.
image_info : : dict
Expand All @@ -404,13 +404,12 @@ def get_additional_exposure_info(root_file_infos, image_info):
filter_value = '/'.join(set([e.filter for e in root_file_infos]))
pupil_value = '/'.join(set([e.pupil for e in root_file_infos]))
grating_value = '/'.join(set([e.grating for e in root_file_infos]))
else:
elif isinstance(root_file_infos, RootFileInfo):
root_file_info = root_file_infos
filter_value = root_file_info.filter
pupil_value = root_file_info.pupil
grating_value = root_file_info.grating


# Initialize dictionary of file info to show at the top of the page, along
# with another for info that will be in the collapsible text box.
basic_info = {'exp_type': root_file_info.exp_type,
Expand All @@ -437,8 +436,8 @@ def get_additional_exposure_info(root_file_infos, image_info):
'CRDS context': 'N/A',
'PA_V3': 'N/A',
'EXPSTART': root_file_info.expstart
}
else:
}
elif isinstance(root_file_infos, RootFileInfo):
additional_info = {'READPATT': root_file_info.read_patt,
'TITLE': 'N/A',
'NGROUPS': 'N/A',
Expand All @@ -452,7 +451,7 @@ def get_additional_exposure_info(root_file_infos, image_info):
'CRDS context': 'N/A',
'ROLL_REF': 'N/A',
'EXPSTART': root_file_info.expstart
}
}

# Deal with instrument-specific parameters
if root_file_info.instrument == 'NIRSpec':
Expand Down Expand Up @@ -493,7 +492,7 @@ def get_additional_exposure_info(root_file_infos, image_info):
additional_info['TARG_RA'] = header['TARG_RA']
additional_info['TARG_DEC'] = header['TARG_DEC']
additional_info['PA_V3'] = header_sci['PA_V3']
else:
elif isinstance(root_file_infos, RootFileInfo):
additional_info['RA_REF'] = header_sci['RA_REF']
additional_info['DEC_REF'] = header_sci['DEC_REF']
additional_info['ROLL_REF'] = header_sci['ROLL_REF']
Expand Down

0 comments on commit c44b090

Please sign in to comment.