def create_resource(path, name, r, c, field):
    files = []
    for t in T:
        for z in Z:
            for ch in CH:
                if ch in CH_Z:
                    filename = '%s%s%st%.3d%s%.2df%.2dd%sz%s.%s'%(path, dir_z, name, t, r, c, field, ch, z, ext_z)
                else:
                    filename = '%s%s%st%.3d%s%.2df%.2dd%s.%s'%(path, dir_p, name, t, r, c, field, ch, ext_p)
                files.append(filename)

    resource = etree.Element ('image', name='%s_%s_%s_%s'%(name, r, c, field))

    meta = etree.SubElement (resource, 'tag', name='image_meta', type='image_meta')
    etree.SubElement (meta, 'tag', name='image_num_c', value=str(len(CH)), type='number')
    etree.SubElement (meta, 'tag', name='image_num_z', value=str(len(Z)), type='number')
    etree.SubElement (meta, 'tag', name='image_num_t', value=str(len(T)), type='number')
    etree.SubElement (meta, 'tag', name='dimensions', value='XYCZT')

    etree.SubElement (meta, 'tag', name='channel_0_name', value='Hoechst')
    etree.SubElement (meta, 'tag', name='channel_1_name', value='cmfda')
    etree.SubElement (meta, 'tag', name='channel_2_name', value='LysoTrackerRed')

    etree.SubElement (meta, 'tag', name='channel_color_0', value='0,0,255')
    etree.SubElement (meta, 'tag', name='channel_color_1', value='0,255,0')
    etree.SubElement (meta, 'tag', name='channel_color_2', value='255,0,0')

    etree.SubElement (resource, 'tag', name='row', value='%s'%r)
    etree.SubElement (resource, 'tag', name='column', value='%s'%c, type='number')
    etree.SubElement (resource, 'tag', name='field', value='%s'%field, type='number')

    for f in files:
        v = etree.SubElement (resource, 'value')
        v.text = localpath2url(f)
    return resource
##################################################################
# Upload
##################################################################


config = ConfigParser.ConfigParser()
config.read('config.cfg')

root = config.get('Host', 'root') or 'localhost:8080'
user = config.get('Host', 'user') or 'test'
pswd = config.get('Host', 'password') or 'test'

session = BQSession().init_local(user, pswd,  bisque_root=root, create_mex=False)

request = '<image name="%s">'%'series_t_jpeg'
request = '%s<value>%s</value>'%(request, localpath2url('f:/dima/develop/python/bq5irods/data/imagedir/admin/tests/multi_file/series_t_jpeg/t_000241.jpg'))
request = '%s<value>%s</value>'%(request, localpath2url('f:/dima/develop/python/bq5irods/data/imagedir/admin/tests/multi_file/series_t_jpeg'))
request = '%s<tag name="%s" type="%s">'%(request, 'image_meta', 'image_meta')
request = '%s<tag name="%s" value="%s" type="number" />'%(request, 'image_num_z', '1')
request = '%s<tag name="%s" value="%s" type="number" />'%(request, 'image_num_t', '80')
request = '%s<tag name="%s" value="%s" />'%(request, 'dimensions', 'XYCZT')
request = '%s<tag name="%s" value="%s" type="number" />'%(request, 'pixel_resolution_x', '0.4')
request = '%s<tag name="%s" value="%s" type="number" />'%(request, 'pixel_resolution_y', '0.4')
request = '%s<tag name="%s" value="%s" type="number" />'%(request, 'pixel_resolution_t', '2.0')
request = '%s<tag name="%s" value="%s" />'%(request, 'pixel_resolution_unit_x', 'micron')
request = '%s<tag name="%s" value="%s" />'%(request, 'pixel_resolution_unit_y', 'micron')
request = '%s<tag name="%s" value="%s" />'%(request, 'pixel_resolution_unit_t', 'seconds')
request = '%s</tag>'%(request)
request = '%s</image>'%request

#url = session.service_url('data_service', 'image')
# Upload
##################################################################

config = ConfigParser.ConfigParser()
config.read('config.cfg')

root = config.get('Host', 'root') or 'localhost:8080'
user = config.get('Host', 'user') or 'test'
pswd = config.get('Host', 'password') or 'test'

session = BQSession().init_local(user,
                                 pswd,
                                 bisque_root=root,
                                 create_mex=False)

url = urlparse.urljoin(root, url_import)
request = request_xml.replace('{NAME}', 'cx-11.sld#3')
request = request.replace(
    '{PATH}',
    localpath2url(
        'f:/dima/develop/python/bq5irods/data/imagedir/admin/tests/multi_image/Slidebook/cx-11.sld'
    ))
request = request.replace('{SERIES}', '3')

r = save_blob(session, resource=request)
if r is None or r.get('uri') is None:
    print 'Upload failed'
else:
    print 'id: %s' % r.get('resource_uniq')
    print 'url: %s' % r.get('uri')
    def teardown(self):
        self.bq.update_mex('Collecting result...')
        # Post all submex for files and return xml list of results
        #gobjects = self._read_results()
        #tags = [{ 'name': 'outputs',
        #          'tag' : [{'name': 'rootimage', 'type':'image', 'value':self.resource_url,
        #                    'gobject' : [{ 'name': 'root_tips', 'type': 'root_tips', 'gobject' : gobjects }] }]
        #          }]
        #self.bq.finish_mex(tags = tags)
        
#         mex_outputs = self.bq.mex.xmltree.xpath('tag[@name="outputs"]')
#         logging.debug('Outputs mex:' + str(mex_outputs))
#         if mex_outputs:
#             logging.debug('Outputs mex:' + str(mex_outputs))
#             
#             for tag in mex_outputs[0]:
#                 if tag.tag == 'tag' and tag.attrib['name'] == 'TipDetection':
#                     tag.attrib['value'] = "390"
# #                 if tag.tag == 'tag' and tag.attrib['type'] != 'system-input':
# #                     logging.debug('Set options with %s as %s'%(tag.attrib['name'],tag.attrib['value']))
#                     setattr(options,tag.attrib['name'],tag.attrib['value'])
#         else:
#             logging.debug('No Outputs Found on MEX!')
        
        #load result data from the xml file. For testing, just use the fix xml i.e. will be changed later time
        #resultfile = os.path.join(self.options.stagingPath, '0002.jpg_result.xml')
        #reload parameters
        self.mex_parameter_parser(self.options, self.bq.mex.xmltree)
        #get the image downloaded
        image = self.bq.load(self.options.image_url)
        imageDownloaded = image.name + ".tif"
        
        resultfile = os.path.join(self.options.stagingPath, imageDownloaded + '_result.xml')
        
        logging.debug('Result file: ' + resultfile)
    
        #load the result file and display info.
