def test_get_segment_offset_local_stored(test_library_file): """Test the extraction of segment offsets from a single segment PSF library in the temp_data directory. """ # Get test library file test_library_dir = os.path.dirname(test_library_file) seg_id = 12 segment_file = get_library_file(INSTRUMENT, DETECTOR, FILTER, 'CLEAR', '', 0, test_library_dir, segment_id=seg_id) # Set segment = 0 and expect error: with pytest.raises(AssertionError) as e: library_list = [segment_file] get_segment_offset(0, DETECTOR, library_list) assert "Uh-oh. The segment ID of the library does not match the requested segment." in e, \ 'Failed to catch mismatch between segment IDs.' # Put segment 12th on a faked library list and extract the segment offset library_list = [''] * 18 library_list[11] = segment_file x_arcsec, y_arcsec = get_segment_offset(12, DETECTOR, library_list) assert (x_arcsec, y_arcsec) == (-7.412675266715986, -7.905276016530719), \ 'Incorrect conversion of segment offsets'
def test_get_segment_psf_library_file(test_segment_psf_library_file): """Test the identification of a segment PSF library file Parameters ---------- test_segment_psf_library_file : str Path to test segment PSF library used for testing """ instrument = "NIRCam" detector = "NRCA3" filt = "F212N" pupil = "CLEAR" wfe = '' wfe_group = 0 library_path = os.path.dirname(test_segment_psf_library_file) segment_id = 12 # Ensure the right file is found given the right parameters match_file = get_library_file(instrument, detector, filt, pupil, wfe, wfe_group, library_path, wings=False, segment_id=segment_id) assert match_file == test_segment_psf_library_file, \ "Failed to match segment PSF library" # Ensure an error is raised if no file exists that matches with pytest.raises(ValueError) as e: detector = "NRCB5" segment_id = 11 get_library_file(instrument, detector, filt, pupil, wfe, wfe_group, library_path, wings=False, segment_id=segment_id) assert "No PSF library file found matching requested parameters" in e
def get_segment_library_list(instrument, detector, filt, library_path, pupil='CLEAR'): """Given an instrument and filter name along with the path of the PSF library, find the appropriate 18 segment PSF library files. Parameters ----------- instrument : str Name of instrument the PSFs are from detector : str Name of the detector within ```instrument``` filt : str Name of filter used for PSF library creation library_path : str Path pointing to the location of the PSF library pupil : str, optional Name of pupil wheel element used for PSF library creation. Default is 'CLEAR'. segment_id : int or None, optional If specified, returns a segment PSF library file and denotes the ID of the mirror segment Returns -------- library_list : list List of the names of the segment PSF library files for the instrument and filter name """ library_list = [] for seg_id in np.arange(1, 19): segment_file = get_library_file(instrument, detector, filt, pupil, '', 0, library_path, segment_id=seg_id) library_list.append(segment_file) return library_list