def test_get_aper_from_model_msa(): """For a given exposures aperture, make sure the correct aperture reference data is returned for MSA mode""" datmod = PathlossModel() datmod.apertures.append({'shutters': 5}) datmod.meta.exposure.type = 'NRS_MSASPEC' result = get_aperture_from_model(datmod, 5) assert (result == datmod.apertures[0])
def test_get_aper_from_model_fixedslit(): """For a given exposures aperture, make sure the correct aperture reference data is returned for fixedslit mode""" datmod = PathlossModel() datmod.apertures.append({'name': 'S200A1'}) datmod.meta.exposure.type = 'NRS_FIXEDSLIT' result = get_aperture_from_model(datmod, 'S200A1') assert (result == datmod.apertures[0])
def test_do_correction_nis_soss_pupil_position_is_none(): """If pupil_position is None, skip correction""" datmod = MultiSlitModel() pathlossmod = PathlossModel() datmod.meta.exposure.type = 'NIS_SOSS' datmod.meta.visit.tsovisit = False datmod.meta.instrument.pupil_position = None result = do_correction(datmod, pathlossmod) assert (result.meta.cal_step.pathloss == 'SKIPPED')
def test_do_correction_fixed_slit_exception(): """If no matching aperture name found, exit.""" datmod = MultiSlitModel() # Give input_model aperture name datmod.slits.append({'data':np.array([]), 'name':'S200A1'}) # Do assign pathloss model aperture with similar name. pathlossmod = PathlossModel() datmod.meta.exposure.type = 'NRS_FIXEDSLIT' result, _ = do_correction(datmod, pathlossmod) assert(result.meta.cal_step.pathloss == 'COMPLETE')
def test_do_correction_nis_soss_aperture_is_none(): """If no matching aperture is found, skip correction.""" datmod = MultiSlitModel() # Is FULL an option for NIRISS? # The test doesn't care but something to remember. datmod.slits.append({'data':np.array([]), 'name':'FULL'}) # Don't assign pathloss model aperture with similar name pathlossmod = PathlossModel() datmod.meta.exposure.type = 'NIS_SOSS' datmod.meta.visit.tsovisit = False datmod.meta.instrument.pupil_position = 1 result, _ = do_correction(datmod, pathlossmod) assert(result.meta.cal_step.pathloss == 'SKIPPED')
def test_calculate_pathloss_vector_interpolation(): """Calculate the pathloss vector for when interpolation is necessary.""" datmod = PathlossModel() ref_data = { 'pointsource_data': np.ones((10, 10, 10), dtype=np.float32), 'pointsource_wcs': { 'crval2': -0.5, 'crpix2': 1.0, 'cdelt2': 0.5, 'cdelt3': 1.0, 'crval1': -0.5, 'crpix1': 1.0, 'crpix3': 1.0, 'crval3': 1.0, 'cdelt1': 0.5 } } datmod.apertures.append(ref_data) wavelength, pathloss, is_inside_slitlet = calculate_pathloss_vector( datmod.apertures[0].pointsource_data, datmod.apertures[0].pointsource_wcs, 0.0, 0.0) # Wavelength array is calculated with this: crval3 +(float(i+1) - crpix3)*cdelt3 # Where i is the iteration of np.arange(wavesize) which is the 1st dimension of the pointsource # data array. wavelength_comparison = np.array( [1 + (float(i + 1) - 1.0) * 1 for i in np.arange(10)]) assert (np.all(wavelength == wavelength_comparison)) # In this instance we interpolate to get the array for pathloss VS wavelength. # With the current values inside of the of the pointsource_wcs starting at line 143 of pathloss.py # dx1 = 1 - int(1) = 0.0 # dx2 = 1 - dx1 = 1.0 # dy1 = 1 - int(1) = 0.0 # dy2 = 1 - dx1 = 1.0 # This means a11 == a12 == a21 == 0 and a22 == 1 # This simplifies that pathloss vector to: # pathloss_vector = (a22*pathloss_ref[:,i,j]) = (1*pathloss_ref[:1,j]) # Thus pathloss == the input array to the function. pathloss_comparison = datmod.apertures[0].pointsource_data assert (np.all(pathloss == pathloss_comparison)) # With the current wcs values, the logic should be returning True assert (is_inside_slitlet == True)
def test_calculate_pathloss_vector_pointsource_data(): """Calculate pathloss vector for 3D pathloss data""" datmod = PathlossModel() ref_data = { 'pointsource_data': np.ones((10, 10, 10), dtype=np.float32), 'pointsource_wcs': { 'crval2': -0.5, 'crpix2': 1.0, 'cdelt2': 0.05, 'cdelt3': 1, 'crval1': -0.5, 'crpix1': 1.0, 'crpix3': 1.0, 'crval3': 1, 'cdelt1': 0.05 } } datmod.apertures.append(ref_data) wavelength, pathloss, is_inside_slitlet = calculate_pathloss_vector( datmod.apertures[0].pointsource_data, datmod.apertures[0].pointsource_wcs, 0.0, 0.0) # Wavelength array is calculated with this: crval3 +(float(i+1) - crpix3)*cdelt3 # Where i is the iteration of np.arange(wavesize) which is the 1st dimension of the pointsource # data array. wavelength_comparison = np.array( [1 + (float(i + 1) - 1.0) * 1 for i in np.arange(10)]) assert (np.allclose(wavelength, wavelength_comparison)) # pathloss vector gets assigned at beginning of calculate_pathloss_vector and in this # case, doesnt change (np.zeros(wavesize, dtype=np.float32)) pathloss_comparison = np.zeros(10, dtype=np.float32) assert (np.all(pathloss == pathloss_comparison)) # With the current wcs values, the logic should be returning False assert (is_inside_slitlet == False)
def test_calculate_pathloss_vector_uniform_data(): """Calculate the pathloss vector for uniform data arrays.""" datmod = PathlossModel() ref_data = {'uniform_data':np.ones((10,), dtype=np.float32), 'uniform_wcs': {'crpix1': 1.0, 'cdelt1': 1, 'crval1': 1}} datmod.apertures.append(ref_data) wavelength, pathloss, _ = calculate_pathloss_vector(datmod.apertures[0].uniform_data, datmod.apertures[0].uniform_wcs, 0.0, 0.0) # Wavelength array is calculated with this: crval1 +(float(i+1) - crpix1)*cdelt1 # Where i is the iteration of np.arange(wavesize) which is the shape of the uniform # data array. comparison = np.array([1 +(float(i+1) - 1)*1 for i in np.arange(10)]) assert(np.all(wavelength==comparison)) # The same array is returned in this case assert(np.all(datmod.apertures[0].uniform_data == pathloss))