# Buggy code
def __init__(self, filename, filename_info, filetype_info):
    """Initialize the reader."""
    super(HRITJMAFileHandler, self).__init__(
        filename,
        filename_info,
        filetype_info,
        (jma_hdr_map, jma_variable_length_headers, jma_text_headers),
    )

    self.mda["segment_sequence_number"] = self.mda["image_segm_seq_no"]
    self.mda["planned_end_segment_number"] = self.mda["total_no_image_segm"]
    self.mda["planned_start_segment_number"] = 1

    items = self.mda["image_data_function"].split("\r")
    if items[0].startswith("$HALFTONE"):
        self.calibration_table = []
        for item in items[1:]:
            if item == "":
                continue
            key, value = item.split(":=")
            if key.startswith("_UNIT"):
                self.mda["unit"] = item.split(":=")[1]
            elif key.startswith("_NAME"):
                pass
            elif key.isdigit():
                key = int(key)
                value = float(value)
                self.calibration_table.append((key, value))

        self.calibration_table = np.array(self.calibration_table)

    sublon = float(self.mda["projection_name"].strip().split("(")[1][:-1])
    self.mda["projection_parameters"]["SSP_longitude"] = sublon


# Traceback (TypeError)
filenames=find_files_and_readers(base_dir='./DK01_201101010030/', reader='hrit_jma')
scn = Scene(filenames=filenames)

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-2-5fb0dc98e3f1> in <module>()
1 filenames=find_files_and_readers(base_dir='./DK01_201101010030/', reader='hrit_jma')
----> 2 scn = Scene(filenames=filenames)

/mnt/c/Users/harry/gdrive/work/2018-02_rerun/data_sources/mtsat/ext/satpy/satpy/scene.py in __init__(self, filenames, reader, filter_parameters, reader_kwargs, ppp_config_dir, base_dir, sensor, start_time, end_time, area)
148         self.readers = self.create_reader_instances(filenames=filenames,
149                                                     reader=reader,
--> 150                                                     reader_kwargs=reader_kwargs)
151         self.attrs.update(self._compute_metadata_from_readers())
152         self.datasets = DatasetDict()

/mnt/c/Users/harry/gdrive/work/2018-02_rerun/data_sources/mtsat/ext/satpy/satpy/scene.py in create_reader_instances(self, filenames, reader, reader_kwargs)
193                             reader=reader,
194                             reader_kwargs=reader_kwargs,
--> 195                             ppp_config_dir=self.ppp_config_dir)
196
197     @property

/mnt/c/Users/harry/gdrive/work/2018-02_rerun/data_sources/mtsat/ext/satpy/satpy/readers/__init__.py in load_readers(filenames, reader, reader_kwargs, ppp_config_dir)
587             loadables = reader_instance.select_files_from_pathnames(readers_files)
588         if loadables:
--> 589             reader_instance.create_filehandlers(loadables)
590             reader_instances[reader_instance.name] = reader_instance
591             remaining_filenames -= set(loadables)

/mnt/c/Users/harry/gdrive/work/2018-02_rerun/data_sources/mtsat/ext/satpy/satpy/readers/yaml_reader.py in create_filehandlers(self, filenames)
485         for filetype, filetype_info in self.sorted_filetype_items():
486             filehandlers = self.new_filehandlers_for_filetype(filetype_info,
--> 487                                                               filename_set)
488
489             filename_set -= set([fhd.filename for fhd in filehandlers])

/mnt/c/Users/harry/gdrive/work/2018-02_rerun/data_sources/mtsat/ext/satpy/satpy/readers/yaml_reader.py in new_filehandlers_for_filetype(self, filetype_info, filenames)
472                                                           filename_iter)
473         filtered_iter = self.filter_fh_by_metadata(filehandler_iter)
--> 474         return list(filtered_iter)
475
476     def create_filehandlers(self, filenames):

/mnt/c/Users/harry/gdrive/work/2018-02_rerun/data_sources/mtsat/ext/satpy/satpy/readers/yaml_reader.py in filter_fh_by_metadata(self, filehandlers)
445     def filter_fh_by_metadata(self, filehandlers):
446         """Filter out filehandlers using provide filter parameters."""
--> 447         for filehandler in filehandlers:
448             filehandler.metadata['start_time'] = filehandler.start_time
449             filehandler.metadata['end_time'] = filehandler.end_time

/mnt/c/Users/harry/gdrive/work/2018-02_rerun/data_sources/mtsat/ext/satpy/satpy/readers/yaml_reader.py in new_filehandler_instances(self, filetype_info, filename_items)
389                 continue
390
--> 391             yield filetype_cls(filename, filename_info, filetype_info, *req_fh)
392
393     def time_matches(self, fstart, fend):

/mnt/c/Users/harry/gdrive/work/2018-02_rerun/data_sources/mtsat/ext/satpy/satpy/readers/hrit_jma.py in __init__(self, filename, filename_info, filetype_info)
116         self.mda['planned_start_segment_number'] = 1
117
--> 118         items = self.mda['image_data_function'].split('\r')
119         if items[0].startswith('$HALFTONE'):
120             self.calibration_table = []

TypeError: a bytes-like object is required, not 'str'

# Fixed code
def __init__(self, filename, filename_info, filetype_info):
    """Initialize the reader."""
    super(HRITJMAFileHandler, self).__init__(
        filename,
        filename_info,
        filetype_info,
        (jma_hdr_map, jma_variable_length_headers, jma_text_headers),
    )

    self.mda["segment_sequence_number"] = self.mda["image_segm_seq_no"]
    self.mda["planned_end_segment_number"] = self.mda["total_no_image_segm"]
    self.mda["planned_start_segment_number"] = 1

    items = self.mda["image_data_function"].decode().split("\r")
    if items[0].startswith("$HALFTONE"):
        self.calibration_table = []
        for item in items[1:]:
            if item == "":
                continue
            key, value = item.split(":=")
            if key.startswith("_UNIT"):
                self.mda["unit"] = item.split(":=")[1]
            elif key.startswith("_NAME"):
                pass
            elif key.isdigit():
                key = int(key)
                value = float(value)
                self.calibration_table.append((key, value))

        self.calibration_table = np.array(self.calibration_table)

    projection_name = self.mda["projection_name"].decode()
    sublon = float(projection_name.strip().split("(")[1][:-1])
    self.mda["projection_parameters"]["SSP_longitude"] = sublon