Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_frame_type_missing(self) -> None:
with fits.open(self.fitsfile) as hdulist:
hdulist[10].header.remove('ESO DET FRAM TYPE')
hdulist.writeto(self.fitsfile, overwrite=True)
module = NearReadingModule(name_in='read6',
input_dir=self.test_dir+'near',
chopa_out_tag=self.positions[0],
chopb_out_tag=self.positions[1])
self.pipeline.add_module(module)
with pytest.raises(ValueError) as error:
self.pipeline.run_module('read6')
assert str(error.value) == 'Frame type not found in the FITS header. Image number: 9.'
def test_near_median(self) -> None:
module = NearReadingModule(name_in='read1c',
input_dir=self.test_dir+'near',
chopa_out_tag=self.positions[0],
chopb_out_tag=self.positions[1],
combine='median')
self.pipeline.add_module(module)
self.pipeline.run_module('read1c')
data = self.pipeline.get_data(self.positions[0])
assert np.mean(data) == pytest.approx(0.060582854, rel=self.limit, abs=0.)
assert data.shape == (2, 10, 10)
data = self.pipeline.get_data(self.positions[1])
assert np.mean(data) == pytest.approx(0.060582854, rel=self.limit, abs=0.)
assert data.shape == (2, 10, 10)
def test_check_header(self) -> None:
with fits.open(self.fitsfile) as hdulist:
hdulist[0].header['ESO DET CHOP ST'] = 'F'
hdulist[0].header['ESO DET CHOP CYCSKIP'] = 1
hdulist[0].header['ESO DET CHOP CYCSUM'] = 'T'
hdulist.writeto(self.fitsfile, overwrite=True)
module = NearReadingModule(name_in='read4',
input_dir=self.test_dir+'near',
chopa_out_tag=self.positions[0],
chopb_out_tag=self.positions[1])
self.pipeline.add_module(module)
with pytest.warns(UserWarning) as warning:
self.pipeline.run_module('read4')
assert len(warning) == 3
assert warning[0].message.args[0] == 'Dataset was obtained without chopping.'
assert warning[1].message.args[0] == 'Chop cycles (1) have been skipped.'
assert warning[2].message.args[0] == 'FITS file contains averaged images.'
with fits.open(self.fitsfile) as hdulist:
def test_near_subtract_crop_mean(self) -> None:
module = NearReadingModule(name_in='read1b',
input_dir=self.test_dir+'near',
chopa_out_tag=self.positions[0],
chopb_out_tag=self.positions[1],
subtract=True,
crop=(None, None, 0.3),
combine='mean')
self.pipeline.add_module(module)
self.pipeline.run_module('read1b')
data = self.pipeline.get_data(self.positions[0])
assert np.mean(data) == pytest.approx(0., rel=self.limit, abs=0.)
assert data.shape == (2, 7, 7)
data = self.pipeline.get_data(self.positions[1])
assert np.mean(data) == pytest.approx(0., rel=self.limit, abs=0.)
with fits.open(self.fitsfile) as hdulist:
with pytest.warns(UserWarning) as warning:
hdulist[10].header['ESO DET FRAM TYPE'] = 'HCYCLE1'
assert len(warning) == 1
assert warning[0].message.args[0] == 'Keyword name \'ESO DET FRAM TYPE\' is greater ' \
'than 8 characters or contains characters not ' \
'allowed by the FITS standard; a HIERARCH card ' \
'will be created.'
hdulist.writeto(self.fitsfile, overwrite=True)
module = NearReadingModule(name_in='read7',
input_dir=self.test_dir+'near',
chopa_out_tag=self.positions[0],
chopb_out_tag=self.positions[1])
self.pipeline.add_module(module)
with pytest.warns(UserWarning) as warning:
self.pipeline.run_module('read7')
assert len(warning) == 2
assert warning[0].message.args[0] == 'Previous and current chop position (HCYCLE1) are ' \
'the same. Skipping the current image.'
assert warning[1].message.args[0] == 'The number of images is not equal for chop A and ' \
'chop B.'
def test_frame_type_invalid(self) -> None:
with fits.open(self.fitsfile) as hdulist:
hdulist[10].header['ESO DET FRAM TYPE'] = 'Test'
hdulist.writeto(self.fitsfile, overwrite=True)
module = NearReadingModule(name_in='read5',
input_dir=self.test_dir+'near',
chopa_out_tag=self.positions[0],
chopb_out_tag=self.positions[1])
self.pipeline.add_module(module)
with pytest.raises(ValueError) as error:
self.pipeline.run_module('read5')
assert str(error.value) == 'Frame type (Test) not a valid value. Expecting HCYCLE1 or ' \
'HCYCLE2 as value for ESO DET FRAM TYPE.'
def test_near_read(self) -> None:
module = NearReadingModule(name_in='read1a',
input_dir=self.test_dir+'near',
chopa_out_tag=self.positions[0],
chopb_out_tag=self.positions[1])
self.pipeline.add_module(module)
self.pipeline.run_module('read1a')
for item in self.positions:
data = self.pipeline.get_data(item)
assert np.mean(data) == pytest.approx(0.060582854, rel=self.limit, abs=0.)
assert data.shape == (10, 10, 10)