def test_load_pes_only_file(self):
        """
        """

        path = paths.project('test_resources', 'pes_only_test_data.csv')

        positions = trackway.load_positions_file(path)
        self.assertEqual(len(positions.left_manus), 4)
        self.assertEqual(len(positions.right_manus), 5)
        self.assertEqual(len(positions.left_pes), 4)
        self.assertEqual(len(positions.right_pes), 5)
    def test_load_positions_file(self):
        """
        """

        path = paths.project('test_resources', 'test_data.csv')
        positions = trackway.load_positions_file(path)
        self.assertEqual(len(positions.left_manus), 18)
        self.assertEqual(len(positions.right_manus), 20)
        self.assertEqual(len(positions.left_pes), 21)
        self.assertEqual(len(positions.right_pes), 21)

        result = positions.left_pes[0].echo()
        self.assertIsNotNone(result)
Exemplo n.º 3
0
def load_trackway_positions(
        settings: dict,
        existing: limb.Property = None,
        save_as: str = None
) -> limb.Property:
    """
    Loads the trackway positions for the trial from the information provided in
    the settings object, unless an existing trackway positions object has been
    specified

    :param settings:
        Configuration for the simulation trial
    :param existing:
        Optionally the already loaded trackway positions, which will be cloned
        and returned if present
    :param save_as:
        An optional path where the loaded trackway positions shold be saved
    """

    if existing:
        # Ignore if already specified
        return existing.clone()

    data = settings.get('data')

    if isinstance(data, str):
        # Load from a specified file
        if not data.startswith('/'):
            data = os.path.join(settings['path'], data)
        if not os.path.exists(data):
            system.log(
                """
                [ERROR]: No CSV source data exists at the path:

                    {}
                """.format(data)
            )
            raise FileNotFoundError('No CSV source file found')

        return trackway.load_positions_file(data)

    # Generate from configuration settings
    track_offsets = limb.Property().assign(*data['offsets'])
    out = generate.trackway_positions(
        cycle_count=data['count'],
        step_size=data['step_size'],
        track_offsets=track_offsets,
        lateral_displacement=data['lateral_displacement'],
        positional_uncertainty=data.get('uncertainty')
    )

    if not save_as and data.get('save'):
        save_as = data.get('save')

    if save_as:
        trackway.save_positions_file(
            trackway_positions=out,
            path=os.path.join(settings['directory'], save_as)
        )

    return out