SpaceX's Crew Dragon spaceship and Falcon 9 rocket in Cape Canaveral, Florida, at NASA's Kennedy Space Center on May 24.

SpaceX was set to launch astronauts for the first time on Wednesday, thereby restoring NASA's human spaceflight program. But then storm clouds rolled in.

The rocket was fuelled and sitting on the launchpad. Officials had conducted final reviews to make sure everything was ready for liftoff, which was scheduled for 4:33 p.m. ET. NASA astronauts Bob Behnken and Doug Hurley were suited up on board. The mission was a go.

But just 17 minutes before the scheduled liftoff, bad weather - specifically thunderstorm anvil clouds and a strong electric field that could produce lightning strikes - made the skies above Cape Canaveral, Florida, unsafe. The mission commanders called off the launch.

"Not quite going to make it for this," a weather officer said on NASA's live feed of the launch.

He added that if they had an extra 10 minutes to wait, the conditions might have changed. But the window to launch lasts only about one second because of the fast-changing position of the International Space Station, where the spaceship would have headed.

SpaceX's Crew Dragon spaceship and Falcon 9 rocket on May 23.

However, as the launchpad crew unloaded propellant from the rocket, it became clear that the electric field would take at least 25 minutes to reach safe levels.

Storms have battered Cape Canaveral for days; more than 2 inches of rain fell in the area on Monday. On Tuesday, the weather outlook suggested a 60% chance of launch, but by Wednesday morning, the odds were 50-50.

SpaceX - the private rocket company founded by Elon Musk in 2002 - and NASA are now preparing to launch the mission, called Demo-2,  on Saturday. If that launch fails, they have one more opportunity on Sunday.

The 45th Weather Squadron of the US Air Force projected a 40% chance that weather conditions would be unsafe for both Saturday and Sunday launches.

Demo-2 is the culmination of about $3.1 billion (R54 billion) in funding from NASA through the agency's Commercial Crew Program, which is an effort to restore NASA's capability to launch its astronauts into space. The agency lost that in July 2011 after it retired its fleet of space shuttles.

"We are going to launch American astronauts on American rockets from American soil," NASA Administrator Jim Bridenstine said during a televised briefing on May 1. "We're going to do it here in the midst of the coronavirus pandemic, and I'm going to tell you that this is a high-priority mission to the United States of America."

The mission requires Behnken and Hurley to fly SpaceX's Crew Dragon spaceship into orbit after it launches atop a Falcon 9 rocket, then dock with the space station, where they could live for up to 110 days before returning to Earth.

Safe weather means low winds, no lightning, and gentle seas

NASA astronauts Doug Hurley, left, and Bob Behnken on May 23.

This launch is tricky not only because it's a test flight with people on board but also because it has to happen when the space station is more or less flying over the launch site so the spaceship can use less fuel. If the window to launch is missed, the attempt must be scrubbed.

To ensure the moment is right, mission managers monitor weather conditions that could endanger the rocket, including lightning, rain, and heavy clouds.

"You could trigger lightning," Tim Garner, a meteorologist at the National Oceanic and Atmospheric Administration, said on a NASA podcast in 2017. "[A rocket's] mere presence in a high electric field will be that thing that sets off the lightning strike."

That happened to the Apollo 12 mission in 1969. The astronauts inside the rocket felt the lightning strike, and it disabled nine nonessential instrument sensors.

That also seems to have been the threat that delayed SpaceX's launch on Wednesday.

Beyond storms, less obvious weather dynamics can throw a rocket off course. Musk has said that high-altitude wind shear "hits like a sledgehammer." That can cause "control problems," according to NASA's weather criteria for launching Falcon 9.

Those criteria outline the weather conditions needed for the rocket to launch safely, including an absence of lightning and thunderstorm anvil clouds within 10 nautical miles. There also cannot be a cloud layer thicker than 1,371m with freezing temperatures or cumulus clouds with freezing temperatures.

Additionally, SpaceX watches for high seas in the Atlantic Ocean, since that's where emergency rescue boats will be stationed in case Behnken and Hurley have to abort, detach from the rocket, and fly to safety as the Crew Dragon flies overhead.

"We need to make sure that if the crew had to come down, in a launch-escape scenario, that they would come down in a sea state that would keep them safe, and that the rescue forces would be able to come and get them," Benji Reed, the director of crew-mission management at SpaceX, said in a briefing on Friday.

Receive a daily update on your cellphone with all our latest news: click here.

Get the best of our site emailed to you daily: click here.