def _read_file(fname, **kwargs): """ Reading a file with `sunpy.io` for automatic source detection. Parameters ---------- fname : `str` The file path to parse. Returns ------- parsed : `bool` `True` if file has been read. pairs : `list` or `str` List of ``(data, header)`` pairs if ``parsed`` is `True`, ``fname`` if ``parsed`` is `False`. `False` if the file is not supported or incorrect. """ if 'source' not in kwargs.keys() or not kwargs['source']: try: pairs = read_file(fname, **kwargs) new_pairs = [] for pair in pairs: filedata, filemeta = pair if isinstance(filemeta, FileHeader): data = filedata meta = MetaDict(filemeta) new_pairs.append(HDPair(data, meta)) return True, new_pairs except UnrecognizedFileTypeError: return False, fname else: return False, fname
def _read_file(fname, **kwargs): """ Reading a file with `sunpy.io` for automatic source detection. Parameters ---------- fname : `str` The file path to parse. Returns ------- pairs : `list` or `str` List of ``(data, header)`` pairs or ``fname`` if the file is not supported or incorrect. """ if 'source' not in kwargs.keys() or not kwargs['source']: try: if detect_filetype(fname) == 'cdf': # Put import here to ensure there is no import dependency # on cdflib for TimeSeries from sunpy.io.cdf import read_cdf return read_cdf(os.fspath(fname), **kwargs) except UnrecognizedFileTypeError: pass try: pairs = read_file(os.fspath(fname), **kwargs) new_pairs = [] for pair in pairs: filedata, filemeta = pair if isinstance(filemeta, FileHeader): data = filedata meta = MetaDict(filemeta) new_pairs.append(HDPair(data, meta)) return [new_pairs] except UnrecognizedFileTypeError: return [fname] else: return [fname]
def _read_file(self, fname, **kwargs): """ Test reading a file with sunpy.io for automatic source detection. Parameters ---------- fname : filename kwargs Returns ------- parsed : bool True if file has been reading pairs : list or string List of (data, header) pairs if ``parsed`` is ``True`` or ``fname`` if ``False`` """ if 'source' not in kwargs.keys() or not kwargs['source']: try: pairs = read_file(fname, **kwargs) new_pairs = [] for pair in pairs: filedata, filemeta = pair if isinstance(filemeta, FileHeader): data = filedata meta = MetaDict(filemeta) new_pairs.append(HDPair(data, meta)) return True, new_pairs except UnrecognizedFileTypeError: return False, fname else: return False, fname