Interestingly we can’t actually know that we are correct in our calculations of what a planet lightyears away has as its atmosphere because we will never be able to go there and make sure we are correct. It’s a calculation and nothing more. For all we know that planet may not even exist. That’s what’s mind blowing about astronomy. We really don’t have any way of proving anything about what we are observing. All we can say is we are observing. That’s the only thing science can offer us.
Spectroscopy is well established.