I want to learn to write scripts.

A320Flyer

Member
Dec 4, 2013
21
0
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
 

dave_galera

Well-known member
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........
 

A320Flyer

Member
Dec 4, 2013
21
0
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
 

A320Flyer

Member
Dec 4, 2013
21
0
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

dave_galera

Well-known member
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
 

A320Flyer

Member
Dec 4, 2013
21
0
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
 

A320Flyer

Member
Dec 4, 2013
21
0
Thanks, Dave.
Both work perfectly. I'm going to study both in detail.
Many thanks for your help.
Bill
 

dave_galera

Well-known member
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

Last edited:

A320Flyer

Member
Dec 4, 2013
21
0
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.
 

ColinThomas

Member
Sep 22, 2013
21
2
UK
www.astrobin.com
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:

 
  • Like
Reactions: FunTomas and avan1

avan1

Active member
Feb 15, 2011
25
0
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