I want to learn to write scripts.

A320Flyer

Active member
Hi folks,

I'm looking for some help in getting started with writing my own scripts. I'm a looking-to-retire-soon Structural Engineer so a bit of maths doesn't worry me too much. But it has been a looong time since I did any programming ( I remember BASIC well).

A script I would like to write is one that will search a directory of image files and tell me which file has the best SSWEIGHT or WBPPWGHT value in the FITS Header. This would help me when I forget to take note at the time of calibration.

I have followed the "Hello World" tutorial posted elsewhere on the forum but I'm not sure how to proceed from there.

Any help would be much appreciated.

Thanks
Bill
 
You need to learn JavaScript first then dissect the existing scripts to see how things are done. There is no documentation so you have to learn from existing scripts and the odd code snippets that Juan puts out in the forum posts. When I see a script from Juan I always save them for future reference.

If you have any specific questions then ask away........
 
Hi Bill
after "Hello world" there is another simple script to read the fits header and write it to Console (CR Hartmut v. Borneman)
www.werbeagentur.org/oldwexi/write_fitsheader_to_Console.js

maybe thats a start...

More detailed and deeper PI scripts for Fits header handling you find in your PI scripts directory:
FITSKeywods.js
FitsDataView.js

There is a long way to go from Zero....

Gerald
 
Hi Guys
Thanks for the pointers. I’m currently reading the book “Eloquent JavaScript” and I’m in no doubt that it will be an uphill push! Anyway, when else is there to do in this lockdown!!
Ta
Bill
 
Later today I will send you a script that will help you along the way as I nothing to do in lockdown either LOL
 
I think that learning JavaScript from scratch is probably more than I am up to. I don't know if this is allowed (tell me if not), but I have made some edits to the FitsKeywords script and it now does what I need it to do. The problem I have is that it will only open Fits files. How do I get it to open XISF files?


Script.jpg


Thanks for any help.
Bill
 

Attachments

  • FITSKeywords2.zip
    4.7 KB · Views: 67
Line 279

if ( gdd.execute() )
{
if (DEBUGGING_MODE_ON) {console.writeln("Start searching FITS file in SubFolders"); processEvents();}
var fileNames = searchDirectory(gdd.directory+"/*.fit" ,true)
.concat(searchDirectory(gdd.directory+"/*.fits",true))
.concat(searchDirectory(gdd.directory+"/*.fts",true));
if (DEBUGGING_MODE_ON) {console.writeln("Finish searching FITS file in SubFolders"); processEvents();}
this.dialog.getFiles(fileNames);
}

Change fits to xisf

I am doing a much simpler one for you that is easier to understand. Learning Javascript along with modifying/playing with existing scripts is the way to go
 
Hi Dave,

Tried that but I got an error in the console :
"
*** Error [000]: C:/Users/user/Documents/PixInsight/FITSKeywords3.js, line 90: Error: File does not seem a valid FITS file: C:/Users/user/Desktop/SCRIPT TEST/NGC2264-G199-1x1-0014Ha_a.xisf
"

I also changed line 262:

ofd.filters = [["Image Files", "*.fit", "*.fits", "*.fts", "*.xisf"]];

Added xisf so the image requester would show xisf files.

I very much appreciate your help here.
Thanks
Bill
 
This is a script that scans a directory and finds the max value of a keyword, give it a try as it is a very basic routine that you can use for other things. Writes answer to console.

I will do you a version with a proper GUI interface....hang fire!!
 

Attachments

  • FITSMaxKeywordValue.js.zip
    973 bytes · Views: 90
Here is the GUI version, very simple but does the job
 

Attachments

  • BatchFITSMaxKeywordValue.js.zip
    2.8 KB · Views: 105
Hi Bill,
OK I have changed FITSKeywords so it now reads both FITS and XISF files and I have removed the options to Move and Copy etc as these complicated the whole thing and are not necessary for what you wanted it to do....if you want them re-instating just let me know. It is now called FITSKeywordsView.js

The problem was that the function that reads the FITS file was totally unsuitable for XISF files and I had to re-write the whole function and I would have had to re-write the Move and Copy functions also so I didn't bother.....unless you want them.

Let me know how you get on with it and if you want any changes..........don't worry about the time I enjoy programming as I have been doing it for 51 years and as we are locked down gives me something to do!!
 

Attachments

  • FITSKeywordsView.js.zip
    5.2 KB · Views: 87
Last edited:
Hi Dave,
What can I say?! Outstanding!! Thank you so much.
If I think of any more "projects" to keep you entertained, I will be in touch.
Keep safe.
Cheers.
Bill.
 
Hi,

I have also been looking at the Javascript interface since being in lockdown, and think I now have a handle on the basics and GUI manipulation. I have put together some HTML that covers (with code examples)


  1. Access to Scripting Environment
  2. Window Packing In PixInsight
  3. Running Process Instances
  4. Selecting Image to be Active
  5. Writing an Image
  6. Opening an Image
  7. Changing data on a Process Instance
  8. Extracting Class Methods
  9. Creating File and Folder Browser in Widget
  10. PixInsight available icons for widgets
And examples of the following widgets usage:
  • CheckBox
  • ComboBox
  • TextBox
  • TreeBox
  • Label
  • PushButton
  • RadioButton
  • SliderSpinBox
  • Dialog
  • MessageBox
I've just put on Github, so feel free to clone/edit a copy, and tell me of any issues (I am sure there are some more elegant ways that I have located). The top html page is Home.hml

https://github.com/ColinPeterThomas/PixInsight-Javascript-Programming

I was after a way to automate my basic workflow, and now have this in place.

I hope this is useful to others.

Clear skies and keep safe

Colin

p.s. I also have a zip of the html directory, but at 6M it is too large to attach here. I have therefore added to my google drive and should be accessible via the link:

 
Hi,

I have also been looking at the Javascript interface since being in lockdown, and think I now have a handle on the basics and GUI manipulation. I have put together some HTML that covers (with code examples)


  1. Access to Scripting Environment
  2. Window Packing In PixInsight
  3. Running Process Instances
  4. Selecting Image to be Active
  5. Writing an Image
  6. Opening an Image
  7. Changing data on a Process Instance
  8. Extracting Class Methods
  9. Creating File and Folder Browser in Widget
  10. PixInsight available icons for widgets
And examples of the following widgets usage:
  • CheckBox
  • ComboBox
  • TextBox
  • TreeBox
  • Label
  • PushButton
  • RadioButton
  • SliderSpinBox
  • Dialog
  • MessageBox
I've just put on Github, so feel free to clone/edit a copy, and tell me of any issues (I am sure there are some more elegant ways that I have located). The top html page is Home.hml

https://github.com/ColinPeterThomas/PixInsight-Javascript-Programming

I was after a way to automate my basic workflow, and now have this in place.

I hope this is useful to others.

Clear skies and keep safe

Colin

p.s. I also have a zip of the html directory, but at 6M it is too large to attach here. I have therefore added to my google drive and should be accessible via the link:


very informative , thank you
 
Back
Top