Skip to content

Commit

Permalink
Wraps distortion code in XYTransform
Browse files Browse the repository at this point in the history
The new camera objects use XYTransforms to map from one
coordinate system to another.  This means that the DistEst
distortion code needs to be wrapped up in an XYTransform.

The XYTransform is exposed in python by adding an entry to
the XYTransformRegistry.
  • Loading branch information
Simon Krughoff authored and laurenam committed Feb 3, 2015
1 parent f649b18 commit 9ee4c04
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 127 deletions.
74 changes: 0 additions & 74 deletions include/lsst/obs/hsc/HscDistortion.h

This file was deleted.

62 changes: 62 additions & 0 deletions include/lsst/obs/subaru/DistEstXYTransform.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// -*- lsst-c++ -*-

/*
* LSST Data Management System
* Copyright 2008-2015 LSST Corporation.
*
* This product includes software developed by the
* LSST Project (http://www.lsst.org/).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the LSST License Statement and
* the GNU General Public License along with this program. If not,
* see <http://www.lsstcorp.org/LegalNotices/>.
*/

/**
* \file
* @brief Class wrapping the distEst distortion class to present the XYTransform API
*/
#ifndef LSST_OBS_SUBARU_DISTESTXYTRANSFORM_H
#define LSST_OBS_SUBARU_DISTESTXYTRANSFORM_H

#include "lsst/daf/base.h"
#include "lsst/afw/geom/AffineTransform.h"
#include "lsst/afw/geom/Angle.h"
#include "lsst/afw/geom/XYTransform.h"

namespace lsst {
namespace obs {
namespace subaru {


/**
* @brief An XYTransform to wrap the distEst distortion class for inclusion in an XYTransformMap.
*/
class DistEstXYTransform : public afw::geom::XYTransform
{
public:
DistEstXYTransform(afw::geom::Angle const &elevation, double const plateScale);
virtual PTR(afw::geom::XYTransform) clone() const;
virtual Point2D forwardTransform(afw::geom::Point2D const &point) const;
virtual Point2D reverseTransformIterative(afw::geom::Point2D const &point) const;
virtual Point2D reverseTransform(afw::geom::Point2D const &point) const;

private:
afw::geom::Angle _elevation;
double _plateScale;
};



}}}
#endif
3 changes: 2 additions & 1 deletion python/lsst/obs/hsc/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from hscMapper import *
from .hscMapper import *
from .transformRegistry import *
6 changes: 1 addition & 5 deletions python/lsst/obs/hsc/hscLib.i
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,15 @@ Interface class for HSC distortion
%enddef

%feature("autodoc", "1");
%module(package="lsst.obs.subaru", docstring=hscLib_DOCSTRING) hscLib
%module(package="lsst.obs.hsc", docstring=hscLib_DOCSTRING) hscLib

%{
#include "lsst/base.h"
#include "lsst/afw/geom/Point.h"
#include "lsst/afw/geom/Extent.h"
#include "lsst/obs/hsc/HscDistortion.h"
%}

%include "lsst/p_lsstSwig.i"
%import "lsst/afw/cameraGeom/cameraGeomLib.i"
%import "lsst/afw/geom/geomLib.i"

%shared_ptr(lsst::obs::hsc::HscDistortion)

%include "lsst/obs/hsc/HscDistortion.h"
6 changes: 0 additions & 6 deletions python/lsst/obs/hsc/hscMapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import lsst.afw.math as afwMath
import lsst.afw.geom as afwGeom
import lsst.pex.policy as pexPolicy
from .hscLib import HscDistortion

try: # just to let meas_mosaic be an optional dependency
from lsst.meas.mosaic import applyMosaicResults
Expand Down Expand Up @@ -59,11 +58,6 @@ def __init__(self, **kwargs):
):
self.mappings[name].keyDict.update(keys)

# Distortion isn't pluggable, so we'll put in our own
elevation = 45 * afwGeom.degrees
distortion = HscDistortion(elevation)
self.camera.setDistortion(distortion)

# SDSS g': http://www.naoj.org/Observing/Instruments/SCam/txt/g.txt
# SDSS r': http://www.naoj.org/Observing/Instruments/SCam/txt/r.txt
# SDSS i': http://www.naoj.org/Observing/Instruments/SCam/txt/i.txt
Expand Down
25 changes: 25 additions & 0 deletions python/lsst/obs/hsc/transformRegistry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from lsst.afw.geom import xyTransformRegistry
import lsst.afw.geom as afwGeom
from lsst.pex.config import Config, Field
from lsst.obs.subaru.subaruLib import DistEstXYTransform
__all__ = ["xyTransformRegistry"]

