Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def check_valid_ext(self, ext):
"""Check if an extension is valid for reading, and raise ValueError if not.
The ext must both exist and be a table (not an image)
Parameters:
ext (str/int): The extension to check
"""
import fitsio
ext = self._update_ext(ext)
if ext not in self:
raise ValueError("Invalid ext={} for file {} (does not exist)".format(
ext, self.file_name))
if not isinstance(self.file[ext], fitsio.hdu.TableHDU):
raise ValueError("Invalid ext={} for file {} (Not a TableHDU)".format(
ext, self.file_name))
def _append_hdu_info(self, ext):
"""
internal routine
append info for indiciated extension
"""
# raised IOError if not found
hdu_type = self._FITS.movabs_hdu(ext+1)
if hdu_type == IMAGE_HDU:
hdu = ImageHDU(self._FITS, ext)
elif hdu_type == BINARY_TBL:
hdu = TableHDU(
self._FITS, ext,
lower=self.lower, upper=self.upper,
trim_strings=self.trim_strings,
vstorage=self.vstorage, case_sensitive=self.case_sensitive,
iter_row_buffer=self.iter_row_buffer,
write_bitcols=self.write_bitcols)
elif hdu_type == ASCII_TBL:
hdu = AsciiTableHDU(
self._FITS, ext,
lower=self.lower, upper=self.upper,
trim_strings=self.trim_strings,
vstorage=self.vstorage, case_sensitive=self.case_sensitive,
iter_row_buffer=self.iter_row_buffer,
write_bitcols=self.write_bitcols)
else:
mess = ("extension %s is of unknown type %s "
if k_col == '0' and isKColRequired(self.orig_config,num):
raise ValueError("k_col is missing for file %s"%file_name)
if (g1_col != '0' and g2_col == '0') or (g1_col == '0' and g2_col != '0'):
raise ValueError("g1_col, g2_col are invalid for file %s"%file_name)
hdu = treecorr.config.get_from_list(self.config,'hdu',num,int,1)
with fitsio.FITS(file_name, 'r') as fits:
# Technically, this doesn't catch all possible errors. If someone specifies
# an invalid flag_hdu or something, then they'll get the fitsio error message.
# But this should probably catch the majorit of error cases.
if hdu not in fits:
raise ValueError("Invalid hdu=%d for file %s"%(hdu,file_name))
if not isinstance(fits[hdu], fitsio.hdu.TableHDU):
raise ValueError("Invalid hdu=%d for file %s (Not a TableHDU)"%(hdu,file_name))
if x_col != '0':
x_hdu = treecorr.config.get_from_list(self.config,'x_hdu',num,int,hdu)
y_hdu = treecorr.config.get_from_list(self.config,'y_hdu',num,int,hdu)
if x_col not in fits[x_hdu].get_colnames():
raise ValueError("x_col is invalid for file %s"%file_name)
if y_col not in fits[y_hdu].get_colnames():
raise ValueError("y_col is invalid for file %s"%file_name)
if z_col != '0':
z_hdu = treecorr.config.get_from_list(self.config,'z_hdu',num,int,hdu)
if z_col not in fits[z_hdu].get_colnames():
raise ValueError("z_col is invalid for file %s"%file_name)
else:
ra_hdu = treecorr.config.get_from_list(self.config,'ra_hdu',num,int,hdu)
dec_hdu = treecorr.config.get_from_list(self.config,'dec_hdu',num,int,hdu)