26 using namespace hippodraw;
40 for (
int i = 0;
i < number;
i++ ) {
48 value =
"Empty image";
53 if ( value ==
"" ) value =
"<no name>";
54 names.push_back ( value );
63 if ( type ==
Image ) {
83 for (
int i = 0;
i < columns;
i++ ) {
84 char colname [ FLEN_VALUE ];
86 fits_get_colname (
m_fptr, CASEINSEN, const_cast< char * > (
"*"),
88 labels.push_back (
string ( colname ) );
92 labels.push_back (
string (
"none" ) );
104 if ( dimension == 2 ) {
105 labels.push_back (
"Values" );
107 else if ( dimension == 3 ) {
108 const char type[] =
"CTYPE3";
113 for (
int i = 0;
i < number;
i++ ) {
115 labels.push_back ( name +
" " + iv );
147 long nelements = vec.size();
148 vector<double>::iterator
it = vec.begin();
152 fits_read_col_dbl(
m_fptr, column+1, 1, 1, nelements, nulval,
164 string tdimn (
"TDIM" );
167 fits_read_keyword (
m_fptr,
168 const_cast < char * > ( tdimn.c_str() ),
173 if ( value[0] != 0 ) {
174 const string dims = value;
175 unsigned int count = std::count ( dims.begin(), dims.end(),
',' );
178 vector < long > naxes ( count );
179 fits_read_tdim (
m_fptr, column+1, count,
181 shape.resize ( count + 1 );
183 std::copy ( naxes.begin(), naxes.end(), shape.begin() + 1 );
186 shape.resize ( 1, rows );
196 vec.resize ( naxis );
198 vector < long > ::iterator first = vec.begin();
199 long * ptr = & *first;
213 deltas.reserve ( naxis );
215 char key [ FLEN_KEYWORD];
216 char * keyroot = const_cast <
char * > (
"CDELT");
217 for (
int i = 0;
i < naxis;
i++ ) {
219 fits_make_keyn ( keyroot,
i+1, key, &
m_status );
224 deltas.push_back ( value );
227 deltas.push_back ( 1.0 );
238 indices.reserve ( naxis );
240 char key [ FLEN_KEYWORD];
241 char * keyroot = const_cast <
char * > (
"CRPIX" );
242 for (
int i = 0;
i < naxis;
i++ ) {
244 fits_make_keyn ( keyroot,
i+1, key, &
m_status );
249 indices.push_back ( value );
252 indices.push_back ( 1 );
263 values.reserve ( naxis );
265 char key [ FLEN_KEYWORD];
266 char * keyroot = const_cast <
char * > (
"CRVAL" );
267 for (
int i = 0;
i < naxis;
i++ ) {
269 fits_make_keyn ( keyroot,
i+1, key, &
m_status );
274 values.push_back ( value );
277 values.push_back ( 0. );
288 char key [FLEN_KEYWORD];
289 char * keyroot = const_cast <
char * > (
"CTYPE" );
290 for (
int i = 0;
i < 2;
i++ ) {
291 fits_make_keyn ( keyroot,
i+1, key, &
m_status );
296 if ( value.find (
"-AIT" ) == string::npos ) {
311 vector < long > naxes;
315 long nelements = naxes[0] * naxes[1];
317 vector < double >::iterator first = vec.begin();
318 double * ptr = & *first;
321 if ( naxes.size () == 2 ) {
322 long fpixel[2] = { 1, 1 };
323 fits_read_pix (
m_fptr, datatype, fpixel, nelements,
324 & nulval, ptr, & anynul, &
m_status );
326 long fpixel[] = { 1, 1, 1 };
327 fpixel[2] = zplane + 1;
328 fits_read_pix (
m_fptr, datatype, fpixel, nelements,
329 & nulval, ptr, & anynul, &
m_status );
341 long nelements = vec.size();
342 vector<int>::iterator
it = vec.begin();
343 int * ptr =
new int [ nelements ];
346 fits_read_col_int(
m_fptr, column+1, 1, 1, nelements, nulval,
347 ptr, &anynul, &status);
348 copy ( ptr, ptr+nelements, it );
356 const std::vector < std::string > & names,
357 const std::vector < std::vector < int > > & shapes,
358 const std::string & extname )
360 char **
types =
new char * [ columns ];
361 char ** tform =
new char * [ columns ];
365 vector < string > forms;
366 for (
int i = 0;
i < columns;
i ++ ) {
367 types[
i]=
const_cast<char*
> (names[
i].c_str());
369 const vector < int > &
shape = shapes [
i ];
370 unsigned int rank = shape.size();
372 for (
unsigned int j = 1; j <
rank; j++ ) {
373 int dim = shape [ j ];
379 forms.push_back ( form );
381 tform[
i] = strdup ( form.c_str() );
386 m_extname =
const_cast<char*
> (extname.c_str());
388 fits_create_tbl(
m_fptr, BINARY_TBL, 0, columns,
389 types, tform, tunits, m_extname, &
m_status);
391 for (
int i = 0;
i < columns;
i ++ ) {
392 const vector < int > &
shape = shapes [
i ];
393 unsigned int rank = shape.size();
395 vector < long > naxes;
396 for (
unsigned int j = 1; j <
rank; j++ ) {
397 naxes.push_back ( shape [ j ] );
421 LONGLONG nelements = data.size ();
422 LONGLONG firstrow = 1;
423 LONGLONG firstelem = 1;
424 fits_write_col(
m_fptr, TDOUBLE, col+1, firstrow, firstelem, nelements,
425 const_cast < double * > ( &data[0] ), &
m_status);
432 long fpixel[2]={1,1};
433 long nelements = x * y;
434 fits_write_pix (
m_fptr, TDOUBLE, fpixel, nelements,
435 const_cast < double * > ( &data[0] ), &
m_status );
451 char * key = const_cast <
char * > (
"PIXCENT" );
466 char * key1 = const_cast <
char * > (
"CRVAL1" );
467 char * key2 = const_cast <
char * > (
"CRVAL2" );
469 fits_write_key(
m_fptr, TDOUBLE, key1, &value1, NULL, &
m_status );
470 fits_write_key(
m_fptr, TDOUBLE, key2, &value2, NULL, &
m_status );
int m_status
The status return code from the last cfitsio operation.
int fillIntVectorFromColumn(std::vector< int > &vec, int column)
Read elements from an ASCII or binary table column (in the CDU) and fill STL vector<int> with its con...
void fillRefPixelIndices(std::vector< int > &indices) const
Clears and fills the vector with the reference pixel's indexes.
int fillColumnNamesFromTable(std::vector< std::string > &labels)
Clears and fills the vector with the column labels of binary or ASCII table.
A base class for the concrete classes that wrap the cfitsio library.
void writeRefPixelValues(double value1, double value2)
long getNumberOfRows() const
Returns the number of rows in the table.
void * data(numeric::array arr)
int fillFromImage(std::vector< double > &vec, unsigned int axis)
Fills the vector vec from an image HDU.
column
The column indices for 2 dimension data point tuple.
Displays on the Z axis the values of a single column treated as a matrix of values.
std::vector< intptr_t > shape(numeric::array arr)
void writeColumn(int c, const std::vector< double > &data)
Writes the vector to FITS table.
int fillFromTableColumn(std::vector< double > &v, int column)
Fills the vector v from a table column.
The namespace for conversion to string.
HduType getHduType() const
Returns the type of HDU.
int moveToHDU(int hdunum)
Move to a specified absolute HDU number in the FITS file and return the cfitsio status.
PyArray_TYPES type(numeric::array arr)
int fillColumnNamesFromImage(std::vector< std::string > &labels)
Clears and fills the vector with the column labels of a image.
int getImageDimensions() const
Returns the number of dimensions (axes) of an image.
void fillImageDeltas(std::vector< double > &deltas) const
Clears and fills the vector with the delta values of an image.
void writeHDU(long rows, int columns, const std::vector< std::string > &names, const std::vector< std::vector< int > > &shapes, const std::string &extname)
intp size(numeric::array arr)
int rank(numeric::array arr)
int fillDoubleVectorFromColumn(std::vector< double > &vec, int column)
Read elements from an ASCII or binary table column (in the CDU) and fill the vector with its contents...
static Type types[]
An array to allow conversion of integer to enumeration.
string convert(int i)
Converts an integer to a string.
void fillHDUNames(std::vector< std::string > &names)
Clears and fills the vector with the HDU names.
int status() const
Returns the cfitsio status code for the last operation.
int fillColumnNames(std::vector< std::string > &labels)
Clears and fills the vector with the column labels of the current HDU table.
void writePix(long x, long y, const std::vector< double > &data)
int getNumberOfColumns() const
Returns the number of columns in a table.
double doubleValueForKey(const char *key) const
Read a specified keyword value and return it as a double.
FitsFile(const std::string &filename, bool write=false)
Public construction taking a filename as argument.
fitsfile * m_fptr
Pointer to the fits file data structure.
std::string stringValueForKey(const char *key) const
Read a specified keyword value and returns it as a string.
int fillAxisSizes(std::vector< long > &vec) const
Clears and fills the vector vec with the size of each dimension of an image.
int intValueForKey(const char *key) const
Read a specified keyword value and returns it as a int.
void fillRefPixelValues(std::vector< double > &values) const
Clears and fills the vector with the reference pixel's values.
void writeImageHDU(long x, long y)
hippodraw::FitsFile interface
int write(const std::vector< double > &a)
Given the vector it writes it to std stream.
bool isHammerAitoff() const
Returns true if coordinate system of the axis is should undergo Hammer-Aitoff transformation.
int getNumberOfHDU() const
Returns the number of HDU in the file.
void fillShape(std::vector< intptr_t > &shape, int column)
Fills the vector with the shape of the column.
list< QAction * >::iterator it
bool hasKey(const char *key) const
Returns true if the keyword key exists, otherwise returns false.