Convert aesthetic mapping into text labels
551424
def make_labels(mapping):
    
    labels = mapping.copy()
    for ae in labels:
        labels[ae] = strip_calculated_markers(labels[ae])
    return labels
165211
def labels(self, hs_dims=None, prune=False):
        """"""
        if self.ca_as_0th:
            labels = self._cube.labels(include_transforms_for_dims=hs_dims)[1:]
        else:
            labels = self._cube.labels(include_transforms_for_dims=hs_dims)[-2:]

        if not prune:
            return labels

        def prune_dimension_labels(labels, prune_indices):
            """Get pruned labels for single dimension, besed on prune inds."""
            labels = [label for label, prune in zip(labels, prune_indices) if not prune]
            return labels

        labels = [
            prune_dimension_labels(dim_labels, dim_prune_inds)
            for dim_labels, dim_prune_inds in zip(labels, self._prune_indices(hs_dims))
        ]
        return labels
1293054
def toTFExample(image, label):
  """"""
  example = tf.train.Example(
    features=tf.train.Features(
      feature={
        'label': tf.train.Feature(int64_list=tf.train.Int64List(value=label.astype("int64"))),
        'image': tf.train.Feature(int64_list=tf.train.Int64List(value=image.astype("int64")))
      }
    )
  )
  return example.SerializeToString()
32385
def _text_to_graphiz(self, text):
        """"""
        dot = Source(text, format='svg')
        return dot.pipe().decode('utf-8')
175088
def split_styles(mark):
    
    
    markers = [mark._table[key] for key in mark._marker][0]
    nstyles = []
    for m in markers:
        ## fill and stroke are already rgb() since already in markers
        msty = toyplot.style.combine({
            "fill": m.mstyle['fill'],
            "stroke": m.mstyle['stroke'],
            "opacity": m.mstyle["fill-opacity"],
        }, m.mstyle)
        msty = _color_fixup(msty)
        nstyles.append(msty)
    
    ## uses 'marker.size' so we need to loop over it
    lstyles = []
    for m in markers:
        lsty = toyplot.style.combine({
        "font-family": "Helvetica",
        "-toyplot-vertical-align": "middle",
        "fill": toyplot.color.black,
        "font-size": "%rpx" % (m.size * 0.75),
        "stroke": "none",
        "text-anchor": "middle",
        }, m.lstyle)
        ## update fonts
        fonts = toyplot.font.ReportlabLibrary()
        layout = toyplot.text.layout(m.label, lsty, fonts)
        lsty = _color_fixup(layout.style)
        lstyles.append(lsty)
    
    nallkeys = set(itertools.chain(*[i.keys() for i in nstyles]))
    lallkeys = set(itertools.chain(*[i.keys() for i in lstyles]))
    nuniquekeys = []
    nsharedkeys = []
    for key in nallkeys:
        vals = [nstyles[i].get(key) for i in range(len(nstyles))]
        if len(set(vals)) > 1:
            nuniquekeys.append(key)
        else:
            nsharedkeys.append(key)
    luniquekeys = []
    lsharedkeys = []
    for key in lallkeys:
        vals = [lstyles[i].get(key) for i in range(len(lstyles))]
        if len(set(vals)) > 1:
            luniquekeys.append(key)
        else:
            lsharedkeys.append(key)

    ## keys shared between mark and text markers
    repeated = set(lsharedkeys).intersection(set(nsharedkeys))
    for repeat in repeated:
        ## if same then keep only one copy of it
        lidx = lsharedkeys.index(repeat)
        nidx = nsharedkeys.index(repeat)
        if lsharedkeys[lidx] == nsharedkeys[nidx]:
            lsharedkeys.remove(repeat)
        else:
            lsharedkeys.remove(repeat)
            luniquekeys.append(repeat)
            nsharedkeys.remove(repeat)
            nuniquekeys.append(repeat)
            
    ## check node values
    natt = ["%s:%s" % (key, nstyles[0][key]) for key in sorted(nsharedkeys)]
    latt = ["%s:%s" % (key, lstyles[0][key]) for key in sorted(lsharedkeys)]
    shared_styles = ";".join(natt+latt)
    unique_styles = {
        "node": [{k:v for k,v in nstyles[idx].items() if k in nuniquekeys} for idx in range(len(markers))],
        "text": [{k:v for k,v in lstyles[idx].items() if k in luniquekeys} for idx in range(len(markers))]
    }
    
    return shared_styles, unique_styles
