<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def datasets(ctx, client):
 """Migrate dataset metadata."""

    from renku.models._jsonld import asjsonld
    from renku.models.datasets import Dataset
    from renku.models.refs import LinkReference

    from ._checks.location_datasets import _dataset_metadata_pre_0_3_4

    for old_path in _dataset_metadata_pre_0_3_4(client):
        with old_path.open('r') as fp:
            dataset = Dataset.from_jsonld(yaml.safe_load(fp))

        name = str(old_path.parent.relative_to(client.path / 'data'))
        new_path = (
            client.renku_datasets_path / dataset.identifier.hex /
            client.METADATA
        )
        new_path.parent.mkdir(parents=True, exist_ok=True)

        dataset = dataset.rename_files(
            lambda key: os.path.
            relpath(str(old_path.parent / key), start=str(new_path.parent))
        )

        with new_path.open('w') as fp:
            yaml.dump(asjsonld(dataset), fp, default_flow_style=False)

        old_path.unlink()

        LinkReference.create(client=client,
                             name='datasets/' + name).set_reference(new_path)