text stringlengths 0 828 |
|---|
elif method == 'correlation coefficient': |
temp_minus_mean = template - np.mean(template) |
match_value = np.sum(temp_minus_mean**2) |
else: |
raise ValueError('Matching method not implemented') |
condition = ((np.round(transformed_array, decimals=3)>=match_value*raw_tolerance) & |
(np.round(transformed_array, decimals=3)<=match_value*(1./raw_tolerance))) |
return np.transpose(condition.nonzero())" |
4285,"def normalise_correlation(image_tile_dict, transformed_array, template, normed_tolerance=1): |
""""""Calculates the normalisation coefficients of potential match positions |
Then normalises the correlation at these positions, and returns them |
if they do indeed constitute a match |
"""""" |
template_norm = np.linalg.norm(template) |
image_norms = {(x,y):np.linalg.norm(image_tile_dict[(x,y)])*template_norm for (x,y) in image_tile_dict.keys()} |
match_points = image_tile_dict.keys() |
# for correlation, then need to transofrm back to get correct value for division |
h, w = template.shape |
#points_from_transformed_array = [(match[0] + h - 1, match[1] + w - 1) for match in match_points] |
image_matches_normalised = {match_points[i]:transformed_array[match_points[i][0], match_points[i][1]]/image_norms[match_points[i]] for i in range(len(match_points))} |
result = {key:value for key, value in image_matches_normalised.items() if np.round(value, decimals=3) >= normed_tolerance} |
return result.keys()" |
4286,"def normalise_correlation_coefficient(image_tile_dict, transformed_array, template, normed_tolerance=1): |
""""""As above, but for when the correlation coefficient matching method is used |
"""""" |
template_mean = np.mean(template) |
template_minus_mean = template - template_mean |
template_norm = np.linalg.norm(template_minus_mean) |
image_norms = {(x,y):np.linalg.norm(image_tile_dict[(x,y)]- np.mean(image_tile_dict[(x,y)]))*template_norm for (x,y) in image_tile_dict.keys()} |
match_points = image_tile_dict.keys() |
# for correlation, then need to transofrm back to get correct value for division |
h, w = template.shape |
image_matches_normalised = {match_points[i]:transformed_array[match_points[i][0], match_points[i][1]]/image_norms[match_points[i]] for i in range(len(match_points))} |
normalised_matches = {key:value for key, value in image_matches_normalised.items() if np.round(value, decimals=3) >= normed_tolerance} |
return normalised_matches.keys()" |
4287,"def calculate_squared_differences(image_tile_dict, transformed_array, template, sq_diff_tolerance=0.1): |
""""""As above, but for when the squared differences matching method is used |
"""""" |
template_norm_squared = np.sum(template**2) |
image_norms_squared = {(x,y):np.sum(image_tile_dict[(x,y)]**2) for (x,y) in image_tile_dict.keys()} |
match_points = image_tile_dict.keys() |
# for correlation, then need to transofrm back to get correct value for division |
h, w = template.shape |
image_matches_normalised = {match_points[i]:-2*transformed_array[match_points[i][0], match_points[i][1]] + image_norms_squared[match_points[i]] + template_norm_squared for i in range(len(match_points))} |
#print image_matches_normalised |
cutoff = h*w*255**2*sq_diff_tolerance |
normalised_matches = {key:value for key, value in image_matches_normalised.items() if np.round(value, decimals=3) <= cutoff} |
return normalised_matches.keys()" |
4288,"def __init_os_api(self): |
"""""" |
Initialise client objects for talking to OpenStack API. |
This is in a separate function so to be called by ``__init__`` and |
``__setstate__``. |
"""""" |
loader = loading.get_plugin_loader('password') |
auth = loader.load_from_options(auth_url=self._os_auth_url, |
username=self._os_username, |
password=self._os_password, |
project_name=self._os_tenant_name) |
sess = session.Session(auth=auth) |
self.nova_client = nova_client.Client(self.nova_api_version, session=sess) |
self.neutron_client = neutron_client.Client(session=sess) |
self.glance_client = glance_client.Client('2', session=sess) |
self.cinder_client = cinder_client.Client('2', session=sess)" |
4289,"def stop_instance(self, instance_id): |
""""""Stops the instance gracefully. |
:param str instance_id: instance identifier |
"""""" |
instance = self._load_instance(instance_id) |
instance.delete() |
del self._instances[instance_id]" |
4290,"def get_ips(self, instance_id): |
""""""Retrieves all IP addresses associated to a given instance. |
:return: tuple (IPs) |
"""""" |
instance = self._load_instance(instance_id) |
IPs = sum(instance.networks.values(), []) |
return IPs" |
4291,"def is_instance_running(self, instance_id): |
""""""Checks if the instance is up and running. |
:param str instance_id: instance identifier |
:return: bool - True if running, False otherwise |
"""""" |
# Here, it's always better if we update the instance. |
instance = self._load_instance(instance_id, force_reload=True) |
return instance.status == 'ACTIVE'" |
4292,"def _check_keypair(self, name, public_key_path, private_key_path): |
""""""First checks if the keypair is valid, then checks if the keypair |
is registered with on the cloud. If not the keypair is added to the |
users ssh keys. |
:param str name: name of the ssh key |
:param str public_key_path: path to the ssh public key file |
:param str private_key_path: path to the ssh private key file |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.