-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
277 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// -*- LSST-C++ -*- | ||
/* | ||
* LSST Data Management System | ||
* Copyright 2008-2014 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/>. | ||
*/ | ||
|
||
#ifndef LSST_AFW_IMAGE_IMAGE_SUMMARY_H_INCLUDED | ||
#define LSST_AFW_IMAGE_IMAGE_SUMMARY_H_INCLUDED | ||
|
||
#include <string> | ||
|
||
#include "lsst/afw/table/io/Persistable.h" | ||
#include "lsst/afw/typehandling/Storable.h" | ||
#include "lsst/afw/table/BaseRecord.h" | ||
|
||
namespace lsst { | ||
namespace afw { | ||
namespace image { | ||
|
||
/** | ||
*/ | ||
class ImageSummary final : public table::io::PersistableFacade<ImageSummary>, public typehandling::Storable { | ||
using Internal = std::shared_ptr<table::BaseRecord>; | ||
|
||
public: | ||
ImageSummary(table::Schema const&); | ||
ImageSummary(ImageSummary const&); | ||
ImageSummary(ImageSummary&&) = default; | ||
ImageSummary& operator=(ImageSummary const&); | ||
ImageSummary& operator=(ImageSummary&&) = default; | ||
~ImageSummary() override = default; | ||
|
||
/// Whether the map is persistable (true IFF all contained BoundedFields are persistable). | ||
bool isPersistable() const noexcept override; | ||
|
||
/// Create a new ImageSummary that is a copy of this one. | ||
std::shared_ptr<typehandling::Storable> cloneStorable() const override; | ||
|
||
table::Schema getSchema() const { | ||
return _internal->getSchema(); | ||
} | ||
|
||
template <typename T> | ||
typename table::Field<T>::Value getKey(table::Key<T> const& key) const { | ||
return _internal->get(key); | ||
} | ||
|
||
void setBool(std::string const& key, bool value); | ||
void setInt64(std::string const& key, std::int64_t value); | ||
void setDouble(std::string const& key, double value); | ||
void setInternal(table::BaseRecord const & other){ | ||
_internal->assign(other); | ||
} | ||
|
||
private: | ||
std::string getPersistenceName() const override; | ||
|
||
std::string getPythonModule() const override; | ||
|
||
void write(OutputArchiveHandle& handle) const override; | ||
|
||
Internal _internal; | ||
}; | ||
} // namespace image | ||
} // namespace afw | ||
} // namespace lsst | ||
|
||
#endif // !LSST_AFW_IMAGE_IMAGE_SUMMARY_H_INCLUDED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* 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 "pybind11/stl.h" | ||
#include "lsst/utils/python.h" | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
#include "lsst/afw/table/io/python.h" // for addPersistableMethods | ||
#include "lsst/afw/typehandling/Storable.h" | ||
#include "lsst/afw/image/ImageSummary.h" | ||
|
||
namespace py = pybind11; | ||
using namespace pybind11::literals; | ||
|
||
namespace lsst { | ||
namespace afw { | ||
namespace image { | ||
namespace { | ||
|
||
using PyImageSummary = py::class_<ImageSummary, std::shared_ptr<ImageSummary>, typehandling::Storable>; | ||
|
||
void wrapImageSummary(lsst::utils::python::WrapperCollection &wrappers) { | ||
wrappers.wrapType(PyImageSummary(wrappers.module, "ImageSummary"), [](auto &mod, auto &cls) { | ||
cls.def(py::init<table::Schema const &>(), "schema"_a); | ||
cls.def(py::init<ImageSummary const &>(), "imageSummary"_a); | ||
|
||
table::io::python::addPersistableMethods<ImageSummary>(cls); | ||
|
||
/* Members */ | ||
cls.def("__setitem__", &ImageSummary::setBool); | ||
cls.def("__setitem__", &ImageSummary::setInt64); | ||
cls.def("__setitem__", &ImageSummary::setDouble); | ||
|
||
cls.def("__getitem__", [] (ImageSummary const& self, std::string const& key){ | ||
py::object result; | ||
self.getSchema().findAndApply(key, [&self, &key, &result](auto const& item){ | ||
result = py::cast(self.getKey(item.key)); | ||
}); | ||
return result; | ||
}); | ||
}); | ||
} | ||
|
||
PYBIND11_MODULE(_imageSummary, mod) { | ||
lsst::utils::python::WrapperCollection wrappers(mod, "lsst.afw.image"); | ||
wrappers.addSignatureDependency("lsst.afw.table"); // for Schema | ||
wrappers.addInheritanceDependency("lsst.afw.table.io"); | ||
wrappers.addInheritanceDependency("lsst.afw.typehandling"); | ||
wrapImageSummary(wrappers); | ||
wrappers.finish(); | ||
/* Declare CRTP base class. */ | ||
} | ||
} // namespace | ||
} // namespace image | ||
} // namespace afw | ||
} // namespace lsst |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
// -*- LSST-C++ -*- | ||
/* | ||
* LSST Data Management System | ||
* Copyright 2008-2014 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 <memory> | ||
|
||
#include "lsst/afw/image/ImageSummary.h" | ||
#include "lsst/afw/table/io/InputArchive.h" | ||
#include "lsst/afw/table/io/OutputArchive.h" | ||
#include "lsst/afw/table/io/CatalogVector.h" | ||
#include "lsst/afw/table/io/Persistable.cc" | ||
|
||
namespace lsst { | ||
namespace afw { | ||
|
||
template std::shared_ptr<image::ImageSummary> table::io::PersistableFacade<image::ImageSummary>::dynamicCast( | ||
std::shared_ptr<table::io::Persistable> const&); | ||
|
||
namespace image { | ||
|
||
ImageSummary::ImageSummary(table::Schema const& schema) { | ||
auto tbl = table::BaseTable::make(schema); | ||
_internal = tbl->makeRecord(); | ||
} | ||
|
||
ImageSummary::ImageSummary(ImageSummary const& other) { | ||
_internal = other._internal->getTable()->copyRecord(*other._internal); | ||
} | ||
|
||
ImageSummary& ImageSummary::operator=(ImageSummary const& other) { | ||
_internal->assign(*other._internal); | ||
return *this; | ||
} | ||
|
||
|
||
namespace { | ||
|
||
class ImageSummaryFactory : public table::io::PersistableFactory { | ||
public: | ||
std::shared_ptr<table::io::Persistable> read(InputArchive const& archive, | ||
CatalogVector const& catalogs) const override { | ||
LSST_ARCHIVE_ASSERT(catalogs.size() == 1u); | ||
LSST_ARCHIVE_ASSERT(catalogs.front().size() == 1u); | ||
std::shared_ptr<ImageSummary> result = std::make_shared<ImageSummary>(catalogs.front().getSchema()); | ||
result->setInternal(catalogs.front().front()); | ||
return result; | ||
} | ||
|
||
ImageSummaryFactory(std::string const& name) : afw::table::io::PersistableFactory(name) {} | ||
}; | ||
|
||
std::string getImageSummaryPersistenceName() { return "ImageSummary"; } | ||
|
||
ImageSummaryFactory registration(getImageSummaryPersistenceName()); | ||
|
||
} // namespace | ||
|
||
bool ImageSummary::isPersistable() const noexcept {return true;} | ||
|
||
std::string ImageSummary::getPersistenceName() const { return getImageSummaryPersistenceName(); } | ||
|
||
std::string ImageSummary::getPythonModule() const { return "lsst.afw.image"; } | ||
|
||
void ImageSummary::write(OutputArchiveHandle& handle) const { | ||
table::BaseCatalog catalog = handle.makeCatalog(_internal->getSchema()); | ||
std::shared_ptr<table::BaseRecord> record = catalog.addNew(); | ||
record->assign(*_internal); | ||
handle.saveCatalog(catalog); | ||
} | ||
|
||
std::shared_ptr<typehandling::Storable> ImageSummary::cloneStorable() const { | ||
return std::make_unique<ImageSummary>(*this); | ||
} | ||
|
||
void ImageSummary::setBool(std::string const& key, bool value) { | ||
_internal->set(_internal->getSchema().find<table::Flag>(key).key, value); | ||
} | ||
|
||
void ImageSummary::setInt64(std::string const& key, std::int64_t value) { | ||
_internal->set(_internal->getSchema().find<std::int64_t>(key).key, value); | ||
} | ||
|
||
void ImageSummary::setDouble(std::string const& key, double value) { | ||
_internal->set(_internal->getSchema().find<double>(key).key, value); | ||
} | ||
|
||
} // namespace image | ||
} // namespace afw | ||
} // namespace lsst |