It didn't happen by accident, but rather because he "(looks) at both visible light and infrared light and based on how different materials absorb light, (he) can compare that with the laboratory data and make some inference about what kind of materials are present.", and before that because he learned the required stuff to end up doing this.