PixInsight Forum (historical)

Software Development => PCL and PJSR Development => Topic started by: mstriebeck on 2017 August 01 11:46:16

Title: Running PixInsight processes from other apps
Post by: mstriebeck on 2017 August 01 11:46:16
Hi,

I want to use Pixinsight from another app.

More concretely: I want to write an program that optimizes the parameters in ImageIntegration (rejection algorithm, rejection parameters...) by running ImageIntegration inside an optimization loop. And once I have that, parallelize this and then use MANY examples (hope to get examples from others for this) to develop and train a model that gives recommendations.

The first step would just be to run ImageIntegration, providing images and parameter values and capturing the output.

Is this possible? Are there any examples out there?

Thanks
     Mark
Title: Re: Running PixInsight processes from other apps
Post by: Niall Saunders on 2017 August 01 15:55:06
Hi Mark,

Have you considered implementing your optimisation routine(s) from within PixInsight itself?

There are means made available to you to both as JavaScript and as external code (I know a little of the former, and virtually nothing of the latter  :( - however, please feel free to look at my fully documented Batch CMYG DeBayer Script if you feel that JavaScript may give you all the resources that you need).

Hope this helps.
Title: Re: Running PixInsight processes from other apps
Post by: Niall Saunders on 2017 August 01 15:59:13
Hi again Mark,

I did a quick Forum Search and came across this thread - which may also be helpful for you:

https://pixinsight.com/forum/index.php?topic=10441.msg65601#msg65601 (https://pixinsight.com/forum/index.php?topic=10441.msg65601#msg65601)
Title: Re: Running PixInsight processes from other apps
Post by: mstriebeck on 2017 August 01 19:45:23
Thanks for the pointers Niall.

In order to run the automatic optimization and then training a model, I have to parallelize it and dispatch to many machines. That would be much easier if I just use the Pixinsight processes from within an external program (I can just link everything together to one binary).

     Mark
Title: Re: Running PixInsight processes from other apps
Post by: Andres.Pozo on 2017 August 02 00:12:38
When launching PI you can add a command line option to run a script that launches the processes that you want. Using this method your optimization program can launch several parallel instances of PI doing some tasks.

If you need to pass parameters to the script, there are several techniques that you can use. For example, your application can write the parameters in a text file so the script can read them.

I think the biggest problem is that you have to launch PixInsight  for each optimization step and this can be quite slow. I think that there is no way to launch a script in a running instance of PixInsight.

Andrés
Title: Re: Running PixInsight processes from other apps
Post by: georg.viehoever on 2017 August 02 05:12:54
Of course, you can write a Javascript script running inside PixInsight that scans the file system for parameter files, does the operation you want with those parameters and then creates a result file evaluated by the optimizer. Or you could do something via http requests etc.

In fact, that's a mode of operation used by a lot of commercial engineering tools, because many of them have quite considerable startup times, just like PI.

Georg
Title: Re: Running PixInsight processes from other apps
Post by: vicent_peris on 2017 August 02 08:18:36
Hi Mark,

If you want to populate a group of machines with PixInsight instances running specific processes, I think the best way is to write bash scripts that send the commands to each machine. This would be a good approach IMO:

First, we write a small JavaScript script to be run in each PixInsight instance. This script is simply an execution of an ImageIntegration instance with a set of known parameters:

Code: [Select]
var P = new ImageIntegration;
P.images = [ // enabled, path, drizzlePath
   [true, "/home/vicent/Image01.xisf", ""],
   [true, "/home/vicent/Image02.xisf", ""],
   [true, "/home/vicent/Image03.xisf", ""],
   [true, "/home/vicent/Image04.xisf", ""],
   [true, "/home/vicent/Image05.xisf", ""],
   [true, "/home/vicent/Image06.xisf", ""],
   [true, "/home/vicent/Image07.xisf", ""],
   [true, "/home/vicent/Image08.xisf", ""],
   [true, "/home/vicent/Image09.xisf", ""],
   [true, "/home/vicent/Image10.xisf", ""],
   [true, "/home/vicent/Image11.xisf", ""],
   [true, "/home/vicent/Image12.xisf", ""]
];
P.inputHints = "";
P.combination = ImageIntegration.prototype.Average;
P.weightMode = ImageIntegration.prototype.NoiseEvaluation;
P.weightKeyword = "";
P.weightScale = ImageIntegration.prototype.WeightScale_IKSS;
P.ignoreNoiseKeywords = false;
P.normalization = ImageIntegration.prototype.AdditiveWithScaling;
P.rejection = ImageIntegration.prototype.WinsorizedSigmaClip;
P.rejectionNormalization = ImageIntegration.prototype.Scale;
P.minMaxLow = 1;
P.minMaxHigh = 1;
P.pcClipLow = 0.200;
P.pcClipHigh = 0.100;
P.sigmaLow = 4.000;
P.sigmaHigh = 3.000;
P.linearFitLow = 5.000;
P.linearFitHigh = 2.500;
P.ccdGain = 1.00;
P.ccdReadNoise = 10.00;
P.ccdScaleNoise = 0.00;
P.clipLow = true;
P.clipHigh = true;
P.rangeClipLow = true;
P.rangeLow = 0.000000;
P.rangeClipHigh = false;
P.rangeHigh = 0.980000;
P.mapRangeRejection = true;
P.reportRangeRejection = false;
P.largeScaleClipLow = false;
P.largeScaleClipLowProtectedLayers = 2;
P.largeScaleClipLowGrowth = 2;
P.largeScaleClipHigh = false;
P.largeScaleClipHighProtectedLayers = 2;
P.largeScaleClipHighGrowth = 2;
P.generate64BitResult = false;
P.generateRejectionMaps = true;
P.generateIntegratedImage = true;
P.generateDrizzleData = false;
P.closePreviousImages = false;
P.bufferSizeMB = 16;
P.stackSizeMB = 1024;
P.useROI = false;
P.roiX0 = 0;
P.roiY0 = 0;
P.roiX1 = 0;
P.roiY1 = 0;
P.useCache = true;
P.evaluateNoise = true;
P.mrsMinDataFraction = 0.010;
P.noGUIMessages = true;
P.useFileThreads = true;
P.fileThreadOverload = 1.00;

P.executeGlobal();

Once you have this script, it can be executed within a PixInsight shell script (SCP). This script will run the JS and then save the integrated image:

Code: [Select]
run -x "/home/vicent/ImageIntegration.js"
save integration -p=/home/vicent/integrated-image.xisf --nodialog --nomessages --noverify

This SCP can be automatically executed when you launch the PixInsight instance in each machine.

You need then a bash script that regenerates the JS for each machine with the specific settings to be tested.

Finally, you can execute the SCP on each machine with the following command:

Code: [Select]
PixInsight -n --no-startup-check-updates --no-startup-gui-messages --no-splash -r=/home/vicent/PI-shell-script.scp --force-exit
If you're executing this instance on multiple machines in an automated way, you'll need to specify the DISPLAY variable value in which the PixInsight should be run. Of course, you'll need a graphical session running in each machine.


Please let me know if you need any further info.
Best regards,
Vicent.
Title: Re: Running PixInsight processes from other apps
Post by: mstriebeck on 2017 August 02 09:05:44
Thanks a lot for the detailed instructions Vicent! That looks like a good approach.

    Mark
Title: Re: Running PixInsight processes from other apps
Post by: mstriebeck on 2017 August 02 10:12:31
... making progress ...

One more question: is it possible to capture the process output?
Title: Re: Running PixInsight processes from other apps
Post by: David Serrano on 2017 August 02 10:16:50
I think the biggest problem is that you have to launch PixInsight  for each optimization step and this can be quite slow. I think that there is no way to launch a script in a running instance of PixInsight.

Maybe PI could be arranged to be launched only once, and the script would poll for the existence of the config file containing the parameters. When the file appears, the script would do its processing, delete the file and poll again. Then the user can write another file with different parameters to cause the script to fire again without the overhead of launching PI.
Title: Re: Running PixInsight processes from other apps
Post by: mstriebeck on 2017 August 02 10:20:27
I actually tried that by first starting PixInsight in the background and then executing the script. I get the output:

PixInsight Core 01.08.04.1198 Ripley (x64)
Copyright (c) 2003-2016 Pleiades Astrophoto

* Yielded execution to running application instance #1


Unfortunately, nothing happens in the running instance :-(
Title: Re: Running PixInsight processes from other apps
Post by: vicent_peris on 2017 August 02 10:43:25
... making progress ...

One more question: is it possible to capture the process output?

Yes. Type "help log" in the Process Console. You can execute the log command in the SCP file to control the output of the ImageIntegration process. Once you exit PixInsight, you can then analyze externally the log file.
Title: Re: Running PixInsight processes from other apps
Post by: vicent_peris on 2017 August 02 10:45:14
I actually tried that by first starting PixInsight in the background and then executing the script. I get the output:

PixInsight Core 01.08.04.1198 Ripley (x64)
Copyright (c) 2003-2016 Pleiades Astrophoto

* Yielded execution to running application instance #1


Unfortunately, nothing happens in the running instance :-(

PixInsight -n=2 will launch a second instance of PixInsight. Type "PixInsight --help" from the system console.

V.
Title: Re: Running PixInsight processes from other apps
Post by: mstriebeck on 2017 August 02 11:07:47

Yes. Type "help log" in the Process Console. You can execute the log command in the SCP file to control the output of the ImageIntegration process. Once you exit PixInsight, you can then analyze externally the log file.

Perfect - that's exactly what I needed. Thanks!
Title: Re: Running PixInsight processes from other apps
Post by: mstriebeck on 2017 August 02 11:10:35

PixInsight -n=2 will launch a second instance of PixInsight. Type "PixInsight --help" from the system console.

V.

Actually, what I tried to achieve was to start PixInsight in the background and then run my scripts in the running PixInsight instance (i.e. not in a new instance).
Title: Re: Running PixInsight processes from other apps
Post by: vicent_peris on 2017 August 02 11:14:54

PixInsight -n=2 will launch a second instance of PixInsight. Type "PixInsight --help" from the system console.

V.

Actually, what I tried to achieve was to start PixInsight in the background and then run my scripts in the running PixInsight instance (i.e. not in a new instance).

Sorry, this is not possible at this moment. But I think there are plans for that.

For the moment, you should launch PixInsight each time.


V.
Title: Re: Running PixInsight processes from other apps
Post by: mstriebeck on 2017 August 02 11:20:12
OK - thanks. That spares me lots of trying :-)
Title: Re: Running PixInsight processes from other apps
Post by: mstriebeck on 2017 August 02 13:44:08
One more thing:

Is it somehow possible to pass arguments from the calling program through the .scp script all the way down to the Javascript script?

Alternatively, I could create the Javascript from the calling program before invoking PixInsight - but, boy, that gets ugly ...

Thanks!
Title: Re: Running PixInsight processes from other apps
Post by: mstriebeck on 2017 August 02 15:15:23
And another question: can I start Pixinsight minimized? Or even better not launching/showing the UI at all?

Thanks!