Example #1
0
class FontMetric(object):
    def __init__(self, metric_file):
        self.metric = AFM(open(metric_file))

    @staticmethod
    def _map_to_adobe(char):
        c = ord(char)
        if c in UNICODE_TO_ADOBE:
            return UNICODE_TO_ADOBE[c]
        return c

    def get_width(self, char, size):
        # sys.stderr.write(char)
        # sys.stderr.write('\n')
        c = self._map_to_adobe(char)
        return size * (self.metric.get_width_char(c, isord=True) / 1000.0)

    def get_kern_distance(self, c1, c2, size):
        c1 = self._map_to_adobe(c1)
        c2 = self._map_to_adobe(c2)
        return size * (self.metric.get_kern_dist(c1, c2, isord=True) / 1000.0)
Example #2
0
# https://hdbscan.readthedocs.io/en/latest/index.html
# The method may be useful for non uniform samples, allowing automated measurement
# of adhesion and modulus for different phases across the sample surface.

# Import AFM class
from afm import AFM

# Import packages for clustering
import hdbscan
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import sklearn.datasets as data

# Run AFM functions
expt_1 = AFM()
expt_1.run()

# Shape adhesion and modulus data
_adhesion = expt_1.adhesion
_modulus = expt_1.modulus
_adhesion = _adhesion.reshape(-1, 1)
_modulus = _modulus.reshape(-1, 1)
data = np.append(_adhesion, _modulus, axis=1)

# Find clusters
clusterer = hdbscan.HDBSCAN(allow_single_cluster=True, min_cluster_size=10)
clusterer.fit(data)

# Plot condensed tree
clusterer.condensed_tree_.plot(select_clusters=True,
Example #3
0
 def __init__(self, metric_file):
     self.metric = AFM(open(metric_file))