Is the number of wavelengths of light spanning a distance invariant with respect to spacetime distortion? I was recently asked by a friend how the expansion of spacetime affects photons.  I gave him what I feel is a satisfactory general response, but it got me wondering how, exactly to calculate this effect. It occurred to me that a simple way to conceptualize the change in energy was considering comparing the number of wavelengths that would have spanned the distance originally to the number it would take to span the expanded distance.  Given the time contraction of a photon, it seemed reasonable to me to assume that the number of wavelengths spanning the distance traveled would be a constant.  Unfortunately, I never had the opportunity to take a GR class and I don't know if this simple concept is in any way valid.
My question is, is this simple naive approach valid (even if it needs modification)?  That is, given the relation between wavelength and energy
$$E = \frac{hc}{\lambda}$$
where $E$ is the energy, $h$ is Plank's constant, $c$ is the speed of light, and $\lambda$ is the original wavelength of the light, can I make this
$$E = \frac{nhc}{d}$$
where $d$ is the unexpanded distance of a path traveled by light, and $n$ is the number of wavelengths of the initial energy that would span the distance along the path traveled by light.
From this point, is it proper to calculate the fractional change in energy due to a fractional expansion of spacetime by
$$\frac{dE}{dd} = -\frac{nhc}{d^2} $$
where $dd$ is the change in distance due to expansion.  Or, alternatively,
$$E = E_0 + nhc \left(\frac{1}{d_f} - \frac{1}{d_i}\right).$$
There have been several questions about the temperature of the CMB and how the expansion of spacetime reduces it's temperature.  In particular the following closely address the topic at hand:


*

*Have CMB photons "cooled" or been "stretched"?

*Effect of expansion of space on CMB
though none of them addressed the issue in the way I have described.  It is worth noting that in the article linked to in the first of these questions, the authors state "...'all wavelengths of the light ray are doubled' if the scale factor doubles." which seems to give the same proportionality described by my formulation.
My intuition tells me that this is an inappropriate method at least in part because there is no observational frame stationary with reference to the path traveled, but I sense that there are other problems as well.

I just realized that I could equally well refrain from using $n$ and instead just use $d_i/\lambda_0$ or $d_i E_0 /hc$ which gives
$$E = E_0 \left( \frac{d_i}{d_f} \right)$$
 A: The answer is yes for slow deformation compared to the frequency of light, and for cosmological expansion this is a perfect approximation. The relevant literature is old, it is the theory of adiabatic expansion of a box of light developed by Wilhelm Wien in 1898. The principle is that the number of wavelengths of light that fit in the box stays the same when you gradually move the wall outward, so that the light cools as the box expands in an adiabatic way. This led to Wien's displacement principle, and the theory of adiabatic invariance of the quantum number, which was the Einstein-Sommerfeld-deBroglie-Schrodinger path to quantum mechanics.
The way you can see that this is valid is to imagine that the two objects are two cosmological metal plates a certain distance apart. The number of wavelengths between these two plates is an integer and it can't change smoothly, it can only jump up and down. The number of photons inbetween is also an integer, which can't change smoothly. So when the two walls move apart, the number of photons and the number of wavelengths stays fixed.
