Thursday, April 12, 2018

Spring season KStars v2.9.4 is Released!

Glad to announce the release of KStars v2.9.4 aka Emad is now release for Windows, MacOS, and Linux!

The new release brings in more performance improvements and bug fixes.

Spring Galaxy Season
Credit Turki AlAmri

Valentin Boettcher
introduced a highly efficient binary interface for asteroids that would allow quite large (> 100MB) and distant catalogs to be loaded into KStars without a major impact on performance. Before this change, loading any JPL catalogs for faint asteroids (> 15 mag) resulted in significant slowdown of KStars during startup as well as during run-time. Now users can comfortably load fainter asteroids given they have enough system memory to handle it.

Automatic Flat field calculations were fixed for multi-channel DSLR frames along with an improved DSLR popup dialog. The online astrometry option with offline server bug was fixed and now users can connect to local instances of without any problems.

The Ekos scheduler workflow was revamped to evaluate all jobs every time a new job is invoked to ensure all scores are updated accordingly and not only on the first job run. More SEP work for star & galaxy detection is merged into the internal guide module resulting in a better object detection even in noisy environments.
Messier Marathon with Ekos Scheduler

Furthermore, the guide module is now a lot more tolerant to passing clouds. When a star lock is lost, it will attempt to reacquire the lost star for several iterations before giving up.

On the capture frontend, users can now instruct Ekos to take flat field frames exactly at the same focus position where light frames of the same filter were captured. For example, suppose you are taking an LRGB sequence, and the best autofocus position for Green filter is 37,000 ticks. By the time you finish the sequence the focus position would most likely have moved due to the Blue filter (unless they're perfectly parafocal). Once you start capturing flat fields afterwards, typically the focus position is kept as-is. However, now it is possible to synchronize the focus position when capturing flat fields as well. When a flat field Green capture is requested, Ekos shall instruct the focuser to move to 37,000 ticks as indicated by the last successful autofocus operation of the same filter.

Finally, users might have noticed especially on slower systems that opening large FITS files can take a while to load up. In v2.9.4, the FITS handling code was optimized with loading times improving on the order of 300%.

FITS Speed improvements

Turns out that statistics calculations were eating up significant amount of precious CPU cycles. Many of these calculations would greatly benefit from SIMD support like SSE/NEON but since KStars runs on multiple architectures, it requires an architecture-agnostic solution and major refactoring of the code base. Another solution that was more readily available is to employ multiple threads to by partitioning the image and therefore spreading the calculations. It is certainly a poor-man's SIMD in a way, but the results were immediately noticeable.

Using 16 threads, computing min and max values was reduced from 122ms to only 30ms. Running mean and standard deviation calculations took 118ms instead of 270ms. Here is an excerpt from the Qt Concurrent magic that made this signifantly easier to code than using plain pthreads.

QList<QFuture<QPair<double,double>>> futures;

for (int i=0; i < nThreads; i++)
 // Run threads
 futures.append(QtConcurrent::run(this, &FITSData::getSquaredSumAndMean<T>, tStart, (i == (nThreads-1)) ? fStride : tStride));
 tStart += tStride;

double mean=0, squared_sum=0;

// Now wait for results
for (int i=0; i < nThreads; i++)
 QPair<double,double> result = futures[i].result();
 mean += result.first;
 squared_sum += result.second;

double variance = squared_sum / stats.samples_per_channel;

stats.mean[n] = mean/nThreads;
stats.stddev[n] = sqrt(variance);

There is room for more improvement still, especially since now we are loading the FITS twice unnecessarily. This could be resolved by using an implicit sharing data model among FITS files that does not require a deep-copy of the data until the underlying data is altered. This could result in a 100% improvement in loading speeds when using Ekos as well. Stay tuned!

No comments: