Skip to content

Commit 14bbac5

Browse files
committed
Create ImageSummary class
1 parent 1b7e582 commit 14bbac5

File tree

6 files changed

+277
-1
lines changed

6 files changed

+277
-1
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// -*- LSST-C++ -*-
2+
/*
3+
* LSST Data Management System
4+
* Copyright 2008-2014 LSST Corporation.
5+
*
6+
* This product includes software developed by the
7+
* LSST Project (http://www.lsst.org/).
8+
*
9+
* This program is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU General Public License as published by
11+
* the Free Software Foundation, either version 3 of the License, or
12+
* (at your option) any later version.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU General Public License for more details.
18+
*
19+
* You should have received a copy of the LSST License Statement and
20+
* the GNU General Public License along with this program. If not,
21+
* see <http://www.lsstcorp.org/LegalNotices/>.
22+
*/
23+
24+
#ifndef LSST_AFW_IMAGE_IMAGE_SUMMARY_H_INCLUDED
25+
#define LSST_AFW_IMAGE_IMAGE_SUMMARY_H_INCLUDED
26+
27+
#include <string>
28+
29+
#include "lsst/afw/table/io/Persistable.h"
30+
#include "lsst/afw/typehandling/Storable.h"
31+
#include "lsst/afw/table/BaseRecord.h"
32+
33+
namespace lsst {
34+
namespace afw {
35+
namespace image {
36+
37+
/**
38+
39+
*/
40+
class ImageSummary final : public table::io::PersistableFacade<ImageSummary>, public typehandling::Storable {
41+
using Internal = std::shared_ptr<table::BaseRecord>;
42+
43+
public:
44+
ImageSummary(table::Schema const&);
45+
ImageSummary(ImageSummary const&);
46+
ImageSummary(ImageSummary&&) = default;
47+
ImageSummary& operator=(ImageSummary const&);
48+
ImageSummary& operator=(ImageSummary&&) = default;
49+
~ImageSummary() override = default;
50+
51+
/// Whether the map is persistable (true IFF all contained BoundedFields are persistable).
52+
bool isPersistable() const noexcept override;
53+
54+
/// Create a new ImageSummary that is a copy of this one.
55+
std::shared_ptr<typehandling::Storable> cloneStorable() const override;
56+
57+
table::Schema getSchema() const {
58+
return _internal->getSchema();
59+
}
60+
61+
template <typename T>
62+
typename table::Field<T>::Value getKey(table::Key<T> const& key) const {
63+
return _internal->get(key);
64+
}
65+
66+
void setBool(std::string const& key, bool value);
67+
void setInt64(std::string const& key, std::int64_t value);
68+
void setDouble(std::string const& key, double value);
69+
void setInternal(table::BaseRecord const & other){
70+
_internal->assign(other);
71+
}
72+
73+
private:
74+
std::string getPersistenceName() const override;
75+
76+
std::string getPythonModule() const override;
77+
78+
void write(OutputArchiveHandle& handle) const override;
79+
80+
Internal _internal;
81+
};
82+
} // namespace image
83+
} // namespace afw
84+
} // namespace lsst
85+
86+
#endif // !LSST_AFW_IMAGE_IMAGE_SUMMARY_H_INCLUDED

include/lsst/afw/table/BaseRecord.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class BaseRecord {
8080
Schema getSchema() const { return _table->getSchema(); }
8181

8282
/// Return the table this record is associated with.
83-
std::shared_ptr<BaseTable const> getTable() const { return _table; }
83+
std::shared_ptr<BaseTable> getTable() const { return _table; }
8484

8585
/**
8686
* Return a pointer to the underlying elements of a field (non-const).

python/lsst/afw/image/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from ._imageLib import *
2222
from . import pixel
2323
from ._image import *
24+
from ._imageSummary import *
2425
from ._apCorrMap import *
2526
from ._maskedImage import *
2627
from ._visitInfo import * # just here to support deprecation

python/lsst/afw/image/_imageLib.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ void wrapExposure(lsst::utils::python::WrapperCollection &);
3535
void wrapExposureInfo(lsst::utils::python::WrapperCollection &);
3636
void wrapFilterLabel(lsst::utils::python::WrapperCollection &);
3737
void wrapImagePca(lsst::utils::python::WrapperCollection &);
38+
void wrapImageSummary(lsst::utils::python::WrapperCollection &);
3839
void wrapImageUtils(lsst::utils::python::WrapperCollection &);
3940
void wrapPhotoCalib(lsst::utils::python::WrapperCollection &);
4041
void wrapReaders(lsst::utils::python::WrapperCollection &);
@@ -50,6 +51,7 @@ PYBIND11_MODULE(_imageLib, mod) {
5051
wrapExposureInfo(wrappers);
5152
wrapFilterLabel(wrappers);
5253
wrapImagePca(wrappers);
54+
wrapImageSummary(wrappers);
5355
wrapImageUtils(wrappers);
5456
wrapPhotoCalib(wrappers);
5557
wrapReaders(wrappers);
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* This file is part of afw.
3+
*
4+
* Developed for the LSST Data Management System.
5+
* This product includes software developed by the LSST Project
6+
* (https://www.lsst.org).
7+
* See the COPYRIGHT file at the top-level directory of this distribution
8+
* for details of code ownership.
9+
*
10+
* This program is free software: you can redistribute it and/or modify
11+
* it under the terms of the GNU General Public License as published by
12+
* the Free Software Foundation, either version 3 of the License, or
13+
* (at your option) any later version.
14+
*
15+
* This program is distributed in the hope that it will be useful,
16+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
* GNU General Public License for more details.
19+
*
20+
* You should have received a copy of the GNU General Public License
21+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
22+
*/
23+
24+
#include "pybind11/pybind11.h"
25+
#include "pybind11/stl.h"
26+
#include "lsst/utils/python.h"
27+
28+
#include <string>
29+
#include <vector>
30+
31+
#include "lsst/afw/table/io/python.h" // for addPersistableMethods
32+
#include "lsst/afw/typehandling/Storable.h"
33+
#include "lsst/afw/image/ImageSummary.h"
34+
35+
namespace py = pybind11;
36+
using namespace pybind11::literals;
37+
38+
namespace lsst {
39+
namespace afw {
40+
namespace image {
41+
namespace {
42+
43+
using PyImageSummary = py::class_<ImageSummary, std::shared_ptr<ImageSummary>, typehandling::Storable>;
44+
45+
void wrapImageSummary(lsst::utils::python::WrapperCollection &wrappers) {
46+
wrappers.wrapType(PyImageSummary(wrappers.module, "ImageSummary"), [](auto &mod, auto &cls) {
47+
cls.def(py::init<table::Schema const &>(), "schema"_a);
48+
cls.def(py::init<ImageSummary const &>(), "imageSummary"_a);
49+
50+
table::io::python::addPersistableMethods<ImageSummary>(cls);
51+
52+
/* Members */
53+
cls.def("__setitem__", &ImageSummary::setBool);
54+
cls.def("__setitem__", &ImageSummary::setInt64);
55+
cls.def("__setitem__", &ImageSummary::setDouble);
56+
57+
cls.def("__getitem__", [] (ImageSummary const& self, std::string const& key){
58+
py::object result;
59+
self.getSchema().findAndApply(key, [&self, &key, &result](auto const& item){
60+
result = py::cast(self.getKey(item.key));
61+
});
62+
return result;
63+
});
64+
});
65+
}
66+
67+
PYBIND11_MODULE(_imageSummary, mod) {
68+
lsst::utils::python::WrapperCollection wrappers(mod, "lsst.afw.image");
69+
wrappers.addSignatureDependency("lsst.afw.table"); // for Schema
70+
wrappers.addInheritanceDependency("lsst.afw.table.io");
71+
wrappers.addInheritanceDependency("lsst.afw.typehandling");
72+
wrapImageSummary(wrappers);
73+
wrappers.finish();
74+
/* Declare CRTP base class. */
75+
}
76+
} // namespace
77+
} // namespace image
78+
} // namespace afw
79+
} // namespace lsst

src/image/ImageSummary.cc

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
// -*- LSST-C++ -*-
2+
/*
3+
* LSST Data Management System
4+
* Copyright 2008-2014 LSST Corporation.
5+
*
6+
* This product includes software developed by the
7+
* LSST Project (http://www.lsst.org/).
8+
*
9+
* This program is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU General Public License as published by
11+
* the Free Software Foundation, either version 3 of the License, or
12+
* (at your option) any later version.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU General Public License for more details.
18+
*
19+
* You should have received a copy of the LSST License Statement and
20+
* the GNU General Public License along with this program. If not,
21+
* see <http://www.lsstcorp.org/LegalNotices/>.
22+
*/
23+
24+
#include <memory>
25+
26+
#include "lsst/afw/image/ImageSummary.h"
27+
#include "lsst/afw/table/io/InputArchive.h"
28+
#include "lsst/afw/table/io/OutputArchive.h"
29+
#include "lsst/afw/table/io/CatalogVector.h"
30+
#include "lsst/afw/table/io/Persistable.cc"
31+
32+
namespace lsst {
33+
namespace afw {
34+
35+
template std::shared_ptr<image::ImageSummary> table::io::PersistableFacade<image::ImageSummary>::dynamicCast(
36+
std::shared_ptr<table::io::Persistable> const&);
37+
38+
namespace image {
39+
40+
ImageSummary::ImageSummary(table::Schema const& schema) {
41+
auto tbl = table::BaseTable::make(schema);
42+
_internal = tbl->makeRecord();
43+
}
44+
45+
ImageSummary::ImageSummary(ImageSummary const& other) {
46+
_internal = other._internal->getTable()->copyRecord(*other._internal);
47+
}
48+
49+
ImageSummary& ImageSummary::operator=(ImageSummary const& other) {
50+
_internal->assign(*other._internal);
51+
return *this;
52+
}
53+
54+
55+
namespace {
56+
57+
class ImageSummaryFactory : public table::io::PersistableFactory {
58+
public:
59+
std::shared_ptr<table::io::Persistable> read(InputArchive const& archive,
60+
CatalogVector const& catalogs) const override {
61+
LSST_ARCHIVE_ASSERT(catalogs.size() == 1u);
62+
LSST_ARCHIVE_ASSERT(catalogs.front().size() == 1u);
63+
std::shared_ptr<ImageSummary> result = std::make_shared<ImageSummary>(catalogs.front().getSchema());
64+
result->setInternal(catalogs.front().front());
65+
return result;
66+
}
67+
68+
ImageSummaryFactory(std::string const& name) : afw::table::io::PersistableFactory(name) {}
69+
};
70+
71+
std::string getImageSummaryPersistenceName() { return "ImageSummary"; }
72+
73+
ImageSummaryFactory registration(getImageSummaryPersistenceName());
74+
75+
} // namespace
76+
77+
bool ImageSummary::isPersistable() const noexcept {return true;}
78+
79+
std::string ImageSummary::getPersistenceName() const { return getImageSummaryPersistenceName(); }
80+
81+
std::string ImageSummary::getPythonModule() const { return "lsst.afw.image"; }
82+
83+
void ImageSummary::write(OutputArchiveHandle& handle) const {
84+
table::BaseCatalog catalog = handle.makeCatalog(_internal->getSchema());
85+
std::shared_ptr<table::BaseRecord> record = catalog.addNew();
86+
record->assign(*_internal);
87+
handle.saveCatalog(catalog);
88+
}
89+
90+
std::shared_ptr<typehandling::Storable> ImageSummary::cloneStorable() const {
91+
return std::make_unique<ImageSummary>(*this);
92+
}
93+
94+
void ImageSummary::setBool(std::string const& key, bool value) {
95+
_internal->set(_internal->getSchema().find<table::Flag>(key).key, value);
96+
}
97+
98+
void ImageSummary::setInt64(std::string const& key, std::int64_t value) {
99+
_internal->set(_internal->getSchema().find<std::int64_t>(key).key, value);
100+
}
101+
102+
void ImageSummary::setDouble(std::string const& key, double value) {
103+
_internal->set(_internal->getSchema().find<double>(key).key, value);
104+
}
105+
106+
} // namespace image
107+
} // namespace afw
108+
} // namespace lsst

0 commit comments

Comments
 (0)