Author Topic: Strategy for calling a JavaScript driven by a GUI multiple times  (Read 3679 times)

Offline rga218

  • Newcomer
  • Posts: 37
Hi, I'd like to automate a series of calls to the CatalogStarGenerator script. My anticipated workflow was to place a series of  'run' commands (with parameters specified with the -p switch) in a text file and then execute this file somehow. However, this doesn't seem to work, since one needs to click on the "Run" button to execute the script. I'm sure I'm doing something silly... could somebody suggest how I could automate a series of calls to the CatalogStarGenerator script? As a minimal example, I'd like to stick the following two commands in a text file and have them run without me having to interact with the GUI.

run -x -p="sgen_useImageMetadata,false" -p="sgen_width,3352" -p="sgen_height,2532" -p="sgen_projection,0" -p="sgen_ra,140.95624907820334" -p="sgen_dec,50.766868161759604" -p="sgen_epoch,2451544.5" -p="sgen_rotation,-89.64123220744744" -p="sgen_resolution,0.0007912807534924661" -p="sgen_xpixsz,7.4" -p="SDSS_magMin,1000" -p="SDSS_magMax,1000" -p="SDSS_magnitudeFilter,gmag" -p="SDSS_classFilter,0" -p="sgen_projectionOriginMode,0" -p="sgen_vizierServer,http://vizier.u-strasbg.fr/" -p="sgen_autoGraphics,false" -p="sgen_minMagnitude,13" -p="sgen_maxMagnitude,19" -p="sgen_backgroundMagnitude,21.5" -p="sgen_PSF,1" -p="sgen_FWHM,3" -p="sgen_beta,2" -p="sgen_generateNoise,true" --md5="375eb5938b12e994dbcb6788f26784a6" -p="isGlobalTarget,true" -p="isViewTarget,false" "$PXI_SRCDIR/scripts/AdP/CatalogStarGenerator.js"

run -x -p="sgen_useImageMetadata,false" -p="sgen_width,3352" -p="sgen_height,2532" -p="sgen_projection,0" -p="sgen_ra,139.95" -p="sgen_dec,56.86" -p="sgen_epoch,2451544.5" -p="sgen_rotation,-89.64123220744744" -p="sgen_resolution,0.0007912807534924661" -p="sgen_xpixsz,7.4" -p="SDSS_magMin,1000" -p="SDSS_magMax,1000" -p="SDSS_magnitudeFilter,gmag" -p="SDSS_classFilter,0" -p="sgen_projectionOriginMode,0" -p="sgen_vizierServer,http://vizier.u-strasbg.fr/" -p="sgen_autoGraphics,false" -p="sgen_minMagnitude,13" -p="sgen_maxMagnitude,19" -p="sgen_backgroundMagnitude,21.5" -p="sgen_PSF,1" -p="sgen_FWHM,3" -p="sgen_beta,2" -p="sgen_generateNoise,true" --md5="375eb5938b12e994dbcb6788f26784a6" -p="isGlobalTarget,true" -p="isViewTarget,false" "$PXI_SRCDIR/scripts/AdP/CatalogStarGenerator.js"


Thanks,

Bob

Roberto Abraham
Professor of Astronomy & Astrophysics
University of Toronto

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Hi Bob,

