def dim_unit_scaling(in_unit, out_unit):
    """
    Calculate the scaling factor to convert from the input unit (in_unit) to
    the output unit (out_unit). in_unit and out_unit must be a string and one
    of ['nm', 'um', 'mm', 'cm', 'm', 'km']. 

    inputs
    ======
    in_unit : str
        Input unit
    out_unit :str
        Output unit

    returns
    =======
    scaling_factor : float
    """
    unit_vals = {'nm': 1e-09, 'um': 1e-06, 'mm': 0.001, 'cm': 0.01, 'm': 
        1.0, 'km': 1000.0}
    if in_unit not in unit_vals:
        raise ValueError('Invalid input unit {}. Must be one of {}'.format(
            in_unit, list(unit_vals.keys())))
    if out_unit not in unit_vals:
        raise ValueError('Invalid input unit {}. Must be one of {}'.format(
            in_unit, list(unit_vals.keys())))
    return unit_vals[in_unit] / unit_vals[out_unit]
