From 7b1bede44987c63f4af0649a25f7d31f9f0cb297 Mon Sep 17 00:00:00 2001 From: Melanie Simet Date: Wed, 20 Jun 2018 17:20:12 -0600 Subject: [PATCH 1/8] Fix bug in helper.py where inconsistent arrays returned False instead of two arrays (#103) --- tests/helper.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tests/helper.py b/tests/helper.py index c14bf72..ee4051f 100644 --- a/tests/helper.py +++ b/tests/helper.py @@ -16,14 +16,12 @@ def FormatSame(arr1,arr2): Then return a tuple of the two arrays, which can then be passed to the numpy.testing functions. """ if not arr1.shape==arr2.shape: - return False + return (arr1, arr2) arr1 = numpy.array(arr1) # to protect against FITSrecs - if not len(arr1.dtype.names)==len(arr2.dtype.names): - return False - if not arr1.shape==arr2.shape: - return False + if not len(arr1.dtype.names)==len(arr2.dtype.names) or not arr1.shape==arr2.shape: + return (arr1, arr2) arr1 = arr1.astype(arr1.dtype.newbyteorder('=')) arr2 = arr2.astype(arr2.dtype.newbyteorder('=')) arr2.dtype.names = arr1.dtype.names - return (arr1,arr2) + return (arr1, arr2) From 13e1b3b476b2e80064ff9a82500f7ce5b4f25b47 Mon Sep 17 00:00:00 2001 From: Melanie Simet Date: Wed, 20 Jun 2018 17:27:47 -0600 Subject: [PATCH 2/8] Fix test_correlation_functions.py to work with later versions of TreeCorr (#103) --- tests/test_correlation_functions.py | 40 ++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/tests/test_correlation_functions.py b/tests/test_correlation_functions.py index a537768..b2325b0 100755 --- a/tests/test_correlation_functions.py +++ b/tests/test_correlation_functions.py @@ -48,10 +48,38 @@ def setUp(self): dtype=[("R_nom [deg]", float), (" [deg]", float), ("", float), ("", float), ("sigma", float), ("weight", float), ("npairs", float)]) + self.expected_result_meanlogr = numpy.array( + [(0.053888, 0.054459, -2.9109, 0.022059, -4.2588e-02, 0.025785, 182., 182.), + (0.062596, 0.062105, -2.7799, 0.0037377, 2.9950e-02, 0.020788, 280., 280.), + (0.072711, 0.072468, -2.6254, 0.018572, -4.1915e-02, 0.017547, 393., 393.), + (0.08446, 0.084946, -2.4664, -0.0092076, -6.1220e-03, 0.015557, 500., 500.), + (0.098107, 0.098256, -2.321, 0.019855, 9.5542e-03, 0.014469, 578., 578.), + (0.11396, 0.11411, -2.1713, 0.0076978, 4.3697e-03, 0.010679, 1061., 1061.), + (0.13237, 0.13435, -2.0082, 0.0097326, -4.2636e-03, 0.010371, 1125., 1125.), + (0.15376, 0.15209, -1.8839, 0.0024, -7.1487e-03, 0.0090482, 1478., 1478.), + (0.17861, 0.17727, -1.7306, 0.0029644, -1.9988e-03, 0.0072297, 2315., 2315.), + (0.20747, 0.20774, -1.5723, 0.0016518, -2.6162e-03, 0.0065797, 2795., 2795.), + (0.241, 0.24133, -1.4225, -0.012766, 2.9823e-04, 0.0052742, 4350., 4350.), + (0.27994, 0.28572, -1.2533, 0.0013257, -1.1404e-03, 0.0046513, 5593., 5593.), + (0.32517, 0.3273, -1.1179, -0.0025167, 3.0612e-04, 0.0045542, 5834., 5834.), + (0.37772, 0.37581, -0.98021, -0.0034272, -5.5511e-03, 0.0034589, 10114., 10114.), + (0.43875, 0.43984, -0.82263, 0.00019999, -2.4145e-03, 0.0030951, 12631., 12631.), + (0.50965, 0.49764, -0.69848, -0.0037836, 5.5003e-04, 0.0030254, 13220., 13220.), + (0.592, 0.58802, -0.53226, 0.0021309, 9.0001e-05, 0.0036726, 8971., 8971.), + (0.68766, 0.68766, -0.37447, 0., 0.0000e+00, 0., 0., 0.), + (0.79877, 0.79877, -0.22468, 0., 0.0000e+00, 0., 0., 0.), + (0.92784, 0.92784, -0.074893, 0., 0.0000e+00, 0., 0., 0.)], + dtype=[("R_nom [deg]", float), ("meanR [deg]", float), + ("meanlogR [deg]", float), ("gamT", float), ("gamX", float), + ("sigma", float), ("weight", float), ("npairs", float)]) + def test_getCF(self): """Test getCF() directly, without first processing by child classes.""" + # Note: bin_slop 1 is not optimal for bins this small, but an earlier version of TreeCorr + # did this by default with the settings here; we define bin_slop 1 for backwards + # compatibility stile_args = {'ra_units': 'degrees', 'dec_units': 'degrees', 'min_sep': 0.05, 'max_sep': 1, - 'sep_units': 'degrees', 'nbins': 20} + 'sep_units': 'degrees', 'nbins': 20, 'bin_slop': 1} cf = stile.sys_tests.CorrelationFunctionSysTest() dh = temp_data_handler() lens_data = stile.ReadASCIITable('../examples/example_lens_catalog.dat', @@ -65,9 +93,13 @@ def test_getCF(self): g1=source_data['g1'], g2=source_data['g2'], ra_units='degrees', dec_units='degrees') results = cf.getCF('ng', lens_catalog, source_catalog, **stile_args) - numpy.testing.assert_array_equal(*helper.FormatSame(results, self.expected_result)) + if "meanlogR [deg]" in results.dtype.names: + expected = self.expected_result_meanlogr + else: + expected = self.expected_result + numpy.testing.assert_array_equal(*helper.FormatSame(results, expected)) results2 = cf.getCF('ng', lens_data, source_data, config=stile_args) - self.assertEqual(self.expected_result.dtype.names, results.dtype.names) + self.assertEqual(expected.dtype.names, results.dtype.names) # Missing necessary data file numpy.testing.assert_equal(results, results2) self.assertRaises(TypeError, @@ -84,7 +116,7 @@ def test_getCF(self): def test_generator(self): """Make sure the CorrelationFunctionSysTest() generator returns the right objects""" - object_list = ['GalaxyShear', 'BrightStarShear', 'StarXGalaxyDensity', 'StarXGalaxyShear', + object_list = ['GalaxyShear', 'BrightStarShear', 'StarXGalaxyDensity', 'StarXGalaxyShear', 'StarXStarShear', 'GalaxyDensityCorrelation', 'StarDensityCorrelation'] for object_type in object_list: object_1 = stile.CorrelationFunctionSysTest(object_type) From 0ca0955a1b84cbec86547ccb6f7fbd614eaad608 Mon Sep 17 00:00:00 2001 From: Melanie Simet Date: Wed, 20 Jun 2018 17:29:17 -0600 Subject: [PATCH 3/8] Updates to FITS file handling for later versions of astropy --- stile/file_io.py | 27 +++++++++++++++------ stile/stile_utils.py | 9 +++++++ tests/test_data/image_and_table.fits | Bin 11520 -> 11520 bytes tests/test_data/table.fits | Bin 8640 -> 8640 bytes tests/test_data/two_tables.fits | Bin 14400 -> 14400 bytes tests/test_file_io.py | 35 ++++++++++++++++++--------- 6 files changed, 52 insertions(+), 19 deletions(-) diff --git a/stile/file_io.py b/stile/file_io.py index f2efd55..7d78752 100644 --- a/stile/file_io.py +++ b/stile/file_io.py @@ -11,6 +11,12 @@ has_fits = True except ImportError: has_fits = False +try: + import astropy.table + has_astropy = True + from .stile_utils import Table +except ImportError: + has_astropy = False import numpy import os import stile_utils @@ -51,7 +57,10 @@ def ReadFITSTable(file_name, hdu=1, fields=None): skip some fields. :returns: The contents of the requested HDU. """ - return stile_utils.FormatArray(ReadFITSImage(file_name, hdu), fields=fields) + if has_astropy: + return stile_utils.FormatArray(Table.read(file_name, hdu), fields=fields) + else: + return stile_utils.FormatArray(ReadFITSImage(file_name, hdu), fields=fields) def ReadASCIITable(file_name, **kwargs): @@ -167,7 +176,7 @@ def WriteASCIITable(file_name, data_array, fields=None, print_header=False): warnings.warn('No named data type, so requested header cannot be printed.') numpy.savetxt(file_name, data, fmt=_format_str(data.dtype)) else: - numpy.savetxt(file_name, data, fmt=_format_str(data.dtype)) + numpy.savetxt(file_name, data, fmt=' '.join(_format_str(data.dtype))) # And, of course, PyFITS *also* uses a different format specification character set. _fits_dict = {'b': 'L', # boolean @@ -210,11 +219,15 @@ def WriteFITSTable(file_name, data_array, fields=None): data = _handleFields(data_array, fields) cols = [fits_handler.Column(name=data.dtype.names[i], format=_coerceFitsFormat(data.dtype[i]), array=data[data.dtype.names[i]]) for i in range(len(data.dtype))] - table = fits_handler.new_table(cols) - hdulist = fits_handler.HDUList(fits_handler.PrimaryHDU(), table) - hdulist.append(table) - hdulist.verify() - hdulist.writeto(file_name) + if hasattr(fits_handler, 'new_table'): + table = fits_handler.new_table(cols) + hdulist = fits_handler.HDUList(fits_handler.PrimaryHDU(), table) + hdulist.append(table) + hdulist.verify() + hdulist.writeto(file_name) + else: + table = fits_handler.TableHDU.from_columns(cols) + table.writeto(file_name) def WriteTable(file_name, data_array, fields=None): diff --git a/stile/stile_utils.py b/stile/stile_utils.py index ae66143..4bf7f3a 100644 --- a/stile/stile_utils.py +++ b/stile/stile_utils.py @@ -142,6 +142,15 @@ def __str__(self): ret_str += '\t%f %f\n'%(self.percentiles[index], self.values[index]) return ret_str + +try: + import astropy.table + class Table(astropy.table.Table): + @property + def shape(self): + return (len(self), len(self.colnames)) +except ImportError: + pass fieldNames = { 'dec': 'the declination of the object', diff --git a/tests/test_data/image_and_table.fits b/tests/test_data/image_and_table.fits index d15fc89953f848abcb7dab0a35c19748877f22e7..0749f0734b6e9a07788ed69be5d90d0839505251 100644 GIT binary patch delta 224 zcmZpOYKYp>mDMrL4H2dQXgPb0(0 ze3H&!X=A9gu`x(`^8?0DtTKjrrUq!hRolQIBQ+-{e`2GUBG5=>mDMrI({N&L~wo<@d~ z&+$5gWsRY-#>ODo%?^y8SY-_LObyV0tG0nbMruw@{=`NxMWBhsdT0s^3_wcK^Yc@Z TDpNsjG2I-<_?~le0^@T4XwW+4 literal 8640 zcmeH~O-sW-5I{u`{26o0QQIE$QnaB2M`Pjvxam{5^{q+Y~;y~(mU zZKNEBKiWSJzurF={rEuNKMzNW7qMg`w|PJAA3AYR`E9G<4fQ<8>(lX6e%o^HR!_F- z<2%d?8^QNG*ik`aCYjLB3-_P#21ou1o}N-yOXiljn7R7;a)0$aQy!ThWRc%aCFI#L zi}zu?R(ENhzxu`CFy|kJz#d z^-K-WfUCBF0nAnf1)wHlJ#$ngh8C!5OcWFh^$bi6jF6R?0@WBJ%rV^@$oQUfasuPi z$qwAadC_F^StSBqe4rA|>}all!;6y}R8d0!=pJDB2s0TQLqp&bYY2`I$Vkn}$wxRJ Z8W6}H1hYW_k)EHQl2n zO(jyx{3-Lp%LYAGD?BnS#Ez^*83=#?2!H?xfB*=9z{4kC+Q}#whZp1xf{^tGBj2lC z)hWfxjLRJ<9;brDS7n>iTFGI0ul;lP?)`Jok9XYtbLXYjOGP$U3)7D$`%av6eNz;A zUAG>cH|Xj5rkK1Pe++dWf5f~nm-%*0YcBapC?VbR!n@z;bq@FydTy0!wQLypqsz#> zzQg^nx6EuQ(xh3Hu}>4f*bh$%JCoJ#zv_pN%-C@J;mYdiDXEBddS-pa{(5n`Eylfe zdS-oA@BQCcALh4`B0fL>1V8`;K;Rw;yt#f-kCWbu?+-YzSO3}YtKO%%tN;9^+==%7?!WP$ z^@~ettDW@r>$CpztG>P9c6!DiKR3@SyqSJdlxoR#dd45Odho}qzXoI=00JNY0w8ce uVDCRKM4INe!^27Mxy|Q!p2Ry*egXISmJkvU009sH0T2KI5CDP4N#F+3Sm7i9 diff --git a/tests/test_file_io.py b/tests/test_file_io.py index 230a191..c843cc8 100644 --- a/tests/test_file_io.py +++ b/tests/test_file_io.py @@ -3,6 +3,8 @@ import os import helper import unittest +from stile import file_io +from astropy.io import fits try: import stile except: @@ -49,15 +51,25 @@ def setUp(self): (55, 'tenth', 'jj', 55.0)], dtype='l, S7, S2, d') # contents of test_data/[table.fits, image_and_table.fits, two_tables.fits (hdu 2)] - self.fits_table = numpy.array([(1.5, 'hello', 2), (3, 'goodbye', 5)], - dtype=[('q', float), ('status', 'S7'), ('final', int)]) + self.fits_table = numpy.array([(1.5, 'hello ', 2), (3, 'goodbye', 5)], + dtype=[('q', numpy.float64), ('status', 'S7'), ('final', numpy.int32)]) # contents of first extension of test_data/two_tables.fits self.fits_table_2 = numpy.array([(1.5, 2), (3.7, 4), (1050.2, 5)], - dtype=[('red', float), ('blue', int)]) + dtype=[('red', numpy.float64), ('blue', numpy.int32)]) # contents of test_data/[image_int.fits, image_and_table.fits] self.fits_int_image = numpy.array([[1, 2], [3, 4]]) # contents of test_data/image_float.fits self.fits_float_image = numpy.array([[1.0, 2.1], [3.4, 1.6]]) + +# hdu = fits.PrimaryHDU(self.fits_int_image) +# cols = [fits.Column(name=self.fits_table.dtype.names[i], format=file_io._coerceFitsFormat(self.fits_table.dtype[i]), +# array=self.fits_table[self.fits_table.dtype.names[i]]) for i in range(len(self.fits_table.dtype))] +# table_hdu = fits.TableHDU.from_columns(self.fits_table) +# hdulist = fits.HDUList([hdu, table_hdu]) +# hdulist.writeto('test.fits') +# table_hdu_1 = fits.TableHDU.from_columns(self.fits_table_2) +# table_hdu_2 = fits.TableHDU.from_columns(self.fits_table) +# fits.HDUList([fits.PrimaryHDU(), table_hdu_1, table_hdu_2]).writeto('test2.fits') def test_ReadFITSImage(self): """Test the ability to read in a FITS image.""" @@ -119,13 +131,14 @@ def test_WriteASCIITable(self): raise RuntimeError('Arrays are equal, but should not have the same format') except AssertionError: pass - numpy.testing.assert_equal(results.astype('f'), self.table1.astype('f')) + results = results.astype(self.table1.dtype) + numpy.testing.assert_equal(results, self.table1) # check field reordering field_list = ['f3', 'f4', 'f6', 'f0', 'f2', 'f1', 'f5'] stile.file_io.WriteASCIITable(filename, self.table1, fields=field_list) - results = stile.ReadASCIITable(filename) - numpy.testing.assert_equal(results.astype('f'), self.table1[field_list].astype('f')) + results = stile.ReadASCIITable(filename).astype(self.table1[field_list].dtype) + numpy.testing.assert_equal(results, self.table1[field_list]) os.close(handle) if not stile.file_io.has_fits: # If there is a FITS handler, this table would be written as a FITS table, so we @@ -145,7 +158,7 @@ def test_WriteFITSTable(self): stile.WriteFITSTable(filename, self.fits_table) try: self.assertTrue( - stile.file_io.fits_handler.FITSDiff('test_data/table.fits', 'temp.fits')) + stile.file_io.fits_handler.FITSDiff('test_data/table.fits', filename).identical) except AttributeError: # FITSDiff seems to not exist for one of my pyfits installations numpy.testing.assert_equal(stile.ReadFITSTable('test_data/table.fits'), @@ -155,13 +168,11 @@ def test_WriteFITSTable(self): # Now see if WriteTable properly sends things through WriteFITSTable handle, filename = tempfile.mkstemp() stile.WriteTable(filename, self.fits_table_2) - numpy.testing.assert_equal(stile.ReadFITSTable('test_data/two_tables.fits'), - stile.ReadFITSTable(filename)) + res = stile.ReadFITSTable(filename) + numpy.testing.assert_array_equal(stile.ReadFITSTable('test_data/two_tables.fits'), + stile.ReadFITSTable(filename)) os.close(handle) - handle, filename = tempfile.mkstemp() - self.assertRaises(TypeError, stile.WriteFITSTable, filename, []) - os.close(handle) if __name__ == '__main__': if not stile.file_io.has_fits: From 51ab4523667a44cd4d848ef026ffca8acd69a523 Mon Sep 17 00:00:00 2001 From: Melanie Simet Date: Wed, 20 Jun 2018 17:29:39 -0600 Subject: [PATCH 4/8] Fix bug in test_stats.py --- tests/test_stats.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_stats.py b/tests/test_stats.py index 32f5e02..6c1ab2d 100644 --- a/tests/test_stats.py +++ b/tests/test_stats.py @@ -58,7 +58,7 @@ def test_statsystest_basic(self): self.check_results(result) result = test_obj(tuple(test_vec)) self.check_results(result) - result = test_obj(test_vec.reshape((0.5*self.n_points_test, 2))) + result = test_obj(test_vec.reshape((int(0.5*self.n_points_test), 2))) self.check_results(result) def test_statsystest_exceptions(self): From be033a2b2e615e5d48f3375d2aa978c30171861a Mon Sep 17 00:00:00 2001 From: Melanie Simet Date: Wed, 20 Jun 2018 17:30:00 -0600 Subject: [PATCH 5/8] Update treecorr_utils to work with later versions of TreeCorr --- stile/treecorr_utils.py | 22 ++++++++++++++++++---- tests/test_treecorr_utils.py | 19 +++++++++++++++---- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/stile/treecorr_utils.py b/stile/treecorr_utils.py index 4fc33ba..fc62185 100644 --- a/stile/treecorr_utils.py +++ b/stile/treecorr_utils.py @@ -6,7 +6,8 @@ import file_io import treecorr from treecorr.corr2 import corr2_valid_params - +use_2form = any([key[:2]=='n2' for key in corr2_valid_params]) +print use_2form, "use2form" def Parser(): import argparse @@ -104,6 +105,16 @@ def ReadTreeCorrResultsFile(file_name): fields = [field for field in fields if field != '.'] return stile_utils.FormatArray(output, fields=fields) +# This next bit of code is so we work with both the 'n2_*' and the 'nn_*' treecorr args +def fixform(key): + if key[-4:]=='_col': + return key + elif key[1]=='2' and not use_2form and not key[0]=='m': + return key[0]+key[0]+key[2:] + elif key[0]==key[1] and use_2form: + return key[0]+'2'+key[2:] + return key + def PickTreeCorrKeys(input_dict): """ @@ -121,7 +132,10 @@ def PickTreeCorrKeys(input_dict): treecorr_dict = input_dict['treecorr_kwargs'] else: treecorr_dict = {} - for key in corr2_valid_params: - if key in input_dict: - treecorr_dict[key] = input_dict[key] + for key in input_dict: + newkey = fixform(key) + if newkey in corr2_valid_params: + treecorr_dict[newkey] = input_dict[key] + okeys = set(input_dict.keys()) + nkeys = set(treecorr_dict.keys()) return treecorr_dict diff --git a/tests/test_treecorr_utils.py b/tests/test_treecorr_utils.py index 24a1bbf..cdc2b75 100644 --- a/tests/test_treecorr_utils.py +++ b/tests/test_treecorr_utils.py @@ -24,13 +24,16 @@ def setUp(self): 'k_col': 9, 'w_col': 10, 'flip_g1': False, 'flip_g2': False, 'pairwise': False, 'min_sep': 0.1, 'max_sep': 10, 'nbins': 10, 'bin_size': 0.99, 'sep_units': 'degrees', 'bin_slop': 0.8, - 'n2_file_name': 'o1.dat', 'n2_statistic': 'compensated', 'ng_file_name': 'o2.dat', 'ng_statistic': 'compensated', - 'g2_file_name': 'o3.dat', 'nk_file_name': 'o4.dat', 'nk_statistic': 'simple', - 'k2_file_name': 'o5.dat', 'kg_file_name': 'o6.dat', 'precision': 3, + 'nk_file_name': 'o4.dat', 'nk_statistic': 'simple', + 'kg_file_name': 'o6.dat', 'precision': 3, 'm2_file_name': 'o7.dat', 'm2_uform': 'Crittenden', 'nm_file_name': 'o8.dat', 'norm_file_name': 'o9.dat', 'verbose': 3, 'num_threads': 16, 'split_method': 'median'} + self.dict3_has2 = {'n2_file_name': 'o1.dat', 'n2_statistic': 'compensated', + 'g2_file_name': 'o3.dat', 'k2_file_name': 'o5.dat'} + self.dict3_no2 = {'nn_file_name': 'o1.dat', 'nn_statistic': 'compensated', + 'gg_file_name': 'o3.dat', 'kk_file_name': 'o5.dat'} # The output of a run of TreeCorr. self.treecorr_output = numpy.array( [(5.389e-02, 5.443e-02, 2.206e-02, -4.259e-02, 2.578e-02, 1.820e+02, 1.820e+02), @@ -61,7 +64,7 @@ def test_ReadTreeCorrResultsFile(self): arr = stile.ReadTreeCorrResultsFile('test_data/TreeCorr_output.dat') numpy.testing.assert_equal(arr, self.treecorr_output) # Seems to depend on which version of NumPy which error is raised - self.assertRaises((TypeError, StopIteration), stile.ReadTreeCorrResultsFile, + self.assertRaises((TypeError, StopIteration, ValueError), stile.ReadTreeCorrResultsFile, 'test_data/empty_file.dat') def test_PickTreeCorrKeys(self): @@ -73,6 +76,14 @@ def test_PickTreeCorrKeys(self): self.assertEqual(new_dict, self.dict2, msg='All entries from the dict should have been copied to the '+ 'new dict') + if stile.treecorr_utils.use_2form: + new_dict = stile.treecorr_utils.PickTreeCorrKeys(self.dict3_no2) + for key in new_dict: + self.assertIn(key[0]+'2'+key[2:], self.dict3_has2) + else: + new_dict = stile.treecorr_utils.PickTreeCorrKeys(self.dict3_has2) + for key in new_dict: + self.assertIn(key[0]+key[0]+key[2:], self.dict3_no2) if __name__ == '__main__': From 9f4669631dd19486edfbb94ee01b3ae1c00faa12 Mon Sep 17 00:00:00 2001 From: Melanie Simet Date: Wed, 20 Jun 2018 20:12:20 -0400 Subject: [PATCH 6/8] Update test_file_io.py to really work with different versions of fits readers, plus remove a few leftover diagnostic code lines (#103) --- stile/treecorr_utils.py | 1 - tests/test_file_io.py | 40 +++++++++++++++++++++++++--------------- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/stile/treecorr_utils.py b/stile/treecorr_utils.py index fc62185..44e62d5 100644 --- a/stile/treecorr_utils.py +++ b/stile/treecorr_utils.py @@ -7,7 +7,6 @@ import treecorr from treecorr.corr2 import corr2_valid_params use_2form = any([key[:2]=='n2' for key in corr2_valid_params]) -print use_2form, "use2form" def Parser(): import argparse diff --git a/tests/test_file_io.py b/tests/test_file_io.py index c843cc8..f1e93c1 100644 --- a/tests/test_file_io.py +++ b/tests/test_file_io.py @@ -61,16 +61,6 @@ def setUp(self): # contents of test_data/image_float.fits self.fits_float_image = numpy.array([[1.0, 2.1], [3.4, 1.6]]) -# hdu = fits.PrimaryHDU(self.fits_int_image) -# cols = [fits.Column(name=self.fits_table.dtype.names[i], format=file_io._coerceFitsFormat(self.fits_table.dtype[i]), -# array=self.fits_table[self.fits_table.dtype.names[i]]) for i in range(len(self.fits_table.dtype))] -# table_hdu = fits.TableHDU.from_columns(self.fits_table) -# hdulist = fits.HDUList([hdu, table_hdu]) -# hdulist.writeto('test.fits') -# table_hdu_1 = fits.TableHDU.from_columns(self.fits_table_2) -# table_hdu_2 = fits.TableHDU.from_columns(self.fits_table) -# fits.HDUList([fits.PrimaryHDU(), table_hdu_1, table_hdu_2]).writeto('test2.fits') - def test_ReadFITSImage(self): """Test the ability to read in a FITS image.""" if stile.file_io.has_fits: @@ -137,7 +127,9 @@ def test_WriteASCIITable(self): # check field reordering field_list = ['f3', 'f4', 'f6', 'f0', 'f2', 'f1', 'f5'] stile.file_io.WriteASCIITable(filename, self.table1, fields=field_list) - results = stile.ReadASCIITable(filename).astype(self.table1[field_list].dtype) + results = stile.ReadASCIITable(filename) + results.dtype.names = field_list + results = results.astype(self.table1[field_list].dtype) numpy.testing.assert_equal(results, self.table1[field_list]) os.close(handle) if not stile.file_io.has_fits: @@ -161,16 +153,34 @@ def test_WriteFITSTable(self): stile.file_io.fits_handler.FITSDiff('test_data/table.fits', filename).identical) except AttributeError: # FITSDiff seems to not exist for one of my pyfits installations - numpy.testing.assert_equal(stile.ReadFITSTable('test_data/table.fits'), - stile.ReadFITSTable(filename)) + try: + numpy.testing.assert_equal(stile.ReadFITSTable('test_data/table.fits'), + stile.ReadFITSTable(filename)) + except AssertionError: + old_write = stile.ReadFITSTable('test_data/table.fits') + new_write = stile.ReadFITSTable(filename) + for colname in new_write.dtype.names: + self.assertIn(colname, old_write.dtype.names) + if isinstance(old_write[colname][0], str): + self.assertTrue(all([a.strip()==b.strip() for a,b in zip(old_write[colname], new_write[colname])])) + else: + numpy.testing.assert_equal(old_write[colname], new_write[colname]) + os.close(handle) # Now see if WriteTable properly sends things through WriteFITSTable handle, filename = tempfile.mkstemp() stile.WriteTable(filename, self.fits_table_2) res = stile.ReadFITSTable(filename) - numpy.testing.assert_array_equal(stile.ReadFITSTable('test_data/two_tables.fits'), - stile.ReadFITSTable(filename)) + try: + numpy.testing.assert_array_equal(stile.ReadFITSTable('test_data/two_tables.fits'), + stile.ReadFITSTable(filename)) + except AssertionError: # Sometimes this fails because of dtype reasons + old_write = stile.ReadFITSTable('test_data/two_tables.fits') + new_write = stile.ReadFITSTable(filename) + for colname in new_write.dtype.names: + self.assertIn(colname, old_write.dtype.names) + numpy.testing.assert_equal(old_write[colname], new_write[colname]) os.close(handle) From c1b08b577ef73b6538b6a6cfe5d87db16bbc34d1 Mon Sep 17 00:00:00 2001 From: Melanie Simet Date: Thu, 21 Jun 2018 12:26:21 -0600 Subject: [PATCH 7/8] Add Travis yaml file --- .travis.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..311befa --- /dev/null +++ b/.travis.yml @@ -0,0 +1,22 @@ +branches: + only: + - master + +language: python +python: + - 2.7 + +install: + - pip install numpy scipy astropy codecov matplotlib TreeCorr + +script: + - cd tests + - "nosetests test*.py --with-coverage --cover-package=stile --with-doctest --cover-erase" + +after_success: + # The multiprocessing stages don't get properly incorporated into the .coverage file unless + # we do this command. (Some of the .coverage.* files are in the ../examples directory.) + - coverage xml + - codecov + + From 37cdf43ecb23d51381490117f780baf04ce65066 Mon Sep 17 00:00:00 2001 From: Melanie Simet Date: Fri, 13 Jul 2018 18:20:33 -0700 Subject: [PATCH 8/8] Update Changelog (#101) --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d07c664..b6b6e7e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ +7/13/18: Add codecov yaml files (issue #101) 7/11/18: Update code to python3 3/17/16: Update documentation to Sphinx standard and add documentation build files (issue #17) 2/17/16: Changes to correlation function plots & documentation (issue #77)