You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Seems like scipy has some circular statistics support that might overlap with astropy a little. However, API is not exactly the same and I am not sure if both sides cover all the same use cases. There is a need to do the following:
Have a plan and roadmap to deprecate what we have and point people upstream.
If Option 4 is not possible, clearly document why and when user should choose one over the other.
circmean
astropy: astropy.stats.circstats.circmean(data[, axis, weights]) Computes the circular mean angle of an array of circular data.
scipy: scipy.stats.circmean(samples[, high, low, axis, nan_policy]) Compute the circular mean for samples in a range.
circstd
astropy: astropy.stats.circstats.circstd(data[, axis, weights, method]) Computes the circular standard deviation of an array of circular data.
scipy: scipy.stats.circstd(samples[, high, low, axis, ...]) Compute the circular standard deviation for samples assumed to be in the range [low to high].
circvar
astropy: astropy.stats.circstats.circvar(data[, axis, weights]) Computes the circular variance of an array of circular data.
scipy: circvar(samples[, high, low, axis, nan_policy]) Compute the circular variance for samples assumed to be in a range.
I recently worked on circular/directional stats in scipy. Indeed there is some duplication, it would be great to collaborate/coordinate a little bit.
Before talking about APIs, I wanted to point out recent additions to scipy that could be helpful for astronomy:
we implemented a numerical fitting method for the von Mises distribution (see here) that gives a quick and accurate result also for the concentration parameter $\kappa$. astropy currently uses an approximation for the concentration parameter. You could consider using the scipy method instead (after a deprecation cycle maybe). Be aware that this is only available in scipy's main branch and not released yet.
directional_stats is a generalization of circmean and circvar that works in arbitrary dimensions. I would expect that especially $n=3$ must be very interesting for astropy.
the new distribution uniform_direction enables to sample uniformly from the surface of a hyphersphere
I am currently working on implementing the Von Mises-Fisher distribution, a generalization of the Von Mises distribution (see here).
One function from astropy that would be useful for scipy would be the Rayleigh test for uniformity on the hypersphere. Can your implementation be generalized to $n$ dimensions maybe?
Regarding the duplication of circmean, circvar and circstd: could astropy just use the scipy methods under the hood for some time and then maybe deprecate them in the long run? From what I see, scipy's implementation lets the user choose axis and a nan policy (not available in astropy) but does not allow weights yet (available in astropy). Those could be added if we decide to go this route.
Thank you for the update! Looks like a bulk of these were implemented here by @mirca back in #4472 . Our current stats subpackage maintainer is @larrybradley . Personally, I am very interested in re-using scipy but the problem is getting devs time to work on this campaign that would probably drag on for months if not years.
For a feature that is not in any released scipy, we would be hesitant to use. It is much simpler for us to switch over if the feature is already in our minversion of scipy, which we could consider bumping as long as it adheres to APE 18.
Bit from the sidelines, but yes to using scipy where possible - these routines are not astronomy specific! But it will be a bit of a slow trajectory, obviously.
Just thought I'd note that the SciPy and Astropy definitions of circular variance were different in the past. SciPy's was corrected in 1.9.0 by gh-5747scipy/scipy#5747, so they are consistent now. (The documentation of Astropy's circvar mentions the discrepancy; that could be updated.)
Thanks @pllim. For future participants, my interest in #13749 (comment) has expired, but I thought I'd median that SciPy's circular median PR (scipy/scipy#24166) has merged.
Activity
dschmitz89 commentedon Mar 11, 2023
Hi astropy people,
I recently worked on circular/directional stats in scipy. Indeed there is some duplication, it would be great to collaborate/coordinate a little bit.
Before talking about APIs, I wanted to point out recent additions to scipy that could be helpful for astronomy:
circmeanandcircvarthat works in arbitrary dimensions. I would expect that especiallyuniform_directionenables to sample uniformly from the surface of a hyphersphereOne function from astropy that would be useful for scipy would be the Rayleigh test for uniformity on the hypersphere. Can your implementation be generalized to$n$ dimensions maybe?
Regarding the duplication of
circmean,circvarandcircstd: could astropy just use thescipymethods under the hood for some time and then maybe deprecate them in the long run? From what I see, scipy's implementation lets the user choose axis and a nan policy (not available in astropy) but does not allow weights yet (available in astropy). Those could be added if we decide to go this route.CC @mdhaber
pllim commentedon Mar 13, 2023
Thank you for the update! Looks like a bulk of these were implemented here by @mirca back in #4472 . Our current
statssubpackage maintainer is @larrybradley . Personally, I am very interested in re-usingscipybut the problem is getting devs time to work on this campaign that would probably drag on for months if not years.For a feature that is not in any released
scipy, we would be hesitant to use. It is much simpler for us to switch over if the feature is already in our minversion of scipy, which we could consider bumping as long as it adheres to APE 18.astropy/setup.cfg
Line 77 in 386b52e
mhvk commentedon Mar 13, 2023
Bit from the sidelines, but yes to using
scipywhere possible - these routines are not astronomy specific! But it will be a bit of a slow trajectory, obviously.mdhaber commentedon Mar 13, 2023
Just thought I'd note that the SciPy and Astropy definitions of circular variance were different in the past. SciPy's was corrected in 1.9.0 by
gh-5747scipy/scipy#5747, so they are consistent now. (The documentation of Astropy'scircvarmentions the discrepancy; that could be updated.)larrybradley commentedon Mar 13, 2023
Thanks, @mdhaber. I'll update the astropy
circvardocs.The scipy PR that made them consistent is scipy/scipy#5747
mdhaber commentedon Dec 16, 2025
pllim commentedon Dec 17, 2025
mdhaber commentedon Aug 23, 2026
Thanks @pllim. For future participants, my interest in #13749 (comment) has expired, but I thought I'd median that SciPy's circular median PR (scipy/scipy#24166) has merged.