def _insert_entity_resources(ovEntity, xnatEntity): xnat = xnatEntity._intf for rsrc in iterate_entity_collection(xnatEntity.resources): label = xnat_api(rsrc.label) if not label: label = "<empty>" for f in iterate_entity_collection(rsrc.files): url, uti = file_info(xnat, f) ovEntity.addURLResource(uti, xnat_api(f.label) + ' (' + label + ')', url)
def import_project(dsc, xnatProject, timezone='UTC'): """ Import a single XNAT project. """ projectID = xnat_api(xnatProject.id) name = xnat_api(xnatProject.attrs.get, 'xnat:projectData/name') purpose = xnat_api(xnatProject.attrs.get, 'xnat:projectData/description') # Find the earliest session date in the project xnat = xnatProject._intf sessionTypes = xnat.inspect.experiment_types() if len(sessionTypes) == 0: sessionTypes = ('xnat:mrSessionData', 'xnat:ctSessionData') #raise XnatImportError("No session types defined in database") minSessionDate = None for sessionType in sessionTypes: columns = (sessionType + '/DATE', sessionType + '/PROJECT') xnat_api_pause() query = xnat.select(sessionType, columns=columns).where([ (sessionType + '/Project', '=', projectID), 'AND' ]) sessionDates = [ datetime.fromtimestamp(mktime(strptime(row['date'], DATE_FORMAT))) for row in query if len(row['date']) > 0 ] if len(sessionDates) > 0: for sd in sessionDates: if minSessionDate is not None: if sd < minSessionDate: minSessionDate = sd else: minSessionDate = sd if minSessionDate is not None: startTime = to_joda_datetime(minSessionDate, timezone) else: startTime = api.datetime() ctx = dsc.getContext() project = ctx.insertProject(name, purpose, startTime) _import_entity_common(project, xnatProject) for s in iterate_entity_collection(xnatProject.subjects): src = import_source(dsc, s) for session in iterate_entity_collection(s.sessions): import_session(dsc, src, project, session) return project
def import_project(dsc, xnatProject, timezone="UTC"): """ Import a single XNAT project. """ projectID = xnat_api(xnatProject.id) name = xnat_api(xnatProject.attrs.get, "xnat:projectData/name") purpose = xnat_api(xnatProject.attrs.get, "xnat:projectData/description") # Find the earliest session date in the project xnat = xnatProject._intf sessionTypes = xnat.inspect.experiment_types() if len(sessionTypes) == 0: sessionTypes = ("xnat:mrSessionData", "xnat:ctSessionData") # raise XnatImportError("No session types defined in database") minSessionDate = None for sessionType in sessionTypes: columns = (sessionType + "/DATE", sessionType + "/PROJECT") xnat_api_pause() query = xnat.select(sessionType, columns=columns).where([(sessionType + "/Project", "=", projectID), "AND"]) sessionDates = [ datetime.fromtimestamp(mktime(strptime(row["date"], DATE_FORMAT))) for row in query if len(row["date"]) > 0 ] if len(sessionDates) > 0: for sd in sessionDates: if minSessionDate is not None: if sd < minSessionDate: minSessionDate = sd else: minSessionDate = sd if minSessionDate is not None: startTime = to_joda_datetime(minSessionDate, timezone) else: startTime = api.datetime() ctx = dsc.getContext() project = ctx.insertProject(name, purpose, startTime) _import_entity_common(project, xnatProject) for s in iterate_entity_collection(xnatProject.subjects): src = import_source(dsc, s) for session in iterate_entity_collection(s.sessions): import_session(dsc, src, project, session) return project
def should_set_subject_datatype_property(self): xnatProject = self._import_first_project()[0] ctx = self.dsc.getContext() for s in iterate_entity_collection(xnatProject.subjects): subjectID = xnat_api(s.id) sources = ctx.getSources(subjectID) eq_(1, len(sources)) eq_(sources[0].getOwnerProperty(DATATYPE_PROPERTY), xnat_api(s.datatype))
def should_import_all_subjects_for_project(self): xnatProject = self._import_first_project()[0] ctx = self.dsc.getContext() for s in iterate_entity_collection(xnatProject.subjects): subjectID = xnat_api(s.id) sources = ctx.getSources(subjectID) eq_(1, len(sources)) eq_(sources[0].getOwnerProperty('xnat:subjectURI'), s._uri)
except (DatabaseError, StopIteration): _log.error("Unable to retrieve parameter " + k) except DatabaseError, e: _log.error("Unable to set parameters") parametersDict = {} parameters = dict2map(parametersDict) scannerParameters = parameters ovation = api.ovation_package() BYTE_DATATYPE = ovation.NumericDataType( ovation.NumericDataFormat.SignedFixedPointDataType, 1, ovation.NumericByteOrder.ByteOrderNeutral) for r in iterate_entity_collection(xnatScan.resources): _log.info(" Resource " + xnat_api(r.label)) # Insert one epoch group per resource group resourceGroup = g.insertEpochGroup(xnat_api(r.label), g.getStartTime()) for f in iterate_entity_collection(r.files): # Import one epoch per resource file e = resourceGroup.insertEpoch( g.getStartTime(), g.getEndTime(), #TODO scanType, parameters) url, uti = file_info(xnatScan._intf, f) _log.info(" File " + xnat_api(r.label))
if k.startswith(dtype + '/parameters/'): parametersDict[k] = xnat_api(xnatScan.attrs.get, k) except (DatabaseError,StopIteration): _log.error("Unable to retrieve parameter " + k) except DatabaseError, e: _log.error("Unable to set parameters") parametersDict = {} parameters = dict2map(parametersDict) scannerParameters = parameters ovation = api.ovation_package() BYTE_DATATYPE = ovation.NumericDataType(ovation.NumericDataFormat.SignedFixedPointDataType, 1, ovation.NumericByteOrder.ByteOrderNeutral) for r in iterate_entity_collection(xnatScan.resources): _log.info(" Resource " + xnat_api(r.label)) # Insert one epoch group per resource group resourceGroup = g.insertEpochGroup(xnat_api(r.label), g.getStartTime()) for f in iterate_entity_collection(r.files): # Import one epoch per resource file e = resourceGroup.insertEpoch( g.getStartTime(), g.getEndTime(), #TODO scanType, parameters ) url,uti = file_info(xnatScan._intf, f)