<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def save(self, filename):
 """Writes the image to a file. Parameters filename : :obj:`str` The file to save the image to. Must be one of .png, .jpg, .npy, or .npz. Raises ------ ValueError If an unsupported file type is specified. """

        filename = str(filename)
        file_root, file_ext = os.path.splitext(filename)
        if file_ext in COLOR_IMAGE_EXTS:
            im_data = self._image_data()
            if im_data.dtype.type == np.uint8:
                pil_image = PImage.fromarray(im_data.squeeze())
                pil_image.save(filename)
            else:
                try:
                    import png
                except:
                    raise ValueError('PyPNG not installed! Cannot save 16-bit images')
                png.fromarray(im_data, 'L').save(filename)
        elif file_ext == '.npy':
            np.save(filename, self._data)
        elif file_ext == '.npz':
            np.savez_compressed(filename, self._data)
        else:
            raise ValueError('Extension %s not supported' % (file_ext))