Skip to main content

DoubleRainbow

People love rainbows. The problem is that forecasters lack the... well, foresight, to give the people the lucious rainbow details they want. The idea to fill this gaping hole in supply came from Akira Kakkar at MHacks 6, and I'm lucky to call him, Jenny Zhang and Philip Tsang my co-developers on the project for those critical first 36 hours. I personally released an alpha a year later because this project's momentum isn't allowed to stop. For the sake of all that is round and colorful.

Detecting rainbows is feasible from just satellite and radar data, and boils down a geometry problem on these two datasets. From a quick detour into the mechanics of rainbows the problem statement will essentially just pop out.

Rainbow mechanics

Rainbows are pretty simple! Even higher-order rainbows from multiple internal reflection (double-rainbow and beyond) follow the proceeding explanation after they exit the raindrop.

Light physics tells us that a visible light ray reflects in a raindrop by about 42° (independent of the size of the drop — it's all because of refractive indexes). The sun is so far away that all its rays run almost parallel, so in direct sunlight let's just say they are. Consider an unbroken sheet of rain in front of the viewer lit by these parallel sun rays. Then the crucial observation is that points on the sheet the ray from the sun and the ray to the viewer are 42° apart, the viewer will see the first direct reflection of the sun ray (split because of dispersion within the droplet). Joining these points together forms the familiar band of color, always elliptical in real life, although the general solution to this geometry problem isn't always.

Watch as $v_y$ increases (i.e. the sun altitude increases), the solutions transition from elliptical to hyperbolic:

Note then that whenever an area of a rain sheet is illuminated by direct sunlight, there is some point on the ground where a viewer will see a rainbow band.

When obscured by a cloud, the sun's light rays are scattered by the water vapor and are no longer tightly bundled in parallel rays, so no coherent rainbow forms.

Then at every point on our map, let's calculate the sun's ray direction from time of day and latitude. Above a radar precipiation map, let's overlay a "cloudmask", which is just a map of cloud cover derived from satellite imagery. Wherever we can trace a sun ray from the ground at the boundary of a radar blob without hitting the cloudmask, there should be a rainbow! 🌈

Implementation

NOAA and NASA publish the most frequent and diverse array of weather products in the English-speaking world, so the contiguous US is featured in this pilot implementation, due to the availability of current radar, cloudmask and ground observations (for cloud ceiling height).

Sources

Sources did not come easily, since they needed to be totally open and properly indexed for autonomous download by the server. The cloudmask sources its data from the geostationary weather satellite GOES-EAST, processed and published by CIMSS. Radar is a national composite from the Mesonet run and maintained by Iowa State University, an excellent repository of present and historical, high-resolution radar imagery. Ground observations come directly from NOAA's API for METAR weather stations across the US.

Processing

The outer borders of radar blobs come from OpenCV's findContours. For all these peripheral pixels, I rely on pysolar to spit out the azimuth (compass direction) and altitude (angle subtended with the ground) of the sun. The cloud ceiling of a given radar blob is assumed to be constant, so any METAR station the program finds within the blob will do.

The program traces the sun ray from the ground to the ceiling elevation and checks if the cloud mask is empty. These points on the radar blob are marked in the webfront map.

GitHub

acrylic-origami/DoubleRainbow