void StarCatalog::write() const { std::vector<std::string> files = MakeMultiName(_params, "stars"); const int nfiles = files.size(); for(int i=0; i<nfiles; ++i) { const std::string& file = files[i]; dbg<<"Writing star catalog to file: "<<file<<std::endl; bool isFitsIo = false; if (_params.keyExists("stars_io")) { std::vector<std::string> ios = _params["stars_io"]; Assert(ios.size() == files.size()); isFitsIo = (ios[i] == "FITS"); } else if (file.find("fits") != std::string::npos) { isFitsIo = true; } try { if (isFitsIo) { writeFits(file); } else { std::string delim = " "; if (_params.keyExists("stars_delim")) { std::vector<std::string> delims = _params["stars_delim"]; Assert(delims.size() == files.size()); delim = delims[i]; } else if (file.find("csv") != std::string::npos) { delim = ","; } writeAscii(file,delim); } } catch (CCfits::FitsException& e) { xdbg<<"Caught FitsException: \n"<<e.message()<<std::endl; throw WriteException( "Error writing to "+file+" -- caught error\n" + e.message()); } catch (std::exception& e) { xdbg<<"Caught std::exception: \n"<<e.what()<<std::endl; throw WriteException( "Error writing to "+file+" -- caught error\n" + e.what()); } catch (...) { xdbg<<"Caught unknown exception"<<std::endl; throw WriteException( "Error writing to "+file+" -- caught unknown error"); } } dbg<<"Done Write StarCatalog\n"; }
void StarCatalog::writeAscii(std::string file, std::string delim) const { Assert(int(_id.size()) == size()); Assert(int(_pos.size()) == size()); Assert(int(_sky.size()) == size()); Assert(int(_noise.size()) == size()); Assert(int(_flags.size()) == size()); Assert(int(_mag.size()) == size()); Assert(int(_sg.size()) == size()); Assert(int(_objsize.size()) == size()); Assert(int(_is_star.size()) == size()); std::ofstream fout(file.c_str()); if (!fout) { throw WriteException("Error opening stars file"+file); } Form sci8; sci8.sci().trail(0).prec(8); Form fix3; fix3.fix().trail(0).prec(3); Form fix6; fix6.fix().trail(0).prec(6); const int ntot = size(); for (int i=0; i<ntot; ++i) { fout << _id[i] << delim << fix3(_pos[i].getX()) << delim << fix3(_pos[i].getY()) << delim << fix3(_sky[i]) << delim << sci8(_noise[i]) << delim << _flags[i] << delim << fix3(_mag[i]) << delim << fix3(_sg[i]) << delim << fix6(_objsize[i]) << delim << _is_star[i] << delim << std::endl; } }
void PsfCatalog::writeAscii(std::string file, std::string delim) const { Assert(int(_id.size()) == size()); Assert(int(_pos.size()) == size()); Assert(int(_sky.size()) == size()); Assert(int(_noise.size()) == size()); Assert(int(_flags.size()) == size()); Assert(int(_nu.size()) == size()); Assert(int(_psf.size()) == size()); const int npsf = size(); std::ofstream fout(file.c_str()); if (!fout) { throw WriteException("Error opening psf file"+file); } Form sci8; sci8.sci().trail(0).prec(8); Form fix3; fix3.fix().trail(0).prec(3); Form fix6; fix6.fix().trail(0).prec(3); for(int i=0;i<npsf;++i) { fout << _id[i] << delim << fix3(_pos[i].getX()) << delim << fix3(_pos[i].getY()) << delim << fix3(_sky[i]) << delim << sci8(_noise[i]) << delim << _flags[i] << delim << fix3(_nu[i]) << delim << _psf[i].getOrder() << delim << fix6(_psf[i].getSigma()); const int ncoeff = _psf[i].size(); for(int j=0;j<ncoeff;++j) { fout << delim << sci8(_psf[i](j)); } fout << std::endl; } }
/** * Writes the specified number of bytes from buffer uint32_to memory. * If all of the bytes could not be written, a WriteException is thrown. * * @param address The starting address to write to. * @param buffer The source buffer to write from. * @param size The number of bytes to write. */ void Write(uint32_t address, const void* buffer, size_t size) { StackTrace trace(__METHOD__, __FILE__, __LINE__); if (process_write(_handle, address, buffer, size) == false) { throw WriteException(); } }
void ShearCatalog::writeAscii(std::string file, std::string delim) const { Assert(int(_id.size()) == size()); Assert(int(_pos.size()) == size()); Assert(int(_sky.size()) == size()); Assert(int(_noise.size()) == size()); Assert(int(_flags.size()) == size()); Assert(int(_skypos.size()) == size()); Assert(int(_shear.size()) == size()); Assert(int(_nu.size()) == size()); Assert(int(_cov.size()) == size()); Assert(int(_meas_galorder.size()) == size()); Assert(int(_shape.size()) == size()); std::ofstream fout(file.c_str()); if (!fout) { throw WriteException("Error opening shear file"+file); } bool output_psf = _params.read("shear_output_psf",false); Form sci8; sci8.sci().trail(0).prec(8); Form fix3; fix3.fix().trail(0).prec(3); Form fix8; fix8.fix().trail(0).prec(8); Form fix6; fix6.fix().trail(0).prec(6); const int ngals = size(); for(int i=0;i<ngals;++i) { fout << _id[i] << delim << fix3(_pos[i].getX()) << delim << fix3(_pos[i].getY()) << delim << fix3(_sky[i]) << delim << sci8(_noise[i]) << delim << _flags[i] << delim << fix8(_skypos[i].getX()/3600.) << delim << fix8(_skypos[i].getY()/3600.) << delim << sci8(real(_shear[i])) << delim << sci8(imag(_shear[i])) << delim << fix3(_nu[i]) << delim << sci8(_cov[i](0,0)) << delim << sci8(_cov[i](0,1)) << delim << sci8(_cov[i](1,1)) << delim //<< _shape[i].getOrder() << delim << _meas_galorder[i] << delim << fix6(_shape[i].getSigma()); const int ncoeff = _shape[i].size(); for(int j=0;j<ncoeff;++j) fout << delim << sci8(_shape[i](j)); if (output_psf) { Assert(_fitpsf); BVec interp_psf(_fitpsf->getPsfOrder(),_fitpsf->getSigma()); interp_psf = (*_fitpsf)(_pos[i]); fout << delim << interp_psf.getOrder() << delim << fix6(interp_psf.getSigma()); const int npsf_coeff = interp_psf.size(); for(int j=0;j<npsf_coeff;++j) fout << delim << sci8(interp_psf(j)); } fout << std::endl; } }