Locked History Actions

DeepZot/Imengine/API

Generating Models from Code

The library contains C++ classes that mirror the expression structure of the command-line src and psf parameters. See src/imdemo.cc for a working example. The main ingredients are described below.

First, you need to include the public API and (for convenience) define some namespace aliases:

#include "imengine/imengine.h"
namespace img = imengine;
namespace mod = imengine::models;

Next, build the source and psf models. For example, a Sersic (n=1) radial profile transformed by an intrinsic ellipticity (e1,e2) and weak-lensing shear (g1,g2):

img::AbsRadialProfilePtr sersic(new mod::ExponentialProfile(re));
img::AbsCoordTransformPtr srcShear(new img::EllipticityTransform(e1,e2,g1,g2));
img::AbsPixelFunctionPtr source(new img::TransformedProfileFunction(sersic,srcShear));

After building your source and psf, combine them to create an engine, initialized for a specified image size:

img::BilinearImageEngine<img::FastTransform> engine(source,psf);
engine.initialize(npix);

Finally, generate images using, for example:

img::ArrayImageWriter stamp;
engine.generate(stamp,dx,dy);

The stamp object in this case is just an output array of pixels that you can easily examine:

for(int y = 0; y < npix; ++y) {
  for(int x = 0; x < npix; ++x) {
    std::cout << ' ' << stamp.getValue(x,y);
  }
  std::cout << std::endl;
}

If this output model is not a good match to your application (for example, if your images are very large) you can use a lower-level pixel streaming protocol by extending the AbsImageWriter interface.

In case any imengine errors are detected at runtime, they will result in a img::RuntimeError exception being thrown, that you can most simply handle like this:

try {
  // ... your code here ...
}
catch(img::RuntimeError const &error) {
  std::cout << "RuntimeError in imengine: " << error.what() << std::endl;
}