Author Topic: Automating PixInsight  (Read 635 times)

Offline brew

  • Newcomer
  • Posts: 47
Automating PixInsight
« on: 2019 December 21 17:59:01 »
I am interested in suggestions for how to implement a particular task in PixInsight. I am an experienced programmer, and have written a couple of PI scripts, so I understand that process.

The task: I am running ACP with Scheduler. The current system will generate a bunch of panel flats in the early evening, including various filters and rotator angles. The system then runs a number of lights through the night. I have a darks library already created for various temperatures and binning sizes.

The next day I manually run BPP to create master flats from the individual files, then manually run BPP to calibrate (and maybe align and integrate) the individual lights. I have to match up the lights to the appropriate flats based on the date.

I would like to automate this process. I would like to somehow kick off PI with a couple of parameters to automatically run a script of my own. This script would find the folder containing the individual flats and set up and run BPP to create the master flats.

A similar approach would kick off PI to calibrate the lights with the correct flat, dark, and bias masters.

Questions:

1) Clearly PI is normally run interactively; I don't know if it supports some way of running it automatically and exiting when it is done. Can I start PI with some type of run string arguments so it starts a particular script? For example, something like
      pixinsight.exe /start myFlatsScript param1 param2
    
2) I see how to run various processes in my script. Can I run a script (like BPP) in a similar way? At first glance I only see processes being invoked this way.

With a Process, things like

var P = new HistogramTransformation;
P.H = [ // c0, m, c1, r0, r1
   [0.00000000, 0.50000000, 1.00000000, 0.00000000, 1.00000000],
   [0.00000000, 0.50000000, 1.00000000, 0.00000000, 1.00000000],
   [0.00000000, 0.50000000, 1.00000000, 0.00000000, 1.00000000],
   [0.00000000, 0.18627451, 1.00000000, 0.00000000, 1.00000000],
   [0.00000000, 0.50000000, 1.00000000, 0.00000000, 1.00000000]
];

Can I do something similar with a script?

Thanks for any help.
brew

Offline hvb356

  • PixInsight Enthusiast
  • **
  • Posts: 77
Re: Automating PixInsight
« Reply #1 on: 2019 December 21 23:55:12 »

I can't present a ready solution for you, just one item in the mosiak of automation functions:

FileWatcher object

This allows you to write a 'sleeping script' waiting on file/directory events. I.e.: such script can monitor changes of files with follow up actions.

Hartmut
TOA-150, ML8300, CFW2-7 w. Astronomik HaLRGB, PDF, EM-400, guiding FS-60 + ST402, ASCOM bsd. image acquisition

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Re: Automating PixInsight
« Reply #2 on: 2019 December 22 02:42:43 »
Hi Brew,

Everything you are describing can be implemented without problems in current PixInsight versions. Hartmut's answer heads you in the right direction.

Quote
1) Clearly PI is normally run interactively; I don't know if it supports some way of running it automatically and exiting when it is done. Can I start PI with some type of run string arguments so it starts a particular script?

This can be done by running the PixInsight core application with some command-line arguments. The information below has been excerpted from the command line help (available by running PixInsight --help). If you don't have any instance of PixInsight running, you can use the -r (or --run) argument:

-r=<file_path> | --run=<file_path>

      <file_path> is a local path specification to a script file that will be
      loaded and executed just after the startup procedure. This argument can
      be used multiple times to define an ordered set of scripts that will be
      executed after the startup script.


In addition, you can run a script (or a list of scripts) and force application termination:

--force-exit

      After running all scripts specified with -r arguments, exit the
      application unconditionally.

      ** Warning ** No modified data will be saved if this option is specified.


If you are running one or more instances of PixInsight (you can have up to 256 instances of the core application running simultaneously), you can use interprocess communication with the -x argument:

-x=[<slot>:]<file_path> | --execute=[<slot>:]<file_path>

      Send a script execution command to a running instance of the PixInsight
      core application. <slot> is an optional application slot with the same
      meaning as for the -n option. <file_path> is a path to an existing
      script file that will be executed by the target instance. If no <slot>
      is specified, the execute command will be sent to the first running
      instance.


However, your best option is, as Hartmut has pointed out, an instance of the PixInsight core application running a script that monitors the file system with the FileWatcher object and other core PJSR objects. This scheme allows you to implement extremely sophisticated and complex automated tasks. Let me know if you need help with this implementation, and I'll be glad to assist you.

Quote
2) I see how to run various processes in my script. Can I run a script (like BPP) in a similar way?

Yes. You can #include a script (standard C syntax) in your script, then run it with a simple function call. Most scripts implement a main() function as an entry point. Depending on the scripts you want to use, you may have to make some modifications. For example, BPP and WBPP run interactively, so you'll probably have to modify them slightly to force them to run without a dialog window. In general, these modifications are relatively simple.
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline brew

  • Newcomer
  • Posts: 47
Re: Automating PixInsight
« Reply #3 on: 2019 December 22 08:20:11 »
Excellent! This is exactly what I need. This lets me spend all kinds of time playing around >:D