Skip to content

Commit

Permalink
Add PixelMap subclass using AST mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
cmsaunders committed Nov 27, 2023
1 parent aa71a13 commit b9b48c3
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 2 deletions.
12 changes: 12 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ add_compile_definitions(USE_YAML=TRUE)

find_library(FFTW3 fftw3 REQUIRED)

# find astshim library using EUPS package environent variable as hint
find_library(ASTSHIM_LIBRARIES
astshim REQUIRED
HINTS $ENV{ASTSHIM_DIR}/lib
)
#find astshim include directory
find_path(
ASTSHIM_INCLUDES
astshim.h REQUIRED
HINTS $ENV{ASTSHIM_DIR}/include
)

# TMV or Eigen must be available, but TMV is preferred
find_package(TMV QUIET)
if(TMV_FOUND)
Expand Down
2 changes: 1 addition & 1 deletion astrometry/CMakeLists.txt
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)
36 changes: 36 additions & 0 deletions astrometry/include/PixelMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#ifdef USE_YAML
#include "yaml-cpp/yaml.h"
#endif
#include "astshim.h"

#include "Std.h"
#include "LinearAlgebra.h"
#include "Astrometry.h"
Expand Down Expand Up @@ -332,5 +334,39 @@ namespace astrometry {
void operator=(const ColorTerm& rhs) = delete;

};

class ASTMap: public PixelMap {
// Class representing a constant shift of position
public:
ASTMap(const ast::Mapping& mapping_, string name_=""):
PixelMap(name_), mapping(mapping_) {}

//virtual PixelMap* duplicate() const {return new ASTMap(mapping.copy());}
//virtual PixelMap* duplicate() const {return new ASTMap(*this);}
virtual PixelMap* duplicate() const;
//virtual PixelMap* duplicate() const {return new IdentityMap();}

~ASTMap() {}

static string type() {return "AST";}

ast::Mapping mapping;

void toWorld(double xpix, double ypix,
double &xworld, double &yworld,
double color=astrometry::NODATA) const;
// inverse map:
void toPix(double xworld, double yworld,
double &xpix, double &ypix,
double color = astrometry::NODATA) const;

#ifdef USE_YAML
virtual void write(YAML::Emitter &os) const
{
os << YAML::BeginMap << YAML::Key << "Type" << YAML::Value << type()
<< YAML::EndMap;
}
#endif
};
} // namespace astrometry
#endif //PIXMAP_H
27 changes: 27 additions & 0 deletions astrometry/src/PixelMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
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];
}
2 changes: 1 addition & 1 deletion pydir/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set(PYTHON_MODULE_EXTENSION ".so")

pybind11_add_module(wcsfit wcsfit.cpp)

target_link_libraries(wcsfit PUBLIC subs cfitsio)
target_link_libraries(wcsfit PUBLIC subs cfitsio ${ASTSHIM_LIBRARIES})

target_include_directories(wcsfit PUBLIC ${PROJECT_SOURCE_DIR}/include)

Expand Down
5 changes: 5 additions & 0 deletions pydir/wcsfit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "TPVMap.h"
#include "WCSFoFRoutine.h"
#include "WCSFitRoutine.h"
#include "astshim.h"

using namespace pybind11::literals;
namespace py = pybind11;
Expand Down Expand Up @@ -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>(),
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>(),
Expand Down
1 change: 1 addition & 0 deletions ups/gbdes.table
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
setupRequired(astshim)
envPrepend(PYTHONPATH, ${PRODUCT_DIR}/build/pydir)

0 comments on commit b9b48c3

Please sign in to comment.