|
3 | 3 | import edu.caltech.ipac.firefly.util.FileLoader; |
4 | 4 | import nom.tam.fits.Fits; |
5 | 5 | import nom.tam.fits.FitsException; |
| 6 | +import org.junit.After; |
6 | 7 | import org.junit.Assert; |
| 8 | +import org.junit.Before; |
7 | 9 | import org.junit.Test; |
8 | 10 |
|
9 | 11 | import java.lang.reflect.InvocationTargetException; |
|
14 | 16 | * Created by ymei on 3/28/16. |
15 | 17 | * 10/19/16 |
16 | 18 | * 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; |
18 | 22 | */ |
19 | 23 | public class ZscaleTest { |
20 | 24 |
|
| 25 | + //Input fits file: |
21 | 26 | 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 | + |
22 | 32 |
|
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 { |
32 | 38 |
|
| 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 | + } |
33 | 45 |
|
34 | | - // Private!!! |
| 46 | + @After |
| 47 | + /** |
| 48 | + * Release the memories |
| 49 | + */ |
| 50 | + public void tearDown() { |
| 51 | + float1d = null; |
| 52 | + imageHeader = null; |
35 | 53 | } |
36 | | - */ |
| 54 | + |
37 | 55 |
|
38 | 56 | @Test |
39 | 57 | public void testZscalRetval() throws FitsException, NoSuchMethodException, InvocationTargetException, IllegalAccessException { |
40 | 58 |
|
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); |
69 | 71 |
|
70 | 72 | double z1 = zscaleRetval.getZ1(); |
71 | 73 | double z2 = zscaleRetval.getZ2(); |
|
0 commit comments