-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DM-41634: Add PixelMap subclass using AST mappings #15
Changes from 3 commits
08a7f4f
e5f2b52
064e686
4b51838
8278526
c7ff475
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
add_library(astrometry src/Astrometry.cpp src/PiecewiseMap.cpp src/PixelMapCollection.cpp src/SubMap.cpp | ||
src/Wcs.cpp src/PixelMap.cpp src/PolyMap.cpp src/TemplateMap.cpp src/YAMLCollector.cpp) | ||
|
||
target_include_directories(astrometry PUBLIC ${PROJECT_SOURCE_DIR}/astrometry/include) | ||
target_include_directories(astrometry PUBLIC ${PROJECT_SOURCE_DIR}/astrometry/include ${ASTSHIM_INCLUDES}) | ||
target_link_libraries(astrometry PUBLIC Eigen3::Eigen ${FFTW3_LIBRARIES} yaml-cpp gbutil) |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -17,6 +17,8 @@ | |||||
#ifdef USE_YAML | ||||||
#include "yaml-cpp/yaml.h" | ||||||
#endif | ||||||
#include "astshim.h" | ||||||
|
||||||
#include "Std.h" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is ugly in the original There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, it's not great, but we decided not to go through and change all the original code. New code is supposed to ignore this, but I forgot in the instance you commented on below. |
||||||
#include "LinearAlgebra.h" | ||||||
#include "Astrometry.h" | ||||||
|
@@ -332,5 +334,37 @@ namespace astrometry { | |||||
void operator=(const ColorTerm& rhs) = delete; | ||||||
|
||||||
}; | ||||||
|
||||||
class ASTMap: public PixelMap { | ||||||
// Class representing a constant shift of position | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand why the ASTMap class is described as representing solely a constant shift. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a mistake due to my using a different class as a template. |
||||||
public: | ||||||
ASTMap(const ast::Mapping& mapping_, string name_=""): | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for catching this. We've been trying to include |
||||||
PixelMap(name_), mapping(mapping_) {} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be much better to make the Normally that would result in really horrible bugs, and the copy constructor would have been disabled to protect against that, and I find it strange that that's not the case in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I've implemented what you suggest. Can you check and see if I did what you meant? I also changed |
||||||
|
||||||
virtual PixelMap* duplicate() const; | ||||||
|
||||||
~ASTMap() {} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can be declared as default dtor
Suggested change
|
||||||
|
||||||
static string type() {return "AST";} | ||||||
|
||||||
ast::Mapping mapping; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be better for this to be private. |
||||||
|
||||||
void toWorld(double xpix, double ypix, | ||||||
double &xworld, double &yworld, | ||||||
double color=astrometry::NODATA) const; | ||||||
void toPix(double xworld, double yworld, | ||||||
double &xpix, double &ypix, | ||||||
double color = astrometry::NODATA) const; | ||||||
|
||||||
#ifdef USE_YAML | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you know if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, yaml is built into the mappings and if USE_YAML is false some key classes don't get built. Long term, it would be nice to remove this dependence though. |
||||||
// AST maps are not expected to be used for output, so we do not | ||||||
// attempt to write a full description to yaml. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could, because AST mappings can be serialized to ASDF YAML. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good to know. I'm not going to implement that now, because I think it's pretty unlikely it will be needed. |
||||||
virtual void write(YAML::Emitter &os) const | ||||||
{ | ||||||
os << YAML::BeginMap << YAML::Key << "Type" << YAML::Value << type() | ||||||
<< YAML::EndMap; | ||||||
} | ||||||
#endif | ||||||
}; | ||||||
} // namespace astrometry | ||||||
#endif //PIXMAP_H |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -350,3 +350,30 @@ ConstantMap::create(const YAML::Node& node, | |
} | ||
} | ||
#endif | ||
|
||
PixelMap* | ||
ASTMap::duplicate() const { | ||
std::shared_ptr<ast::Mapping> newMapping = mapping.copy(); | ||
return new ASTMap(*newMapping); | ||
} | ||
|
||
void | ||
ASTMap::toWorld(double xpix, double ypix, | ||
double& xworld, double& yworld, | ||
double color) const { | ||
|
||
std::vector<double> pixCoords{xpix, ypix}; | ||
std::vector<double> worldCoord = mapping.applyForward(pixCoords); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm a bit worried that this is going to be slow. AST is much faster if you give it many coordinates to transform and it's even faster if you ask it to transform a regular pixel grid to WCS in one go (astMapGrid). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did a timing test, and there is a slow-down, but it's not prohibitive. This will only be used in a couple places in setting up the astrometric fit. For 31 visits, the time it took to do source association went from ~4 seconds to ~7 seconds, and the fit initialization went from ~33 seconds to ~41 seconds. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok. I assume it's not possible to run this in bulk given the way gbdes calls the transformation code, but I imagine it would pull all that time back if you did that. |
||
xworld = worldCoord[0]; | ||
yworld = worldCoord[1]; | ||
} | ||
|
||
void | ||
ASTMap::toPix( double xworld, double yworld, | ||
double &xpix, double &ypix, | ||
double color) const { | ||
std::vector<double> worldCoords(xworld, yworld); | ||
std::vector<double> pixCoord = mapping.applyInverse(worldCoords); | ||
xpix = pixCoord[0]; | ||
ypix = pixCoord[1]; | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -13,6 +13,7 @@ | |||||
#include "TPVMap.h" | ||||||
#include "WCSFoFRoutine.h" | ||||||
#include "WCSFitRoutine.h" | ||||||
#include "astshim.h" | ||||||
|
||||||
using namespace pybind11::literals; | ||||||
namespace py = pybind11; | ||||||
|
@@ -102,6 +103,10 @@ PYBIND11_MODULE(wcsfit, m) { | |||||
py::class_<astrometry::SubMap, astrometry::PixelMap>(m, "SubMap") | ||||||
.def(py::init<list<astrometry::PixelMap *> const &, std::string, bool>()); | ||||||
|
||||||
py::class_<astrometry::ASTMap, astrometry::PixelMap>(m, "ASTMap") | ||||||
.def(py::init<ast::Mapping, std::string>(), | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
If this isn't marked as a reference or pointer we'll get more type-slicing in the pybind11 layer. |
||||||
py::arg("mapping_"), py::arg("name_") = ""); | ||||||
|
||||||
py::class_<astrometry::Wcs, std::shared_ptr<astrometry::Wcs>>(m, "Wcs") | ||||||
.def(py::init<astrometry::PixelMap *, astrometry::SphericalCoords const &, std::string, double, | ||||||
bool>(), | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
setupRequired(astshim) | ||
envPrepend(PYTHONPATH, ${PRODUCT_DIR}/build/pydir) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't comment on this line below
This adds the target
WCSfit
as an executablelinking all static libs.
astrometry
which linksastshim
Linking everything into one shlib
gbdes
might work and link this to this executable. Or removethis target if it is not needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need an executable target here, unless @cmsaunders still finds it convenient for comparison-testing sometimes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to just leave in instructions for how to build the executable if needed.