Author Topic: StarAlignment: Translation Vectors Table  (Read 3443 times)

Offline afortunato

  • Newcomer
  • Posts: 4
StarAlignment: Translation Vectors Table
« on: 2014 May 23 23:59:39 »
Good morning!

As this is my first post on the PI forum, I would like first of all to congratulate the team on the wonderful work done with this software.
I have been struggling for years to find something that was powerful and flexible and, moreover, worked well on Mac OS X.

I am happy to report that my quest in that specific area is over... ;-)

Now, to the topic of the conversation...

I want to analyse the image to image drift of a set of pictures in an integration stack (to get a feeling of the polar misalignment and periodic error).
The idea was to export the components of the translation vector (dx, dy) as they are calculated by the StarAlignment routine.

I can see such components in the output of the console but, in order to avoid manually copying and pasting, I was wondering whether a summary table could be generated.
What I need is something very simple like: [Time of acquisition], [dx], [dy]. Any idea whether this table could be automatically generated?

Thanks!   

Offline bitli

  • PTeam Member
  • PixInsight Guru
  • ****
  • Posts: 513
Re: StarAlignment: Translation Vectors Table
« Reply #1 on: 2014 May 24 09:19:45 »
The star alignment is fortunately one of the few processes making its result available in the form of properties. Even better: they are documented.  However the only way to access the results is via a script as far as I know (maybe some process is already using them and saving them somewhere ?).

Here is a simple script that execute a process icon named 'sa' (you must create it on the desktop first) and creates a file named 'sa.csv' in the output directory with all the information provided by the process.  Look at the documentation for details.  Making the name of the process and output file selectable is left as an exercise for the reader  ;)

Including other information like the time of imaging would need to access the FITS keys. This requires some more coding - i may do it one day if it is raining. You can also save them using the script FITSKeys, I think.

I have just made minimal tests with this script, so check that it provides what you need.

Code: [Select]
"use strict";

// ExecuteSA.js
// Execute a StarAlignment and save the results in a CVS file
// The name of the process

var PROCESS_NAME = "sa";
var CSV_FILE_NAME = "sa.csv";
// In some locale the separator could be different as the comma is used as decimal point
var CSV_SEPARATOR = ",";

// To check the type of the process icon
var PROCESS_TYPE = "StarAlignment";

// The list of items according to the documentation
var COL_NAMES= ["outputImage","outputMask","pairMatches","inliers","overlapping","regularity","quality","rmsError","rmsErrorAvgDev","peakErrorX","peakErrorY",
                "H11","H12","H13","H21","H22","H23","H31","H32","H33","frameAdaptationBiasRK","frameAdaptationBiasG","frameAdaptationBiasB","frameAdaptationSlopeRK",
                "frameAdaptationSlopeG","frameAdaptationSlopeB","frameAdaptationAvgDevRK","frameAdaptationAvgDevG","frameAdaptationAvgDevB"];


function writeCsvLine(csvFile, data) {
   for (var colIndex=0; colIndex<data.length; colIndex++) {
      if (colIndex>0) {
         csvFile.outText(CSV_SEPARATOR);
      }
      var value = data[colIndex];
      if ("string" === typeof value) {
         // Assume that there is no character to escape, adapt if needed
         csvFile.outText("\""+ value + "\"");
      } else {
         csvFile.outText(value.toString());
      }
   }
   csvFile.outTextLn("");
}

// ----------------------------------------------------------------------------
function main() {
   var sa = ProcessInstance.fromIcon(PROCESS_NAME);
   if (sa === null) {
      Console.writeln("Process Icon '" + PROCESS_NAME + "' no found - exit.");
      return;
   }
   if (sa.processId() !== PROCESS_TYPE) {
      Console.writeln("Process Icon '" + PROCESS_NAME + "' not a '" + PROCESS_TYPE +"' but a '" + sa.processId() +"' - exit.");
      return;
   }

   // Create file at the beginning to make sure it is writeable
   Console.writeln("Creating file '" + CSV_FILE_NAME + "' in '" + sa.outputDirectory + "'");
   var csvFile = new File();
   csvFile.openOrCreate(sa.outputDirectory  + "/" + CSV_FILE_NAME);
   try {
     
      // Write header
      //Console.writeln("header: " + COL_NAMES);
      writeCsvLine(csvFile,COL_NAMES);


     Console.writeln("Execting process '" + PROCESS_NAME + "' globally.");
     Console.writeln("-------------------------------------------------");
     var result = sa.executeGlobal();
     Console.writeln("-------------------------------------------------");
     Console.writeln("Process '" + PROCESS_NAME + "' executed, status = " + result);
     
     if (result) {
        var outputData = sa.outputData;
        Console.writeln(outputData.length + " images processed");
         
        // Write each image
        for (var imageIndex=0; imageIndex<outputData.length; imageIndex++) {
           var imageData = outputData[imageIndex];
           // Console.writeln(imageIndex + ": " + imageData);
           writeCsvLine(csvFile, imageData);
        }
        Console.writeln("File '" + CSV_FILE_NAME + "' created in '" + sa.outputDirectory + "'");
     } else {
        Console.writeln("Process failed, no data in output file");
     }
     
  } finally {
     csvFile.close();
  }
 
}



main();

-- bitli

Offline afortunato

  • Newcomer
  • Posts: 4
Re: StarAlignment: Translation Vectors Table
« Reply #2 on: 2014 May 24 16:11:51 »
Thank you very much! I will give it a shot and post the results! :-)

Offline georg.viehoever

  • PTeam Member
  • PixInsight Jedi Master
  • ******
  • Posts: 2132
Re: StarAlignment: Translation Vectors Table
« Reply #3 on: 2014 May 26 09:56:32 »
An alternative to Bitli's script: When aligning images, PI stores the transformation matrix as FITS keywords ALIGNHxy. If you dont have much rotation and scaling, ALIGNH13 and ALIGNH23 are translation dx and dy. You get those keys into a txt file, you can use the FITS Keywords script that comes with PI (ignore the error messages you see on the console, it is an "old" script.)

If you have a lot of rotation and scaling, you need to do further decoding of the matrix.
Georg
Georg (6 inch Newton, unmodified Canon EOS40D+80D, unguided EQ5 mount)