Get a length limited unit name for drawing units.
504815
def get_unit_name(self, surf, name, radius):
    """"""
    key = (name, radius)
    if key not in self._name_lengths:
      max_len = surf.world_to_surf.fwd_dist(radius * 1.6)
      for i in range(len(name)):
        if self._font_small.size(name[:i + 1])[0] > max_len:
          self._name_lengths[key] = name[:i]
          break
      else:
        self._name_lengths[key] = name
    return self._name_lengths[key]
1111140
def unit(self):
        """"""
        return Vector(
            (self.x / self.magnitude()),
            (self.y / self.magnitude()),
            (self.z / self.magnitude())
        )
1011754
def parse_angular_length_quantity(string_rep, unit=u.deg):
        
        unit_mapping = {
            '"': u.arcsec,
            "'": u.arcmin,
            'd': u.deg,
            'r': u.rad,
            'i': u.dimensionless_unscaled,
            'p': u.dimensionless_unscaled
        }
        has_unit = string_rep[-1] not in string.digits
        if has_unit:
            unit = unit_mapping[string_rep[-1]]
            return u.Quantity(float(string_rep[:-1]), unit=unit)
        else:
            return u.Quantity(float(string_rep), unit=unit)
907750
def _canonical_unit_name(name):
    '''
    
    '''
    if not isinstance(name, six.string_types):
        name = six.text_type(name)
    if any(name.endswith(suffix) for suffix in VALID_UNIT_TYPES):
        return name
    return '%s.service' % name
941711
def get_unit_by_name(self, unit_name: str) -> typing.Optional['BaseUnit']:
        
        VALID_STR.validate(unit_name, 'get_unit_by_name')
        for unit in self.units:

            if unit.unit_name == unit_name:
                return unit
        return None
572984
def size_from_name(size, sizes):

    """"""

    by_name = [s for s in sizes if s.name == size]
    if len(by_name) > 1:
        raise Exception('more than one image named %s exists' % size)
    return by_name[0]
25099
def unit(self, parameter):
        ""
        parameter = self._get_parameter_name(parameter).lower()
        return self._parameters[parameter]['Unit']
460013
def get_kws(self):
        """"""
        ret = self.kws['dict'].copy()
        act_set = self.kws['set']
        if 'shorten' in act_set and 'goobj2fncname' not in ret:
            ret['goobj2fncname'] = ShortenText().get_short_plot_name
        return ret
1150012
def scourLength(length):
    
    length = SVGLength(length)

    return scourUnitlessLength(length.value) + Unit.str(length.units)
256629
def parse_angular_length_quantity(string_rep):
        
        unit_mapping = {
            'deg': u.deg,
            'rad': u.rad,
            'arcmin': u.arcmin,
            'arcsec': u.arcsec,
            'pix': u.dimensionless_unscaled,
            '"': u.arcsec,
            "'": u.arcmin,
        }
        regex_str = re.compile(r'([0-9+,-.]*)(.*)')
        str = regex_str.search(string_rep)
        unit = str.group(2)
        if unit:
            if unit in unit_mapping:
                return u.Quantity(str.group(1), unit=unit_mapping[unit])
            return u.Quantity(str.group(1))
        else:
            raise CRTFRegionParserError('Units must be specified for {0} '.format(string_rep))
1197305
def _printed_len(some_string):
  """"""
  return len([x for  x in ANSI_ESC_RE.sub('', some_string)
              if x in string.printable])
778514
private String getPrefixNameBySize() {
        StringBuilder buffer = new StringBuilder();
        buffer.append("_").append(width).append("x").append(height);
        return new String(buffer);
    }
366261
def p_unit(self, p):
        
        unit = TimexLexer.reserved_words[p[1]]
        unit = unit.lower()
        p[0] = unit
816741
def get_symbol(units) -> str:
    
    if kind(units) == "energy":
        d = {}
        d["nm"] = r"\lambda"
        d["wn"] = r"\bar\nu"
        d["eV"] = r"\hslash\omega"
        d["Hz"] = r"f"
        d["THz"] = r"f"
        d["GHz"] = r"f"
        return d.get(units, "E")
    elif kind(units) == "delay":
        return r"\tau"
    elif kind(units) == "fluence":
        return r"\mathcal{F}"
    elif kind(units) == "pulse_width":
        return r"\sigma"
    elif kind(units) == "temperature":
        return r"T"
    else:
        return kind(units)
398796
def get_unit(a):
    """"""
    typestr = a.dtype.str
    i = typestr.find('[')
    if i == -1:
        raise TypeError("Expected a datetime64 array, not %s", a.dtype)
    return typestr[i + 1: -1]
388977
@Override
    public String name(String name, Meter.Type type, @Nullable String baseUnit) {
        String formattedName = StringEscapeUtils.escapeJson(delegate.name(name, type, baseUnit));
        return StringUtils.truncate(formattedName, NAME_MAX_LENGTH);
    }
1098852
def extract_units(string_in):
    
    start = '('
    stop = ')'
    return string_in[string_in.index(start) + 1:string_in.index(stop)]