#       tree.parse('/home/tuan/bisque/modules/RootNavLinuxModuleV3/0002.jpg_result.xml')
        tree = etree.ElementTree()
        tree.parse(resultfile)
        rootNode = tree.getroot()
#         
        logging.debug('Root node: ' + rootNode.tag)
#          
        # # look for the Tips Output tag
        tipDetectionNode = rootNode.findall("./Output/TipsDetected")
        
        outputTag = etree.Element('tag', name='outputs')
        outputSubTag = etree.SubElement(outputTag, 'tag', name='summary')
        
        if len(tipDetectionNode) > 0:
            
            totalAttrib = tipDetectionNode[0].get('total')
            
            logging.debug('tipDetectionNode : ' + totalAttrib)
            
            ##etree.SubElement(outputTag, 'tag', name='TipDetection', value=str(23))
            #etree.SubElement( outputSubTag, 'tag', name='Tip(s) detected', value=str(23))
            
            
            etree.SubElement( outputSubTag, 'tag', name='Tip(s) detected', value=totalAttrib)
            
           
            #using testing image: /home/tuan/bisque/modules/RootNavLinuxModuleV3/FeatureMapInMain.png
            #filepath = '/home/tuan/bisque/modules/RootNavLinuxModuleV3/FeatureMapInMain.png'
            #filepath = '/home/tuan/bisque/modules/RootNavLinuxModuleV3/0002_copy.jpg'
            #just for testing
           
            outputImgTag = etree.SubElement(outputTag, 'tag', name='OutputImage', value=self.options.image_url)
            #outputImgTag = etree.SubElement(outputTag, 'tag', name='OutputImage', value=localpath2url(filepath))
            #gObjectValue = ""
            #gObjectTag = etree.SubElement(outputImgTag, 'gobject', name='PointsDetected')
            logging.debug('appending children to the output image tag')
            gObjectTag = rootNode.findall("./Output/TipsDetected/gobject")[0]
            outputImgTag.append(gObjectTag)
            
            #test colour (this works for one point, change colour from red to yello)
            #etree.SubElement(gObjectTag[0], 'tag', name='color', value="#ffff00")
            
            #for tip in tipDetectionNode[0]:
            #    gPoint = etree.SubElement(gObjectTag, 'point', name=tip.attrib['id'])
            #    etree.SubElement(gPoint, 'vertex', x=tip.attrib['x'], y=tip.attrib['y'])
             
        #display root info
        #rootsTopMostNodes = rootNode.findall("./Output/RootTree/Root")
        
        rootsTopMostNodes = rootNode.xpath('./Output/RootTree/Root[@order="-1"]')
        
        for root in rootsTopMostNodes:
            etree.SubElement( outputSubTag, 'tag', name='Root length', value=root.get('length'))
            etree.SubElement( outputSubTag, 'tag', name='Root area', value=root.get('area'))
            etree.SubElement( outputSubTag, 'tag', name='Primary root', value=root.get('primaryRoots'))     
            
            
            #outputExtraImgTag = etree.SubElement(outputTag, 'tag', name='OutputExtraImage', value=self.options.image_url)
            
        #resource = etree.Element ('image', name=os.path.basename(filepath), value=localpath2url(filepath))
        #meta = etree.SubElement (resource, 'tag', name='Experimental')
        #etree.SubElement (meta, 'tag', name='numberpoints', value="12")
        
        #resource = etree.Element ('image', name='new file %s'%(os.path.basename(filepath)))
                     
        #logging.debug('resource: ' + str(resource))
        
        
        #self.uploadFileToServer(filepath)
        
        logging.debug('self.bq.service_map in teardown: ' + str(self.bq.service_map))
            
        #url = self.bq.service_url('data_service', 'image')
        #url = self.bq.service_url('blob_service')
        #url = self.bq.service_url('image_service', 'image') ##couldnt use for upload
        #url = self.bq.service_url('/import/transfer') #not a service
        #url = self.bq.service_url('import', 'transfer') #not a service
        #url = self.bq.service_url('import', path='transfer') #not a service
        #url = self.bq.service_url('http://127.0.0.1:8080/', '/import/transfer') #not a service
        #response = save_blob(self.bq, resource=resource)
        
        #logging.debug('url : ' + str(url))
        #response_xml = self.bq.postblob(localpath2url(filepath), xml=resource) #post image to bisque and get the response
        
        #logging.debug('response_xml: ' + str(response_xml))
        
        #r =  self.bq.postxml(url, resource, method='POST')
        
        
        #logging.debug('Response: ' + str(r))
        
        #response = self.bq.postblob(filepath, xml=resource)
        #response = self.bq.postblob(filepath, xml=resource)
        #blob = etree.XML(response).find('./')
        
        
        # if blob is None or blob.get('uri') is None:
        #    logging.debug('Could not insert the Histogram file into the system')
        #    self.bq.fail_mex('Could not insert the Histogram file into the system')
        # else:
            # outputExtraImgTag = etree.SubElement(outputTag, 'tag', name='/home/tuan/bisque/modules/RootNavLinuxModuleV3/FeatureMapInMain.png')
        #    outputExtraImgTag = etree.SubElement(outputTag, 'tag', name='OutputExtraImage', value=blob.get('uri'), type='image')
            
       # if r is None or r.get('uri') is None:
        #    logging.debug('Could not insert the Histogram file into the system')
       #     self.bq.fail_mex('Could not insert the Histogram file into the system')
       # else:
            # outputExtraImgTag = etree.SubElement(outputTag, 'tag', name='/home/tuan/bisque/modules/RootNavLinuxModuleV3/FeatureMapInMain.png')
        #    logging.debug('resource id: %s' %r.get('resource_uniq'))
        #    logging.debug('url: %s' %r.get('uri'))
        #    outputExtraImgTag = etree.SubElement(outputTag, 'tag', name='OutputExtraImage', value=r.get('uri'), type='image')
            # outputExtraImgTag = etree.SubElement(outputImgTag, 'tag', name='OutputExtraImage', value=r.get('value'), type='image')
        #etree.SubElement(outputTag, 'tag', name='OutputImage', value='/home/tuan/bisque/modules/RootNavLinuxModuleV3/FeatureMapInMain.png')
        
        #etree.SubElement(outputTag, 'tag', name='OutputImage', value='file:///home/tuan/bisque/modules/RootNavLinuxModuleV3/FeatureMapInMain.png')
        
        ##########################
        #upload the probability image
        outputFileNode = rootNode.findall("./Output/File")
        
        probabilityimagepathNode = outputFileNode[0].find("ProbabilityImageFile").text
        
        imagefile = os.path.basename(probabilityimagepathNode)
        #get mexid
        parts = self.options.stagingPath.split('/')
        mexid = parts[len(parts) - 1]
        
        resource = etree.Element ('image', name=os.path.join(UPLOADED_FOLDER, mexid, imagefile))
        
        response = self.postblobbytxn(self.bq, (probabilityimagepathNode), xml=resource)
        blob = etree.XML(response).find('./')
        
        if blob is None or blob.get('uri') is None:
            logging.debug('Could not upload the probability image file into the system')
            self.bq.fail_mex('Could not upload the probability image file into the system')
        else:
            ##create node for mex
            linkprobabilityimgupload = blob.get('uri')
            
            probabilityImageTag = etree.SubElement(outputTag, 'tag', name='ProbabilityImage', value=linkprobabilityimgupload, type='image')
        
        
        #######################################################
        
        #output shortest paths
        outputPathImgTag = etree.SubElement(outputTag, 'tag', name='OutputPathImage', value=self.options.image_url)
        
        #get primary paths
        primaryPathsNode = rootNode.findall("./Output/PrimaryPaths")
        if (primaryPathsNode is not None) and (len(primaryPathsNode) > 0):
            for path in primaryPathsNode[0]:
                outputPathImgTag.append(path)
        
        #get lateral paths
        lateralPathsNode = rootNode.findall("./Output/LateralPaths")
        if (lateralPathsNode is not None) and (len(lateralPathsNode) > 0):
            for path in lateralPathsNode[0]:
                outputPathImgTag.append(path)
        
        #node to display the root and convex hull
        outputRootImgTag = etree.SubElement(outputTag, 'tag', name='OutputRootsImage', value=self.options.image_url)
         
        gObjectRootNode = etree.SubElement(outputRootImgTag, 'gobject', name='Roots')
         
        splineInOtherRootsNodes = rootNode.xpath('./Output/RootTree/Root[@order!="-1"]/Spline')
        for spline in splineInOtherRootsNodes:
            #outputRootImgTag.append(spline[0])
            gObjectRootNode.append(spline[0])
         
        for root in rootsTopMostNodes:
            convexNodes = root.findall('ConvexHull')
            for cx in convexNodes:
                #outputRootImgTag.append(cx[0])                
                gObjectRootNode.append(cx[0])
        
        #get data for measurement table
        measurementTablesNode =  rootNode.xpath('./Output/Measurement/Tables')
                
        if (measurementTablesNode is not None and len (measurementTablesNode) > 0):
            #outputRootImgTag.append(measurementTablesNode[0])
            gObjectRootNode.append(measurementTablesNode[0])
        
        #get data for curvature profile
        curvNode = etree.SubElement(gObjectRootNode, 'tag', name='CurvatureProfile')
        curvatureProfileDataNode = rootNode.xpath('./Output/Measurement/CurvatureProfile')
        if (curvatureProfileDataNode is not None and len (curvatureProfileDataNode) > 0):
            for rowDataNode in curvatureProfileDataNode[0]:
                #gObjectRootNode.append()
                gObjectCurv = etree.SubElement(curvNode, 'gobject', type='row')
                etree.SubElement(gObjectCurv, 'tag', name='col0', value=rowDataNode.attrib['col0'])
                etree.SubElement(gObjectCurv, 'tag', name='col1', value=rowDataNode.attrib['col1'])
            
        #get data for travel map
        mapNode = etree.SubElement(gObjectRootNode, 'tag', name='MapProfile')
        mapProfileDataNode = rootNode.xpath('./Output/Measurement/MapProfile')
        if (mapProfileDataNode is not None and len (mapProfileDataNode) > 0):
            #gObjectRootNode.append(mapProfileDataNode[0])
            for rowDataNode in mapProfileDataNode[0]:
                gObjectMap = etree.SubElement(mapNode, 'gobject', type='row')
                etree.SubElement(gObjectMap, 'tag', name='col0', value=rowDataNode.attrib['col0'])
                etree.SubElement(gObjectMap, 'tag', name='col1', value=rowDataNode.attrib['col1'])
                etree.SubElement(gObjectMap, 'tag', name='col2', value=rowDataNode.attrib['col2'])
            
        #get data for RSML file for downloading 
        #extract rsml file from xml data
        inputFileNode = rootNode.findall("./Input/File")
        rsmlFileNode = inputFileNode[0].find("RSMLFile").text
        rsmlPathNode = inputFileNode[0].find("RSMLPath").text
                
        #upload rsml file
        parts = self.options.stagingPath.split('/')
        mexid = parts[len(parts) - 1]
        resultrsmlfile = os.path.join(rsmlPathNode, rsmlFileNode)
        #resource = etree.Element ('image', name="\'" + os.path.join(mexid, rsmlFileNode) + "\'")
        resource = etree.Element ('resource', name=os.path.join(mexid, rsmlFileNode))
        #resource = etree.Element ('resource', name='new file %s'%rsmlFileNode )
        #resource = etree.Element ('image', name='new file P.rsml')
        logging.debug('name resource: ' + os.path.join(mexid, rsmlFileNode))
        logging.debug('resultrsmlfile: ' + resultrsmlfile)
        logging.debug('localpath: ' + localpath2url(resultrsmlfile))
        logging.debug('resource: ' + str(resource))
        
        #self.uploadFileToServer(resultrsmlfile);
        
        #response = self.bq.postblob(localpath2url(resultrsmlfile), xml=resource)
        #response = self.bq.postblob((resultrsmlfile), xml=resource)
        response = self.postblobbytxn(self.bq, (resultrsmlfile), xml=resource)
        blob = etree.XML(response).find('./')
        if blob is None or blob.get('uri') is None:
            logging.debug('Could not upload the rsml file into the system')
            self.bq.fail_mex('Could not upload the rsml file into the system')
        else:
            ##create node for mex
            linkdataservice = blob.get('uri')
            linkblobservice = linkdataservice.replace('data_service', 'blob_service');
            outputRSMLFileTag = etree.SubElement(outputTag, 'tag', name='RSMLFile', value=linkblobservice, type='file')
            outputRSMLNameTag = etree.SubElement(outputTag, 'tag', name='RSMLName', value=rsmlFileNode, type='name')
                
        #response = save_blob(self.bq, localpath2url(resultrsmlfile), resource=resource)
