Ejemplo n.º 1
0
    def _parse_path(self, path, **kwargs):
        results = parse_path(path, self._read_file)
        all_ts = []

        # r can be either a TimeSeries, path, or a data, header pair
        for r in results:
            if isinstance(r, GenericTimeSeries):
                all_ts += [r]
            elif isinstance(r, pathlib.Path):
                all_ts += [
                    self._check_registered_widgets(filepath=r, **kwargs)
                ]
            else:
                pairs = r
                # Pairs may be x long where x is the number of HDUs in the file.
                headers = [pair.header for pair in pairs]

                types = []
                for header in headers:
                    try:
                        match = self._get_matching_widget(meta=header,
                                                          **kwargs)
                        if not match == GenericTimeSeries:
                            types.append(match)
                    except (MultipleMatchError, NoMatchError):
                        continue

                if not types:
                    # If no specific classes have been found we can read the data
                    # if we only have one data header pair:
                    if len(pairs) == 1:
                        all_ts += [
                            GenericTimeSeries(pairs[0]._data, pairs[0].header)
                        ]
                        continue
                    else:
                        raise NoMatchError(
                            "Input read by sunpy.io can not find a "
                            "matching class for reading multiple HDUs")
                if len(set(types)) > 1:
                    raise MultipleMatchError(
                        "Multiple HDUs return multiple matching classes.")

                cls = types[0]

                data_header_unit_tuple = cls._parse_hdus(pairs)
                all_ts += self._parse_arg(data_header_unit_tuple)

        return all_ts
Ejemplo n.º 2
0
 def _parse_path(self, arg, **kwargs):
     return parse_path(arg, self._read_file, **kwargs)