Environmental periodicity and ecosystem stability