def binned_source_to_rest(spec: Spectrum, z: float = None) -> Spectrum: """ Takes in a binned source spectrum and shifts it to rest frame. WARNING: Assumes desired wavelengths will be integer values and called (int) on them as a result. If integer wavelengths are NOT desired, this method will need to be modified. :param spec: Binned source spectrum :type spec: Spectrum :param z: Original redshift. If not passed, it will call spec.getRS() and use that value. :type z: float :return: Rest frame spectrum :rtype: Spectrum """ spec = spec.cpy() z = z or spec.getRS() wls = spec.getWavelengths() n = len(wls) for wl in wls: spec[int(wl / (1 + z))] = spec[wl] del spec[wl] return spec