def get_header(filename, debug=False): """ Loads an ANA file and only return the header consisting of the dimensions, size (defined as the product of all dimensions times the size of the datatype, this not relying on actual filesize) and comments. Parameters ---------- filename : `str` Name of file to be read. debug : `bool`, optional Prints verbose debug information. Returns ------- out : `list` A list of `~sunpy.io.header.FileHeader` headers. Examples -------- >>> header = sunpy.io.ana.get_header(filename) # doctest: +SKIP """ if _pyana is None: raise ImportError("C extension for ANA is missing, please rebuild") data = _pyana.fzread(filename, debug) return [FileHeader(data['header'])]
def get_header(filename, debug=False): """ Loads an ANA file and only return the header consisting of the dimensions, size (defined as the product of all dimensions times the size of the datatype, this not relying on actual filesize) and comments. Parameters ---------- filename: string Name of file to be read. debug: bool, optional Prints versbose debug information. Returns ------- out: list A list of FileHeader headers Examples -------- >>> header = sunpy.io.ana.get_header(filename) """ if _pyana is None: raise ImportError("C extension for ANA is missing, please rebuild" ) # pragma: no cover data = _pyana.fzread(filename, debug) return [FileHeader(data['header'])]
def read(filename, debug=False, **kwargs): """ Loads an ANA file and returns the data and a header in a list of (data, header) tuples. Parameters ---------- filename : `str` Name of file to be read. debug : `bool`, optional Prints verbose debug information. Returns ------- out : `list` A list of (data, header) tuples Examples -------- >>> data = sunpy.io.ana.read(filename) # doctest: +SKIP """ if not os.path.isfile(filename): raise IOError("File does not exist!") if _pyana is None: raise ImportError("C extension for ANA is missing, please rebuild.") data = _pyana.fzread(filename, debug) return [HDPair(data['data'], FileHeader(data['header']))]
def get_header(filepath): """ Reads the header from the file Parameters ---------- filepath : `str` The file to be read Returns ------- headers : list A list of headers read from the file """ jp2 = Jp2k(filepath) xml_box = [box for box in jp2.box if box.box_id == 'xml '] xmlstring = ET.tostring(xml_box[0].xml.find('fits')) pydict = xml_to_dict(xmlstring)["fits"] # Fix types for k, v in pydict.items(): if v.isdigit(): pydict[k] = int(v) elif _is_float(v): pydict[k] = float(v) # Remove newlines from comment if 'comment' in pydict: pydict['comment'] = pydict['comment'].replace("\n", "") return [FileHeader(pydict)]
def read(filename, debug=False): """ Loads an ANA file and returns the data and a header in a list of (data, header) tuples. Parameters ---------- filename: string Name of file to be read. debug: bool, optional Prints versbose debug information. Returns ------- out: list A list of (data, header) tuples Examples -------- >>> data = sunpy.io.ana.read(filename) """ if not os.path.isfile(filename): raise IOError("File does not exist!") if _pyana is None: raise ImportError("C extension for ANA is missing, please rebuild" ) # pragma: no cover data = _pyana.fzread(filename, debug) return [(data['data'], FileHeader(data['header']))]
def get_header(afile): """ Read a fits file and return just the headers for all HDU's. In each header, the key WAVEUNIT denotes the wavelength unit which is used to describe the value of the key "WAVELNTH". Parameters ---------- afile : `str` or `astropy.io.fits.HDUList` The file to be read, or HDUList to process. Returns ------- headers : `list` A list of `sunpy.io.header.FileHeader` headers. """ if isinstance(afile, fits.HDUList): hdulist = afile close = False else: hdulist = fits.open(afile, ignore_blank=True) hdulist.verify('silentfix') close = True try: headers = [] for hdu in hdulist: try: comment = "".join(hdu.header['COMMENT']).strip() except KeyError: comment = "" try: history = "".join(hdu.header['HISTORY']).strip() except KeyError: history = "" header = FileHeader(hdu.header) header['COMMENT'] = comment header['HISTORY'] = history # Strip out KEYCOMMENTS to a dict, the hard way keydict = {} for card in hdu.header.cards: if card.comment != '': keydict.update({card.keyword: card.comment}) header['KEYCOMMENTS'] = keydict waveunit = extract_waveunit(header) if waveunit is not None: header['WAVEUNIT'] = waveunit headers.append(header) finally: if close: hdulist.close() return headers
def pixel_from_world(self, hpc_x, hpc_y, normalized=False): """ Get the pixel coordinate from a world coordinate """ fits = self.fits_join.get().fits_file header_dict = FileHeader(fits.get_header_as_dict()) fake_map = Map(np.zeros((1, 1)), header_dict) return mp.pixel_from_world(fake_map, self, hpc_x, hpc_y, normalized=normalized)
def smap(self, data): """Set the value of smap using a dictionary, constructs a fake smap with the desired header :param data: Dict like object from which a header may be constructs :type data: dict-like :returns: None :type return: None """ header_dict = FileHeader(data) fake_map = Map(np.zeros((1, 1)), header_dict) self._smap = fake_map
def get_map(data): """Function get_map: Create a empty with the correct header :param data: TODO :type data: TODO :returns: TODO :type return: TODO """ if issubclass(type(data), GenericMap): return data else: header_dict = FileHeader(data) fake_map = Map(np.zeros((1, 1)), header_dict) return fake_map
def format_comments_and_history(input_header): """ Combine ``COMMENT`` and ``HISTORY`` cards into single entries. Extract ``KEYCOMMENTS`` into a single entry and put ``WAVEUNIT`` into its own entry. Parameters ---------- input_header : `~astropy.io.fits.Header` The header to be processed. Returns ------- `sunpy.io.header.FileHeader` """ try: comment = "".join(input_header['COMMENT']).strip() except KeyError: comment = "" try: history = "".join(input_header['HISTORY']).strip() except KeyError: history = "" header = FileHeader(input_header) header['COMMENT'] = comment header['HISTORY'] = history # Strip out KEYCOMMENTS to a dict, the hard way keydict = {} for card in input_header.cards: if card.comment != '': keydict.update({card.keyword: card.comment}) header['KEYCOMMENTS'] = keydict waveunit = extract_waveunit(header) if waveunit is not None: header['WAVEUNIT'] = waveunit return header
def get_header(filepath): """ Reads the header from the file. Parameters ---------- filepath : `str` The file to be read. Returns ------- headers : list A list of headers read from the file. """ # Put import here to speed up sunpy.io import time from glymur import Jp2k jp2 = Jp2k(filepath) xml_box = [box for box in jp2.box if box.box_id == 'xml '] xmlstring = ET.tostring(xml_box[0].xml.find('fits')) pydict = xml_to_dict(xmlstring)["fits"] # Fix types for k, v in pydict.items(): if v.isdigit(): pydict[k] = int(v) elif _is_float(v): pydict[k] = float(v) # Remove newlines from comment if 'comment' in pydict: pydict['comment'] = pydict['comment'].replace("\n", "") # Is this file a Helioviewer Project JPEG2000 file? pydict['helioviewer'] = xml_box[0].xml.find('helioviewer') is not None return [FileHeader(pydict)]
from astropy.time import Time from astropy.units import Unit, nm, quantity, equivalencies import sunpy from sunpy import config from sunpy.time import parse_time from sunpy.io.header import FileHeader from sunpy.io import fits, file_tools as sunpy_filetools from sunpy.util.types import DatabaseEntryType TIME_FORMAT = config.get("general", "time_format") DEFAULT_HEADER = FileHeader([('SIMPLE', True), ('BITPIX', 8), ('NAXIS', 0), ('EXTEND', True), ('COMMENT', ''), ('HISTORY', ''), ('KEYCOMMENTS', { 'SIMPLE': 'conforms to FITS standard', 'BITPIX': 'array data type', 'NAXIS': 'number of array dimensions' }), ('WAVEUNIT', None)]) __all__ = [ 'WaveunitNotFoundError', 'WaveunitNotConvertibleError', 'JSONDump', 'FitsHeaderEntry', 'FitsKeyComment', 'Tag', 'DatabaseEntry', 'entries_from_query_result', 'entries_from_file', 'entries_from_dir', 'display_entries' ] Base = declarative_base() # required for the many-to-many relation on tags:entries association_table = Table('association', Base.metadata,
def __world_from_pixel_norm(self, x: float, y: float) -> Any: fits = self.fits_join.get().fits_file header_dict = FileHeader(fits.get_header_as_dict()) fake_map = Map(np.zeros((1, 1)), header_dict) return mp.world_from_pixel_norm(fake_map, self, x, y)