// Mark III - interrogate camera for exposure limits // verify exposure time stability import java.lang.Math; double EvaluateImageTiming(Float etime, Float[] deviations) { // measure average shutter time // calculate the standard deviation & mean long nPts = 0; double mean_ = 0; double M2 = 0; double delta; long value; Long boxValue = new Long(0); String valueList = new String(""); mmc.setExposure( etime); for( int titter =0; titter<12; ++ titter){ value = System.currentTimeMillis(); mmc.snapImage(); value = System.currentTimeMillis() - value; boxValue = value; if( 0 < valueList.length()) valueList += ", "; valueList += boxValue.toString(); // one-pass algorithm for mean and std from Welford / Knuth ++nPts; delta = value - mean_; mean_ = mean_ + delta/nPts; M2 = M2 + delta*(value - mean_); // #This expression uses the new value of mean_ img = mmc.getImage(); gui.displayImage(img); } double variance = M2/(nPts - 1); double meanScaling = 1.; // autobox only the final results !! Float standardDeviation = new Float(java.lang.Math.pow(variance,0.5)); Double theMean = new Double(mean_); print(etime.toString() + " durations: {" + valueList+ "} : " + theMean.toString()+ " std: " + standardDeviation.toString() ); deviations[0] = (Float)standardDeviation; return mean_; }; int warnings = 0; int errors = 0; String theCamera = new String(mmc.getCameraDevice()); Double minExposure = new Double(0.); Double maxExposure = new Double(3600000.); if (mmc.hasProperty(theCamera,"Exposure")){ if( mmc.hasPropertyLimits(theCamera,"Exposure") ){ minExposure = mmc.getPropertyLowerLimit(theCamera,"Exposure"); maxExposure = mmc.getPropertyUpperLimit(theCamera,"Exposure"); } }; print ("current camera is " + theCamera + " current exposure range is [" + minExposure.toString() +"," + maxExposure.toString() + "]" ); for( int ite = 0; ite <2; ++ite){ mmc.setAutoShutter((1==ite)); Float [] stdevs0 = new Float[1]; Float [] stdevs1 = new Float[1]; Float [] stdevs2 = new Float[1]; print("running with autoshutter " + (1==ite?"on":"off" )); Double st1 = new Double(0); Double st2 = new Double(0); mmc.setExposure(minExposure); exptime = mmc.getExposure(); // measure the shortest snap time on this equipment mmc.snapImage(); ro0 = System.currentTimeMillis(); mmc.getImage(); ro0 = System.currentTimeMillis() - ro0; // always include the minimum exposure time! Boolean ranMinExposureTime = false; Double loopexptime = new Double(0); for( loopexptime = 0; loopexptime < 1000; loopexptime*=10) { exptime = loopexptime; if( maxExposure < exptime) break; if(ranMinExposureTime && exptime < minExposure) { continue; } ranMinExposureTime =(exptime < minExposure); exptime = java.lang.Math.max(exptime,minExposure); EvaluateImageTiming(exptime, stdevs0); if( 0 == loopexptime) loopexptime = 0.01; } }; print("test completed"); print("total warnings "); print(warnings); print("total errors "); print(errors);