35 CPFITS_BASE(CPFITS_BASE &&ff){
40 void operator=(CPFITS_BASE &&ff){
45 void check_status(
int status,std::string s =
"Error in CPFITS"){
47 fits_report_error(stderr, status);
48 std::cerr << s << std::endl;
49 throw std::invalid_argument(s);
54 std::mutex mutex_lock;
63 std::lock_guard<std::mutex> hold(mutex_lock);
66 fits_get_num_hdus(fptr, &hdunum, &status);
72 int get_current_hdu_num(){
73 std::lock_guard<std::mutex> hold(mutex_lock);
75 fits_get_hdu_num(fptr,&hdunum);
80 int change_hdu(
int i){
81 int hdunum = get_num_hdus();
82 if(i > hdunum || i < 1){
83 throw std::invalid_argument(
"out of range");
88 std::lock_guard<std::mutex> hold(mutex_lock);
89 fits_movabs_hdu(fptr,i,&hdutype,&status);
97 int get_current_hdu_type(
bool verbose=
false){
99 int hdutype,status = 0;
100 fits_get_hdu_type(fptr,&hdutype,&status);
101 check_status(status);
104 std::cout <<
"type: " ;
107 std::cout <<
"Image" << std::endl;
110 std::cout <<
"ASCII table" << std::endl;
113 std::cout <<
"Binary table" << std::endl;
136 void reset_imageInfo(){
137 std::lock_guard<std::mutex> hold(mutex_lock);
140 fits_get_img_type(fptr,&bitpix,&status);
141 check_status(status);
142 fits_get_img_dim(fptr,&Ndims,&status);
143 check_status(status);
145 fits_get_img_size(fptr,Ndims,sizes.data(),&status);
146 check_status(status);
150 void imageDimensions(std::vector<long> &my_sizes){
151 my_sizes.resize(sizes.size());
157 std::lock_guard<std::mutex> hold(mutex_lock);
158 int keysexist,status=0;
159 return fits_get_hdrspace(fptr,&keysexist,NULL,&status);
163 int readKey(std::string keyname,
double &value){
164 std::lock_guard<std::mutex> hold(mutex_lock);
166 return fits_read_key(fptr,TDOUBLE,keyname.c_str(),
167 &value,NULL,&status);
169 int readKey(std::string keyname,
float &value){
170 std::lock_guard<std::mutex> hold(mutex_lock);
172 return fits_read_key(fptr,TFLOAT,keyname.c_str(),
173 &value,NULL,&status);
175 int readKey(std::string keyname,
int &value){
176 std::lock_guard<std::mutex> hold(mutex_lock);
178 return fits_read_key(fptr,TINT,keyname.c_str(),
179 &value,NULL,&status);
181 int readKey(std::string keyname,
size_t &value){
182 std::lock_guard<std::mutex> hold(mutex_lock);
184 return fits_read_key(fptr,TULONG,keyname.c_str(),
185 &value,NULL,&status);
187 int readKey(std::string keyname,
long &value){
188 std::lock_guard<std::mutex> hold(mutex_lock);
190 return fits_read_key(fptr,TLONG,keyname.c_str(),
191 &value,NULL,&status);
193 int readHeader(std::vector<std::string> &headercards,
bool verbose=
false){
194 std::lock_guard<std::mutex> hold(mutex_lock);
195 int nkeys,status=0,hdupos;
196 char card[FLEN_CARD];
199 fits_get_hdu_num(fptr, &hdupos);
200 fits_get_hdrspace(fptr, &nkeys, NULL, &status);
202 if(verbose) printf(
"Header listing for HDU #%d:\n", hdupos);
204 for (
int ii = 1; ii <= nkeys; ii++) {
205 if (fits_read_record(fptr, ii, card, &status))
break;
206 if(verbose) printf(
"%s\n", card);
207 headercards.push_back(card);
209 if(verbose) printf(
"END\n\n");
217 std::vector<std::string> cards;
218 return readHeader(cards,
true);
227 std::vector<long> sizes;
239 CPFITS_READ(std::string filename,std::string extension=
""
240 ,
bool verbose =
false) {
245 fits_open_image(&fptr,filename.c_str(), READONLY, &status);
247 filename = filename + extension;
248 fits_open_image(&fptr,filename.c_str(), READONLY, &status);
251 check_status(status,
"Problem with input fits file.");
255 std::cout <<
"Opening file : " << filename << std::endl;
256 std::cout <<
" status : " << status << std::endl;
262 fits_close_file(fptr, &status);
269 CPFITS_BASE::operator=(std::move(ff));
273 void reset(std::string filename,std::string extension=
""){
274 std::lock_guard<std::mutex> hold(mutex_lock);
276 fits_close_file(fptr, &status);
277 check_status(status);
280 fits_open_image(&fptr,filename.c_str(), READONLY, &status);
282 filename = filename + extension;
283 fits_open_image(&fptr,filename.c_str(), READONLY, &status);
285 check_status(status);
290 int read(std::vector<double> &output,std::vector<long> &size){
293 imageDimensions(size);
295 for(
long n : size) nelements *= n;
296 std::vector<long> start(size.size(),1);
298 output.resize(nelements);
299 std::lock_guard<std::mutex> hold(mutex_lock);
301 return fits_read_pix(fptr,TDOUBLE,start.data(),nelements
302 ,NULL,output.data(),NULL, &status);
305 int read(std::vector<float> &output,std::vector<long> &size){
308 imageDimensions(size);
310 for(
long n : size) nelements *= n;
311 std::vector<long> start(size.size(),1);
312 output.resize(nelements);
315 std::lock_guard<std::mutex> hold(mutex_lock);
316 return fits_read_pix(fptr,TFLOAT,start.data(),nelements
317 ,NULL,output.data(),NULL, &status);
320 int read(std::valarray<float> &output,std::vector<long> &size){
323 imageDimensions(size);
325 for(
long n : size) nelements *= n;
326 std::vector<long> start(size.size(),1);
328 output.resize(nelements);
331 std::lock_guard<std::mutex> hold(mutex_lock);
332 return fits_read_pix(fptr,TFLOAT,start.data(),nelements
333 ,NULL,&output[0],NULL, &status);
335 int read(std::valarray<double> &output,std::vector<long> &sizes){
337 imageDimensions(sizes);
340 long long nelements=1;
341 for(
long n : sizes) nelements *= n;
342 std::vector<long> start(sizes.size(),1);
343 output.resize(nelements);
346 std::lock_guard<std::mutex> hold(mutex_lock);
347 int error = fits_read_pix(fptr,TDOUBLE,start.data(),nelements
348 ,NULL,&output[0],NULL, &status);
349 check_status(status,
"PixMap Read Failure");
356 int read(std::vector<std::vector<T> > &output){
358 std::vector<long> size;
360 int status =
read(tmp,size);
361 output.resize(size[0]);
363 for(
size_t i=0 ; i < size[0] ; ++i){
364 output[i].resize(size[1]);
365 for(T &x : output[i]){
377 std::lock_guard<std::mutex> hold(mutex_lock);
378 return fits_read_pix(fptr,TDOUBLE,start,nelements
379 ,NULL,output,NULL, &status);
381 int read_block(
float *output,
long nelements,
long * start){
383 std::lock_guard<std::mutex> hold(mutex_lock);
384 return fits_read_pix(fptr,TFLOAT,start,nelements
385 ,NULL,output,NULL, &status);
393 std::lock_guard<std::mutex> hold(mutex_lock);
394 return fits_read_subset(fptr,TDOUBLE,lowerleft,upperright,inc
395 ,NULL,output,NULL,&status);
401 std::lock_guard<std::mutex> hold(mutex_lock);
402 return fits_read_subset(fptr,TFLOAT,lowerleft,upperright,inc
403 ,NULL,output,NULL,&status);
407class CPFITS_WRITE :
public CPFITS_BASE {
412 CPFITS_WRITE operator=(CPFITS_WRITE );
415 CPFITS_WRITE(std::string filename,
bool append =
false,
bool verbose =
false) {
418 if(verbose) std::cout <<
"Creating file : " << filename << std::endl;
419 if(filename[0] !=
'!') filename =
"!" + filename;
421 fits_create_file(&fptr, filename.c_str(), &status);
422 check_status(status);
425 fits_open_image(&fptr,filename.c_str(),READWRITE,&status);
430 fits_create_file(&fptr, filename.c_str(), &status);
431 check_status(status);
433 if(verbose) std::cout <<
"Creating file : " << filename << std::endl;
435 if(verbose) std::cout <<
"Appending to file : " << filename << std::endl;
436 check_status(status);
443 fits_close_file(fptr, &status);
444 check_status(status);
448 void write_array(std::vector<double> &array){
449 long n = array.size();
451 std::lock_guard<std::mutex> hold(mutex_lock);
452 fits_create_img(fptr,DOUBLE_IMG,1,&n, &status);
453 check_status(status);
454 std::vector<long> fpixel(1,1);
455 fits_write_pix(fptr,TDOUBLE,fpixel.data(),
456 n,array.data(),&status);
457 check_status(status);
460 void write_array(std::vector<float> &array){
461 long n = array.size();
463 std::lock_guard<std::mutex> hold(mutex_lock);
464 fits_create_img(fptr,FLOAT_IMG,1,&n, &status);
465 check_status(status);
466 std::vector<long> fpixel(1,1);
467 fits_write_pix(fptr,TFLOAT,fpixel.data(),
468 n,array.data(),&status);
469 check_status(status);
473 void write_image(std::vector<double> &im,std::vector<long> &size){
475 for(
size_t i : size) n *= i;
476 assert(im.size() == n);
478 std::lock_guard<std::mutex> hold(mutex_lock);
479 fits_create_img(fptr,DOUBLE_IMG,size.size(),
480 size.data(), &status);
481 check_status(status);
482 std::vector<long> fpixel(size.size(),1);
483 fits_write_pix(fptr,TDOUBLE,fpixel.data(),
484 im.size(),im.data(),&status);
485 check_status(status);
487 void write_image(
double *im,std::vector<long> &size){
489 for(
size_t i : size) n *= i;
491 std::lock_guard<std::mutex> hold(mutex_lock);
492 fits_create_img(fptr,DOUBLE_IMG,size.size(),
493 size.data(), &status);
494 check_status(status);
495 std::vector<long> fpixel(size.size(),1);
496 fits_write_pix(fptr,TDOUBLE,fpixel.data(),
498 check_status(status);
500 void write_image(std::vector<float> &im,std::vector<long> &size){
502 for(
size_t i : size) n *= i;
503 assert(im.size() == n);
505 std::lock_guard<std::mutex> hold(mutex_lock);
506 fits_create_img(fptr,FLOAT_IMG,size.size(),
507 size.data(), &status);
508 check_status(status);
509 std::vector<long> fpixel(size.size(),1);
510 fits_write_pix(fptr,TFLOAT,fpixel.data(),
511 im.size(),im.data(),&status);
512 check_status(status);
514 void write_image(
float *im,std::vector<long> &size){
516 for(
size_t i : size) n *= i;
518 std::lock_guard<std::mutex> hold(mutex_lock);
519 fits_create_img(fptr,FLOAT_IMG,size.size(),
520 size.data(), &status);
521 check_status(status);
522 std::vector<long> fpixel(size.size(),1);
523 fits_write_pix(fptr,TFLOAT,fpixel.data(),
525 check_status(status);
527 void write_image(std::valarray<double> &im,std::vector<long> &size){
529 for(
size_t i : size) n *= i;
530 assert(im.size() == n);
532 std::lock_guard<std::mutex> hold(mutex_lock);
533 fits_create_img(fptr,DOUBLE_IMG,size.size(),
534 size.data(), &status);
535 check_status(status);
538 std::vector<long> fpixel(size.size(),1);
539 fits_write_pix(fptr,TDOUBLE,fpixel.data(),
540 im.size(),&im[0],&status);
541 check_status(status);
543 void write_image(std::valarray<float> &im,std::vector<long> &size){
545 for(
size_t i : size) n *= i;
546 assert(im.size() == n);
548 std::lock_guard<std::mutex> hold(mutex_lock);
549 fits_create_img(fptr,FLOAT_IMG,size.size(),
550 size.data(), &status);
551 check_status(status);
552 std::vector<long> fpixel(size.size(),1);
553 fits_write_pix(fptr,TFLOAT,fpixel.data(),
554 im.size(),&im[0],&status);
555 check_status(status);
560 void write_image(std::vector<std::vector<T> > &im){
561 std::vector<long> size(2);
563 size[1] = im[0].size();
566 std::vector<T> tmp(size[0]*size[1]);
567 for(
long i=0; i<size[0] ; ++i){
568 for(
long j=0; j<size[1] ; ++j){
573 write_image(tmp,size);
577 int writeKey(std::string key,std::string value,std::string comment ){
579 char *s = strdup(value.c_str());
580 std::lock_guard<std::mutex> hold(mutex_lock);
581 int error = fits_write_key(fptr,TSTRING,key.c_str(),
582 s,comment.c_str(),&status);
586 int writeKey(std::string key,
double value,std::string comment ){
588 std::lock_guard<std::mutex> hold(mutex_lock);
589 return fits_update_key(fptr,TDOUBLE,key.c_str(),
590 &value,comment.c_str(),&status);
592 int writeKey(std::string key,
float value,std::string comment ){
594 std::lock_guard<std::mutex> hold(mutex_lock);
595 return fits_update_key(fptr,TFLOAT,key.c_str(),
596 &value,comment.c_str(),&status);
598 int writeKey(std::string key,
int value,std::string comment ){
600 std::lock_guard<std::mutex> hold(mutex_lock);
601 return fits_update_key(fptr,TINT,key.c_str(),
602 &value,comment.c_str(),&status);
604 int writeKey(std::string key,
long value,std::string comment ){
606 std::lock_guard<std::mutex> hold(mutex_lock);
607 return fits_update_key(fptr,TLONG,key.c_str(),
608 &value,comment.c_str(),&status);
610 int writeKey(std::string key,
size_t value,std::string comment ){
612 std::lock_guard<std::mutex> hold(mutex_lock);
613 return fits_update_key(fptr,TULONG,key.c_str(),
614 &value,comment.c_str(),&status);
618 int writeHeader(std::vector<std::string> &cards){
620 for(
auto &str : cards){
621 fits_write_record(fptr, str.c_str(), &status);
627 void copyHeader(CPFITS_BASE &input){
628 std::vector<std::string> cards;
629 input.readHeader(cards);
645 void reset_tableInfo(){
647 fits_get_num_rows(fptr, &Nrow, &status);
648 fits_get_num_cols(fptr, &Ncol, &status);
650 std::vector<std::string> col_names;
652 int get_colnames(std::vector<std::string> &names){
662 for(
auto &name : names){
663 fits_get_colname(fptr,CASESEN,(
char*)(c.c_str()),colname, &colnum, &status);
676 fits_open_table(&fptr,filename.c_str(), READONLY, &status);
677 check_status(status,
"Problem with input fits file.");
680 fits_get_num_hdus(fptr, &num, &status);
682 throw std::runtime_error(
"Not enough HDUs in " + filename);
685 fits_movabs_hdu(fptr,hdunum, &hdutype, &status);
686 check_status(status,
"Problem with input fits file. HDU "+std::to_string(hdunum));
687 if(hdutype != BINARY_TBL){
688 std::cerr <<
"HDU " << hdunum <<
" in " << filename <<
" is not a binary table" << std::endl;
689 throw std::runtime_error(
"wrong HDUs in " + filename);
694 get_colnames(col_names);
697 std::cerr <<
"No data was found in file " << filename << std::endl;
701 std::cout <<
"Opening file : " << filename << std::endl;
702 std::cout << Ncol <<
" columns" << std::endl;
703 std::cout << Nrow <<
" rows" << std::endl;
709 fits_close_file(fptr, &status);
715 CPFITS_BASE::operator=(std::move(ff));
718 long rows(){
return Nrow;}
719 long ncol(){
return Ncol;}
721 int column_index(std::string &colname){
724 fits_get_colnum(fptr, CASEINSEN,(
char*)(colname.c_str())
726 check_status(status,
"Column does not exist.");
731 std::vector<std::string> get_colnames(){
return col_names;}
733 int read_column(std::string &colname,std::vector<float> &vecf){
735 int col, status=0,anyval=0;
736 col = column_index(colname);
738 if(vecf.size() < Nrow ) vecf.resize(Nrow);
740 fits_read_col_flt(fptr, col, 1, 1,Nrow,0,
741 vecf.data(),&anyval, &status);
745 int read_column(std::string &colname,
long firstsrow,
long nelements,std::vector<float> &vecf,
float nulval = -100){
747 int status=0,anyval=0;
748 int colnum = column_index(colname);
750 if(vecf.size() < nelements ) vecf.resize(nelements);
751 fits_read_col(fptr,TFLOAT,colnum, firstsrow, 1,nelements,&nulval,
752 vecf.data(),&anyval, &status);
753 check_status(status);
757 int read_column(
int colnum,
long firstsrow,
long nelements,std::vector<float> &vecf,
float nulval = -100){
759 int status=0,anyval=0;
761 if(vecf.size() < nelements ) vecf.resize(nelements);
763 fits_read_col(fptr,TFLOAT,colnum, firstsrow, 1,nelements,&nulval,
764 vecf.data(), &anyval, &status);
766 check_status(status);
771 int read_column(std::string &colname,
long firstsrow,
long nelements,std::vector<double> &vecf,
double nulval = -100){
773 int status=0,anyval=0;
774 int colnum = column_index(colname);
776 if(vecf.size() < nelements ) vecf.resize(nelements);
777 fits_read_col(fptr,TDOUBLE,colnum, firstsrow, 1,nelements,&nulval,
778 vecf.data(),&anyval, &status);
779 check_status(status);
783 int read_column(
int colnum,
long firstsrow,
long nelements,std::vector<double> &vecf,
double nulval = -100){
785 int status=0,anyval=0;
787 if(vecf.size() < nelements ) vecf.resize(nelements);
788 fits_read_col(fptr,TDOUBLE,colnum, firstsrow, 1,nelements,&nulval,
789 vecf.data(),&anyval, &status);
790 check_status(status);
794 int read_column(std::string &colname,
long firstsrow,
long nelements,std::vector<long> &vecf,
int nulval = -100){
796 int status=0,anyval=0;
797 int colnum = column_index(colname);
799 if(vecf.size() < nelements ) vecf.resize(nelements);
800 fits_read_col(fptr,TLONG,colnum, firstsrow, 1,nelements,&nulval,
801 vecf.data(),&anyval, &status);
802 check_status(status);
806 int read_column(
int colnum,
long firstsrow,
long nelements,std::vector<long> &vecf,
int nulval = -100){
808 int status=0,anyval=0;
810 if(vecf.size() < nelements ) vecf.resize(nelements);
811 fits_read_col(fptr,TLONG,colnum, firstsrow, 1,nelements,&nulval,
812 vecf.data(),&anyval, &status);
813 check_status(status);
821 int typecode,status=0;
823 fits_get_coltype(fptr,colnum,&typecode,
824 &repeat,&width,&status);
825 check_status(status);
830 int read_column(
int column_index,std::vector<float> &vecf){
832 int status=0,anyval=0;
834 if(column_index < 1){
835 std::cerr <<
"CPFITS: column number must be > 0" << std::endl;
836 throw std::invalid_argument(
"Error in CPFITS");
838 if(column_index > Ncol){
839 std::cerr <<
"CPFITS: there are only " << Ncol <<
" columns." << std::endl;
840 throw std::invalid_argument(
"Error in CPFITS");
842 if(vecf.size() < Nrow ) vecf.resize(Nrow);
844 fits_read_col_flt(fptr, column_index, 1, 1,Nrow,0,
845 vecf.data(),&anyval, &status);
851 template <
typename T>
852 void read(std::vector<T> data,
int ncol){
854 int status = 0,anyval=0;
855 long i, n, nread, ntodo, nrest;
856 long buffer_size = 20000;
857 std::vector<float> fitscol(buffer_size);
859 for(
int col = 1 ; col != ncol ; ++col){
864 ntodo = (nrest < buffer_size) ? nrest : buffer_size;
865 fits_read_col_flt(fptr, col, nread + 1, 1, ntodo, 0,
866 fitscol.data(),&anyval, &status);
867 for (i = 0; i < ntodo; i++) data[i + nread][col-1] = fitscol[i];
880 template<
typename T>
884 std::map<std::string,int> datamap;
885 std::vector<std::string> all_column_names;
886 std::vector<std::string> used_column_names;
887 std::string filename;
889 std::vector<std::vector<T> > data;
891 std::vector<int> column_index;
897 ,std::vector<std::string> &columns
899 ,
bool verbose =
false
900 ):filename(datafile),cpfits(filename,hdu,verbose),n0(1){
902 all_column_names = cpfits.get_colnames();
904 if(columns.size() == 0){
905 used_column_names = all_column_names;
907 used_column_names = columns;
910 std::cout <<
"Reading " << used_column_names.size() <<
" columns." << std::endl;
912 for(std::string a : used_column_names){
913 column_index.push_back(cpfits.column_index(a));
916 for(
int i=0 ; i<used_column_names.size() ; ++i){
917 datamap[used_column_names[i]] = i;
920 data.resize(column_index.size());
924 std::vector<std::string> get_all_columnnames(){
return all_column_names;}
925 std::vector<std::string> get_used_columnnames(){
return all_column_names;}
930 int ncol=data.size();
931 for(
int i=0; i<ncol ; ++i){
943 std::vector<std::function<
bool(T &)> > &accept
947 long chunksize = 10000;
948 int ncol = column_index.size();
949 long nrow = cpfits.rows();
950 int requirements = accept.size();
955 for(
int i=0; i<ncol ; ++i){
960 if(maxsize > 0) nrow = MIN(maxsize + n0,nrow);
962 if(requirements > ncol){
963 throw std::invalid_argument(
"Too many requirments");
966 std::vector<std::vector<T> > tdata(ncol);
968 chunksize = MIN(nrow-n0+1,chunksize);
970 if(data[0].capacity() - data[0].size() < chunksize ){
971 for(
int i=0; i<ncol ; ++i){
972 data[i].reserve(chunksize + data[i].capacity());
976 for(
int i=0 ; i< ncol ; ++i){
977 cpfits.read_column(column_index[i],n0,chunksize,tdata[i]);
981 for(
long j = 0 ; j < chunksize ; ++j){
983 for(
int i=0; i<requirements; ++i){
984 accpt *= accept[i](tdata[i][j]);
988 for(
int i=0; i<ncol ; ++i){
989 data[i].push_back( tdata[i][j] ) ;
1000 std::function<
bool(T,T)> &binary_accept
1001 ,std::pair<int,int> index_binary
1002 ,std::vector<std::function<
bool(T &)> > &unary_accept
1003 ,std::vector<int> index_unary
1007 long chunksize = 10000;
1008 int ncol = column_index.size();
1009 long nrow = cpfits.rows();
1011 if(unary_accept.size() != index_unary.size() )
throw std::invalid_argument(
"index_unary wrong sized ");
1016 for(
int i=0; i<ncol ; ++i){
1021 if(maxsize > 0) nrow = MIN(maxsize + n0,nrow);
1023 if(index_unary.size() > ncol){
1024 throw std::invalid_argument(
"Too many requirments");
1027 std::vector<std::vector<T> > tdata(ncol);
1029 chunksize = MIN(nrow-n0+1,chunksize);
1031 if(data[0].capacity() - data[0].size() < chunksize ){
1032 for(
int i=0; i<ncol ; ++i){
1033 data[i].reserve(chunksize + data[i].capacity());
1037 for(
int i=0 ; i< ncol ; ++i){
1038 cpfits.read_column(column_index[i],n0,chunksize,tdata[i]);
1042 for(
long j = 0 ; j < chunksize ; ++j){
1044 bool accpt = binary_accept(tdata[index_binary.first][j],tdata[index_binary.second][j] );
1047 for(
int i : index_unary){
1048 accpt *= unary_accept[k++]( tdata[i][j] );
1052 for(
int i=0; i<ncol ; ++i){
1053 data[i].push_back( tdata[i][j] ) ;
1064 int read(
long maxsize=-1){
1065 int ncol = column_index.size();
1066 long nrow = cpfits.rows();
1067 if(maxsize==-1) maxsize = nrow;
1069 long chunksize = nrow-n0+1;
1071 chunksize = (maxsize < chunksize) ? maxsize : chunksize;
1073 for(
int i=0 ; i< ncol ; ++i){
1074 cpfits.read_column(column_index[i],n0,chunksize,data[i]);
1082 std::vector<std::vector<T> > ranges(
bool verbose){
1083 std::vector<std::vector<T> > ranges;
1084 int ncol = column_index.size();
1085 long nrow = cpfits.rows();
1086 long chunksize = 100000;
1088 ranges.resize(ncol);
1089 for(
auto &v : ranges) v.resize(2);
1091 std::vector<T> tdata;
1092 for(
int i=0 ; i< ncol ; ++i){
1093 cpfits.read_column(column_index[i],1,1,tdata);
1105 chunksize = (nrow-n+1 < chunksize) ? nrow-n+1 : chunksize;
1108 for(
int i=0 ; i< ncol ; ++i){
1109 cpfits.read_column(column_index[i],n,chunksize,tdata);
1111 ranges[i][0] = MIN(a,ranges[i][0]);
1112 ranges[i][1] = MAX(a,ranges[i][1]);
1119 for(
int i=0 ; i< ncol ; ++i){
1120 std::cout << ranges[i][0] <<
" <= " << used_column_names[i] <<
" <= " << ranges[i][1] << std::endl;
1128 std::vector<T>& operator[](
const std::string &label){
1129 if(datamap.find(label) == datamap.end()){
1130 std::cerr <<
"No label - " << label <<
" - in " << filename <<std::endl;
1131 throw std::invalid_argument(
"no label");
1133 return data[datamap[label]];
1134 for(
auto c : all_column_names ) std::cout << c <<
" ";
1135 std::cout << std::endl;
1136 throw std::invalid_argument(label +
" was not one of the columns of the galaxy data file :" + filename);
1140 std::vector<T>& operator[](
int i){
1145 void sortby(std::string name){
1146 std::vector<size_t> index(data[0].size());
1147 size_t N = index.size();
1148 for(
size_t i=0 ; i<N ; ++i) index[i] = i;
1151 std::vector<T> tmp_v(N);
1153 for(
size_t j=0 ; j<data.size() ; ++j){
1154 for(
size_t i=0 ; i<N ; ++i){
1155 tmp_v[i] = data[j][index[i]];
1157 swap(data[j],tmp_v);
1162 void addColumn(std::string name){
1163 int nc = number_of_columns();
1164 long nr = number_of_rows();
1165 data.emplace_back(nr);
1166 all_column_names.push_back(name);
1167 used_column_names.push_back(name);
1172 size_t number_of_rows(){
return data[0].size();}
1173 size_t number_of_columns(){
return data.size();}
read only fits file interface
Definition cpfits.h:636
int gettype(int colnum)
get data type of column
Definition cpfits.h:820
read only fits file interface
Definition cpfits.h:232
int read(std::vector< double > &output, std::vector< long > &size)
read the whole image into a vector
Definition cpfits.h:290
int read_subset(float *output, long *lowerleft, long *upperright)
read a rectangular subset of the image
Definition cpfits.h:398
int read_subset(double *output, long *lowerleft, long *upperright)
read a rectangular subset of the image
Definition cpfits.h:390
int read(std::valarray< float > &output, std::vector< long > &size)
read the whole image into a valarray
Definition cpfits.h:320
int read(std::vector< float > &output, std::vector< long > &size)
read the whole image into a vector
Definition cpfits.h:305
int read(std::vector< std::vector< T > > &output)
read the whole image into a vector
Definition cpfits.h:356
void reset(std::string filename, std::string extension="")
close old and reopen a new file
Definition cpfits.h:273
int read_block(double *output, long nelements, long *start)
read the whole image into a vector
Definition cpfits.h:375
void sort_indexes(const std::vector< T > &v, std::vector< size_t > &index)
Find the indexes that sort a vector in asending order.
Definition utilities_slsim.h:1171