Exemplo n.º 1
0
    def get_label(self, projected=False):
        """
        Return a data label for the given field, including units.
        """
        name = self.name[1]
        if self.display_name is not None:
            name = self.display_name

        # Start with the field name
        data_label = r"$\rm{%s}" % name

        # Grab the correct units
        if projected:
            raise NotImplementedError
        else:
            if self.ds is not None:
                units = Unit(self.units, registry=self.ds.unit_registry)
            else:
                units = Unit(self.units)
        # Add unit label
        if not units.is_dimensionless:
            data_label += r"\ \ (%s)" % (units.latex_representation())

        data_label += r"$"
        return data_label
Exemplo n.º 2
0
 def _get_axes_unit_labels(self, unit_x, unit_y):
     axes_unit_labels = ['', '']
     comoving = False
     hinv = False
     for i, un in enumerate((unit_x, unit_y)):
         unn = None
         if hasattr(self.data_source, 'axis'):
             if hasattr(self.ds.coordinates, "image_units"):
                 # This *forces* an override
                 unn = self.ds.coordinates.image_units[
                     self.data_source.axis][i]
             elif hasattr(self.ds.coordinates, "default_unit_label"):
                 axax = getattr(self.ds.coordinates, "%s_axis" %
                                ("xy"[i]))[self.data_source.axis]
                 unn = self.ds.coordinates.default_unit_label.get(
                     axax, None)
         if unn is not None:
             axes_unit_labels[i] = r'\ \ \left(' + unn + r'\right)'
             continue
         # Use sympy to factor h out of the unit.  In this context 'un'
         # is a string, so we call the Unit constructor.
         expr = Unit(un, registry=self.ds.unit_registry).expr
         h_expr = Unit('h', registry=self.ds.unit_registry).expr
         # See http://docs.sympy.org/latest/modules/core.html#sympy.core.expr.Expr
         h_power = expr.as_coeff_exponent(h_expr)[1]
         # un is now the original unit, but with h factored out.
         un = str(expr * h_expr**(-1 * h_power))
         un_unit = Unit(un, registry=self.ds.unit_registry)
         cm = Unit('cm').expr
         if str(un).endswith('cm') and cm not in un_unit.expr.atoms():
             comoving = True
             un = un[:-2]
         # no length units besides code_length end in h so this is safe
         if h_power == -1:
             hinv = True
         elif h_power != 0:
             # It doesn't make sense to scale a position by anything
             # other than h**-1
             raise RuntimeError
         if un not in ['1', 'u', 'unitary']:
             if un in formatted_length_unit_names:
                 un = formatted_length_unit_names[un]
             else:
                 un = Unit(un, registry=self.ds.unit_registry)
                 un = un.latex_representation()
                 if hinv:
                     un = un + '\,h^{-1}'
                 if comoving:
                     un = un + '\,(1+z)^{-1}'
                 pp = un[0]
                 if pp in latex_prefixes:
                     symbol_wo_prefix = un[1:]
                     if symbol_wo_prefix in prefixable_units:
                         un = un.replace(pp, "{" + latex_prefixes[pp] + "}",
                                         1)
             axes_unit_labels[i] = '\ \ (' + un + ')'
     return axes_unit_labels
    def get_label(self, projected=False):
        """
        Return a data label for the given field, including units.
        """
        name = self.name[1]
        if self.display_name is not None:
            name = self.display_name

        # Start with the field name
        data_label = r"$\rm{%s}" % name

        # Grab the correct units
        if projected:
            raise NotImplementedError
        else:
            units = Unit(self.units)
        # Add unit label
        if not units.is_dimensionless:
            data_label += r"\ \ (%s)" % (units.latex_representation())

        data_label += r"$"
        return data_label
Exemplo n.º 4
0
 def get_units(self):
     if self.ds is not None:
         u = Unit(self.units, registry=self.ds.unit_registry)
     else:
         u = Unit(self.units)
     return u.latex_representation()
Exemplo n.º 5
0
 def get_projected_units(self):
     u = Unit(self.units) * Unit('cm')
     return u.latex_representation()
Exemplo n.º 6
0
 def get_units(self):
     u = Unit(self.units)
     return u.latex_representation()
 def get_projected_units(self):
     u = Unit(self.units)*Unit('cm')
     return u.latex_representation()
 def get_units(self):
     u = Unit(self.units)
     return u.latex_representation()