Load and save file

outdoorboy

Well-known member
Hello,

I have debayered a directory with "Fits files" into a new directory using Process "Debayer". PixInsight has saved the files as xisf files. Now I want to save the files via script into a directory as fits files.

Code:
var img = new Image();
//img.readRawFile("H:\\2022-10-05\\1tag\\2022-10-05\\Saturn\\Debayer_Biliear\\Saturn_00001_d.xisf");
img.readRawFile("H:\\2022-10-05\\1tag\\2022-10-05\\Saturn\\21_14_45\\Saturn_00001.fits");

now I get this error

*** Error [000]: C:/Users/franz/Documents/mf_PixInsight/Test.js, line 19: Error: The file is not recognized as a valid PCL swap image file: H:\2022-10-05\1tag\2022-10-05\Saturn\21_14_45/Saturn_00001.fits

QUESTION 1:
how can i load an xisf file and save it as a fits file.

QUESTION 2:
If I create a dialog and read the directory into a TreeBox how can I reach all files then

thanks Franz
 
I experimented a little and found a solution. However, I don't want to open the file in a window and saving it requires user input.

Code:
var w = ImageWindow.open( "H:/2022-10-05/1tag/2022-10-05/Saturn/Debayer_Biliear/Saturn_00001_d.xisf" );
for ( var i in w )
{
  w[i].show();
  w[i].zoomToOptimalFit();
}

//for ( var i in w )
  w[i].saveAs( "H:/2022-10-05/1tag/2022-10-05/Saturn/C_Fits/Saturn_00001.fits" );

  for ( var i in w )
  w[i].close();

How do I load the xisf file without opening it in a window and save it without user input?
 
Solution:

It looks like the image must always be opened in an ImageWindow!

Code:
      var file = "H:/2022-10-05/1tag/2022-10-05/Saturn/Debayer_Biliear/Saturn_00002_d.xisf"
      var w = null;
      
      w = ImageWindow.open( file );

      if (!w || w.isNull)
         throw "Image does not exist: '" + file + "'";
      else
      {
         for ( var i in w )
         {
            // w[i].show();
            // w[i].zoomToOptimalFit();
          
            w[i].saveAs( "H:/2022-10-05/1tag/2022-10-05/Saturn/C_Fits/Saturn_00002.fits", false, false, true, false );
            w[i].forceClose();
         }
      }
 
try reading the included script called BatchFormatConversion.js. it should give you some hints about how to do this.

rob
 
Thanks !!!

That was exactly what I wanted to write.

Why write yourself when there is already a ready script.

franz
 
Back
Top