Skip to content
Snippets Groups Projects
Commit 2f6018fd authored by Robert Butora's avatar Robert Butora
Browse files

overlap: adds check pix-range 0.5...NAXISn+0.5 and fixes GRID-axis double->long conversion

parent 20fe7d88
Branches
Tags
No related merge requests found
......@@ -104,6 +104,8 @@ std::vector<Bounds> calc_bounds(std::string header, std::string skysys, std::str
*
* FIXME add check : 'Domain ?= GRID' where assumption is made that first data point is centered at (1,1)
*/
std::vector<uint_bounds> calc_overlap(const std::string header, const coordinates coord, int& ov_code)
{
LOG_trace(__func__);
......@@ -136,6 +138,7 @@ std::vector<uint_bounds> calc_overlap(const std::string header, const coordinate
LOG_STREAM << "pix ranges[uint]:";
int ix = 0;
for(double_xy dbl_range : pix_ranges.pixel_ranges)
{
if(dbl_range.x < 0)
......@@ -146,36 +149,46 @@ std::vector<uint_bounds> calc_overlap(const std::string header, const coordinate
throw out_of_range(string{__FILE__} + ":" + to_string(__LINE__)
+ " pixel axis from overlap y is negative " + to_string(dbl_range.y));
// FIXME review conversion double -> uint: result must be: 1 <= result <= NAXISn
// conversion double -> uint: result must be: 1 <= result <= NAXISn
// because NAXISn start with 1 (FITS standard) which corresponds to ASTlib's GRID-domain
// FitsChan uses GRID Domain for FITS-pixel coords
// in GRID first element represents a pixel-range: [0.5..1.5) (0.5 in pixel_1 ; 1.5 in pixel_2)
//
// dbl-range is checked to be within 0.5 .. NAXIS+0.5 in ast_frameset::overlap()
if(dbl_range.x <= dbl_range.y)
{
uint_bounds ui_range{lround(dbl_range.x), lround(dbl_range.y), dbl_range.type};
long lowb = lround(dbl_range.x);
long upb = lround(dbl_range.y);
long NAXISi = frm_set.get_naxis(ix++);
if(lowb == (NAXISi + 1)) lowb--;
if(upb == (NAXISi + 1)) upb--;
uint_bounds ui_range{lowb, upb, dbl_range.type};
uint_bounds_vec.push_back(ui_range);
LOG_STREAM << " " << ui_range;
}
else
{
uint_bounds ui_range{lround(dbl_range.y), lround(dbl_range.x), dbl_range.type};
long lowb = lround(dbl_range.y);
long upb = lround(dbl_range.x);
long NAXISi = frm_set.get_naxis(ix++);
if(lowb == (NAXISi + 1)) lowb--;
if(upb == (NAXISi + 1)) upb--;
uint_bounds ui_range{lowb, upb, dbl_range.type};
uint_bounds_vec.push_back(ui_range);
LOG_STREAM << " " << ui_range;
LOG_STREAM << "s" << ui_range;
}
}
LOG_STREAM << endl;
LOG_STREAM << "uint_bounds: " << uint_bounds_vec.size()
<< " pix_ranges:: " << pix_ranges.pixel_ranges.size()
<< endl;
return uint_bounds_vec;
}
void write_previous2(string header, string filename)
{
std::ofstream out(filename);
......
......@@ -147,6 +147,11 @@ ast::frameset::frameset(string header)
}
long ast::frameset::get_naxis(int ix)
{
return m_NAXISn[ix];
}
bool is_specdomain(AstFrame * frm)
{
......@@ -1082,17 +1087,37 @@ overlap_ranges ast::frameset::overlap(coordinates coord)
if ( !astOK || (pixOverlap == AST__NULL) )
throw runtime_error(failed_with_status(__FILE__,__LINE__,"astCmpRegion( header AND coord )"));
AstFrame * pixFrame = (AstFrame*)astGetRegionFrame( pixOverlap );
if ( !astOK )
throw runtime_error(failed_with_status(__FILE__,__LINE__,"astGetRegionFrame( pixOverlap )"));
const char * c_domain = astGetC(pixFrame,"Domain");
string domain{(c_domain==nullptr) ? "<null>" : c_domain};
if(domain.compare("GRID") != 0)
throw runtime_error("Expects GRID domain but it is: " + domain);
double lbnd[AXES_CNT];
double ubnd[AXES_CNT];
astGetRegionBounds(pixOverlap, lbnd, ubnd);
if ( !astOK )
throw runtime_error(failed_with_status(__FILE__,__LINE__,"astGetRegionBounds( pixOverlap )"));
LOG_STREAM <<"BOUNDS overlap in domain: " << domain << endl;
log_bounds("BOUNDS overlap PIX: ", m_NAXIS, lbnd, ubnd);
int ix;
for(ix=0; ix<m_NAXIS; ix++)
for(ix=0; ix<m_NAXIS; ix++) // FIXME why not Naxis ? which can be Naxis > NAXIS
{
if(lbnd[ix] < p1[ix])
throw runtime_error("lower-bound of overlap on pixel-grid less then "
+ to_string(p1[ix]) + ": " + to_string(lbnd[ix])
+ " for NAXIS = " + to_string(ix+1));
if(ubnd[ix] > (p2[ix]) )
throw runtime_error("upper-bound of overlap on pixel-grid more then NAXIS["
+ to_string(ix+1) + "] + 0.5 = " + to_string(p1[ix])
+ ": " + to_string(ubnd[ix]));
pix_ranges.push_back({lbnd[ix],ubnd[ix],m_axis_type[ix]});
}
}
......
......@@ -24,6 +24,8 @@ class frameset
frameset(std::string header);
~frameset();
long get_naxis(int ix);
bool has_specframe(void);
bool has_timeaxis(void);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment