Astronomers have telescopes that can photograph the planets and other objects under different spectrums of light, such as X-ray, gamma rays, and ultra-violet. Each mineral reacts to light differently and we can deduce the composition of something from far away without having to sample it firsthand.
Edit: I’m not an expert. And apparently this is just how they detect atmospheres of objects in space. My bad.
Latest Answers