dmsky.utils subpackage¶
dmsky.utils.coords module¶
Utilities for working with coordinates.
-
dmsky.utils.coords.
angsep
(lon1, lat1, lon2, lat2)[source]¶ Angular separation (deg) between two sky coordinates. Faster than creating astropy coordinate objects.
Parameters: - lon1 (numpy.array) –
- lat1 (numpy.array) –
- lon2 (numpy.array) –
- lat2 (numpy.array) – Coordinates (in degrees)
Returns: dist – Angular seperations (in degrees)
Return type: numpy.array
Notes
The angular separation is calculated using the Vincenty formula [1], which is slighly more complex and computationally expensive than some alternatives, but is stable at at all distances, including the poles and antipodes.
-
dmsky.utils.coords.
cel2gal
(ra, dec)[source]¶ Convert celestial coordinates (J2000) to Galactic coordinates. (Much faster than astropy for small arrays.)
Parameters: - ra (numpy.array) –
- dec (numpy.array) – Celestical Coordinates (in degrees)
Returns: - glon (numpy.array)
- glat (numpy.array) – Galactic Coordinates (in degrees)
-
dmsky.utils.coords.
gal2cel
(glon, glat)[source]¶ Convert Galactic coordinates to celestial coordinates (J2000). (Much faster than astropy for small arrays.)
Parameters: - glon (numpy.array) –
- glat (numpy.array) – Galactic Coordinates (in degrees)
Returns: - ra (numpy.array)
- dec (numpy.array) – Celestical Coordinates (in degrees)
dmsky.utils.speed module¶
Utilities for speed testing
dmsky.utils.healpix module¶
dmsky.utils.stat_funcs module¶
Utilities for statistical operations
-
dmsky.utils.stat_funcs.
lgauss
(x, mu, sigma=1.0, logpdf=False)[source]¶ Log10 normal distribution…
Parameters: Returns: vals – Output values, same shape as x
Return type: numpy.array
-
dmsky.utils.stat_funcs.
ln_norm
(x, mu, sigma=1.0)[source]¶ Natural log of scipy norm function truncated at zero
-
dmsky.utils.stat_funcs.
lnlgauss
(x, mu, sigma=1.0, logpdf=False)[source]¶ Log-likelihood of the natural log of a Gaussian
dmsky.utils.tools module¶
Random python tools
-
dmsky.utils.tools.
get_items
(items, library)[source]¶ Grab list items recursing through existing rosters. Careful of recursion traps.
Some prefix comprehension: ‘++’ = Always add ‘+’ = Add only if unique ‘–’ = Remove last occurence ‘-’ = Remove all occurences
-
dmsky.utils.tools.
merge_dict
(d0, d1, add_keys=True, append=False)[source]¶ Merge two target dicts into a new dict.
Parameters: - d0 (Base dictionary) –
- d1 (Update dictionary) –
Returns: d
Return type: A new dictionary merging d and u
-
dmsky.utils.tools.
update_dict
(d0, d1, add_keys=True, append=False)[source]¶ Recursively update the contents of dictionary d0 with the contents of python dictionary d1.
Parameters: - d0 (Base dictionary) –
- d1 (Update dictionary) –
dmsky.utils.units module¶
Simple module to deal with unit conversion
-
class
dmsky.utils.units.
Units
[source]¶ Bases:
object
Simple class to keep track of unit conversions
-
cm
= 1¶
-
cm3_s
= 1.0¶
-
static
convert_from
(value, key)[source]¶ Convert to cgs units from a different type of units
Parameters: - value (scalar or array-like, the input value(s)) –
- key (str, a key corresponding to one of the globals defined above) –
Returns: Return type: the input values, converted to cgs units
-
static
convert_to
(value, key)[source]¶ Convert from cgs units to a different type of units
Parameters: - value (scalar or array-like, the input value(s)) –
- key (str, a key corresponding to one of the globals defined above) –
Returns: Return type: the input values, converted to requested units
-
deg2
= 0.00030461741978670857¶
-
g
= 1.0¶
-
g_cm3
= 1.0¶
-
static
get_value
(key)[source]¶ Get a conversion value based on a key
This is here to make it easy to automate unit conversion
Parameters: key (str, a key corresponding to one of the globals defined above) – Returns: Return type: the conversion constant
-
gev
= 1.78266e-24¶
-
gev2_cm5
= 3.1778766755999995e-48¶
-
gev_cm2
= 1.78266e-24¶
-
gev_cm3
= 1.78266e-24¶
-
hr
= 3600.0¶
-
k
= 'gev_cm3'¶
-
km
= 100000.0¶
-
kpc
= 3.08568e+21¶
-
m
= 100.0¶
-
m2
= 10000.0¶
-
map_from_astropy
= {'GeV / cm2': 'gev_cm2', 'GeV / cm3': 'gev_cm3', 'GeV2 / cm5': 'gev2_cm5', 'cm3 / s': 'cm3_s', 'g / cm3': 'g_cm3'}¶
-
map_to_astropy
= {'cm3_s': 'cm3 / s', 'g_cm3': 'g / cm3', 'gev2_cm5': 'GeV2 / cm5', 'gev_cm2': 'GeV / cm2', 'gev_cm3': 'GeV / cm3'}¶
-
msun
= 1.98892e+33¶
-
msun2_kpc5
= 1.4141002588357058e-41¶
-
msun2_pc5
= 1.4141002588357058e-26¶
-
msun_kpc3
= 6.769625720905608e-32¶
-
msun_pc3
= 6.769625720905608e-23¶
-
pc
= 3.08568e+18¶
-
v
= 'GeV / cm3'¶
-
dmsky.utils.wcs module¶
Interface with wcs.
Adapted from fermipy.skymap
-
dmsky.utils.wcs.
create_image_hdu
(data, wcs, name=None)[source]¶ Create a astropy.io.fits.ImageHDU object
-
dmsky.utils.wcs.
create_image_wcs
(skydir, cdelt, npix, coordsys='CEL', projection='AIT')[source]¶ Create a blank image and associated WCS object
-
dmsky.utils.wcs.
create_wcs
(skydir, coordsys='CEL', projection='AIT', cdelt=1.0, crpix=1.0, naxis=2, energies=None)[source]¶ Create a WCS object. :param skydir: Sky coordinate of the WCS reference point. :type skydir: ~astropy.coordinates.SkyCoord :param coordsys: :type coordsys: str :param projection: :type projection: str :param cdelt: :type cdelt: float :param crpix: In the first case the same value is used for x and y axes :type crpix: float or (float,float) :param naxis: Number of dimensions of the projection. :type naxis: {2, 3} :param energies: Array of energies that defines the third dimension if naxis=3. :type energies: array-like