One sunny day in southern California, Kathleen O’Dell was walking her dog when the cacophony of birds stopped her in her tracks. Curiosity pulled her to a gap in the nearby hedge, through which she spied a great metal cage, an aviary full of tropical birds.

In days to follow, each time she walked by the birds’ home, the backyard of a grand old-fashioned estate, her imagination would go wild with stories. And from these fantastical imaginings she wrote “The Aviary,” an enchanting historical fiction set in coastal Maine.

“The Aviary,” released in hardcover in September, follows 13-year-old Clara, a girl who has obediently stayed at home for her entire childhood because of her fragile health. But things begin to change as the birds in the aviary start to call out to her and mysteries unfold.

Story continues below advertisement.

“There’s one place you go when you’re writing,” said O’Dell. “The great thing about the whole writing process to me is that you don’t just go there when you’re writing. You can get stuck there.”

Inside an old mansion in the 1850s, Clara’s world consists of her mother (who is the caretaker), the cook and the old, kind widow who owns the vast property. But Clara starts to realize her strength when encouraged by her first true friend and ghosts (of sorts) from a time when the mansion was teeming with life.

O’Dell, author of the contemporary Agnes Parker series, learned about what children enjoy reading from years working at a public school library, and from listening to her own children. Whenever a child would latch onto a book, she would become excited with them.

Historical fiction is a new genre for O’Dell, but she said everything about the challenge was enjoyable. To learn how her characters might talk, she read literature from the turn of the century, such as novels by Edith Wharton and lesser-known tales on gutenberg.org, a free online collection of books nearly lost to time.

“I thought it was the perfect tale, sort of a Gothic story, a spooky story — of course, it didn’t call for a southern California setting,” said O’Dell.

O’Dell came up with the story’s fictional Maine town from a childhood friend, Carla, who used to live in Bar Harbor. O’Dell, originally from Portland, Oregon, has never been to Maine, though she hopes to visit some day. Her research took the form of online photos of coastal towns, maps of the state’s terrain and websites on Maine history.

“I was looking for ports and harbors and places ships could come in, and I was kind of amazed at how forbidding a lot of the shoreline is. The little safe harbors are few and far between,” she said.

Much of the book takes place inside the mansion, Clara’s domain, and only a few parts of Maine come into play, such as an old cemetery, the small islands off Bar Harbor and the town’s New England architecture. But it is in the mansion where all of the magic takes place.

“I’ve heard a lot that it reminds people of ‘The Secret Garden,’ which I haven’t read,” said O’Dell.

In fact, it’s “The Wolves of Willoughby Chase” by Joan Aiken that most inspired “The Aviary,” because it too is a tale about two young female heroes bound by friendship.

“I think we have such a need for connection, and I found that through my entire life, I’ve held on to so many old friendships,” O’Dell said. “There is no one like a person’s best friend, their co-conspirator, the person who sympathizes with you.”

O’Dell has written books outside or in a study, but this book she wrote in the kitchen, and she can’t explain why. Once she starts writing, it doesn’t matter much where she is. The story sweeps her away.

“When I got back there in my mind, living in the turn of the century, I really didn’t want to leave,” O’Dell said. “I realize that we live in an era that really can’t be beat in a lot of ways, but I became enraptured with it.

“It was really hard. I’ve never had writer’s block, but after I finished this book, it was really difficult to get started on another book,” she said. “I wanted to stay there, but I had to move on.”

This spring, after writing the novel, O’Dell noticed a flock of wild parrots screeching in the woods surrounding her home. When she approached them, they gnawed bark off the olive trees and threw scraps down at her, reminding her of the mischievous birds in “The Aviary.” While gazing at their green and red feathers, she said she was drawn back to the fictional Maine mansion, endearing Clara and the magic of her imagination.