You can write a console shell script to run both commands: just put them (as you've written them in your post) in a text file with .scp suffix, and execute it with the run command:

run --execute-mode=auto "/path/to/my/script.scp"

(to avoid script versioning problems, better remove the --md5 arguments from both run commands in the script)

However, this won't work as you expect. AFAIK, the CatalogStarGenerator script will always open a dialog window, so it requires user interaction. The minimal interaction required is just one click on the OK button, but without it, the script will block the whole PixInsight platform forever. This means that this script can't be pipelined. A very simple modification would allow non-interactive execution (for example, an additional command-line argument to select the non-interactive mode). Andrés ???
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline rga218

  • Newcomer
  • Posts: 37
Thanks Juan. Andrés has been incredibly helpful in the past and I will prevail upon him again with this request.
Roberto Abraham
Professor of Astronomy & Astrophysics
University of Toronto

Offline Andres.Pozo

  • PTeam Member
  • PixInsight Padawan
  • ****
  • Posts: 927
Hi,

I can modify my scripts for adding the option of running them in an non-interactive way.

However and as a temporal workaround some of them when applied on a target (drag the icon over an image) don't show the dialog. ImageSolver, AnnotateImage and CatalogStarGenerator can be ran this way. I implemented this behavior for being able to use the scripts on ImageContainers and ProcessContainers.

So, what you need can be done creating an icon for each instance of CatalogStarGenerator, adding the icons to a ProcessContainer and then run the container on any image.

Offline rga218

  • Newcomer
  • Posts: 37
Dear Andrés,

Thanks very much for being willing to make the change to the scripts. Your scripts, and your willingness to tweak them, have really helped me grow to love using PixInsight.

Your suggested temporary workaround helps; dragging process icons around is turning out to be a nice abstraction and I like using icons to organize my work, particularly when I'm doing things by hand, which is certainly 90% of the battle when I am at the stage of playing with ideas for how best to reduce the data. But once I've gotten to the point where I know exactly what needs to get done, I like to try to bring the whole thing together in a single script that goes from raw data to fully reduced data (otherwise in six months I'll have forgotten what I did). Of course I can just save a project file too (which has indeed proven very useful) but it's nice to be able to just set a script running and go end-to-end on the data flow.

Thanks again!

Bob
Roberto Abraham
Professor of Astronomy & Astrophysics
University of Toronto

Offline Andres.Pozo

  • PTeam Member
  • PixInsight Padawan
  • ****
  • Posts: 927
I have a new version of CatalogStarGenerator, ImageSolver, AnnotateImage and AperturePhotometry with a non-interactive mode. When these scripts are launched with the parameter "non_interactive" with a "true" value the configuration dialog is not shown.
I will give the new code to Juan for including it in the next version of PI.

For example:
Code: [Select]
run -x -p="isGlobalTarget,true" -p="isViewTarget,false" -p="sgen_useImageMetadata,false" -p="sgen_width,1024" -p="sgen_height,1024"
 -p="sgen_projection,0" -p="sgen_ra,0" -p="sgen_dec,0" -p="sgen_epoch,2456293.5" -p="sgen_rotation,0"
 -p="sgen_resolution,0.0002777777777777778" -p="sgen_xpixsz,5" -p="PPMXL_magMin,1000" -p="PPMXL_magMax,15"
 -p="PPMXL_magnitudeFilter,r1mag" -p="sgen_projectionOriginMode,0" -p="sgen_vizierServer,http://vizier.u-strasbg.fr/"
 -p="sgen_autoGraphics,true" -p="sgen_minMagnitude,6" -p="sgen_maxMagnitude,15" -p="sgen_backgroundMagnitude,16" -p="sgen_PSF,1"
 -p="sgen_FWHM,1" -p="sgen_beta,2" -p="sgen_generateNoise,true" -p="isGlobalTarget,true" -p="isViewTarget,false"
 -p="non_interactive,true" "C:/PixInsight/CatalogStarGenerator.js"

There is another possibility although more complex. ImageSolver and CatalogStarGenerator can also be executed from other scripts. These scripts have tree parts: the configuration dialog, the engine and the "main" function. If the preprocessor constants "USE_CATSTARGEN_LIBRARY" or "USE_SOLVER_LIBRARY" are defined before including the files "ImageSolver.js" or "CatalogStarGenerator.js" the "main" function is deactivated but the classes of the dialog and engine are still available.

Example of executing CatalogStarGenerator from another script without opening the user interface:
Code: [Select]
#include <pjsr/DataType.jsh>

#define SETTINGS_MODULE "Test"

#include "WCSmetadata.jsh"
#include "AstronomicalCatalogs.jsh"
#include "SearchCoordinatesDialog.js"

#define USE_CATSTARGEN_LIBRARY
#include "CatalogStarGenerator.js"
#undef USE_CATSTARGEN_LIBRARY

var csg = new CatalogStarGenerator();

csg.useImageMetadata = false;
csg.ra = 225; // Right ascension in deg
csg.dec = -75; // Declination in deg
csg.epoch = Math.complexTimeToJD(2014, 4, 1);
csg.width = 1024;
csg.height = 1024;
csg.rotation = 0;
csg.resolution = 1 / 3600; // Resolution in degrees
csg.projection = 0; // Gnomonic projection
csg.projectionOriginMode = 0;

csg.vizierServer = "http://vizier.u-strasbg.fr/";
csg.catalog = new PPMXLCatalog();
csg.catalog.magnitudeFilter = "r1mag";
csg.catalog2 = new NullCatalog();
csg.autoGraphics = true;
csg.maxMagnitude = 15;
csg.generateNoise = true;

var targetW = csg.Generate();
targetW.show();

This has been available in both scripts for a long time although I didn't document it.

Offline rga218

  • Newcomer
  • Posts: 37
> This has been available in both scripts for a long time although I didn't document it.

Hi Andrés, thanks a lot, I just tried this and it does just what I need. By doing some minimal hacking of your code and passing parameters to the 'run' built-in command via the -p argument I put together a script to do exactly what I need.

Thanks again,

Bob

P.S. To get the JavaScript to work with the built-in 'run' command I had to make the paths to the include files explicit, i.e.

#include "/Applications/PixInsight.app/Contents/src/scripts/AdP/WCSmetadata.jsh"

Is there an environment variable I need to have set in order for PixInsight to be able to find the header files?
Roberto Abraham
Professor of Astronomy & Astrophysics
University of Toronto