grale.lensinfocache

This module provides the LensInfoCache class, which can be used to cache the calculations performed in a LensInfo object. This can be done either just in memory, or written to disk as well. In the latter case, if at a later time the cache does not exist in memory anymore but can be loaded from disk, this can save time recalculating e.g. the mass map.

exception grale.lensinfocache.LensInfoCacheException

An exception that’s generated if something goes wrong in a function provided by this module.

class grale.lensinfocache.LensInfoCache(z_d, rangeInfos={}, cosmology='default')

The main class to keep track of LensInfo objects, for different lens models (at same redshift), but for certain sizes. This can come in handy when several inversion results need to be compared.

__init__(z_d, rangeInfos={}, cosmology='default')

Initialize the instance, where a lens redshift of z_d will be assumed for all stored LensInfo objects. Together with cosmology, this will be passed on to the constructor of each LensInfo instance.

Further information about what to calculate is stored in rangeInfos. This is a dictionary with keys that can be chosen freely, the values are passed on to a LensInfo constructor to specify for example the size of the region. This way, for example, you could prepare the cache to hold LensInfo instances for a smaller, strong lensing region, and a wider, weak lensing region:

{ "strong": { "size": 120*ANGLE_ARCSEC },
  "weak": { "size": 400*ANGLE_ARCSEC, "zs": 2.5 } }

When e.g. getLensInfo(someModel, "strong") is called for the "strong" parameters, either a new LensInfo is constructed, or a cached one (from memory or from disk) is returned, depending on whether or not the lens model someModel (specified as a lens object or a file name) has been seen before.

clear()

Clears the caches that are stored in memory, but does not remove anything stored on disk.

getLensInfo(fileNameOrLens, rangeName)

Returns the LensInfo object for the model specified by fileNameOrLens, for the size specified by rangeName. This last parameter should have been specified in the constructor.

getLensInfoEntry(fileNameOrLens)

Returns the complete entry for the lens model in fileNameOrLens, which can either be the name of a file, or a lens model in memory. This contains the information about all currently known LensInfo objects, with sizes as specified in the constructor, for the lens model. If it doesn’t exist in the in-memory or on-disk cache yet, new LensInfo objects are created.

saveCaches()

Save all caches that are currently in memory to disk.