code: def numpy_array_2d_to_fits(array_2d, file_path, overwrite=False):
      
      if overwrite and os.path.exists(file_path):
          os.remove(file_path)
  
      new_hdr = fits.Header()
      hdu = fits.PrimaryHDU(np.flipud(array_2d), new_hdr)
      hdu.writeto(file_path)
docs: Write a 2D NumPy array to a .fits file.
  
      Before outputting a NumPy array, the array is flipped upside-down using np.flipud. This is so that the arrays \
      appear the same orientation as .fits files loaded in DS9.
  
      Parameters
      ----------
      array_2d : ndarray
          The 2D array that is written to fits.
      file_path : str
          The full path of the file that is output, including the file name and '.fits' extension.
      overwrite : bool
          If True and a file already exists with the input file_path the .fits file is overwritten. If False, an error \
          will be raised.
  
      Returns
      -------
      None
  
      Examples
      --------
      array_2d = np.ones((5,5))
      numpy_array_to_fits(array=array_2d, file_path='/path/to/file/filename.fits', overwrite=True)