The return of endangered New Zealand sea lions to breed on the mainland after hundreds of years has sparked delight among conservationists, but also some surprising moments for residents.

The sea lions have popped up in unexpected — and sometimes populated — places in recent years, including a golf course (prompting the city council to close down a busy road for weeks to ensure the mom and pup could cross the road to get to the beach) and a forest. One young sea lion even waddled through automatic doors to dip into a community pool.

Now, a new study could help New Zealanders live with their neighbors and better protect them in the future by predicting where the animals could turn up. The research, published in the Methods in Ecology and Evolution journal, integrates algorithm-based models with data from wildlife experts and rangers for a better forecast to spot threats or suitable habitats.

“It just gives us a lot more information to better arm ourselves for managing the growth of the population in the future,” said Laura Boren, a science adviser for the New Zealand Department of Conservation who worked with the researchers.

And it could help local communities share the coast, “so that people can really start welcoming back sea lions and not be afraid of bumping into them, because they are really cool animals,” Boren said.

Sea lions are “generally quite confident around people,” according to the Department of Conservation. “They may completely ignore you if they are resting, but may chase people and dogs that approach too closely.”

Boren said that people “stumbling upon sea lions in the bush” could find them intimidating, particularly as adult females can weigh more than 400 pounds and can be intent on defending their pups.

By contrast, pups or younger animals can be “just really cheeky and they’ll like to play games,” she added. “If you realize that they’re just trying to get you to play … don’t buy into it. Just take a photo and walk away.”

The sea lions bred long ago along the coast of New Zealand, until hunting drove them away. A rare sea lion species threatened with extinction — some 10,000 remain, facing risks from fisheries and disease — they had moved deep into the New Zealand Subantarctic Islands to the south to breed instead.

In the late 1990s, a female sea lion gave birth on the mainland, a development that conservationists have not been able to fully explain. It led to a slow comeback that now sees around 20 pups born every summer in the south of the country, something ecologist Veronica Frans, the study’s lead author, describes as “amazing.”

Her work with people in the field accounts for factors that predictions with models can miss, such as fencing and roads, a tool that could help others study where different species will roam, said Frans, a PhD student at Michigan State University.

New Zealand’s conservation agency will use the research to plan how best to manage land, removing potential barriers that could stop female sea lions from reaching breeding habitats. The country is keen to manage threats to the endangered animals, given the sharp declines in the number of pups since the late ’90s, according to Boren.

“The habitat and foraging and everything for the females on the mainland is better quality for them” compared with the subantarctic islands, she added. “We do hope that we’ll see more of them coming back on the mainland.”