def update_differentials_to_match(original, velocity_reference, preserve_observer_frame=False):
    '\n    Given an original coordinate object, update the differentials so that\n    the final coordinate is at the same location as the original coordinate\n    but co-moving with the velocity reference object.\n\n    If preserve_original_frame is set to True, the resulting object will be in\n    the frame of the original coordinate, otherwise it will be in the frame of\n    the velocity reference.\n    '
    if (not velocity_reference.data.differentials):
        raise ValueError('Reference frame has no velocities')
    if (('obstime' in velocity_reference.frame_attributes) and hasattr(original, 'obstime')):
        velocity_reference = velocity_reference.replicate(obstime=original.obstime)
    original_icrs = original.transform_to(ICRS())
    velocity_reference_icrs = velocity_reference.transform_to(ICRS())
    differentials = velocity_reference_icrs.data.represent_as(CartesianRepresentation, CartesianDifferential).differentials
    data_with_differentials = original_icrs.data.represent_as(CartesianRepresentation).with_differentials(differentials)
    final_icrs = original_icrs.realize_frame(data_with_differentials)
    if preserve_observer_frame:
        final = final_icrs.transform_to(original)
    else:
        final = final_icrs.transform_to(velocity_reference)
    return final.replicate(representation_type=CartesianRepresentation, differential_type=CartesianDifferential)
Given an original coordinate object, update the differentials so that
the final coordinate is at the same location as the original coordinate
but co-moving with the velocity reference object.

If preserve_original_frame is set to True, the resulting object will be in
the frame of the original coordinate, otherwise it will be in the frame of
the velocity reference.
def update_differentials_to_match(original, velocity_reference, preserve_observer_frame=False):
    '\n    Given an original coordinate object, update the differentials so that\n    the final coordinate is at the same location as the original coordinate\n    but co-moving with the velocity reference object.\n\n    If preserve_original_frame is set to True, the resulting object will be in\n    the frame of the original coordinate, otherwise it will be in the frame of\n    the velocity reference.\n    '
    if (not velocity_reference.data.differentials):
        raise ValueError('Reference frame has no velocities')
    if (('obstime' in velocity_reference.frame_attributes) and hasattr(original, 'obstime')):
        velocity_reference = velocity_reference.replicate(obstime=original.obstime)
    original_icrs = original.transform_to(ICRS())
    velocity_reference_icrs = velocity_reference.transform_to(ICRS())
    differentials = velocity_reference_icrs.data.represent_as(CartesianRepresentation, CartesianDifferential).differentials
    data_with_differentials = original_icrs.data.represent_as(CartesianRepresentation).with_differentials(differentials)
    final_icrs = original_icrs.realize_frame(data_with_differentials)
    if preserve_observer_frame:
        final = final_icrs.transform_to(original)
    else:
        final = final_icrs.transform_to(velocity_reference)
    return final.replicate(representation_type=CartesianRepresentation, differential_type=CartesianDifferential)