546063
function label (composition) {
  const label = path => (composition, name, array) => {
    const p = path + (name !== undefined ? (array === undefined ? `.${name}` : `[${name}]`) : '')
    composition = visit(composition, label(p)) // copy
    composition.path = p
    return composition
  }
  return label('')(composition)
}
498489
def label(self,x,y,label,offset=[0,0]):
        """"""
        (xc,yc)=self.p2c([x,y])
        return self.create_text(xc-offset[0],yc-offset[1],text=label)
1293560
def make_dom_map(pmt_directions, values, nside=512, d=0.2, smoothing=0.1):
    
    import healpy as hp
    discs = [hp.query_disc(nside, dir, 0.2) for dir in pmt_directions]
    npix = hp.nside2npix(nside)
    pixels = np.zeros(npix)
    for disc, value in zip(discs, values):
        for d in disc:
            pixels[d] = value
    if smoothing > 0:
        return hp.sphtfunc.smoothing(pixels, fwhm=smoothing, iter=1)
    return pixels
28641
function mapAttrName(node, text, maps, id, nodeId, isComponent)
  {
    var attrs = text.match(__matchAttr),
        mapText,
        mapValues,
        attr,
        title,
        value,
        item,
        len = attrs.length,
        titleMap,
        localMap,
        x = 0,
        lenn,
        i = 0;
    
    for(x;x<len;x++)
    {
      attr = attrs[x].split(':');
      title = attr[0];
      value = attr[1].replace(__replaceSingleQuotes, '');
      
      if(title.match(__matchInsert))
      {
        titleMap = new mapObject({
          local_id: id,
          node_id: nodeId,
          mapIndex: maps.length,
          mapTextIndex: 0,
          text: title,
          maps: maps,
          mapText: [title],
          type: 'attr',
          isInsert: true,
          node: node,
          isAttr: true,
          isPointer: isComponent,
          isProperty: true
        })
        maps.push(titleMap)
        titleMap.mapText = [maps[(maps.length - 1)]];
      }
      else if(title.match(__matchText))
      {
        titleMap = new mapObject({
          local_id: id,
          node_id: nodeId,
          mapIndex: maps.length,
          mapTextIndex: 0,
          text: title,
          maps: maps,
          mapText: [title],
          type: 'attr',
          node: node,
          isAttr: true,
          listener: 'setAttribute',
          local: node,
          isPointer: isComponent,
          isProperty: true
        })
        maps.push(titleMap);
        titleMap.mapText = [maps[(maps.length - 1)]];
      }
      
      mapText = splitText(value);
      mapValues = (titleMap ? titleMap.mapValues : maps);
      lenn = mapText.length;
      i = 0;
      
      for(i;i<lenn;i++)
      {
        item = mapText[i];
        if(item.match(__matchInsert))
        {
          localMap = new mapObject({
            local_id: id,
            node_id: nodeId,
            mapIndex: mapValues.length,
            mapTextIndex: i,
            text: item,
            mapText: mapText,
            maps: mapValues,
            type: 'attr',
            isInsert: true,
            property: title,
            listener: title,
            node: node,
            isAttr: true,
            isPointer: isComponent,
            isPropertyValue: true
          });
          titleMap.mapValues.push(localMap)
        }
        else if(item.match(__matchText))
        {
          localMap = new mapObject({
            local_id: id,
            node_id: nodeId,
            mapIndex: mapValues.length,
            mapTextIndex: i,
            text: item,
            mapText: mapText,
            maps: mapValues,
            type: 'attr',
            property: title,
            listener: title,
            node: node,
            isAttr: true,
            isPointer: isComponent,
            isPropertyValue: true
          });
          titleMap.mapValues.push(localMap)
        }
        else
        {
          localMap = item;
        }
        mapText[i] = localMap;
      }
      titleMap.values = mapText;
    }
  }
