コード例 #1
0
    def _post_init(self, val, **field_args):
        """Initialize float field"""

        if isinstance(val, PositionArray):
            if val.cls_name != "PositionArray":
                raise exceptions.InitializationError(
                    f"Argument 'val' cannot be of type '{val.cls_name}', must be of type 'PositionArray' or numpy/list"
                )
            data = val
        else:
            try:
                system = field_args.pop("system")
            except KeyError:
                raise exceptions.InitializationError(
                    f"{self._factory.__name__}() missing 1 required positional argument: 'system'"
                ) from None

            data = self._factory(val, system, **field_args)

        # Check that unit is not given, overwrite with system units
        if self._unit is not None and self._unit != data.unit():
            raise exceptions.InitializationError("Parameter 'unit' should not be specified for positions")
        self._unit = data.unit()

        # Check that the correct number of observations are given
        if len(data) != self.num_obs:
            raise ValueError(f"{self.name!r} initialized with {len(data)} values, expected {self.num_obs}")

        # Store the data as a PositionArray
        self.data = data
コード例 #2
0
    def _post_init(self, val, **field_args):
        """Initialize time field"""
        if isinstance(val, TimeArray):
            data = val
        else:
            try:
                scale = field_args.pop("scale")
            except KeyError:
                raise exceptions.InitializationError(
                    f"{self._factory.__name__}() missing 1 required positional argument: 'scale'"
                ) from None

            try:
                fmt = field_args.pop("fmt")
            except KeyError:
                raise exceptions.InitializationError(
                    f"{self._factory.__name__}() missing 1 required positional argument: 'fmt'"
                ) from None

            data = self._factory(val, scale, fmt, **field_args)

        # Check that unit is not given, overwrite with time scale
        if self._unit is not None:
            raise exceptions.InitializationError(
                "Parameter 'unit' should not be specified for times")
        self._unit = None

        # Check that the correct number of observations are given
        if len(data) != self.num_obs:
            raise ValueError(
                f"{self.name!r} initialized with {len(data)} values, expected {self.num_obs}"
            )

        # Store the data as a TimeArray
        self.data = data
コード例 #3
0
    def _post_init(self, val, **field_args):
        """Initialize position delta field"""
        if isinstance(val, PosVelDeltaArray):
            data = val
        else:
            try:
                system = field_args.pop("system")
            except KeyError:
                raise exceptions.InitializationError(
                    f"{self._factory.__name__}() missing 1 required positional argument: 'system'"
                ) from None
            data = self._factory(val, system, **field_args)

        # Check that unit is not given, overwrite with system units
        if self._unit is not None and self._unit != data.unit():
            raise exceptions.InitializationError(
                "Parameter 'unit' should not be specified for position and velocity deltas"
            )
        self._unit = data.unit()

        # Check that the correct number of observations are given
        if len(data) != self.num_obs:
            raise ValueError(
                f"{self.name!r} initialized with {len(data)} values, expected {self.num_obs}"
            )

        # Store the data as a PosVelDeltaArray
        self.data = data
コード例 #4
0
    def _post_init(self, val, **field_args):
        """Initialize float field"""
        if field_args:
            raise exceptions.InitializationError(
                f"{self._factory.__name__}() received unknown argument {','.join(field_args.keys())}"
            )

        data = self._factory(val, dtype=bool)

        # Check that the correct number of observations are given
        if len(data) != self.num_obs:
            raise ValueError(
                f"{self.name!r} initialized with {len(data)} values, expected {self.num_obs}"
            )

        # We only support 1- and 2-dimensional arrays
        if data.ndim < 1 or data.ndim > 2:
            raise ValueError(
                f"{self.name!r} initialized with {data.ndim}-dimensional data, "
                "only 1- and 2-dimensional values are supported")

        # Check that unit is not given
        if self._unit is not None:
            raise exceptions.InitializationError(
                "Parameter 'unit' should not be specified for boolean arrays")

        # Store the data as a regular numpy array
        self.data = data
コード例 #5
0
    def _post_init(self, val, **field_args):
        """Initialize field"""
        if field_args:
            raise exceptions.InitializationError(f"Unknown input parameter {','.join(field_args.keys())}")

        if isinstance(val, Collection):
            data = val
        else:
            data = self._factory()

        # Check that unit is not given
        if self._unit is not None:
            raise exceptions.InitializationError("Parameter 'unit' should not be specified for collections")

        # Store the data as a Collection
        self.data = data
コード例 #6
0
    def _post_init(self, val, **dir_args):
        """Initialize float field"""
        if isinstance(val, DirectionArray):
            data = val
        else:
            data = self._factory(val, **dir_args)

        # Check that unit is not given, overwrite with direction units
        if self._unit is not None and self._unit != data.unit():
            raise exceptions.InitializationError(
                "Parameter 'unit' should not be specified for directions")
        self._unit = data.unit()

        # Check that the correct number of observations are given
        if len(data) != self.num_obs:
            raise ValueError(
                f"{self.name!r} initialized with {len(data)} values, expected {self.num_obs}"
            )

        # Check that the correct number of columns are given
        if data.ndim != 2:
            raise ValueError(
                f"{self.name!r} initialized with {data.ndim} columns, expected 2 (ra, dec)"
            )

        # Store the data as a TimeArray
        self.data = data