#         response = save_blob(self.bq, resultrsmlfile, resource=resource)
#                        
#         if response is None or response.get('uri') is None:
#             logging.debug('Could not upload the rsml file into the system')
#             self.bq.fail_mex('Could not upload the rsml file into the system')
#         else:
#             #create node for mex
#             outputRSMLFileTag = etree.SubElement(outputTag, 'tag', name='RSMLFile', value=response.get('uri'), type='file')
              
        
        #or using # self.bq.addTag()
        #self.bq.finish_mex(tags = [outputTag], gobjects = [gObjectRootNode])
        self.bq.finish_mex(tags = [outputTag])
        #self.bq.finish_mex('Finished')
        self.bq.close()
        return;
root = config.get('Host', 'root') or 'localhost:8080'
user = config.get('Host', 'user') or 'test'
pswd = config.get('Host', 'password') or 'test'

session = BQSession().init_local(user,
                                 pswd,
                                 bisque_root=root,
                                 create_mex=False)

start = datetime.now()
url = urlparse.urljoin(root, url_import)
members = []
for f in files:
    resource = etree.Element('resource',
                             name=os.path.basename(f),
                             value=localpath2url(f))
    print etree.tostring(resource)
    r = save_blob(session, resource=resource)
    #r = session.postblob(xml=resource)
    if r is None or r.get('uri') is None:
        print 'Upload failed for %s' % f
    else:
        members.append(r.get('uri'))
