Skip to content

Commit 2d64994

Browse files
authored
Merge pull request #263 from Caltech-IPAC/DM-7781-UpdateZscaleTest
DM-7781-UpdateZscaleTest: Added setUp() and tearDown(); Directly call…
2 parents e71d2ae + 40eb6c4 commit 2d64994

File tree

1 file changed

+42
-40
lines changed

1 file changed

+42
-40
lines changed

src/firefly/test/edu/caltech/ipac/visualize/plot/ZscaleTest.java

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import edu.caltech.ipac.firefly.util.FileLoader;
44
import nom.tam.fits.Fits;
55
import nom.tam.fits.FitsException;
6+
import org.junit.After;
67
import org.junit.Assert;
8+
import org.junit.Before;
79
import org.junit.Test;
810

911
import java.lang.reflect.InvocationTargetException;
@@ -14,58 +16,58 @@
1416
* Created by ymei on 3/28/16.
1517
* 10/19/16
1618
* DM-8028
17-
* Use teh UnitTestUtility to load file
19+
* Use the UnitTestUtility to load file
20+
* 01/07/2017 DM-7188
21+
* Added the setUp() and tearDown(); Directly called Zscale.cdl_zscale;
1822
*/
1923
public class ZscaleTest {
2024

25+
//Input fits file:
2126
private static String filename = "WISE-Band-4.fits";
27+
28+
//Prepare the parameters for calling cdl_zscale:
29+
private ImageHeader imageHeader = null;
30+
private float[] float1d = null;
31+
2232

23-
/**
24-
@Test
25-
public void testFitLineRetvalAbnormalInputs() {
26-
float[] data = {1,2,3,4,5,6,7,8,9};
27-
int npix = 0;
28-
float krej = 2.2f;
29-
int ngrow = 6;
30-
int maxiter = 5;
31-
Zscale.FitLineRetval fitLineRetval = Zscale.fitLine (data, npix, krej, ngrow, maxiter);
33+
@Before
34+
/**
35+
* An one dimensional array is created and it is used to run the unit test for Histogram's public methods
36+
*/
37+
public void setUp() throws FitsException {
3238

39+
Fits fits = FileLoader.loadFits(ZscaleTest.class,filename );
40+
FitsRead[] fry = FitsRead.createFitsReadArray(fits);
41+
float1d = fry[0].getDataFloat();
42+
imageHeader = fry[0].getImageHeader();
43+
44+
}
3345

34-
// Private!!!
46+
@After
47+
/**
48+
* Release the memories
49+
*/
50+
public void tearDown() {
51+
float1d = null;
52+
imageHeader = null;
3553
}
36-
*/
54+
3755

3856
@Test
3957
public void testZscalRetval() throws FitsException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
4058

41-
//String inFitsName = TEST_ROOT + filename;
42-
// For IntelliJ run:
43-
//String inFitsName = filename;
44-
Fits fits = FileLoader.loadFits(ZscaleTest.class,filename );
45-
FitsRead[] fry = FitsRead.createFitsReadArray(fits);
46-
float[] float1d = fry[0].getDataFloat();
47-
ImageHeader imageHeader = fry[0].getImageHeader();
48-
49-
//Make rangeValues:
50-
int lowerWhich = 91;
51-
double lowerValue = 1.0;
52-
int upperWhich = 91;
53-
double upperValue = 1.0;
54-
double betaValue = 1.0;
55-
double gammaValue = 2.0;
56-
int algorithm = 45;
57-
int zscale_contrast = 25;
58-
int zscale_samples = 600;
59-
int zscale_samples_per_line = 120;
60-
double bias = 0.5;
61-
double contrast = 1.0;
62-
RangeValues rangeValues = new RangeValues(lowerWhich, lowerValue, upperWhich, upperValue, betaValue, gammaValue, algorithm, zscale_contrast, zscale_samples, zscale_samples_per_line, bias, contrast);
63-
64-
65-
//Make the method getZscaleValue accessible:
66-
Method m = FitsRead.class.getDeclaredMethod("getZscaleValue", float[].class, ImageHeader.class, RangeValues.class);
67-
m.setAccessible(true);
68-
Zscale.ZscaleRetval zscaleRetval = (Zscale.ZscaleRetval)m.invoke(fry[0], new Object[]{float1d, imageHeader, rangeValues});
59+
60+
int nx = imageHeader.naxis1;
61+
int ny = imageHeader.naxis2;
62+
int bitpix = imageHeader.bitpix;
63+
double blank_value = imageHeader.blank_value;
64+
65+
double contrast = 0.25;
66+
int opt_size = 600;
67+
int len_stdline = 120;
68+
69+
70+
Zscale.ZscaleRetval zscaleRetval = Zscale.cdl_zscale(float1d, nx, ny, bitpix, contrast, opt_size, len_stdline, blank_value);
6971

7072
double z1 = zscaleRetval.getZ1();
7173
double z2 = zscaleRetval.getZ2();

0 commit comments

Comments
 (0)