code: def mem_ds(res, extent, srs=None, dtype=gdal.GDT_Float32):
      
      #These round down to int
      #dst_ns = int((extent[2] - extent[0])/res)
      #dst_nl = int((extent[3] - extent[1])/res)
      #This should pad by 1 pixel, but not if extent and res were calculated together to give whole int
      dst_ns = int((extent[2] - extent[0])/res + 0.99)
      dst_nl = int((extent[3] - extent[1])/res + 0.99)
      m_ds = gdal.GetDriverByName('MEM').Create('', dst_ns, dst_nl, 1, dtype)
      m_gt = [extent[0], res, 0, extent[3], 0, -res]
      m_ds.SetGeoTransform(m_gt)
      if srs is not None:
          m_ds.SetProjection(srs.ExportToWkt())
      return m_ds
docs: Create a new GDAL Dataset in memory
  
      Useful for various applications that require a Dataset