'Return an instance of the model which has units for which the parameter
values are compatible with the data units specified.
The input and output Quantity objects should be given as keyword
arguments.
Notes
This method is needed in order to be able to fit models with units in
the parameters, since we need to temporarily strip away the units from
the model during the fitting (which might be done by e.g. scipy
functions).
The units that the parameters will gain are not necessarily the units of
the input data, but are derived from them. Model subclasses that want
fitting to work in the presence of quantities need to define a
_parameter_units_for_data_units method that takes the input and output
units (as two dictionaries) and returns a dictionary giving the target
units for each parameter.'

def with_units_from_data(self, **kwargs):

    model = self.copy()
    inputs_unit = {inp: getattr(kwargs[inp], u'unit', dimensionless_unscaled) for inp in self.inputs if (kwargs[inp] is not None)}
    outputs_unit = {out: getattr(kwargs[out], u'unit', dimensionless_unscaled) for out in self.outputs if (kwargs[out] is not None)}
    parameter_units = self._parameter_units_for_data_units(inputs_unit, outputs_unit)
    for (name, unit) in parameter_units.items():
        parameter = getattr(model, name)
        parameter._set_unit(unit, force=True)
    return model
