# Path: beyond/frames/local.py
# def to_local(frame, orbit, expanded=True):
#     """Provide the transformation matrix to convert a vector from an inertial frame
#     to a local orbital reference frame of choice
# 
#     Args:
#         frame (str): Name of the local orbital frame ('QSW' or 'TNW')
#         orbit (List[float]) : cartesian coordinates (length 6)
#         expanded (bool) : If ``True`` the returned matrix is 6x6, 3x3 otherwise
#     Return:
#         numpy.ndarray : Transformation matrix
# 
#     >>> delta_tnw = [1, 0, 0]
#     >>> p = [-6142438.668, 3492467.560, -25767.25680]
#     >>> v = [505.8479685, 942.7809215, 7435.922231]
#     >>> pv = p + v
#     >>> mat = to_local("TNW", pv, expanded=False).T
#     >>> delta_inert = mat @ delta_tnw
#     >>> all(delta_inert == v / norm(v))
#     True
#     """
# 
#     if frame.upper() == "QSW":
#         m = to_qsw(orbit)
#     elif frame.upper() == "TNW":
#         m = to_tnw(orbit)
#     else:
#         raise ValueError(f"Unknown local orbital frame : {frame}")
# 
#     if expanded:
#         m = expand(m)
# 
#     return m
# 
# Path: beyond/frames/frames.py
# def get_frame(frame):
#     """Frame factory
# 
#     Args:
#         frame (str): name of the desired frame
#     Return:
#         Frame: the object representing the frame demanded
#     Raise:
#         ~beyond.frames.frames.UnknownFrameError
#     """
# 
#     if frame not in dynamic.keys() and config.get(
#         "env", "jpl", "dynamic_frames", fallback=False
#     ):
#         from ..env.jpl import create_frames, JplConfigError
# 
#         try:
#             create_frames()
#         except (JplConfigError, UnknownBodyError) as e:
#             raise UnknownFrameError(frame) from e
# 
#     try:
#         return dynamic[frame]
#     except KeyError:
#         raise UnknownFrameError(frame)


import numpy as np
from ..frames.local import to_local
from ..frames.frames import get_frame
    @frame.setter
    def frame(self, frame):

        _local = ("TNW", "QSW")

        if isinstance(frame, str) and frame not in _local:
            frame = get_frame(frame)

        if frame == self.frame:
            # The frame is the same as the current one
            return

        # Here we use a two step method
        # First we compute the matrix m1, which represents the
        # rotation from the current frame to the parent frame
        # Second we compute the matrix m2 which represents the
        # rotation from the parent frame to the target frame

        # Handle previous frame to parent frame conversion
        if self.frame in ("TNW", "QSW"):
            m1 = to_local(self.frame, self.orb).T
        elif self.frame != self._orb_frame:
            m1 = self.frame.orientation.convert_to(
                self.orb.date, self._orb_frame.orientation
            )
        else:
            m1 = np.identity(6)

        # handle parent frame to target frame conversion
        if frame in ("TNW", "QSW"):

# Path: beyond/frames/local.py
# def to_local(frame, orbit, expanded=True):
#     """Provide the transformation matrix to convert a vector from an inertial frame
#     to a local orbital reference frame of choice
# 
#     Args:
#         frame (str): Name of the local orbital frame ('QSW' or 'TNW')
#         orbit (List[float]) : cartesian coordinates (length 6)
#         expanded (bool) : If ``True`` the returned matrix is 6x6, 3x3 otherwise
#     Return:
#         numpy.ndarray : Transformation matrix
# 
#     >>> delta_tnw = [1, 0, 0]
#     >>> p = [-6142438.668, 3492467.560, -25767.25680]
#     >>> v = [505.8479685, 942.7809215, 7435.922231]
#     >>> pv = p + v
#     >>> mat = to_local("TNW", pv, expanded=False).T
#     >>> delta_inert = mat @ delta_tnw
#     >>> all(delta_inert == v / norm(v))
#     True
#     """
# 
#     if frame.upper() == "QSW":
#         m = to_qsw(orbit)
#     elif frame.upper() == "TNW":
#         m = to_tnw(orbit)
#     else:
#         raise ValueError(f"Unknown local orbital frame : {frame}")
# 
#     if expanded:
#         m = expand(m)
# 
#     return m
# 
# Path: beyond/frames/frames.py
# def get_frame(frame):
#     """Frame factory
# 
#     Args:
#         frame (str): name of the desired frame
#     Return:
#         Frame: the object representing the frame demanded
#     Raise:
#         ~beyond.frames.frames.UnknownFrameError
#     """
# 
#     if frame not in dynamic.keys() and config.get(
#         "env", "jpl", "dynamic_frames", fallback=False
#     ):
#         from ..env.jpl import create_frames, JplConfigError
# 
#         try:
#             create_frames()
#         except (JplConfigError, UnknownBodyError) as e:
#             raise UnknownFrameError(frame) from e
# 
#     try:
#         return dynamic[frame]
#     except KeyError:
#         raise UnknownFrameError(frame)


# Path: beyond/orbits/cov.py
import numpy as np
from ..frames.local import to_local
from ..frames.frames import get_frame

    @frame.setter
    def frame(self, frame):

        _local = ("TNW", "QSW")

        if isinstance(frame, str) and frame not in _local:
            frame = get_frame(frame)

        if frame == self.frame:
            # The frame is the same as the current one
            return

        # Here we use a two step method
        # First we compute the matrix m1, which represents the
        # rotation from the current frame to the parent frame
        # Second we compute the matrix m2 which represents the
        # rotation from the parent frame to the target frame

        # Handle previous frame to parent frame conversion
        if self.frame in ("TNW", "QSW"):
            m1 = to_local(self.frame, self.orb).T
        elif self.frame != self._orb_frame:
            m1 = self.frame.orientation.convert_to(
                self.orb.date, self._orb_frame.orientation
            )
        else:
            m1 = np.identity(6)

        # handle parent frame to target frame conversion
        if frame in ("TNW", "QSW"):

            m2 = to_local(frame, self.orb)