413589
def transformer(data, label):
    
    data = mx.image.imresize(data, IMAGE_SIZE, IMAGE_SIZE)
    data = mx.nd.transpose(data, (2, 0, 1))
    data = data.astype(np.float32) / 128.0 - 1
    return data, label
875625
function mapStyleAttr(node, text, maps, id, nodeId, isComponent)
  {
    var styles = text.match(__matchStyles),
        isFullStyle = (styles && styles[0].match(__matchText) && styles.length === 1),
        mapText,
        mapValues,
        style,
        title,
        value,
        item,
        len = styles.length,
        titleMap,
        localMap,
        x = 0,
        lenn,
        i = 0;
    
    if(isFullStyle)
    {
      item = styles[0];
      if(item.match(__matchInsert))
      {
        localMap = new mapObject({
            local_id: id,
            node_id: nodeId,
            mapIndex: maps.length,
            mapTextIndex: 0,
            text: item,
            maps: maps,
            mapText: [item],
            type: 'style',
            isInsert: true,
            property: 'style',
            local: node.style,
            node: node,
            isInlineStyle: true,
            isFullStyle: true,
            isPointer: isComponent
          })
          maps.push(localMap)
          localMap.mapText = [maps[(maps.length - 1)]];
      }
      else if(item.match(__matchText))
      {
        localMap = new mapObject({
            local_id: id,
            node_id: nodeId,
            mapIndex: maps.length,
            mapTextIndex: 0,
            text: item,
            maps: maps,
            mapText: [item],
            type: 'style',
            property: 'style',
            listener: 'style',
            local: node.style,
            node: node,
            isInlineStyle: true,
            isFullStyle: true,
            isPointer: isComponent
          })
          maps.push(localMap)
          localMap.mapText = [maps[(maps.length - 1)]];
      }
    }
    else
    {
      for(x;x<len;x++)
      {
        if(styles[x].indexOf(':') === -1)
        {
          title = styles[x];
          value = '';
        }
        else
        {
          style = styles[x].split(':');
          title = style[0];
          value = style[1];
        }
        /* First we try to match the title */
        if(title.match(__matchInsert))
        {
          titleMap = new mapObject({
            local_id: id,
            node_id: nodeId,
            mapIndex: maps.length,
            mapTextIndex: 0,
            text: title,
            maps: maps,
            mapText: [title],
            type: 'style',
            isInsert: true,
            property: 'style',
            node: node,
            local: node.style,
            isFullProp: !(value),
            isInlineStyle: true,
            isPointer: isComponent,
            isProperty: true
          })
          maps.push(titleMap)
          titleMap.mapText = [maps[(maps.length - 1)]];
        }
        else if(title.match(__matchText))
        {
          titleMap = new mapObject({
            local_id: id,
            node_id: nodeId,
            mapIndex: maps.length,
            mapTextIndex: 0,
            text: title,
            maps: maps,
            mapText: [title],
            type: 'style',
            property: 'style',
            node: node,
            local: node.style,
            isFullProp: !(value),
            isInlineStyle: true,
            isPointer: isComponent,
            isProperty: true
          })
          maps.push(titleMap)
          titleMap.mapText = [maps[(maps.length - 1)]];
        }
        else
        {
          titleMap = undefined;
        }
        /* Then we try to match the value */
        mapText = splitText(value);
        mapValues = (titleMap ? titleMap.mapValues : maps);
        lenn = mapText.length;
        i = 0;

        for(i;i<lenn;i++)
        {
          item = mapText[i];
          if(item.match(__matchInsert))
          {
            localMap = new mapObject({
              local_id: id,
              node_id: nodeId,
              mapIndex: mapValues.length,
              mapTextIndex: i,
              text: item,
              mapText: mapText,
              maps: mapValues,
              node: node,
              type: 'style',
              isInsert: true,
              property: title,
              local: node.style,
              localAttr: title,
              isInlineStyle: true,
              isPointer: isComponent,
              isPropertyValue: true
            })
            if(!titleMap)
            {
              maps.push(localMap);
              localMap.mapText = [maps[(maps.length - 1)]];
            }
            else
            {
              titleMap.mapValues.push(localMap)
            }
          }
          else if(item.match(__matchText))
          {
            localMap = new mapObject({
              local_id: id,
              node_id: nodeId,
              mapIndex: mapValues.length,
              mapTextIndex: i,
              text: item,
              mapText: mapText,
              maps: mapValues,
              node: node,
              type: 'style',
              property: title,
              listener: title,
              local: node.style,
              localAttr: title,
              isInlineStyle: true,
              isPointer: isComponent,
              isPropertyValue: true
            })
            if(!titleMap)
            {
              maps.push(localMap);
              localMap.mapText = [maps[(maps.length - 1)]];
            }
            else
            {
              titleMap.mapValues.push(localMap)
            }
          }
          else
          {
            localMap = item;
          }
          mapText[i] = localMap;
        }
        if(titleMap) titleMap.values = mapText;
      }
    }
  }
