The New York Aquarium has cherished its big-city setting by the sea for half a century. But the ocean that is the aquarium’s lifeblood dealt it a shattering blow last fall.

Superstorm Sandy’s surge overran carefully calibrated tanks with oily, debris-filled water, knocked out even backup power to all the exhibits and made it impossible to check on some of them for days. Managers contemplated shipping animals away and wondered whether the institution itself could survive in its spot on Coney Island.

Five months later, more than 80 percent of the collection is intact, and visitors should be able to see walruses, angelfish, otters and others when about half the aquarium reopens in late spring. A planned expansion remains on track, now coupled with rebuilding and flood-proofing an institution that aims to be an object lesson in enduring on the shore.

“I don’t think we could abandon this facility. Not that we didn’t think about it — we thought through everything,” aquarium Director Jon Forrest Dohlin said this week as he stood amid pipes and cables in a now-empty jellyfish exhibit.

“We want to be here, and we also want to be able to talk to the community about what we did, how we handled this, and how the city of New York can start to look toward the future of living in this coastal environment.”

As he walked through the 14-acre grounds, penguins watched like squat sentries from their outdoor habitat. Walruses snoozed as sea lions arced through the air on their trainers’ cues, staying in practice for shows to resume in a few months.

There’s no firm date yet for this spring’s partial reopening. The rest of the exhibits, including the new $120 million shark display, could open in 2016, but no firm date is set.

Meanwhile, the Wildlife Conservation Society, which runs the aquarium, is determining how much insurance and government aid may pay toward fixing roughly $65 million in estimated damage.

Sandy’s surge coursed through air-intake vents in flood doors under the Coney Island boardwalk, punched through sand into the parking lot and rushed in from the parking lot after a creek overflowed blocks away.

As the water rose 3 feet high in Dohlin’s ground-floor office, he watched it pour down a stairwell into a basement that housed exhibits and the equipment that keeps them alive.

“‘We lost the aquarium,’” he thought.

Basements were under up to 15 feet of water. Generators were either damaged or useless because equipment needed to distribute their power was fried. The pump house that draws from the ocean to refresh the 1.5 million-gallon exhibits was out of commission, as were systems that treat the seawater, tailor it to different environments and maintain the oxygen levels, temperatures and water chemistry the aquarium’s 12,000 animals need.

None had been evacuated. That would have been very difficult to arrange in the few days the aquarium had to prepare, Dohlin said.

Scrambling to save the collection, 18 staffers used hospital-style canisters to get crucial oxygen into the water, rebuilt filters and pumps on the fly and called in equipment from the Wildlife Conservation Society’s four zoos. They mixed artificial seawater in garbage cans and warmed rooms with space heaters to keep water temperatures up, animal operations director David DeNardo said.

The koi and some other fish were dead. But many other fish and all the mammals were fine — including Mitik, an orphaned walrus calf that arrived only weeks before. He seemed to enjoy splashing in a couple of feet of surge water, Dohlin said.