How to use the ndlib.ndtype.READONLY_TRUE function in ndlib

To help you get started, we’ve selected a few ndlib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github neurodata / ndstore / django / stats / views.py View on Github external
m = re.match(r"(?P[\w+]+)/(?P[\w+]+)/genhist/$", webargs)
      [token, channel] = [i for i in m.groups()]
    except Exception, e:
      logger.error("Incorrect format for web arguments {}. {}".format(webargs, e))
      return HttpResponseBadRequest("Incorrect format for web arguments {}. {}".format(webargs, e))

    # check to make sure token exists
    tokenobj = get_object_or_404(Token, token_name = token)
    # get the project
    projectobj = tokenobj.project
    # get the channel
    chanobj = get_object_or_404(Channel, project = projectobj, channel_name = channel)
    # get the dataset
    datasetobj = projectobj.dataset

    if (chanobj.readonly == READONLY_TRUE):
      # we can only generate histograms on writeable channels
      return HttpResponseBadRequest("Error: Channel must not be readonly to generate histograms.")

    # now that we have a channel, kickoff the background job that will generate the histogram
    # determine number of bits (2**bits = numbins)
    if (chanobj.channel_datatype == UINT8):
      bits = 8
    elif (chanobj.channel_datatype == UINT16):
      bits = 16
    #elif (chanobj.channel_datatype == UINT32):
      #  bits = 32
    else:
      return HttpResponseBadRequest("Error: Unsupported datatype ({})".format(chanobj.channel_datatype))

    if 'ROI' in params.keys():
      # run one histogram task for each ROI
github neurodata / ndstore / webservices / ndwsrest.py View on Github external
try:
    m = re.match("(\w+)/(\w+)/setField/(\d+)/(\w+)/(\w+|[\d+,.]+)/$", webargs)
    [token, channel, annid, field, value] = [i for i in m.groups()]
  except:
    logger.error("Illegal setField request. Wrong number of arguments. Web Args: {}".format(webargs))
    raise NDWSError("Illegal setField request. Wrong number of arguments. Web Args:{}".format(webargs))
    
  with closing (NDProjectsDB()) as projdb:
    proj = projdb.loadToken ( token )

  with closing (RamonDB(proj)) as rdb:
    ch = NDChannel.fromName(proj, channel)
    
    # Don't write to readonly channels
    if ch.readonly == READONLY_TRUE:
      logger.error("Attempt to write to read only channel {} in project. Web Args:{}".format(ch.getChannelName(), proj.project_name, webargs))
      raise NDWSError("Attempt to write to read only channel {} in project. Web Args: {}".format(ch.getChannelName(), proj.project_name, webargs))
    
    rdb.updateAnnotation(ch, annid, field, value)
github neurodata / ndstore / webservices / ndwsnifti.py View on Github external
def ingestNIFTI ( niftifname, ch, db, proj ):
  """Ingest the nifti file into a database. No cutout arguments. Must be an entire channel."""     

  # load the nifti data
  nifti_img = nibabel.load(niftifname)
  nifti_data = np.array(nifti_img.get_data())
  
  # Don't write to readonly channels
  if ch.readonly == READONLY_TRUE:
    logger.warning("Attempt to write to read only channel {} in project {}".format(ch.channel_name, proj.project_name))
    raise NDWSError("Attempt to write to read only channel {} in project {}".format(ch.channel_name, proj.project_name))

  # check that the data is the right shape
  if nifti_data.shape != tuple(proj.datasetcfg.dataset_dim(0)) and nifti_data.shape != tuple(proj.datasetcfg.dataset_dim(0) + [ch.time_range[1]-ch.time_range[0]+1]):
    logger.warning("Not correct shape")
    raise NDWSError("Not correct shape")
    
  nifti_data = nifti_data.transpose()

  nifti_data = np.array(nifti_data,ND_dtypetonp[ch.channel_datatype])

  # create the nifti header
  nh = NDNiftiHeader.fromImage(ch, nifti_img)

  try: