Skip to content

Commit

Permalink
update python wrappers
Browse files Browse the repository at this point in the history
update copyright banners

apply clang-format
  • Loading branch information
Matthias Wittgen committed Mar 22, 2021
1 parent 2a5702d commit e1b732b
Show file tree
Hide file tree
Showing 63 changed files with 1,242 additions and 1,326 deletions.
9 changes: 1 addition & 8 deletions python/lsst/afw/cameraGeom/SConscript
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
## -*- python -*-
from lsst.sconsUtils import scripts
scripts.BasicSConscript.pybind11(['cameraSys',
'camera/camera',
'detector/detector',
'amplifier/amplifier',
'orientation',
'transformMap',
'detectorCollection/detectorCollection'],
addUnderscore=False)
scripts.BasicSConscript.python(['_cameraGeom'])
37 changes: 19 additions & 18 deletions python/lsst/afw/cameraGeom/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# This file is part of afw.
#
# LSST Data Management System
# Copyright 2008, 2009, 2010 LSST Corporation.
#
# This product includes software developed by the
# LSST Project (http://www.lsst.org/).
# Developed for the LSST Data Management System.
# This product includes software developed by the LSST Project
# (https://www.lsst.org).
# See the COPYRIGHT file at the top-level directory of this distribution
# for details of code ownership.
#
# 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
Expand All @@ -15,23 +16,23 @@
# 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/>.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.


"""Application Framework classes to handle a mosaic camera's geometry
"""
from .cameraGeomLib import *
from ._cameraGeom import *
from ._detector import *
from ._amplifier import *
from .cameraConfig import *
from .detectorCollection import *
from .camera import *
from .cameraFactory import *
from .cameraGeomEnumDicts import *
from .makePixelToTanPixel import *
from .assembleImage import *
from .rotateBBoxBy90 import *
from ._detectorCollection import *
from ._camera import *
from ._cameraFactory import *
from ._cameraGeomEnumDicts import *
from ._makePixelToTanPixel import *
from ._assembleImage import *
from ._rotateBBoxBy90 import *
from .pupil import *
from .transformConfig import *
from ._transformConfig import *
NullLinearityType = "None" # linearity type indicating no linearity correction wanted
125 changes: 125 additions & 0 deletions python/lsst/afw/cameraGeom/_amplifier.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/*
* This file is part of afw.
*
* Developed for the LSST Data Management System.
* This product includes software developed by the LSST Project
* (https://www.lsst.org).
* See the COPYRIGHT file at the top-level directory of this distribution
* for details of code ownership.
*
* 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 GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#include "pybind11/pybind11.h"
#include <lsst/utils/python.h>
#include "pybind11/stl.h"

#include "ndarray/pybind11.h"

#include "lsst/afw/table/BaseRecord.h"
#include "lsst/afw/cameraGeom/Amplifier.h"

namespace py = pybind11;
using namespace pybind11::literals;

namespace lsst {
namespace afw {
namespace cameraGeom {

using PyAmplifier = py::class_<Amplifier, std::shared_ptr<Amplifier>>;
using PyAmplifierBuilder = py::class_<Amplifier::Builder, Amplifier, std::shared_ptr<Amplifier::Builder>>;

void wrapAmplifier(lsst::utils::python::WrapperCollection &wrappers) {
wrappers.addInheritanceDependency("lsst.afw.table");
wrappers.wrapType(py::enum_<ReadoutCorner>(wrappers.module, "ReadoutCorner"), [](auto &mod, auto &enm) {
enm.value("LL", ReadoutCorner::LL);
enm.value("LR", ReadoutCorner::LR);
enm.value("UR", ReadoutCorner::UR);
enm.value("UL", ReadoutCorner::UL);
});
wrappers.wrapType(py::enum_<AssemblyState>(wrappers.module, "AssemblyState"), [](auto &mod, auto &enm) {
enm.value("RAW", AssemblyState::RAW);
enm.value("SCIENCE", AssemblyState::SCIENCE);
});
auto amplifier = wrappers.wrapType(PyAmplifier(wrappers.module, "Amplifier"), [](auto &mod, auto &cls) {
cls.def_static("getRecordSchema", &Amplifier::getRecordSchema);
cls.def("toRecord", &Amplifier::toRecord);
cls.def("rebuild", &Amplifier::rebuild);
cls.def("getName", &Amplifier::getName);
cls.def("getBBox", &Amplifier::getBBox);
cls.def("getGain", &Amplifier::getGain);
cls.def("getReadNoise", &Amplifier::getReadNoise);
cls.def("getSaturation", &Amplifier::getSaturation);
cls.def("getSuspectLevel", &Amplifier::getSuspectLevel);
cls.def("getReadoutCorner", &Amplifier::getReadoutCorner);
cls.def("getLinearityCoeffs", &Amplifier::getLinearityCoeffs);
cls.def("getLinearityType", &Amplifier::getLinearityType);
cls.def("getLinearityThreshold", &Amplifier::getLinearityThreshold);
cls.def("getLinearityMaximum", &Amplifier::getLinearityMaximum);
cls.def("getLinearityUnits", &Amplifier::getLinearityUnits);
cls.def("getRawBBox", &Amplifier::getRawBBox);
cls.def("getRawDataBBox", &Amplifier::getRawDataBBox);
cls.def("getRawFlipX", &Amplifier::getRawFlipX);
cls.def("getRawFlipY", &Amplifier::getRawFlipY);
cls.def("getRawXYOffset", &Amplifier::getRawXYOffset);
cls.def("getRawHorizontalOverscanBBox", &Amplifier::getRawHorizontalOverscanBBox);
cls.def("getRawVerticalOverscanBBox", &Amplifier::getRawVerticalOverscanBBox);
cls.def("getRawPrescanBBox", &Amplifier::getRawPrescanBBox);
cls.def("getRawSerialOverscanBBox", &Amplifier::getRawSerialOverscanBBox);
cls.def("getRawParallelOverscanBBox", &Amplifier::getRawParallelOverscanBBox);
cls.def("getRawSerialPrescanBBox", &Amplifier::getRawSerialPrescanBBox);
cls.def("getRawHorizontalPrescanBBox", &Amplifier::getRawHorizontalPrescanBBox);
});
wrappers.wrapType(PyAmplifierBuilder(amplifier, "Builder"), [](auto &mod, auto &cls) {
cls.def_static("fromRecord", &Amplifier::Builder::fromRecord);
cls.def(py::init());
cls.def("finish", &Amplifier::Builder::finish);
cls.def("assign", [](Amplifier::Builder &self, Amplifier const &other) { self = other; });
cls.def("setName", &Amplifier::Builder::setName, "name"_a);
cls.def("setBBox", &Amplifier::Builder::setBBox, "bbox"_a);
cls.def("setGain", &Amplifier::Builder::setGain, "gain"_a);
cls.def("setReadNoise", &Amplifier::Builder::setReadNoise, "readNoise"_a);
cls.def("setSaturation", &Amplifier::Builder::setSaturation, "saturation"_a);
cls.def("setSuspectLevel", &Amplifier::Builder::setSuspectLevel, "suspectLevel"_a);
cls.def("setReadoutCorner", &Amplifier::Builder::setReadoutCorner, "corner"_a);
cls.def("setLinearityCoeffs", &Amplifier::Builder::setLinearityCoeffs, "coeffs"_a);
// Backwards compatibility: accept std::vector (list in Python) in
// addition to ndarray::Array (np.ndarray)
cls.def("setLinearityCoeffs", [](Amplifier::Builder &self, std::vector<double> const &coeffs) {
ndarray::Array<double, 1, 1> array = ndarray::allocate(coeffs.size());
std::copy(coeffs.begin(), coeffs.end(), array.begin());
self.setLinearityCoeffs(array);
});
cls.def("setLinearityType", &Amplifier::Builder::setLinearityType, "type"_a);
cls.def("setLinearityThreshold", &Amplifier::Builder::setLinearityThreshold, "threshold"_a);
cls.def("setLinearityMaximum", &Amplifier::Builder::setLinearityMaximum, "maximum"_a);
cls.def("setLinearityUnits", &Amplifier::Builder::setLinearityUnits, "units"_a);
cls.def("setRawBBox", &Amplifier::Builder::setRawBBox, "bbox"_a);
cls.def("setRawDataBBox", &Amplifier::Builder::setRawDataBBox, "bbox"_a);
cls.def("setRawFlipX", &Amplifier::Builder::setRawFlipX, "rawFlipX"_a);
cls.def("setRawFlipY", &Amplifier::Builder::setRawFlipY, "rawFlipY"_a);
cls.def("setRawXYOffset", &Amplifier::Builder::setRawXYOffset, "offset"_a);
cls.def("setRawHorizontalOverscanBBox", &Amplifier::Builder::setRawHorizontalOverscanBBox, "bbox"_a);
cls.def("setRawVerticalOverscanBBox", &Amplifier::Builder::setRawVerticalOverscanBBox, "bbox"_a);
cls.def("setRawPrescanBBox", &Amplifier::Builder::setRawPrescanBBox, "bbox"_a);
cls.def("setRawSerialOverscanBBox", &Amplifier::Builder::setRawSerialOverscanBBox, "bbox"_a);
cls.def("setRawParallelOverscanBBox", &Amplifier::Builder::setRawParallelOverscanBBox, "bbox"_a);
cls.def("setRawSerialPrescanBBox", &Amplifier::Builder::setRawSerialPrescanBBox, "bbox"_a);
cls.def("setRawHorizontalPrescanBBox", &Amplifier::Builder::setRawHorizontalPrescanBBox, "bbox"_a);
});
}

} // namespace cameraGeom
} // namespace afw
} // namespace lsst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

__all__ = ["ReadoutCornerValNameDict", "ReadoutCornerNameValDict"]

from .amplifier import ReadoutCorner
from ._cameraGeom import ReadoutCorner


ReadoutCornerValNameDict = {
Expand Down
File renamed without changes.
123 changes: 123 additions & 0 deletions python/lsst/afw/cameraGeom/_camera.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*
* This file is part of afw.
*
* Developed for the LSST Data Management System.
* This product includes software developed by the LSST Project
* (https://www.lsst.org).
* See the COPYRIGHT file at the top-level directory of this distribution
* for details of code ownership.
*
* 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 GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#include "pybind11/pybind11.h"
#include <lsst/utils/python.h>

#include "pybind11/stl.h"

#include "lsst/utils/python.h"
#include "lsst/afw/table/io/python.h"
#include "lsst/afw/cameraGeom/Camera.h"

namespace py = pybind11;
using namespace py::literals;

namespace lsst {
namespace afw {
namespace cameraGeom {

using PyCamera = py::class_<Camera, DetectorCollection, std::shared_ptr<Camera>>;
using PyCameraBuilder = py::class_<Camera::Builder, DetectorCollectionBase<Detector::InCameraBuilder>,
std::shared_ptr<Camera::Builder>>;

// Bindings here are ordered to match the order of the declarations in
// Camera.h to the greatest extent possible; modifications to this file should
// attempt to preserve this.

void wrapCamera(lsst::utils::python::WrapperCollection &wrappers) {
wrappers.addInheritanceDependency("lsst.afw.table.io");
wrappers.addSignatureDependency("lsst.afw.cameraGeom");
auto camera = wrappers.wrapType(PyCamera(wrappers.module, "Camera"), [](auto &mod, auto &cls) {
cls.def("rebuild", &Camera::rebuild);
cls.def("getName", &Camera::getName);
cls.def("getPupilFactoryName", &Camera::getPupilFactoryName);
cls.def("findDetectors", &Camera::findDetectors, "point"_a, "cameraSys"_a);
cls.def("findDetectorsList", &Camera::findDetectorsList, "pointList"_a, "cameraSys"_a);
// transform methods are wrapped with lambdas that translate exceptions for backwards compatibility
cls.def(
"getTransform",
[](Camera const &self, CameraSys const &fromSys, CameraSys const &toSys) {
try {
return self.getTransform(fromSys, toSys);
} catch (pex::exceptions::NotFoundError &err) {
PyErr_SetString(PyExc_KeyError, err.what());
throw py::error_already_set();
}
},
"fromSys"_a, "toSys"_a);
cls.def("getTransformMap", &Camera::getTransformMap);
cls.def(
"transform",
[](Camera const &self, lsst::geom::Point2D const &point, CameraSys const &fromSys,
CameraSys const &toSys) {
try {
return self.transform(point, fromSys, toSys);
} catch (pex::exceptions::NotFoundError &err) {
PyErr_SetString(PyExc_KeyError, err.what());
throw py::error_already_set();
}
},
"point"_a, "fromSys"_a, "toSys"_a);
cls.def(
"transform",
[](Camera const &self, std::vector<lsst::geom::Point2D> const &points,
CameraSys const &fromSys, CameraSys const &toSys) {
try {
return self.transform(points, fromSys, toSys);
} catch (pex::exceptions::NotFoundError &err) {
PyErr_SetString(PyExc_KeyError, err.what());
throw py::error_already_set();
}
},
"points"_a, "fromSys"_a, "toSys"_a);
table::io::python::addPersistableMethods(cls);
});
wrappers.wrapType(PyCameraBuilder(camera, "Builder"), [](auto &mod, auto &cls) {
cls.def(py::init<std::string const &>(), "name"_a);
cls.def(py::init<Camera const &>(), "camera"_a);
cls.def("finish", &Camera::Builder::finish);
cls.def("getName", &Camera::Builder::getName);
cls.def("setName", &Camera::Builder::setName);
cls.def("getPupilFactoryName", &Camera::Builder::getPupilFactoryName);
cls.def("setPupilFactoryName", &Camera::Builder::setPupilFactoryName);
cls.def("setPupilFactoryClass", [](Camera::Builder &self, py::object pupilFactoryClass) {
std::string pupilFactoryName = "lsst.afw.cameraGeom.pupil.PupilFactory";
if (!pupilFactoryClass.is(py::none())) {
pupilFactoryName = py::str("{}.{}").format(pupilFactoryClass.attr("__module__"),
pupilFactoryClass.attr("__name__"));
}
self.setPupilFactoryName(pupilFactoryName);
});
cls.def("setTransformFromFocalPlaneTo", &Camera::Builder::setTransformFromFocalPlaneTo, "toSys"_a,
"transform"_a);
cls.def("discardTransformFromFocalPlaneTo", &Camera::Builder::discardTransformFromFocalPlaneTo);
cls.def("add", &Camera::Builder::add);
cls.def("__delitem__", py::overload_cast<int>(&Camera::Builder::remove));
cls.def("__delitem__", py::overload_cast<std::string const &>(&Camera::Builder::remove));
});
}

} // namespace cameraGeom
} // namespace afw
} // namespace lsst
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

# Camera object below is the same one exported by the pybind11 camera
# module, so we don't need to re-export it here.
__all__ = []
__all__ = ['Camera']

from lsst.utils import continueClass, doImport
from .camera import Camera
from ._cameraGeom import Camera


@continueClass # noqa: F811 (FIXME: remove for py 3.8+)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@

import os.path
from lsst.afw.table import BaseCatalog
from .cameraGeomLib import FOCAL_PLANE, FIELD_ANGLE, PIXELS, TAN_PIXELS, ACTUAL_PIXELS, CameraSys, \
Amplifier
from .camera import Camera
from .makePixelToTanPixel import makePixelToTanPixel
from ._cameraGeom import FOCAL_PLANE, FIELD_ANGLE, PIXELS, TAN_PIXELS, ACTUAL_PIXELS, CameraSys
from ._cameraGeom import Amplifier
from ._camera import Camera
from ._makePixelToTanPixel import makePixelToTanPixel
from .pupil import PupilFactory

cameraSysList = [FIELD_ANGLE, FOCAL_PLANE, PIXELS, TAN_PIXELS, ACTUAL_PIXELS]
Expand Down

0 comments on commit e1b732b

Please sign in to comment.