def _attemptOpenAsDvidVolume(self, filePath): """ Two ways to specify a dvid volume. 1) via a file that contains the hostname, uuid, and dataset name (1 per line) 2) as a url, e.g. http://localhost:8000/api/node/uuid/dataname """ if os.path.splitext(filePath)[1] == '.dvidvol': with open(filePath) as f: filetext = f.read() hostname, uuid, dataname = filetext.splitlines() opDvidVolume = OpDvidVolume( hostname, uuid, dataname, transpose_axes=True, parent=self ) return [opDvidVolume], opDvidVolume.Output if '://' in filePath: url_format = "^protocol://hostname/api/node/uuid/dataname(\\?query_string)?" for field in ['protocol', 'hostname', 'uuid', 'dataname', 'query_string']: url_format = url_format.replace( field, '(?P<' + field + '>[^?]+)' ) match = re.match( url_format, filePath ) if match: fields = match.groupdict() try: query_string = fields['query_string'] query_args = {} if query_string: query_args = dict( map(lambda s: s.split('='), query_string.split('&')) ) opDvidVolume = OpDvidVolume( fields['hostname'], fields['uuid'], fields['dataname'], query_args, transpose_axes=True, parent=self ) return [opDvidVolume], opDvidVolume.Output except OpDvidVolume.DatasetReadError as e: raise OpInputDataReader.DatasetReadError( *e.args ) return ([], None)
def _attemptOpenAsDvidVolume(self, filePath): """ Two ways to specify a dvid volume. 1) via a file that contains the hostname, uuid, and dataset name (1 per line) 2) as a url, e.g. http://localhost:8000/api/node/uuid/dataname """ if os.path.splitext(filePath)[1] == '.dvidvol': with open(filePath) as f: filetext = f.read() hostname, uuid, dataname = filetext.splitlines() opDvidVolume = OpDvidVolume(hostname, uuid, dataname, transpose_axes=True, parent=self) return [opDvidVolume], opDvidVolume.Output if '://' not in filePath: return ([], None) # not a url url_format = "^protocol://hostname/api/node/uuid/dataname(\\?query_string)?" for field in [ 'protocol', 'hostname', 'uuid', 'dataname', 'query_string' ]: url_format = url_format.replace(field, '(?P<' + field + '>[^?]+)') match = re.match(url_format, filePath) if not match: # DVID is the only url-based format we support right now. # So if it looks like the user gave a URL that isn't a valid DVID node, then error. raise OpInputDataReader.DatasetReadError( "Invalid URL format for DVID: {}".format(filePath)) fields = match.groupdict() try: query_string = fields['query_string'] query_args = {} if query_string: query_args = dict( map(lambda s: s.split('='), query_string.split('&'))) try: opDvidVolume = OpDvidVolume(fields['hostname'], fields['uuid'], fields['dataname'], query_args, transpose_axes=True, parent=self) return [opDvidVolume], opDvidVolume.Output except: # Maybe this is actually a roi opDvidRoi = OpDvidRoi(fields['hostname'], fields['uuid'], fields['dataname'], transpose_axes=True, parent=self) return [opDvidRoi], opDvidRoi.Output except OpDvidVolume.DatasetReadError as e: raise OpInputDataReader.DatasetReadError(*e.args)
def _attemptOpenAsDvidVolume(self, filePath): """ Two ways to specify a dvid volume. 1) via a file that contains the hostname, uuid, and dataset name (1 per line) 2) as a url, e.g. http://localhost:8000/api/node/uuid/dataname """ if os.path.splitext(filePath)[1] == ".dvidvol": with open(filePath) as f: filetext = f.read() hostname, uuid, dataname = filetext.splitlines() opDvidVolume = OpDvidVolume(hostname, uuid, dataname, parent=self) return [opDvidVolume], opDvidVolume.Output if "://" not in filePath: return ([], None) # not a url url_format = "^protocol://hostname/api/node/uuid/dataname(\\?query_string)?" for field in [ "protocol", "hostname", "uuid", "dataname", "query_string" ]: url_format = url_format.replace(field, "(?P<" + field + ">[^?]+)") match = re.match(url_format, filePath) if not match: # DVID is the only url-based format we support right now. # So if it looks like the user gave a URL that isn't a valid DVID node, then error. raise OpInputDataReader.DatasetReadError( "Invalid URL format for DVID: {}".format(filePath)) fields = match.groupdict() try: query_string = fields["query_string"] query_args = {} if query_string: query_args = dict( [s.split("=") for s in query_string.split("&")]) try: opDvidVolume = OpDvidVolume(fields["hostname"], fields["uuid"], fields["dataname"], query_args, parent=self) return [opDvidVolume], opDvidVolume.Output except: # Maybe this is actually a roi opDvidRoi = OpDvidRoi(fields["hostname"], fields["uuid"], fields["dataname"], parent=self) return [opDvidRoi], opDvidRoi.Output except OpDvidVolume.DatasetReadError as e: raise OpInputDataReader.DatasetReadError(*e.args) from e
def _test_volume(self, hostname, uuid, dataname, start, stop): """ hostname: The dvid server host uuid: The node we can test with dataname: The data instance to test with start, stop: The bounds of the cutout volume to retrieve from the server. C ORDER FOR THIS TEST BECAUSE we use transpose_axes=True """ # Retrieve from server graph = Graph() opDvidVolume = OpDvidVolume(hostname, uuid, dataname, {}, transpose_axes=True, graph=graph) subvol = opDvidVolume.Output(start, stop).wait() # Retrieve from file (which uses fortran order) slicing = tuple(slice(x, y) for x, y in zip(start, stop)) slicing = tuple(reversed(slicing)) expected_data = self.original_data[slicing] # Compare. assert ( subvol.view(numpy.ndarray) == expected_data.transpose() ).all(),\ "Data from server didn't match data from file!"
def _test_volume(self, hostname, h5filename, uuid, dataname, start, stop): """ hostname: The dvid server host h5filename: The h5 file to compare against h5group: The hdf5 group, also used as the uuid of the dvid dataset h5dataset: The dataset name, also used as the name of the dvid dataset start, stop: The bounds of the cutout volume to retrieve from the server. C ORDER FOR THIS TEST BECAUSE we use transpose_axes=True """ # Retrieve from server graph = Graph() opDvidVolume = OpDvidVolume(hostname, uuid, dataname, {}, transpose_axes=True, graph=graph) subvol = opDvidVolume.Output(start, stop).wait() # Retrieve from file (which uses fortran order) slicing = tuple(slice(x, y) for x, y in zip(start, stop)) slicing = tuple(reversed(slicing)) with h5py.File(h5filename, 'r') as f: expected_data = f['all_nodes'][uuid][dataname][slicing] # Compare. assert ( subvol.view(numpy.ndarray) == expected_data.transpose() ).all(),\ "Data from server didn't match data from file!"