Ejemplo n.º 1
0
 def sanitize_depth(self, depth):
     if iterable(depth):
         validate_width_tuple(depth)
         depth = (self.ds.quan(depth[0], fix_unitary(depth[1])), )
     elif isinstance(depth, Number):
         depth = (self.ds.quan(depth, 'code_length',
                               registry=self.ds.unit_registry), )
     elif isinstance(depth, YTQuantity):
         depth = (depth, )
     else:
         raise YTInvalidWidthError(depth)
     return depth
Ejemplo n.º 2
0
def validate_iterable_width(width, ds, unit=None):
    if isinstance(width[0], tuple) and isinstance(width[1], tuple):
        validate_width_tuple(width[0])
        validate_width_tuple(width[1])
        return (
            ds.quan(width[0][0], fix_unitary(width[0][1])),
            ds.quan(width[1][0], fix_unitary(width[1][1])),
        )
    elif isinstance(width[0], Number) and isinstance(width[1], Number):
        return (ds.quan(width[0], "code_length"), ds.quan(width[1], "code_length"))
    elif isinstance(width[0], YTQuantity) and isinstance(width[1], YTQuantity):
        return (ds.quan(width[0]), ds.quan(width[1]))
    else:
        validate_width_tuple(width)
        # If width and unit are both valid width tuples, we
        # assume width controls x and unit controls y
        try:
            validate_width_tuple(unit)
            return (
                ds.quan(width[0], fix_unitary(width[1])),
                ds.quan(unit[0], fix_unitary(unit[1])),
            )
        except YTInvalidWidthError:
            return (
                ds.quan(width[0], fix_unitary(width[1])),
                ds.quan(width[0], fix_unitary(width[1])),
            )