class DistEstXYTransformConfig(Config):
elevation = Field(
doc = """Elevation in degrees to use in constructing the transform""",
dtype = float,
default = 45.,
)
plateScale = Field(
doc = """Platescale in arcsec/mm""",
dtype = float,
)
def makeDistEstTransform(config):
""" Make a DistEst XYTransform object
@param[in] config: pexConfig.Config object containing the elevation and plateScale needed to construct the
transform
"""
elevation = afwGeom.Angle(config.elevation, afwGeom.degrees)
return DistEstXYTransform(elevation, config.plateScale)
makeDistEstTransform.ConfigClass = DistEstXYTransformConfig
xyTransformRegistry.register("distEst", makeDistEstTransform)
5 changes: 4 additions & 1 deletion python/lsst/obs/subaru/subaruLib.i
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Interface class for subaru crosstalk correction
#include "lsst/afw/image.h"
#include "lsst/afw/image/MaskedImage.h"
#include "lsst/obs/subaru/Crosstalk.h"
#include "lsst/obs/subaru/DistEstXYTransform.h"
%}

%include "lsst/p_lsstSwig.i"
Expand All @@ -39,7 +40,9 @@ namespace std {
%import "lsst/afw/cameraGeom/cameraGeomLib.i"
%import "lsst/afw/image/imageLib.i"

//%shared_ptr(lsst::obs::hscSim::HscDistortion)
%shared_ptr(lsst::obs::subaru::DistEstXYTransform);

%include "lsst/obs/subaru/DistEstXYTransform.h"

%include "lsst/obs/subaru/Crosstalk.h"
//%template(vectorCalib) std::vector<boost::shared_ptr<const lsst::afw::image::Calib> >;
Expand Down
63 changes: 63 additions & 0 deletions src/DistEstXYTransform.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// -*- lsst-c++ -*-

/*
* LSST Data Management System
* Copyright 2008-2015 LSST Corporation.
*
* This product includes software developed by the
* LSST Project (http://www.lsst.org/).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the LSST License Statement and
* the GNU General Public License along with this program. If not,
* see <http://www.lsstcorp.org/LegalNotices/>.
*/

#include "lsst/obs/subaru/DistEstXYTransform.h"
#include "hsc/meas/match/distest.h"
#include "boost/make_shared.hpp"

namespace lsst {
namespace obs {
namespace subaru {

DistEstXYTransform::DistEstXYTransform(afw::geom::Angle const &elevation, double const plateScale)
: afw::geom::XYTransform(), _elevation(elevation), _plateScale(afw::geom::arcsecToRad(plateScale))
{ }

PTR(afw::geom::XYTransform) DistEstXYTransform::clone() const
{
return boost::make_shared<DistEstXYTransform> (_elevation, afw::geom::radToArcsec(_plateScale));
}

afw::geom::Point2D DistEstXYTransform::forwardTransform(afw::geom::Point2D const &point) const
{
float x, y;
hsc::meas::match::getUndistortedPosition(point.getX(), point.getY(), &x, &y, _elevation.asDegrees());
return afw::geom::Point2D(x*_plateScale,y*_plateScale);
}

afw::geom::Point2D DistEstXYTransform::reverseTransformIterative(afw::geom::Point2D const &point) const
{
float x, y;
hsc::meas::match::getDistortedPositionIterative(point.getX(), point.getY(), &x, &y, _elevation.asDegrees());
return afw::geom::Point2D(x/_plateScale,y/_plateScale);
}

afw::geom::Point2D DistEstXYTransform::reverseTransform(afw::geom::Point2D const &point) const
{
float x, y;
hsc::meas::match::getDistortedPosition(point.getX(), point.getY(), &x, &y, _elevation.asDegrees());
return afw::geom::Point2D(x/_plateScale,y/_plateScale);
}

}}}
40 changes: 0 additions & 40 deletions src/HscDistortion.cc

This file was deleted.

1 comment on commit 9ee4c04

@PaulPrice
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work? This seems to be feeding positions into distEst in units of mm, while I believe distEst is expecting pixels.

Please sign in to comment.