ImagePtr Calibrator::operator()(const ImagePtr image) const { unsigned int floatlimit = std::numeric_limits<float>::digits; // find the appropriate frame to use for the correction images ImageRectangle frame; if (rectangle == ImageRectangle()) { frame = ImageRectangle(ImagePoint(), image->size()); } // use pixel size to decide which type to use for the result image if (image->bitsPerPixel() <= floatlimit) { // create adapters for darks and flats with float values ConstPixelValueAdapter<float> pvdark(dark); WindowAdapter<float> wdark(pvdark, frame); ConstPixelValueAdapter<float> pvflat(flat); WindowAdapter<float> wflat(pvflat, frame); TypedCalibrator<float> calibrator(wdark, wflat); return calibrator(image); } ConstPixelValueAdapter<double> pvdark(dark); WindowAdapter<double> wdark(pvdark, frame); ConstPixelValueAdapter<double> pvflat(flat); WindowAdapter<double> wflat(pvflat, frame); TypedCalibrator<double> calibrator(wdark, wflat); return calibrator(image); }
////////////////////////////////////////////////////////////////////// // Interpolator implementation ////////////////////////////////////////////////////////////////////// Interpolator::Interpolator(const ImagePtr& _dark, const ImageRectangle _frame) : dark(_dark), frame(_frame) { floatdark = dynamic_cast<Image<float> *>(&*dark); doubledark = dynamic_cast<Image<double> *>(&*dark); if ((NULL == floatdark) && (NULL == doubledark)) { throw std::runtime_error("only float or double images are " "suitable as darks"); } if (_frame == ImageRectangle()) { frame = _dark->getFrame(); } }
int main(int argc, char *argv[]) { // parse command line arguments int c; while (EOF != (c = getopt(argc, argv, "d"))) switch (c) { case 'd': debuglevel = LOG_DEBUG; break; } // create a camera instance SimCamera camera; CcdPtr ccd = camera.getCcd(0); GuiderPortPtr guiderport = camera.getGuiderPort(); // we will always use 1 sec exposures Exposure exposure(ImageRectangle(ImagePoint(160,120), ImageSize(320, 240)), 1); // make 10 images 1 second appart (should give small drift) counter = 0; while (counter < 10) { ccd->startExposure(exposure); ImagePtr image = ccd->getImage(); writeimage(image); } // now move for 5 seconds guiderport->activate(5, 0, 0, 0); sleep(5); ccd->startExposure(exposure); writeimage(ccd->getImage()); guiderport->activate(0, 5, 0, 0); sleep(5); ccd->startExposure(exposure); writeimage(ccd->getImage()); guiderport->activate(0, 0, 5, 0); sleep(5); ccd->startExposure(exposure); writeimage(ccd->getImage()); guiderport->activate(0, 0, 0, 5); sleep(5); ccd->startExposure(exposure); writeimage(ccd->getImage()); return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { debugthreads = 1; Exposure exposure; unsigned int nImages = 1; std::string reponame; std::string filtername; int c; int longindex; double temperature = std::numeric_limits<double>::quiet_NaN(); while (EOF != (c = getopt_long(argc, argv, "b:c:de:f:hn:p:r:t:?", longopts, &longindex))) switch (c) { case 'b': exposure.mode(Binning(optarg)); break; case 'c': Configuration::set_default(optarg); break; case 'd': debuglevel = LOG_DEBUG; break; case 'e': exposure.exposuretime(atof(optarg)); break; case 'f': filtername = std::string(optarg); break; case 'h': case '?': usage(argv[0]); return EXIT_SUCCESS; case 'n': nImages = atoi(optarg); break; case 'p': exposure.purpose(Exposure::string2purpose(optarg)); break; case 'r': reponame = std::string(optarg); break; case 't': temperature = atof(optarg); break; case 1: exposure.frame(ImageRectangle(optarg)); break; default: throw std::runtime_error("unknown option"); } // next argument must be instrument name or help if (optind >= argc) { std::cerr << "missing instrument name" << std::endl; return EXIT_FAILURE; } std::string instrumentname(argv[optind++]); // get the configuration ConfigurationPtr config = Configuration::get(); // backend for instruments InstrumentBackend instrumentbackend(config->database()); InstrumentPtr instrument = instrumentbackend.get(instrumentname); // get the image repository ImageRepoPtr repo(NULL); if (reponame.size() > 0) { ImageRepoConfigurationPtr imagerepos = ImageRepoConfiguration::get(config); repo = imagerepos->repo(reponame); } // prepare a repository from which we can extract the devices Repository repository; Devices devices(repository); // get the devices CameraPtr camera = devices.getCamera(instrument->getCamera(0).deviceurl()); CcdPtr ccd = devices.getCcd(instrument->getCcd(0).deviceurl()); // If temperature is set, and a cooler is present, initialize the // cooler and wait until temperature is reached CoolerPtr cooler(NULL); if ((temperature == temperature) && (instrument->hasCooler())) { double absolute = 273.15 + temperature; if (absolute < 0) { std::string msg = stringprintf("illegal temperature: %f", temperature); debug(LOG_ERR, DEBUG_LOG, 0, "%s", msg.c_str()); throw std::runtime_error(msg); } cooler = devices.getCooler(instrument->getCooler(0).deviceurl()); cooler->setTemperature(absolute); cooler->setOn(true); double delta; do { double actual = cooler->getActualTemperature(); delta = fabs(absolute - actual); debug(LOG_DEBUG, DEBUG_LOG, 0, "set: %.1f, actual: %.1f, delta: %.1f", absolute, actual, delta); } while (delta > 1); } // if the instrument has a filter wheel, we get a pointer to it // and try FilterWheelPtr filterwheel(NULL); if (instrument->hasFilterWheel()) { filterwheel = devices.getFilterWheel( instrument->getFilterWheel(0).deviceurl()); filterwheel->wait(20); if (filtername.size() > 0) { filterwheel->select(filtername); filterwheel->wait(20); } } // start the stream unsigned int imagesRetrieved = 0; ccd->startStream(exposure); while (imagesRetrieved < nImages) { ImagePtr image = ccd->getEntry(true).image; debug(LOG_DEBUG, DEBUG_LOG, 0, "got image[%u] %s", ++imagesRetrieved, image->size().toString().c_str()); if (!image->hasMetadata(std::string("INSTRUME"))) { image->setMetadata(FITSKeywords::meta( std::string("INSTRUME"), instrument->name())); } // do something about the image if (repo) { repo->save(image); } } // stop the stream ccd->stopStream(); // find out how many images were dropped if (ccd->dropped() > 0) { std::cerr << "images dropped: " << ccd->dropped() << std::endl; } // turn off the cooler if (cooler) { cooler->setOn(false); } return EXIT_SUCCESS; }
ImageRectangle operator/(const ImageRectangle& rect, const Binning& binning) { return ImageRectangle(rect.origin() / binning, rect.size() / binning); }
void ImageRectangleTest::testConstructor() { debug(LOG_DEBUG, DEBUG_LOG, 0, "testEquality() begin"); CPPUNIT_ASSERT(*r3 == ImageRectangle(ImageSize(640, 480))); debug(LOG_DEBUG, DEBUG_LOG, 0, "testEquality() end"); }