251051
def _normalize_label(self, s, wsmap):
        
        toks = []
        for tok in list(set(self.npattern.sub(' ', s).split(' '))):
            if tok in wsmap:
                tok=wsmap[tok]
            if tok != "":
                toks.append(tok)
        toks.sort()
        return " ".join(toks)
556131
def _monomer_pattern_label(mp):
    """"""
    site_strs = []
    for site, cond in mp.site_conditions.items():
        if isinstance(cond, tuple) or isinstance(cond, list):
            assert len(cond) == 2
            if cond[1] == WILD:
                site_str = '%s_%s' % (site, cond[0])
            else:
                site_str = '%s_%s%s' % (site, cond[0], cond[1])
        elif isinstance(cond, numbers.Real):
            continue
        else:
            site_str = '%s_%s' % (site, cond)
        site_strs.append(site_str)
    return '%s_%s' % (mp.monomer.name, '_'.join(site_strs))
1208958
def label_for(self, name):
        ''''''
        method = getattr(self, name)
        if method.__doc__ and method.__doc__.strip():
            return method.__doc__.strip().splitlines()[0]
        return humanize(name.replace(self._prefix, ''))
661041
def translate_labels(val):
    '''
    
    '''
    if not isinstance(val, dict):
        if not isinstance(val, list):
            val = split(val)
        new_val = {}
        for item in val:
            if isinstance(item, dict):
                if len(item) != 1:
                    raise SaltInvocationError('Invalid label(s)')
                key = next(iter(item))
                val = item[key]
            else:
                try:
                    key, val = split(item, '=', 1)
                except ValueError:
                    key = item
                    val = ''
            if not isinstance(key, six.string_types):
                key = six.text_type(key)
            if not isinstance(val, six.string_types):
                val = six.text_type(val)
            new_val[key] = val
        val = new_val
    return val
267989
def transformer(data, label):
    """"""
    # resize to 64x64
    data = mx.image.imresize(data, 64, 64)
    # transpose from (64, 64, 3) to (3, 64, 64)
    data = mx.nd.transpose(data, (2, 0, 1))
    # normalize to [-1, 1]
    data = data.astype(np.float32)/128 - 1
    # if image is greyscale, repeat 3 times to get RGB image.
    if data.shape[0] == 1:
        data = mx.nd.tile(data, (3, 1, 1))
    return data, label
1166961
def build_colormap(palette, info):
        """"""

        from trollimage.colormap import Colormap
        if 'palette_meanings' in palette.attrs:
            palette_indices = palette.attrs['palette_meanings']
        else:
            palette_indices = range(len(palette))

        sqpalette = np.asanyarray(palette).squeeze() / 255.0
        tups = [(val, tuple(tup))
                for (val, tup) in zip(palette_indices, sqpalette)]
        colormap = Colormap(*tups)
        if 'palette_meanings' not in palette.attrs:
            sf = info.get('scale_factor', np.array(1))
            colormap.set_range(
                *(np.array(info['valid_range']) * sf + info.get('add_offset', 0)))

        return colormap, sqpalette