def redistribute_temperatures(in_system, temperatures):
    """
    In this function array of `temperatures` is parsed into chunks that belong to stellar surface and spots.

    :param in_system: instance to redistribute temperatures
    :param temperatures: numpy.array; temperatures from the whole surface, ordered: surface, spot1, spot2...
    :param in_system: instance to redistribute temperatures
    """
    for component in ['primary', 'secondary']:
        star = getattr(in_system, component)
        counter = len(star.temperatures)
        star.temperatures = temperatures[component][:counter]
        if star.has_spots():
            for spot_index, spot in star.spots.items():
                spot.temperatures = temperatures[component][counter:counter +
                    len(spot.temperatures)]
                counter += len(spot.temperatures)
    return in_system
