def ingestNIFTI ( niftifname, ch, db, proj ):     

  # load the nifti data
  nifti_img = nibabel.load(niftifname)
  nifti_data = np.array(nifti_img.get_data())

  if len(nifti_data.shape) == 3:

    # reshape the nifti data to include a channel dimension
    nifti_data = nifti_data.transpose()
    
    if ch.getDataType() in DTYPE_uint16:   
      nifti_data = np.uint16(nifti_data.reshape([1]+list(nifti_data.shape)))
    elif ch.getDataType() in DTYPE_float32:
      nifti_data = np.float32(nifti_data.reshape([1]+list(nifti_data.shape)))
    else:
      logger.warning("Illegal data type for NIFTI service. Type={}".format(ch.getDataType()))
      raise OCPCAError("Illegal data type for NIFTI service. Type={}".format(ch.getDataType()))

    # check that the data is the right shape
    if nifti_data.shape[1:] != tuple(proj.datasetcfg.imagesz[0]):
      logger.warning("Data shape {} does not match dataset shape {}.".format(nifti_data.shape, proj.datasetcfg.imagesz[0]))
      raise OCPCAError("Data shape {} does not match dataset shape {}.".format(nifti_data.shape, proj.datasetcfg.imagesz[0]))

  elif len(nifti_data.shape) == 4:

    # reshape the nifti data to include a channel dimension
    nifti_data = nifti_data.transpose()
    nifti_data = nifti_data.reshape([1]+list(nifti_data.shape))

    # check that the data is the right shape
    if nifti_data.shape[1:3] != tuple(proj.datasetcfg.imagesz[0]) or nifti_data.shape[4] != proj.datasetcfg.endtime - proj.datasetcfg.starttime:
      logger.warning("Data shape {} does not match dataset shape {}.".format(nifti_data.shape, proj.datasetcfg.imagesz[0]))
      raise OCPCAError("Data shape {} does not match dataset shape {}.".format(nifti_data.shape, proj.datasetcfg.imagesz[0]))

  # Don't write to readonly channels
  if ch.getReadOnly() == READONLY_TRUE:
    logger.warning("Attempt to write to read only project {}".format(proj.getDBName()))
    raise OCPCAError("Attempt to write to read only project {}".format(proj.getDBName()))

  if not nifti_data.dtype == OCP_dtypetonp[ch.getDataType()]:
    logger.warning("Wrong datatype in POST")
    raise OCPCAError("Wrong datatype in POST")

  # create the model and populate
  nh = NIFTIHeader()
  nh.channel_id = ch.getChannelModel().id

  # dump the header 
  nh.header = pickle.dumps(nifti_img.header)

  # dump the affine transform 
  nh.affine = pickle.dumps(nifti_img.affine)
 
  if ch.getChannelType() in IMAGE_CHANNELS:
    db.writeCuboid ( ch, (0,0,0), 0, nifti_data )

  elif ch.getChannelType() in TIMESERIES_CHANNELS:
    db.writeTimeCuboid(ch, corner, 0, timerange, nifti_data)

  else:
    logger.warning("Writing to a channel with an incompatible data type. {}" % (ch.getChannelType()))
    raise OCPCAError ("Writing to a channel with an incompatible data type. {}" % (ch.getChannelType()))

  # save the header if the data was written
  nh.save()
Computes the nonzero componentwise L1 cross-distances between the vectors
dataset/ETHPy150Open neurodata/ndstore/ocpca/ocpcanifti.py/ingestNIFTI--crossover with--dataset/ETHPy150Open OpenMDAO/OpenMDAO-Framework/openmdao.lib/src/openmdao/lib/surrogatemodels/multifi_cokriging_surrogate.py/l1_cross_distances