コード例 #7
0
    def _post_init(self, val, **field_args):
        """Initialize float field"""
        if field_args:
            raise exceptions.InitializationError(
                f"{self._factory.__name__}() received unknown argument {','.join(field_args.keys())}"
            )
        if isinstance(val, np.ndarray) and val.dtype == self.dtype:
            data = val
        else:
            data = self._factory(val, dtype=self.dtype)

        # Check that the correct number of observations are given
        if len(data) != self.num_obs:
            raise ValueError(
                f"{self.name!r} initialized with {len(data)} values, expected {self.num_obs}"
            )

        # We only support 1- and 2-dimensional arrays
        # if data.ndim < 1 or data.ndim > 2:
        #    raise ValueError(
        #        f"{self.name!r} initialized with {data.ndim}-dimensional data, "
        #        "only 1- and 2-dimensional values are supported"
        #    )

        # Handle units
        if self._unit is not None:
            self._unit = self._validate_unit(data, self._unit)

        # Store the data as a regular numpy array
        self.data = data
コード例 #8
0
ファイル: float.py プロジェクト: uasau/midgard
    def _post_init(self, val, **field_args):
        """Initialize float field"""
        if field_args:
            raise exceptions.InitializationError(
                f"{self._factory.__name__}() received unknown argument {','.join(field_args.keys())}"
            )

        data = self._factory(val, dtype=float)

        # Check that the correct number of observations are given
        if len(data) != self.num_obs:
            raise ValueError(
                f"{self.name!r} initialized with {len(data)} values, expected {self.num_obs}"
            )

        # We only support 1- and 2-dimensional arrays
        if data.ndim < 1 or data.ndim > 2:
            raise ValueError(
                f"{self.name!r} initialized with {data.ndim}-dimensional data, "
                "only 1- and 2-dimensional values are supported")

        # Handle units
        if self._unit is not None:
            cols = 1 if data.ndim == 1 else data.shape[1]
            if isinstance(self._unit, str):
                self._unit = (self._unit, ) * cols
            elif len(self._unit) != cols:
                raise ValueError(
                    f"Number of units ({len(self._unit)}) must equal number of columns ({cols})"
                )

        # Store the data as a regular numpy array
        self.data = data
コード例 #9
0
def g2t_pos(gcrs: "GcrsPosition", time: "Time" = None) -> "TrsPosition":
    """Transforms input array from gcrs to trs coordinates"""
    if time is None:
        time = gcrs.time
        if time is None:
            raise mg_exceptions.InitializationError("Time is not defined")
    gcrs = np.asarray(gcrs)[:, :, None]
    return (rotation.gcrs2trs(time) @ gcrs)[:, :, 0]
コード例 #10
0
def g2t_vel(gcrs: "GcrsVelocity", time: "Time" = None) -> "TrsVelocity":
    """Transforms input array from gcrs to trs coordinates"""
    if time is None:
        time = gcrs.time
        if time is None:
            raise mg_exceptions.InitializationError("Time is not defined")
    gcrs = nputil.col(gcrs)
    return _matmul(rotation.dgcrs2trs_dt(time), gcrs)
コード例 #11
0
def t2g_pos(trs: "TrsPosition", time: "Time" = None) -> "GcrsPosition":
    """Transforms input array from trs to gcrs coordinates"""
    if time is None:
        time = trs.time
        if time is None:
            raise mg_exceptions.InitializationError("Time is not defined")
    trs = nputil.col(trs)
    return _matmul(rotation.trs2gcrs(time), trs)
コード例 #12
0
def t2g_vel(trs: "TrsVelocity", time: "Time" = None) -> "GcrsVelocity":
    """Transforms input array from trs to gcrs coordinates"""
    if time is None:
        time = trs.time
        if time is None:
            raise mg_exceptions.InitializationError("Time is not defined")
    trs = np.asarray(trs)[:, :, None]
    return (rotation.dtrs2gcrs_dt(time) @ trs)[:, :, 0]
コード例 #13
0
def delta_t2y(trs: "TrsPositionDelta",
              time: "Time" = None) -> "YawPositionDelta":
    """Convert position deltas from TRS to YAW"""
    if time is None:
        time = trs.time
        if time is None:
            raise mg_exceptions.InitializationError("Time is not defined")
    t2y = rotation.trs2yaw(trs.ref_pos, time)
    return _matmul(t2y, trs.mat)
コード例 #14
0
def delta_y2t(yaw: "YawPositionDelta",
              time: "Time" = None) -> "TrsPositionDelta":
    """Convert position deltas from YAW to TRS"""
    if time is None:
        time = yaw.time
        if time is None:
            raise mg_exceptions.InitializationError("Time is not defined")
    y2t = rotation.yaw2trs(yaw.ref_pos, time)
    return _matmul(y2t, yaw.mat)
