def test_jones(): """ Test when data file has more than one element in Jones matrix. Currently we do not have a testfile, so we will artifically create one and check for internal consistency. """ cal_in = UVCal() cal_out = UVCal() testfile = os.path.join(DATA_PATH, 'zen.2457698.40355.xx.fitsA') write_file = os.path.join(DATA_PATH, 'test/outtest_jones.fits') message = testfile + ' appears to be an old calfits format which' uvtest.checkWarnings(cal_in.read_calfits, [testfile], message=message) # Create filler jones info cal_in.jones_array = np.array([-5, -6, -7, -8]) cal_in.Njones = 4 cal_in.flag_array = np.zeros(cal_in._flag_array.expected_shape(cal_in), dtype=bool) cal_in.gain_array = np.ones(cal_in._gain_array.expected_shape(cal_in), dtype=np.complex64) cal_in.quality_array = np.zeros( cal_in._quality_array.expected_shape(cal_in)) cal_in.write_calfits(write_file, clobber=True) cal_out.read_calfits(write_file) nt.assert_equal(cal_in, cal_out) # Repeat for delay version testfile = os.path.join(DATA_PATH, 'zen.2457698.40355.xx.HH.uvc.fits') message = [ testfile + ' appears to be an old calfits format which', testfile + ' appears to be an old calfits format for delay files' ] uvtest.checkWarnings(cal_in.read_calfits, [testfile], message=message, nwarnings=2) # Create filler jones info cal_in.jones_array = np.array([-5, -6, -7, -8]) cal_in.Njones = 4 cal_in.flag_array = np.zeros(cal_in._flag_array.expected_shape(cal_in), dtype=bool) cal_in.delay_array = np.ones(cal_in._delay_array.expected_shape(cal_in), dtype=np.float64) cal_in.quality_array = np.zeros( cal_in._quality_array.expected_shape(cal_in)) cal_in.write_calfits(write_file, clobber=True) cal_out.read_calfits(write_file) nt.assert_equal(cal_in, cal_out) del (cal_in) del (cal_out)
def test_errors(): """ Test for various errors. """ cal_in = UVCal() cal_out = UVCal() testfile = os.path.join(DATA_PATH, 'zen.2457698.40355.xx.HH.uvc.fits') write_file = os.path.join(DATA_PATH, 'test/outtest_firstcal.fits') message = [testfile + ' appears to be an old calfits format which', testfile + ' appears to be an old calfits format for delay files'] uvtest.checkWarnings(cal_in.read_calfits, [testfile], message=message, nwarnings=2) cal_in.set_unknown_cal_type() nt.assert_raises(ValueError, cal_in.write_calfits, write_file, run_check=False, clobber=True) # change values for various axes in flag and total quality hdus to not match primary hdu uvtest.checkWarnings(cal_in.read_calfits, [testfile], message=message, nwarnings=2) # Create filler jones info cal_in.jones_array = np.array([-5, -6, -7, -8]) cal_in.Njones = 4 cal_in.flag_array = np.zeros(cal_in._flag_array.expected_shape(cal_in), dtype=bool) cal_in.delay_array = np.ones(cal_in._delay_array.expected_shape(cal_in), dtype=np.float64) cal_in.quality_array = np.zeros(cal_in._quality_array.expected_shape(cal_in)) # add total_quality_array so that can be tested as well cal_in.total_quality_array = np.zeros(cal_in._total_quality_array.expected_shape(cal_in)) header_vals_to_double = [{'flag': 'CDELT2'}, {'flag': 'CDELT3'}, {'flag': 'CRVAL5'}, {'totqual': 'CDELT1'}, {'totqual': 'CDELT2'}, {'totqual': 'CRVAL4'}] for i, hdr_dict in enumerate(header_vals_to_double): cal_in.write_calfits(write_file, clobber=True) unit = list(hdr_dict.keys())[0] keyword = hdr_dict[unit] F = fits.open(write_file) data = F[0].data primary_hdr = F[0].header hdunames = uvutils._fits_indexhdus(F) ant_hdu = F[hdunames['ANTENNAS']] flag_hdu = F[hdunames['FLAGS']] flag_hdr = flag_hdu.header totqualhdu = F[hdunames['TOTQLTY']] totqualhdr = totqualhdu.header if unit == 'flag': flag_hdr[keyword] *= 2 elif unit == 'totqual': totqualhdr[keyword] *= 2 prihdu = fits.PrimaryHDU(data=data, header=primary_hdr) hdulist = fits.HDUList([prihdu, ant_hdu]) flag_hdu = fits.ImageHDU(data=flag_hdu.data, header=flag_hdr) hdulist.append(flag_hdu) totqualhdu = fits.ImageHDU(data=totqualhdu.data, header=totqualhdr) hdulist.append(totqualhdu) if float(astropy.__version__[0:3]) < 1.3: hdulist.writeto(write_file, clobber=True) else: hdulist.writeto(write_file, overwrite=True) nt.assert_raises(ValueError, cal_out.read_calfits, write_file, strict_fits=True) # repeat for gain type file testfile = os.path.join(DATA_PATH, 'zen.2457698.40355.xx.fitsA') write_file = os.path.join(DATA_PATH, 'test/outtest_omnical.fits') message = testfile + ' appears to be an old calfits format which' uvtest.checkWarnings(cal_in.read_calfits, [testfile], message=message) # Create filler jones info cal_in.jones_array = np.array([-5, -6, -7, -8]) cal_in.Njones = 4 cal_in.flag_array = np.zeros(cal_in._flag_array.expected_shape(cal_in), dtype=bool) cal_in.gain_array = np.ones(cal_in._gain_array.expected_shape(cal_in), dtype=np.complex64) cal_in.quality_array = np.zeros(cal_in._quality_array.expected_shape(cal_in)) # add total_quality_array so that can be tested as well cal_in.total_quality_array = np.zeros(cal_in._total_quality_array.expected_shape(cal_in)) header_vals_to_double = [{'totqual': 'CDELT1'}, {'totqual': 'CDELT2'}, {'totqual': 'CDELT3'}, {'totqual': 'CRVAL4'}] for i, hdr_dict in enumerate(header_vals_to_double): cal_in.write_calfits(write_file, clobber=True) unit = list(hdr_dict.keys())[0] keyword = hdr_dict[unit] F = fits.open(write_file) data = F[0].data primary_hdr = F[0].header hdunames = uvutils._fits_indexhdus(F) ant_hdu = F[hdunames['ANTENNAS']] totqualhdu = F[hdunames['TOTQLTY']] totqualhdr = totqualhdu.header if unit == 'totqual': totqualhdr[keyword] *= 2 prihdu = fits.PrimaryHDU(data=data, header=primary_hdr) hdulist = fits.HDUList([prihdu, ant_hdu]) totqualhdu = fits.ImageHDU(data=totqualhdu.data, header=totqualhdr) hdulist.append(totqualhdu) if float(astropy.__version__[0:3]) < 1.3: hdulist.writeto(write_file, clobber=True) else: hdulist.writeto(write_file, overwrite=True) nt.assert_raises(ValueError, cal_out.read_calfits, write_file, strict_fits=True)