print "Inserted all in: %s" % (datetime.now() - start)

dataset = etree.Element('dataset',
                        name=os.path.basename(os.path.dirname(files[0])))
for m in members:
    n = etree.SubElement(dataset, 'value')
    n.text = m
Beispiel #6
0
# model document
##################################################################

resource = etree.Element('connoisseur',
                         name="Watersipora: aiBrandon",
                         resource_uniq="00-4Eq9rrT6SuWoApxPUNDgUf")

files = [
    '/XYZ/network_weights.caffemodel',
    '/XYZ/mean.binaryproto',
    '/XYZ/deploy.prototxt',
    '/XYZ/solver.prototxt',
]
for f in files:
    v = etree.SubElement(resource, 'value')
    v.text = localpath2url(f)

etree.SubElement(resource, 'tag', name="author", value="dima")
etree.SubElement(resource,
                 'tag',
                 name="license",
                 type="license",
                 value="unrestricted")
etree.SubElement(resource,
                 'tag',
                 name="copyright",
                 type="copyright",
                 value="CBI, UCSB")
etree.SubElement(
    resource,
    'tag',
    def teardown(self):
        self.bq.update_mex('Collecting result...')
        # Post all submex for files and return xml list of results
        #gobjects = self._read_results()
        #tags = [{ 'name': 'outputs',
        #          'tag' : [{'name': 'rootimage', 'type':'image', 'value':self.resource_url,
        #                    'gobject' : [{ 'name': 'root_tips', 'type': 'root_tips', 'gobject' : gobjects }] }]
        #          }]
        #self.bq.finish_mex(tags = tags)
        
#         mex_outputs = self.bq.mex.xmltree.xpath('tag[@name="outputs"]')
#         logging.debug('Outputs mex:' + str(mex_outputs))
#         if mex_outputs:
#             logging.debug('Outputs mex:' + str(mex_outputs))
#             
#             for tag in mex_outputs[0]:
#                 if tag.tag == 'tag' and tag.attrib['name'] == 'TipDetection':
#                     tag.attrib['value'] = "390"
# #                 if tag.tag == 'tag' and tag.attrib['type'] != 'system-input':
# #                     logging.debug('Set options with %s as %s'%(tag.attrib['name'],tag.attrib['value']))
#                     setattr(options,tag.attrib['name'],tag.attrib['value'])
#         else:
#             logging.debug('No Outputs Found on MEX!')
        
        #load result data from the xml file. For testing, just use the fix xml i.e. will be changed later time
        #resultfile = os.path.join(self.options.stagingPath, '0002.jpg_result.xml')
        #reload parameters
        self.mex_parameter_parser(self.options, self.bq.mex.xmltree)
        #get the image downloaded
        image = self.bq.load(self.options.image_url)
        imageDownloaded = image.name + ".tif"
        
        resultfile = os.path.join(self.options.stagingPath, imageDownloaded + '_result.xml')
        
        logging.debug('Result file: ' + resultfile)
    
        #load the result file and display info.
#       tree.parse('/home/tuan/bisque/modules/RootNavLinuxModuleV3/0002.jpg_result.xml')
        tree = etree.ElementTree()
        tree.parse(resultfile)
        rootNode = tree.getroot()
#         
        logging.debug('Root node: ' + rootNode.tag)
#          
        # # look for the Tips Output tag
        tipDetectionNode = rootNode.findall("./Output/TipsDetected")
        
        outputTag = etree.Element('tag', name='outputs')
        outputSubTag = etree.SubElement(outputTag, 'tag', name='summary')
        
        if len(tipDetectionNode) > 0:
            
            totalAttrib = tipDetectionNode[0].get('total')
            
            logging.debug('tipDetectionNode : ' + totalAttrib)
            
            ##etree.SubElement(outputTag, 'tag', name='TipDetection', value=str(23))
            #etree.SubElement( outputSubTag, 'tag', name='Tip(s) detected', value=str(23))
            
            
            etree.SubElement( outputSubTag, 'tag', name='Tip(s) detected', value=totalAttrib)
            
            
            #using testing image: /home/tuan/bisque/modules/RootNavLinuxModuleV3/FeatureMapInMain.png
            #filepath = '/home/tuan/bisque/modules/RootNavLinuxModuleV3/FeatureMapInMain.png'
            filepath = '/home/tuan/bisque/modules/RootNavLinuxModuleV3/0002_copy.jpg'
            #just for testing
           
            outputImgTag = etree.SubElement(outputTag, 'tag', name='OutputImage', value=self.options.image_url)
            #outputImgTag = etree.SubElement(outputTag, 'tag', name='OutputImage', value=localpath2url(filepath))
            #gObjectValue = ""
            #gObjectTag = etree.SubElement(outputImgTag, 'gobject', name='PointsDetected')
            logging.debug('appending children to the output image tag')
            gObjectTag = rootNode.findall("./Output/TipsDetected/gobject")[0]
            outputImgTag.append(gObjectTag)
            
            #test colour (this works for one point, change colour from red to yello)
            #etree.SubElement(gObjectTag[0], 'tag', name='color', value="#ffff00")
            
            #for tip in tipDetectionNode[0]:
            #    gPoint = etree.SubElement(gObjectTag, 'point', name=tip.attrib['id'])
            #    etree.SubElement(gPoint, 'vertex', x=tip.attrib['x'], y=tip.attrib['y'])
             
              
        
            #outputExtraImgTag = etree.SubElement(outputTag, 'tag', name='OutputExtraImage', value=self.options.image_url)
            
            resource = etree.Element ('image', name=os.path.basename(filepath), value=localpath2url(filepath))
            meta = etree.SubElement (resource, 'tag', name='Experimental')
            etree.SubElement (meta, 'tag', name='numberpoints', value="12")
            
            #resource = etree.Element ('image', name='new file %s'%(os.path.basename(filepath)))
                         
            logging.debug('resource: ' + str(resource))
            
            
            #self.uploadFileToServer(filepath)
            
            logging.debug('self.bq.service_map in teardown: ' + str(self.bq.service_map))
            
            #url = self.bq.service_url('data_service', 'image')
            #url = self.bq.service_url('blob_service')
            #url = self.bq.service_url('image_service', 'image') ##couldnt use for upload
            #url = self.bq.service_url('/import/transfer') #not a service
            #url = self.bq.service_url('import', 'transfer') #not a service
            #url = self.bq.service_url('import', path='transfer') #not a service
            #url = self.bq.service_url('http://127.0.0.1:8080/', '/import/transfer') #not a service
            #response = save_blob(self.bq, resource=resource)
            
            #logging.debug('url : ' + str(url))
            #response_xml = self.bq.postblob(localpath2url(filepath), xml=resource) #post image to bisque and get the response
            
            #logging.debug('response_xml: ' + str(response_xml))
            
            #r =  self.bq.postxml(url, resource, method='POST')
            
            
            #logging.debug('Response: ' + str(r))
            
            #response = self.bq.postblob(filepath, xml=resource)
            #response = self.bq.postblob(filepath, xml=resource)
            #blob = etree.XML(response).find('./')
            
            
            # if blob is None or blob.get('uri') is None:
            #    logging.debug('Could not insert the Histogram file into the system')
            #    self.bq.fail_mex('Could not insert the Histogram file into the system')
            # else:
                # outputExtraImgTag = etree.SubElement(outputTag, 'tag', name='/home/tuan/bisque/modules/RootNavLinuxModuleV3/FeatureMapInMain.png')
            #    outputExtraImgTag = etree.SubElement(outputTag, 'tag', name='OutputExtraImage', value=blob.get('uri'), type='image')
                
           # if r is None or r.get('uri') is None:
            #    logging.debug('Could not insert the Histogram file into the system')
           #     self.bq.fail_mex('Could not insert the Histogram file into the system')
           # else:
                # outputExtraImgTag = etree.SubElement(outputTag, 'tag', name='/home/tuan/bisque/modules/RootNavLinuxModuleV3/FeatureMapInMain.png')
            #    logging.debug('resource id: %s' %r.get('resource_uniq'))
            #    logging.debug('url: %s' %r.get('uri'))
            #    outputExtraImgTag = etree.SubElement(outputTag, 'tag', name='OutputExtraImage', value=r.get('uri'), type='image')
                # outputExtraImgTag = etree.SubElement(outputImgTag, 'tag', name='OutputExtraImage', value=r.get('value'), type='image')
        #etree.SubElement(outputTag, 'tag', name='OutputImage', value='/home/tuan/bisque/modules/RootNavLinuxModuleV3/FeatureMapInMain.png')
        
        #etree.SubElement(outputTag, 'tag', name='OutputImage', value='file:///home/tuan/bisque/modules/RootNavLinuxModuleV3/FeatureMapInMain.png')
        
        #output shortest paths
        outputPathImgTag = etree.SubElement(outputTag, 'tag', name='OutputPathImage', value=self.options.image_url)
        
        #get primary paths
        primaryPathsNode = rootNode.findall("./Output/PrimaryPaths")
        if (primaryPathsNode is not None) and (len(primaryPathsNode) > 0):
            for path in primaryPathsNode[0]:
                outputPathImgTag.append(path)
        
        #get lateral paths
        lateralPathsNode = rootNode.findall("./Output/LateralPaths")
        if (lateralPathsNode is not None) and (len(lateralPathsNode) > 0):
            for path in lateralPathsNode[0]:
                outputPathImgTag.append(path)
                
        #or using # self.bq.addTag()
        self.bq.finish_mex(tags = [outputTag])
        #self.bq.finish_mex('Finished')
        self.bq.close()
        return;
Beispiel #8
0
config.read('config.cfg')

root = config.get('Host', 'root') or 'localhost:8080'
user = config.get('Host', 'user') or 'test'
pswd = config.get('Host', 'password') or 'test'

session = BQSession().init_local(user,
                                 pswd,
                                 bisque_root=root,
                                 create_mex=False)

url = session.service_url('data_service', 'image')

request = '<image name="%s">' % 'kif5b 8102010.mvd2#0'
request = '%s<value>%s</value>' % (request, '%s#0' % localpath2url(
    'f:/dima/develop/python/bq5irods/data/imagedir/admin/tests/multi_file/8102010-kif5b_control/kif5b 8102010.mvd2'
))
request = '%s<value>%s</value>' % (
    request,
    localpath2url(
        'f:/dima/develop/python/bq5irods/data/imagedir/admin/tests/multi_file/8102010-kif5b_control/Data/119.aiix'
    ))
request = '%s<value>%s</value>' % (
    request,
    localpath2url(
        'f:/dima/develop/python/bq5irods/data/imagedir/admin/tests/multi_file/8102010-kif5b_control/Data/151.aiix'
    ))
request = '%s<value>%s</value>' % (
    request,
    localpath2url(
        'f:/dima/develop/python/bq5irods/data/imagedir/admin/tests/multi_file/8102010-kif5b_control/Data/157.aiix'
Beispiel #9
0
    def teardown(self):
        self.bq.update_mex('Collecting result...')
        # Post all submex for files and return xml list of results
        #gobjects = self._read_results()
        #tags = [{ 'name': 'outputs',
        #          'tag' : [{'name': 'rootimage', 'type':'image', 'value':self.resource_url,
        #                    'gobject' : [{ 'name': 'root_tips', 'type': 'root_tips', 'gobject' : gobjects }] }]
        #          }]
        #self.bq.finish_mex(tags = tags)

        #         mex_outputs = self.bq.mex.xmltree.xpath('tag[@name="outputs"]')
        #         logging.debug('Outputs mex:' + str(mex_outputs))
        #         if mex_outputs:
        #             logging.debug('Outputs mex:' + str(mex_outputs))
        #
        #             for tag in mex_outputs[0]:
        #                 if tag.tag == 'tag' and tag.attrib['name'] == 'TipDetection':
        #                     tag.attrib['value'] = "390"
        # #                 if tag.tag == 'tag' and tag.attrib['type'] != 'system-input':
        # #                     logging.debug('Set options with %s as %s'%(tag.attrib['name'],tag.attrib['value']))
        #                     setattr(options,tag.attrib['name'],tag.attrib['value'])
        #         else:
        #             logging.debug('No Outputs Found on MEX!')

        #load result data from the xml file. For testing, just use the fix xml i.e. will be changed later time
        #resultfile = os.path.join(self.options.stagingPath, '0002.jpg_result.xml')
        #reload parameters
        self.mex_parameter_parser(self.options, self.bq.mex.xmltree)
        #get the image downloaded
        image = self.bq.load(self.options.image_url)
        imageDownloaded = image.name + ".tif"

        resultfile = os.path.join(self.options.stagingPath,
                                  imageDownloaded + '_result.xml')

        logging.debug('Result file: ' + resultfile)

        #load the result file and display info.
        #       tree.parse('/home/tuan/bisque/modules/RootNavLinuxModuleV3/0002.jpg_result.xml')
        tree = etree.ElementTree()
        tree.parse(resultfile)
        rootNode = tree.getroot()
        #
        logging.debug('Root node: ' + rootNode.tag)
        #
        # # look for the Tips Output tag
        tipDetectionNode = rootNode.findall("./Output/TipsDetected")

        outputTag = etree.Element('tag', name='outputs')
        outputSubTag = etree.SubElement(outputTag, 'tag', name='summary')

        if len(tipDetectionNode) > 0:

            totalAttrib = tipDetectionNode[0].get('total')

            logging.debug('tipDetectionNode : ' + totalAttrib)

            ##etree.SubElement(outputTag, 'tag', name='TipDetection', value=str(23))
            #etree.SubElement( outputSubTag, 'tag', name='Tip(s) detected', value=str(23))

            etree.SubElement(outputSubTag,
                             'tag',
                             name='Tip(s) detected',
                             value=totalAttrib)

            #using testing image: /home/tuan/bisque/modules/RootNavLinuxModuleV3/FeatureMapInMain.png
            #filepath = '/home/tuan/bisque/modules/RootNavLinuxModuleV3/FeatureMapInMain.png'
            #filepath = '/home/tuan/bisque/modules/RootNavLinuxModuleV3/0002_copy.jpg'
            #just for testing

            outputImgTag = etree.SubElement(outputTag,
                                            'tag',
                                            name='OutputImage',
                                            value=self.options.image_url)
            #outputImgTag = etree.SubElement(outputTag, 'tag', name='OutputImage', value=localpath2url(filepath))
            #gObjectValue = ""
            #gObjectTag = etree.SubElement(outputImgTag, 'gobject', name='PointsDetected')
            logging.debug('appending children to the output image tag')
            gObjectTag = rootNode.findall("./Output/TipsDetected/gobject")[0]
            outputImgTag.append(gObjectTag)

            #test colour (this works for one point, change colour from red to yello)
            #etree.SubElement(gObjectTag[0], 'tag', name='color', value="#ffff00")

            #for tip in tipDetectionNode[0]:
            #    gPoint = etree.SubElement(gObjectTag, 'point', name=tip.attrib['id'])
            #    etree.SubElement(gPoint, 'vertex', x=tip.attrib['x'], y=tip.attrib['y'])

        #display root info
        #rootsTopMostNodes = rootNode.findall("./Output/RootTree/Root")

        rootsTopMostNodes = rootNode.xpath(
            './Output/RootTree/Root[@order="-1"]')

        for root in rootsTopMostNodes:
            etree.SubElement(outputSubTag,
                             'tag',
                             name='Root length',
                             value=root.get('length'))
            etree.SubElement(outputSubTag,
                             'tag',
                             name='Root area',
                             value=root.get('area'))
            etree.SubElement(outputSubTag,
                             'tag',
                             name='Primary root',
                             value=root.get('primaryRoots'))

            #outputExtraImgTag = etree.SubElement(outputTag, 'tag', name='OutputExtraImage', value=self.options.image_url)

        #resource = etree.Element ('image', name=os.path.basename(filepath), value=localpath2url(filepath))
        #meta = etree.SubElement (resource, 'tag', name='Experimental')
        #etree.SubElement (meta, 'tag', name='numberpoints', value="12")

        #resource = etree.Element ('image', name='new file %s'%(os.path.basename(filepath)))

        #logging.debug('resource: ' + str(resource))

        #self.uploadFileToServer(filepath)

        logging.debug('self.bq.service_map in teardown: ' +
                      str(self.bq.service_map))

        #url = self.bq.service_url('data_service', 'image')
        #url = self.bq.service_url('blob_service')
        #url = self.bq.service_url('image_service', 'image') ##couldnt use for upload
        #url = self.bq.service_url('/import/transfer') #not a service
        #url = self.bq.service_url('import', 'transfer') #not a service
        #url = self.bq.service_url('import', path='transfer') #not a service
        #url = self.bq.service_url('http://127.0.0.1:8080/', '/import/transfer') #not a service
        #response = save_blob(self.bq, resource=resource)

        #logging.debug('url : ' + str(url))
        #response_xml = self.bq.postblob(localpath2url(filepath), xml=resource) #post image to bisque and get the response

        #logging.debug('response_xml: ' + str(response_xml))

        #r =  self.bq.postxml(url, resource, method='POST')

        #logging.debug('Response: ' + str(r))

        #response = self.bq.postblob(filepath, xml=resource)
        #response = self.bq.postblob(filepath, xml=resource)
        #blob = etree.XML(response).find('./')

        # if blob is None or blob.get('uri') is None:
        #    logging.debug('Could not insert the Histogram file into the system')
        #    self.bq.fail_mex('Could not insert the Histogram file into the system')
        # else:
        # outputExtraImgTag = etree.SubElement(outputTag, 'tag', name='/home/tuan/bisque/modules/RootNavLinuxModuleV3/FeatureMapInMain.png')
        #    outputExtraImgTag = etree.SubElement(outputTag, 'tag', name='OutputExtraImage', value=blob.get('uri'), type='image')

        # if r is None or r.get('uri') is None:
        #    logging.debug('Could not insert the Histogram file into the system')
        #     self.bq.fail_mex('Could not insert the Histogram file into the system')
        # else:
        # outputExtraImgTag = etree.SubElement(outputTag, 'tag', name='/home/tuan/bisque/modules/RootNavLinuxModuleV3/FeatureMapInMain.png')
        #    logging.debug('resource id: %s' %r.get('resource_uniq'))
        #    logging.debug('url: %s' %r.get('uri'))
        #    outputExtraImgTag = etree.SubElement(outputTag, 'tag', name='OutputExtraImage', value=r.get('uri'), type='image')
        # outputExtraImgTag = etree.SubElement(outputImgTag, 'tag', name='OutputExtraImage', value=r.get('value'), type='image')
        #etree.SubElement(outputTag, 'tag', name='OutputImage', value='/home/tuan/bisque/modules/RootNavLinuxModuleV3/FeatureMapInMain.png')

        #etree.SubElement(outputTag, 'tag', name='OutputImage', value='file:///home/tuan/bisque/modules/RootNavLinuxModuleV3/FeatureMapInMain.png')

        ##########################
        #upload the probability image
        outputFileNode = rootNode.findall("./Output/File")

        probabilityimagepathNode = outputFileNode[0].find(
            "ProbabilityImageFile").text

        imagefile = os.path.basename(probabilityimagepathNode)
        #get mexid
        parts = self.options.stagingPath.split('/')
        mexid = parts[len(parts) - 1]

        resource = etree.Element('image',
                                 name=os.path.join(UPLOADED_FOLDER, mexid,
                                                   imagefile))

        response = self.postblobbytxn(self.bq, (probabilityimagepathNode),
                                      xml=resource)
        blob = etree.XML(response).find('./')

        if blob is None or blob.get('uri') is None:
            logging.debug(
                'Could not upload the probability image file into the system')
            self.bq.fail_mex(
                'Could not upload the probability image file into the system')
        else:
            ##create node for mex
            linkprobabilityimgupload = blob.get('uri')

            probabilityImageTag = etree.SubElement(
                outputTag,
                'tag',
                name='ProbabilityImage',
                value=linkprobabilityimgupload,
                type='image')

        #######################################################

        #output shortest paths
        outputPathImgTag = etree.SubElement(outputTag,
                                            'tag',
                                            name='OutputPathImage',
                                            value=self.options.image_url)

        #get primary paths
        primaryPathsNode = rootNode.findall("./Output/PrimaryPaths")
        if (primaryPathsNode is not None) and (len(primaryPathsNode) > 0):
            for path in primaryPathsNode[0]:
                outputPathImgTag.append(path)

        #get lateral paths
        lateralPathsNode = rootNode.findall("./Output/LateralPaths")
        if (lateralPathsNode is not None) and (len(lateralPathsNode) > 0):
            for path in lateralPathsNode[0]:
                outputPathImgTag.append(path)

        #node to display the root and convex hull
        outputRootImgTag = etree.SubElement(outputTag,
                                            'tag',
                                            name='OutputRootsImage',
                                            value=self.options.image_url)

        gObjectRootNode = etree.SubElement(outputRootImgTag,
                                           'gobject',
                                           name='Roots')

        splineInOtherRootsNodes = rootNode.xpath(
            './Output/RootTree/Root[@order!="-1"]/Spline')
        for spline in splineInOtherRootsNodes:
            #outputRootImgTag.append(spline[0])
            gObjectRootNode.append(spline[0])

        for root in rootsTopMostNodes:
            convexNodes = root.findall('ConvexHull')
            for cx in convexNodes:
                #outputRootImgTag.append(cx[0])
                gObjectRootNode.append(cx[0])

        #get data for measurement table
        measurementTablesNode = rootNode.xpath('./Output/Measurement/Tables')

        if (measurementTablesNode is not None
                and len(measurementTablesNode) > 0):
            #outputRootImgTag.append(measurementTablesNode[0])
            gObjectRootNode.append(measurementTablesNode[0])

        #get data for curvature profile
        curvNode = etree.SubElement(gObjectRootNode,
                                    'tag',
                                    name='CurvatureProfile')
        curvatureProfileDataNode = rootNode.xpath(
            './Output/Measurement/CurvatureProfile')
        if (curvatureProfileDataNode is not None
                and len(curvatureProfileDataNode) > 0):
            for rowDataNode in curvatureProfileDataNode[0]:
                #gObjectRootNode.append()
                gObjectCurv = etree.SubElement(curvNode, 'gobject', type='row')
                etree.SubElement(gObjectCurv,
                                 'tag',
                                 name='col0',
                                 value=rowDataNode.attrib['col0'])
                etree.SubElement(gObjectCurv,
                                 'tag',
                                 name='col1',
                                 value=rowDataNode.attrib['col1'])

        #get data for travel map
        mapNode = etree.SubElement(gObjectRootNode, 'tag', name='MapProfile')
        mapProfileDataNode = rootNode.xpath('./Output/Measurement/MapProfile')
        if (mapProfileDataNode is not None and len(mapProfileDataNode) > 0):
            #gObjectRootNode.append(mapProfileDataNode[0])
            for rowDataNode in mapProfileDataNode[0]:
                gObjectMap = etree.SubElement(mapNode, 'gobject', type='row')
                etree.SubElement(gObjectMap,
                                 'tag',
                                 name='col0',
                                 value=rowDataNode.attrib['col0'])
                etree.SubElement(gObjectMap,
                                 'tag',
                                 name='col1',
                                 value=rowDataNode.attrib['col1'])
                etree.SubElement(gObjectMap,
                                 'tag',
                                 name='col2',
                                 value=rowDataNode.attrib['col2'])

        #get data for RSML file for downloading
        #extract rsml file from xml data
        inputFileNode = rootNode.findall("./Input/File")
        rsmlFileNode = inputFileNode[0].find("RSMLFile").text
        rsmlPathNode = inputFileNode[0].find("RSMLPath").text

        #upload rsml file
        parts = self.options.stagingPath.split('/')
        mexid = parts[len(parts) - 1]
        resultrsmlfile = os.path.join(rsmlPathNode, rsmlFileNode)
        #resource = etree.Element ('image', name="\'" + os.path.join(mexid, rsmlFileNode) + "\'")
        resource = etree.Element('resource',
                                 name=os.path.join(mexid, rsmlFileNode))
        #resource = etree.Element ('resource', name='new file %s'%rsmlFileNode )
        #resource = etree.Element ('image', name='new file P.rsml')
        logging.debug('name resource: ' + os.path.join(mexid, rsmlFileNode))
        logging.debug('resultrsmlfile: ' + resultrsmlfile)
        logging.debug('localpath: ' + localpath2url(resultrsmlfile))
        logging.debug('resource: ' + str(resource))

        #self.uploadFileToServer(resultrsmlfile);

        #response = self.bq.postblob(localpath2url(resultrsmlfile), xml=resource)
        #response = self.bq.postblob((resultrsmlfile), xml=resource)
        response = self.postblobbytxn(self.bq, (resultrsmlfile), xml=resource)
        blob = etree.XML(response).find('./')
        if blob is None or blob.get('uri') is None:
            logging.debug('Could not upload the rsml file into the system')
            self.bq.fail_mex('Could not upload the rsml file into the system')
        else:
            ##create node for mex
            linkdataservice = blob.get('uri')
            linkblobservice = linkdataservice.replace('data_service',
                                                      'blob_service')
            outputRSMLFileTag = etree.SubElement(outputTag,
                                                 'tag',
                                                 name='RSMLFile',
                                                 value=linkblobservice,
                                                 type='file')
            outputRSMLNameTag = etree.SubElement(outputTag,
                                                 'tag',
                                                 name='RSMLName',
                                                 value=rsmlFileNode,
                                                 type='name')

        #response = save_blob(self.bq, localpath2url(resultrsmlfile), resource=resource)


#         response = save_blob(self.bq, resultrsmlfile, resource=resource)
#
#         if response is None or response.get('uri') is None:
#             logging.debug('Could not upload the rsml file into the system')
#             self.bq.fail_mex('Could not upload the rsml file into the system')
#         else:
#             #create node for mex
#             outputRSMLFileTag = etree.SubElement(outputTag, 'tag', name='RSMLFile', value=response.get('uri'), type='file')

#or using # self.bq.addTag()
#self.bq.finish_mex(tags = [outputTag], gobjects = [gObjectRootNode])
        self.bq.finish_mex(tags=[outputTag])
        #self.bq.finish_mex('Finished')
        self.bq.close()
        return
Beispiel #10
0
config.read('config.cfg')

root = config.get('Host', 'root') or 'localhost:8080'
user = config.get('Host', 'user') or 'test'
pswd = config.get('Host', 'password') or 'test'

session = BQSession().init_local(user,
                                 pswd,
                                 bisque_root=root,
                                 create_mex=False)

request = '<image name="%s">' % 'series_z_tiff'
request = '%s<value>%s</value>' % (
    request,
    localpath2url(
        'f:/dima/develop/python/bq5irods/data/imagedir/admin/tests/multi_file/series_z_tiff/z_000001.tiff'
    ))
request = '%s<value>%s</value>' % (
    request,
    localpath2url(
        'f:/dima/develop/python/bq5irods/data/imagedir/admin/tests/multi_file/series_z_tiff'
    ))
request = '%s<tag name="%s" type="%s">' % (request, 'image_meta', 'image_meta')
request = '%s<tag name="%s" value="%s" type="number" />' % (
    request, 'image_num_z', '30')
request = '%s<tag name="%s" value="%s" type="number" />' % (request,
                                                            'image_num_t', '1')
request = '%s<tag name="%s" value="%s" />' % (request, 'dimensions', 'XYCZT')
request = '%s<tag name="%s" value="%s" type="number" />' % (
    request, 'pixel_resolution_x', '0.4')
request = '%s<tag name="%s" value="%s" type="number" />' % (

config = ConfigParser.ConfigParser()
config.read('config.cfg')

root = config.get('Host', 'root') or 'localhost:8080'
user = config.get('Host', 'user') or 'test'
pswd = config.get('Host', 'password') or 'test'

session = BQSession().init_local(user, pswd,  bisque_root=root, create_mex=False)

#url = session.service_url('data_service', 'image')


request = '<image name="%s">'%'AndorMM#0'
request = '%s<value>%s</value>'%(request, '%s#0'%localpath2url('f:/dima/develop/python/bq5irods/data/imagedir/admin/tests/multi_file/AndorMM/DiskInfo5.kinetic'))
request = '%s<value>%s</value>'%(request, localpath2url('f:/dima/develop/python/bq5irods/data/imagedir/admin/tests/multi_file/AndorMM'))
request = '%s</image>'%request

#r = session.postxml(url, etree.fromstring(request), method='POST')
r = save_blob(session, resource=request)
if r is None or r.get('uri') is None:
    print 'Upload failed'
else:
    print 'id: %s'%r.get('resource_uniq')
    print 'url: %s'%r.get('uri')



request = '<image name="%s">'%'AndorMM#1'
request = '%s<value>%s</value>'%(request, '%s#1'%localpath2url('f:/dima/develop/python/bq5irods/data/imagedir/admin/tests/multi_file/AndorMM/DiskInfo5.kinetic'))
config.read('config.cfg')

root = config.get('Host', 'root') or 'localhost:8080'
user = config.get('Host', 'user') or 'test'
pswd = config.get('Host', 'password') or 'test'

session = BQSession().init_local(user,
                                 pswd,
                                 bisque_root=root,
                                 create_mex=False)

request = '<image name="%s">' % 'IM-0001-0001.dcm'
request = '%s<value>%s</value>' % (
    request,
    localpath2url(
        'f:/dima/develop/python/bq5irods/data/imagedir/admin/tests/multi_file/dicom/IM-0001-0001.dcm'
    ))
request = '%s<value>%s</value>' % (
    request,
    localpath2url(
        'f:/dima/develop/python/bq5irods/data/imagedir/admin/tests/multi_file/dicom'
    ))
request = '%s</image>' % request

#url = session.service_url('data_service', 'image')
#r = session.postxml(url, etree.fromstring(request), method='POST')
r = save_blob(session, resource=request)
if r is None or r.get('uri') is None:
    print 'Upload failed'
else:
    print 'id: %s' % r.get('resource_uniq')