コード例 #15
0
def delta_y2t_posvel(yaw: "YawPosVelDelta",
                     time: "Time" = None) -> "TrsPosVelDelta":
    """Convert position deltas from YAW to TRS"""
    if time is None:
        time = yaw.time
        if time is None:
            raise mg_exceptions.InitializationError("Time is not defined")
    y2t = rotation.yaw2trs(yaw.ref_pos, time)
    # TODO: verify this tranformation
    yaw2trs = np.block([[y2t, np.zeros(y2t.shape)], [np.zeros(y2t.shape),
                                                     y2t]])
    return _matmul(yaw2trs, yaw.mat)
コード例 #16
0
def g2t_posvel(gcrs: "GcrsPosVel", time: "Time" = None) -> "TrsPosVel":
    """Transforms input array from gcrs to trs coordinates"""
    if time is None:
        time = gcrs.time
        if time is None:
            raise mg_exceptions.InitializationError("Time is not defined")
    gcrs = nputil.col(gcrs)
    g2t = rotation.gcrs2trs(time)
    dg2t = rotation.dgcrs2trs_dt(time)

    transformation = np.block([[g2t, np.zeros(g2t.shape)], [dg2t, g2t]])
    return _matmul(transformation, gcrs)
コード例 #17
0
def t2g_posvel(trs: "TrsPosVel", time: "Time" = None) -> "GcrsPosVel":
    """Transforms input array from trs to gcrs coordinates"""
    if time is None:
        time = trs.time
        if time is None:
            raise mg_exceptions.InitializationError("Time is not defined")
    trs = nputil.col(trs)
    t2g = rotation.trs2gcrs(time)
    dt2g = rotation.dtrs2gcrs_dt(time)

    transformation = np.block([[t2g, np.zeros(t2g.shape)], [dt2g, t2g]])
    return _matmul(transformation, trs)
コード例 #18
0
def delta_t2y_posvel(trs: "TrsPosVelDelta",
                     time: "Time" = None) -> "YawPosVelDelta":
    """Convert position deltas from TRS to YAW"""
    if time is None:
        time = trs.time
        if time is None:
            raise mg_exceptions.InitializationError("Time is not defined")
    t2y = rotation.trs2yaw(trs.ref_pos, time)
    # TODO: verify this tranformation
    trs2yaw = np.block([[t2y, np.zeros(t2y.shape)], [np.zeros(t2y.shape),
                                                     t2y]])
    return _matmul(trs2yaw, trs.mat)
コード例 #19
0
    def _post_init(self, val, **field_args):
        """Initialize sigma field"""
        if isinstance(val, SigmaArray):
            data = val
        else:
            try:
                sigma = field_args.pop("sigma")
            except KeyError:
                raise exceptions.InitializationError(
                    f"{self._factory.__name__}() missing 1 required positional argument: 'sigma'"
                ) from None

            if field_args:
                raise exceptions.InitializationError(
                    f"{self._factory.__name__}() received unknown argument {','.join(field_args.keys())}"
                )

            data = self._factory(val, sigma)

        # Check that the correct number of observations are given
        if len(data) != self.num_obs:
            raise ValueError(
                f"{self.name!r} initialized with {len(data)} values, expected {self.num_obs}"
            )

        # We only support 1- and 2-dimensional arrays
        if data.ndim < 1 or data.ndim > 2:
            raise ValueError(
                f"{self.name!r} initialized with {data.ndim}-dimensional data, "
                "only 1- and 2-dimensional values are supported")

        # Handle units
        if self._unit is not None:
            self._unit = self._validate_unit(data, self._unit)
            data.set_unit(self._unit)

        # Store the data as a SigmaArray
        self.data = data
コード例 #20
0
def g2t_posvel(gcrs: "GcrsPosVel", time: "Time" = None) -> "TrsPosVel":
    """Transforms input array from gcrs to trs coordinates"""
    if time is None:
        time = gcrs.time
        if time is None:
            raise mg_exceptions.InitializationError("Time is not defined")
    gcrs = np.asarray(gcrs)[:, :, None]
    g2t = rotation.gcrs2trs(time)
    dg2t = rotation.dgcrs2trs_dt(time)

    # Form block diagonal matrix with shape (num_obs, 6, 6)
    transformation = np.block([[g2t, np.zeros(g2t.shape)],
                               [np.zeros(dg2t.shape), dg2t]])
    return (transformation @ gcrs)[:, :, 0]
コード例 #21
0
def t2g_posvel(trs: "TrsPosVel", time: "Time" = None) -> "GcrsPosVel":
    """Transforms input array from trs to gcrs coordinates"""
    if time is None:
        time = trs.time
        if time is None:
            raise mg_exceptions.InitializationError("Time is not defined")
    trs = np.asarray(trs)[:, :, None]
    t2g = rotation.trs2gcrs(time)
    dt2g = rotation.dtrs2gcrs_dt(time)

    # Form block diagonal matrix with shape (num_obs, 6, 6)
    transformation = np.block([[t2g, np.zeros(t2g.shape)],
                               [np.zeros(dt2g.shape), dt2g]])
    return (transformation @ trs)[:, :, 0]