utils - Utilities#

gammapy.utils.cluster Module#

Utilities for hierarchical/agglomerative clustering.

Functions#

standard_scaler(features)

Compute standardized features by removing the mean and scaling to unit variance.

hierarchical_clustering(features[, ...])

Hierarchical clustering using given features.

gammapy.utils.coordinates Package#

Astronomical coordinate calculation utility functions.

Functions#

cartesian(r, theta)

Convert polar coordinates to cartesian coordinates.

fov_to_sky(lon, lat, lon_pnt, lat_pnt)

Transform field-of-view coordinates to sky coordinates.

galactic(x, y, z[, obs_pos])

Compute galactic coordinates lon, lat and distance.

motion_since_birth(v, age, theta, phi)

Compute motion of an astrophysical object with a given velocity, direction and age.

polar(x, y)

Convert cartesian coordinates to polar coordinates.

sky_to_fov(lon, lat, lon_pnt, lat_pnt)

Transform sky coordinates to field-of-view coordinates.

velocity_glon_glat(x, y, z, vx, vy, vz)

Compute projected angular velocity in galactic coordinates.

Variables#

D_SUN_TO_GALACTIC_CENTER

A Quantity represents a number with some associated unit.

gammapy.utils.integrate Module#

Functions#

trapz_loglog(y, x[, axis])

Integrate using the composite trapezoidal rule in log-log space.

gammapy.utils.interpolation Module#

Interpolation utilities.

Functions#

interpolate_profile(x, y[, interp_scale, ...])

Helper function to interpolate one-dimensional profiles.

interpolation_scale([scale])

Interpolation scaling.

Classes#

gammapy.utils.fits Module#

Functions#

earth_location_from_dict(meta)

Create EarthLocation from FITS header dictionary.

Classes#

LazyFitsData([cache])

A lazy FITS data descriptor.

HDULocation(hdu_class[, base_dir, file_dir, ...])

HDU localisation, loading and Gammapy object mapper.

gammapy.utils.random Package#

Random probability distribution helpers.

Functions#

draw(low, high, size, dist[, random_state])

Allow drawing of random numbers from any distribution.

get_random_state(init)

Get a numpy.random.RandomState instance.

normalize(func, x_min, x_max)

Normalize a 1D function over a given range.

pdf(func)

One-dimensional PDF of a given radial surface density.

sample_powerlaw(x_min, x_max, gamma[, size, ...])

Sample random values from a power law distribution.

sample_sphere(size[, lon_range, lat_range, ...])

Sample random points on the sphere.

sample_sphere_distance([distance_min, ...])

Sample random distances if the 3-dim space density is constant.

sample_times(size, rate[, dead_time, ...])

Make random times assuming a Poisson process.

Classes#

InverseCDFSampler(pdf[, axis, random_state])

Inverse CDF sampler.

gammapy.utils.regions Module#

Regions helper functions.

Throughout Gammapy, we use regions to represent and work with regions.

https://astropy-regions.readthedocs.io

We might add in other conveniences and features here, e.g. sky coord contains without a WCS (see “sky and pixel regions” in PIG 10), or some HEALPix integration.

TODO: before Gammapy v1.0, discuss what to do about gammapy.utils.regions. Options: keep as-is, hide from the docs, or to remove it completely (if the functionality is available in astropy-regions directly.

Functions#

compound_region_to_regions(region)

Create list of regions from compound regions.

make_concentric_annulus_sky_regions(center, ...)

Make a list of concentric annulus regions.

make_orthogonal_rectangle_sky_regions(...[, ...])

Utility returning an array of regions to make orthogonal projections.

regions_to_compound_region(regions)

Create compound region from list of regions, by creating the union.

region_to_frame(region, frame)

Convert a region to a different frame.

gammapy.utils.parallel Module#

Multiprocessing and multithreading setup.

Functions#

run_multiprocessing(func, inputs[, backend, ...])

Run function in a loop or in Parallel.

Classes#

multiprocessing_manager([backend, ...])

Context manager to update the default configuration for multiprocessing.

Variables#

BACKEND_DEFAULT

Enum for parallel backend.

N_JOBS_DEFAULT

int([x]) -> integer int(x, base=10) -> integer

POOL_KWARGS_DEFAULT

METHOD_DEFAULT

Enum for pool method.

METHOD_KWARGS_DEFAULT

gammapy.utils.scripts Module#

Utilities to create scripts and command-line tools.

Functions#

from_yaml(text[, sort_keys, checksum])

Read YAML file.

get_images_paths([folder])

Generator yields a Path for each image used in notebook.

make_path(path)

Expand environment variables on Path construction.

read_yaml(filename[, logger, checksum])

Read YAML file.

recursive_merge_dicts(a, b)

Recursively merge two dictionaries.

to_yaml(dictionary[, sort_keys])

dict to yaml

write_yaml(text, filename[, logger, ...])

Write YAML file.

gammapy.utils.table Module#

Table helper utilities.

Functions#

hstack_columns(table, table_other)

Stack the column data horizontally.

table_row_to_dict(row[, make_quantity])

Make one source data dictionary.

table_standardise_units_copy(table)

Standardise units for all columns in a table in a copy.

table_standardise_units_inplace(table)

Standardise units for all columns in a table in place.

gammapy.utils.testing Module#

Utilities for testing.

Functions#

assert_quantity_allclose(actual, desired[, ...])

Assert all-close for Quantity objects.

assert_skycoord_allclose(actual, desired)

Assert all-close for astropy.coordinates.SkyCoord objects.

assert_time_allclose(actual, desired[, atol])

Assert all-close for astropy.time.Time objects.

mpl_plot_check()

Matplotlib plotting test context manager.

requires_data([name])

Decorator to declare required data for tests.

requires_dependency(name)

Decorator to declare required dependencies for tests.

Classes#

Checker()

Base class for checker classes in Gammapy.

gammapy.utils.time Module#

Time related utility functions.

Functions#

absolute_time(time_delta, meta)

Convert a MET into human-readable date and time.

time_ref_from_dict(meta[, format, scale])

Calculate the time reference from metadata.

time_ref_to_dict([time, scale])

Convert the epoch to the relevant FITS header keywords.

time_relative_to_ref(time, meta)

Convert a time using an existing reference.

gammapy.utils.units Module#

Units and Quantity related helper functions.

Functions#

standardise_unit(unit)

Standardise unit.

unit_from_fits_image_hdu(header)

Read unit from a FITS image HDU.