Beispiel #1
0
    def __set__(self, instance, value):
        if super(UnitVectorDescriptor, self).__set__(instance, value):  # the None handler...kinda hacky
            return

        try:
            vec = parse_serializable(value, self.name, instance, self.the_type)
        except Exception as e:
            logger.error(
                'Failed converting {} of type {} to Unit Vector Type type {}\n\t'
                'for field {} of class {} with exception {} - {}.\n\t'
                'Setting value to None, which may be against the standard'.format(
                    value, type(value), self.the_type, self.name, instance.__class__.__name__, type(e), e))
            self.data[instance] = None
            return None

        # noinspection PyTypeChecker
        coords = vec.get_array(dtype=numpy.float64)
        the_norm = norm(coords)
        if the_norm == 0:
            logger.error(
                'The input for field {} is expected to be made into a unit vector.\n\t'
                'In this case, the norm of the input is 0.\n\t'
                'The value is set to None, which may be against the standard.'.format(
                    self.name))
            self.data[instance] = None
        elif the_norm == 1:
            self.data[instance] = vec
        else:
            self.data[instance] = self.the_type.from_array(coords/the_norm)
Beispiel #2
0
    def __set__(self, instance, value):
        if super(SerializableDescriptor, self).__set__(instance, value):  # the None handler...kinda hacky
            return

        try:
            self.data[instance] = parse_serializable(value, self.name, instance, self.the_type)
        except Exception as e:
            logger.error(
                'Failed converting {} of type {} to Serializable type {}\n\t'
                'for field {} of class {} with exception {} - {}.\n\t'
                'Setting value to None, which may be against the standard.'.format(
                    value, type(value), self.the_type, self.name, instance.__class__.__name__, type(e), e))
            self.data[instance] = None
Beispiel #3
0
 def LLH(self, value):
     if value is not None:
         self._LLH = parse_serializable(value, 'LLH', self, LatLonHAEType)
         self._ECF = XYZType.from_array(
             geodetic_to_ecf(self._LLH.get_array(order='LAT')))
Beispiel #4
0
 def ECF(self, value):
     if value is not None:
         self._ECF = parse_serializable(value, 'ECF', self, XYZType)
         self._LLH = LatLonHAEType.from_array(
             ecf_to_geodetic(self._ECF.get_array()))