MCPcopy Create free account
hub / github.com/AstroImageJ/astroimagej / run

Method run

ij/src/main/java/ij/plugin/FITS_Writer.java:58–128  ·  view source on GitHub ↗
(String path)

Source from the content-addressed store, hash-verified

56 public static final ExecutorService savingThread = Executors.newSingleThreadExecutor();
57
58 @AstroImageJ(reason = "commented out GET FILE...file deletion iff exists, use nom.tam for export", modified = true)
59 public void run(String path) {
60 ImagePlus imp = IJ.getImage();
61
62 if (true) { // AIJ uses nom.tam for fits export
63 saveImage(imp, path, imp.getCurrentSlice());
64 return;
65 }
66
67 ImageProcessor ip = imp.getProcessor();
68 int numImages = imp.getImageStackSize();
69 int bitDepth = imp.getBitDepth();
70 if (bitDepth==24) {
71 IJ.error("RGB images are not supported");
72 return;
73 }
74
75 // GET PATH
76 if (path == null || path.trim().length() == 0) {
77 String title = "image.fits";
78 SaveDialog sd = new SaveDialog("Write FITS image",title,".fits");
79 path = sd.getDirectory()+sd.getFileName();
80 }
81
82 /*// GET FILE
83 File f = new File(path);
84 String directory = f.getParent()+File.separator;
85 String name = f.getName();
86 if (f.exists()) f.delete();*/
87 int numBytes = 0;
88
89 cal = imp.getCalibration();
90 unsigned16 = (bitDepth==16 && cal.getFunction()==Calibration.NONE && cal.getCoefficients()==null);
91
92 // GET IMAGE
93 if (bitDepth==8) {
94 numBytes = 1;
95 if (cal.getFunction()!=Calibration.NONE && cal.getCoefficients()!=null) {
96 bZero = cal.getCoefficients()[0];
97 if (cal.getCoefficients()[1] != 0) bScale = cal.getCoefficients()[1];
98 }
99 } else if (ip instanceof ShortProcessor) {
100 numBytes = 2;
101 if (unsigned16) {
102 bZero = 32768.0;
103 bScale = 1.0;
104 } else {
105 if (cal.getCoefficients()[1] != 0) bScale = cal.getCoefficients()[1];
106 bZero = cal.getCoefficients()[0] + (32768.0*bScale);
107 }
108 } else if (ip instanceof FloatProcessor) {
109 numBytes = 4; //float processor does not support calibration - data values are shifted and scaled in FITS_Reader
110 bZero = 0.0; //float values are written back out without shifting
111 bScale = 1.0; //and without scaling
112 }
113
114 int fillerLength = 2880 - ( (numBytes * imp.getWidth() * imp.getHeight()) % 2880 );
115

Callers

nothing calls this directly

Calls 15

getImageMethod · 0.95
saveImageMethod · 0.95
getCurrentSliceMethod · 0.95
getProcessorMethod · 0.95
getImageStackSizeMethod · 0.95
getBitDepthMethod · 0.95
errorMethod · 0.95
getDirectoryMethod · 0.95
getFileNameMethod · 0.95
getCalibrationMethod · 0.95
getWidthMethod · 0.95
getHeightMethod · 0.95

Tested by

no test coverage detected