pynbody.util

Contents

pynbody.util#

util#

Various utility routines used internally by pynbody.

Functions

arrays_are_same(a1, a2)

Returns True if a1 and a2 are numpy views pointing to the exact same underlying data; False otherwise.

bisect(left, right, f[, epsilon, eta, ...])

Finds the value x such that f(x)=0 for a monotonically increasing function f, using a binary search.

chained_slice(s1, s2)

Return a slice s3 with the property that ar[s1][s2] == ar[s3]

concatenate_indexing(i1, i2)

Given either a numpy array or slice for both i1 and i2, return either a numpy array or slice i3 with the property that

cutgz(x)

Strip the .gz ending off a string

deprecated(func[, message])

Mark a method or function as deprecated

eps_as_simarray(f, eps)

Convert th given eps to a SimArray with units of f['pos'] and dtype of f['mass']

equipartition(ar, nbins[, vmin, vmax])

Given an array ar, return nbins+1 monotonically increasing bin edges such that the number of items in each bin is approximately equal.

gamma_inc(a, z[, eps])

Incomplete gamma function accepting complex z, based on algorithm given in numerical recipes (3rd ed)

gauss_jordan(out)

A simple Gauss-Jordan matrix inverter.

gcf(a, b)

get_eps(f)

The gravitational softening length is determined from (in order of preference): 1.

index_before_slice(s, index)

Return an index array new_index with the property that, for a slice s (start, stop and step all positive), ar[s][index] == ar[new_index].

index_of_first(array, find)

Returns the index to the first element in array which satisfies array[index]>=find.

indexing_length(sl_or_ar)

Given either an array or slice, return len(ar[sl_or_ar]) for any array ar which is large enough that the slice does not overrun it.

intersect_slices(s1, s2[, array_length])

Given two python slices s1 and s2, return a new slice which will extract the data of an array d which is in both d[s1] and d[s2].

lcm(a, b)

open_(filename, *args)

Open a file, determining from the filename whether to use gzip decompression

open_with_size(filename, *args)

Open a file for reading, returning also the (decompressed) file size

random_rotation_matrix()

Return a random rotation matrix (Haar measure for 3x3 case), using fast algorithm from Graphics Gems III

rational_matrix_inv(matrix)

A simple replacement for numpy linalg matrix inverse which handles fractions exactly.

relative_slice(s_relative_to, s)

Given a slice s, return a slice s_prime with the property that array[s_relative_to][s_prime] == array[s].

set_array_if_not_same(a_store, a_in[, index])

This routine checks whether a_store and a_in ultimately point to the same buffer; if not, the contents of a_in are copied into a_store.

thread_map(func, *args)

Run func in separate threads, mapping over the arguments in the same way as map(..)

threadsafe_inline(*args, **kwargs)

When scipy.weave.inline is called, it may trigger a compile.

Classes

ExecutionControl()

Modules

pynbody.util.hdf_vds

pynbody.util.iter_subclasses