Coverage for python/lsst/sims/maf/utils/mafUtils.py : 60%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
'gnomonic_project_toxy', 'radec2pix']
""" Set an 'optimal' number of bins using the Freedman-Diaconis rule.
Parameters ---------- datain : numpy.ndarray or numpy.ma.MaskedArray The data for which we want to set the binsize. binmin : float The minimum bin value to consider (if None, uses minimum data value). binmax : float The maximum bin value to consider (if None, uses maximum data value). nbinMax : int The maximum number of bins to create. Sometimes the 'optimal binsize' implies an unreasonably large number of bins, if the data distribution is unusual. nbinMin : int The minimum number of bins to create. Default is 1.
Returns ------- int The number of bins. """ # if it's a masked array, only use unmasked values data = datain.compressed() else: # Check that any good data values remain. nbins = nbinMax warnings.warn('No unmasked data available for calculating optimal bin size: returning %i bins' %(nbins)) # Else proceed. else: # Check if any data points remain within binmin/binmax. nbins = nbinMax warnings.warn('No data available for calculating optimal bin size within range of %f, %f' %(binmin, binmax) + ': returning %i bins' %(nbins)) else: warnings.warn('Optimal bin calculation tried to make %.0f bins, returning %i'%(nbins, nbinMax)) nbins = nbinMax warnings.warn('Optimal bin calculation tried to make %.0f bins, returning %i'%(nbins, nbinMin)) nbins = nbinMin warnings.warn('Optimal bin calculation calculated NaN: returning %i' %(nbinMax)) nbins = nbinMax
""" Calculate the minimum and maximum values of a distribution of points, after discarding data more than 'percentile' from the median. This is useful for determining useful data ranges for plots. Note that 'percentile' percent of the data is retained.
Parameters ---------- data : numpy.ndarray The data to clip. percentile : float Retain values within percentile of the median.
Returns ------- float, float The minimum and maximum values of the clipped data. """ lower_percentile = (100 - percentile) / 2.0 upper_percentile = 100 - lower_percentile min_value = np.percentile(data, lower_percentile) max_value = np.percentile(data, upper_percentile) return min_value, max_value
""" Calculate the x/y values of RA1/Dec1 in a gnomonic projection with center at RAcen/Deccen.
Parameters ---------- RA1 : numpy.ndarray RA values of the data to be projected, in radians. Dec1 : numpy.ndarray Dec values of the data to be projected, in radians. RAcen: float RA value of the center of the projection, in radians. Deccen : float Dec value of the center of the projection, in radians.
Returns ------- numpy.ndarray, numpy.ndarray The x/y values of the projected RA1/Dec1 positions. """ cosc = np.sin(Deccen) * np.sin(Dec1) + np.cos(Deccen) * np.cos(Dec1) * np.cos(RA1-RAcen) x = np.cos(Dec1) * np.sin(RA1-RAcen) / cosc y = (np.cos(Deccen)*np.sin(Dec1) - np.sin(Deccen)*np.cos(Dec1)*np.cos(RA1-RAcen)) / cosc return x, y
""" Calculate the nearest healpixel ID of an RA/Dec array, assuming nside.
Parameters ---------- nside : int The nside value of the healpix grid. ra : numpy.ndarray The RA values to be converted to healpix ids, in radians. dec : numpy.ndarray The Dec values to be converted to healpix ids, in radians.
Returns ------- numpy.ndarray The healpix ids. """ |