docs: def write_asc_grid(x, y, z, filename='output.asc', style=1):
      """Writes gridded data to ASCII grid file (*.asc). This is useful for
      exporting data to a GIS program.
  
      Parameters
      ----------
      x : array_like, shape (N,) or (N, 1)
          X-coordinates of grid points at center of cells.
      y : array_like, shape (M,) or (M, 1)
          Y-coordinates of grid points at center of cells.
      z : array_like, shape (M, N)
          Gridded data values. May be a masked array.
      filename : string, optional
          Name of output *.asc file. Default name is 'output.asc'.
      style : int, optional
          Determines how to write the *.asc file header.
          Specifying 1 writes out DX, DY, XLLCENTER, YLLCENTER.
          Specifying 2 writes out CELLSIZE (note DX must be the same as DY),
          XLLCORNER, YLLCORNER. Default is 1.
      """
  
      if np.ma.is_masked(z):
          z = np.array(z.tolist(-999.))
  
      x = np.squeeze(np.array(x))
      y = np.squeeze(np.array(y))
      z = np.squeeze(np.array(z))
      nrows = z.shape[0]
      ncols = z.shape[1]
  
      if z.ndim != 2:
          raise ValueError("Two-dimensional grid is required to "
                           "write *.asc grid.")
      if x.ndim > 1 or y.ndim > 1:
          raise ValueError("Dimensions of X and/or Y coordinate arrays are not "
                           "as expected. Could not write *.asc grid.")
      if z.shape != (y.size, x.size):
          warnings.warn("Grid dimensions are not as expected. "
                        "Incorrect *.asc file generation may result.",
                        RuntimeWarning)
      if np.amin(x) != x[0] or np.amin(y) != y[0]:
          warnings.warn("Order of X or Y coordinates is not as expected. "
                        "Incorrect *.asc file generation may result.",
                        RuntimeWarning)
  
      dx = abs(x[1] - x[0])
      dy = abs(y[1] - y[0])
      if abs((x[-1] - x[0])/(x.shape[0] - 1)) != dx or \
         abs((y[-1] - y[0])/(y.shape[0] - 1)) != dy:
          raise ValueError("X or Y spacing is not constant; *.asc "
                           "grid cannot be written.")
      cellsize = -1
      if style == 2:
          if dx != dy:
              raise ValueError("X and Y spacing is not the same. "
                               "Cannot write *.asc file in the specified format.")
          cellsize = dx
  
      xllcenter = x[0]
      yllcenter = y[0]
  
      # Note that these values are flagged as -1. If there is a problem in trying
      # to write out style 2, the -1 value will appear in the output file.
      xllcorner = -1
      yllcorner = -1
      if style == 2:
          xllcorner = xllcenter - dx/2.0
          yllcorner = yllcenter - dy/2.0
  
      no_data = -999.
  
      with io.open(filename, 'w') as f:
          if style == 1:
              f.write("NCOLS          " + '{:<10n}'.format(ncols) + '\n')
              f.write("NROWS          " + '{:<10n}'.format(nrows) + '\n')
              f.write("XLLCENTER      " + '{:<10.2f}'.format(xllcenter) + '\n')
              f.write("YLLCENTER      " + '{:<10.2f}'.format(yllcenter) + '\n')
              f.write("DX             " + '{:<10.2f}'.format(dx) + '\n')
              f.write("DY             " + '{:<10.2f}'.format(dy) + '\n')
              f.write("NODATA_VALUE   " + '{:<10.2f}'.format(no_data) + '\n')
          elif style == 2:
              f.write("NCOLS          " + '{:<10n}'.format(ncols) + '\n')
              f.write("NROWS          " + '{:<10n}'.format(nrows) + '\n')
              f.write("XLLCORNER      " + '{:<10.2f}'.format(xllcorner) + '\n')
              f.write("YLLCORNER      " + '{:<10.2f}'.format(yllcorner) + '\n')
              f.write("CELLSIZE       " + '{:<10.2f}'.format(cellsize) + '\n')
              f.write("NODATA_VALUE   " + '{:<10.2f}'.format(no_data) + '\n')
          else:
              raise ValueError("style kwarg must be either 1 or 2.")
  
          for m in range(z.shape[0] - 1, -1, -1):
              for n in range(z.shape[1]):
                  f.write('{:<16.2f}'.format(z[m, n]))
              if m != 0:
                  f.write('\n')