*band_lim:3*band_lim],
			correct_values)

		correct_values = np.ones(band_lim)
		np.testing.assert_almost_equal(phi2[(j_max+1)*band_lim:],
			correct_values)

	def test_s2dw_harmonic(self):
		# Test that the harmonic space representation of the wavelet and
		# scaling function kernels are correctly calculated.
		scale_int = 2
		band_lim = 1024
		j_max = wavelets_base.calc_j_max(band_lim,scale_int)
		phi2 = np.zeros((j_max+2)*band_lim)
		n_quads = 1000
		j_min = 2
		wavelets_base.phi2_s2dw(phi2,band_lim,scale_int,n_quads)

		wav_har = np.zeros((j_max+2)*band_lim)
		scale_har = np.zeros(band_lim)

		wavelets_base.s2dw_harmonic(wav_har,scale_har,band_lim,scale_int,
			n_quads,j_min)

		# Test that the scales below j_min are set to zero
		np.testing.assert_equal(wav_har[:j_min*band_lim],
			np.zeros(j_min*band_lim))

		# Test the scales above j_min by hand
		for j in range(j_min,j_max+1):
			true_values = (phi2[(j+1)*band_lim:(j+2)*band_lim]-
				phi2[j*band_lim:(j+1)*band_lim])
			true_values[true_values<0] = 0
			true_values = np.sqrt(true_values)
			ell = np.arange(band_lim)
			true_values *= np.sqrt(2*ell+1)/np.sqrt(4*np.pi)
			np.testing.assert_almost_equal(
				wav_har[j*band_lim:(j+1)*band_lim],true_values)

	def test_get_max_nside(self):
		# Test that the max nside returned is correct
		nside = 128
		scale_int = 3
		j=1
		self.assertEqual(wavelets_base.get_max_nside(scale_int,j,nside),32)

		# Try a few more values of j and scale_int
		j=2
		self.assertEqual(wavelets_base.get_max_nside(scale_int,j,nside),32)

		j=3
		self.assertEqual(wavelets_base.get_max_nside(scale_int,j,nside),32)

		scale_int=2
		j=4
		self.assertEqual(wavelets_base.get_max_nside(scale_int,j,nside),32)

		# Check that it wont push past nside
		j=9
		self.assertEqual(wavelets_base.get_max_nside(scale_int,j,nside),128)
		j=10
		self.assertEqual(wavelets_base.get_max_nside(scale_int,j,nside),128)

	def test_get_alm_indices(self):
		# Test that the alm indices returned are wbat we expect
		old_lmax = 128
		new_lmax = 256

		new_indices = wavelets_base.get_alm_indices(old_lmax,new_lmax)

		index = 5
		l, m = hp.Alm.getlm(old_lmax,index)
		self.assertEqual(new_indices[index],hp.Alm.getidx(new_lmax,
			l,m))
		index = 100
		l, m = hp.Alm.getlm(old_lmax,index)
		self.assertEqual(new_indices[index],hp.Alm.getidx(new_lmax,
			l,m))
		index = 35
		l, m = hp.Alm.getlm(old_lmax,index)
		self.assertEqual(new_indices[index],hp.Alm.getidx(new_lmax,
			l,m))

	def test_s2dw_wavelet_tranform(self):
		# Check that the python and s2let output match
		input_map_path = self.root_path + 'gmca_test_full_sim_90_GHZ.fits'
		input_map = hp.read_map(input_map_path,dtype=np.float64)
		output_map_prefix = self.root_path +'s2dw_test'
		band_lim = 256
		scale_int = 3
		j_min = 1
		input_fwhm = 1e-10

		# Generate the wavelet maps using the python code
		wavelet_dict = self.wav_class.s2dw_wavelet_tranform(input_map,
			output_map_prefix,band_lim,scale_int,j_min,input_fwhm,
			n_quads=1000)

		# Check the properties we want are set
		self.assertEqual(wavelet_dict['band_lim'],band_lim)
		self.assertEqual(wavelet_dict['scale_int'],scale_int)
		self.assertEqual(wavelet_dict['j_min'],j_min)
		self.assertEqual(wavelet_dict['j_max'],wavelets_base.calc_j_max(
			band_lim,scale_int))
		self.assertEqual(wavelet_dict['original_nside'],128)
		self.assertEqual(wavelet_dict['input_fwhm'],input_fwhm)
		self.assertEqual(wavelet_dict['n_scales'],wavelets_base.calc_j_max(
			band_lim,scale_int)-j_min+2)
		np.testing.assert_equal(wavelet_dict['target_fwhm'],
			np.ones(wavelet_dict['n_scales']+1)*1e-10)

		# Compare the output to the s2let C code output
		scaling_python = hp.read_map(wavelet_dict['scale_map']['path'],
			nest=True)
		scaling_s2let = hp.reorder(hp.read_map(self.root_path +
			'gmca_full_90_GHZ_wav_scal_256_3_1.fits'),r2n=True)
		self.assertLess(np.mean(np.abs(scaling_python-scaling_s2let)),0.001)

		# Repeat the same for the wavelet maps
		for j in range(j_min,wavelet_dict['j_max']+1):
			wav_python = hp.read_map(wavelet_dict['wav_%d_map'%(j)]['path'],
				nest=True)
			wav_s2let = hp.reorder(hp.read_map(self.root_path +
				'gmca_full_90_GHZ_wav_wav_256_3_1_%d.fits'%(j)),r2n=True)
			self.assertLess(np.mean(np.abs(wav_python-wav_s2let)),0.01)

		# Repeat the same test with the precomputed flag
		wavelet_dict = self.wav_class.s2dw_wavelet_tranform(input_map,
			output_map_prefix,band_lim,scale_int,j_min,input_fwhm,
			n_quads=1000,precomputed=True)

		# Check the properties we want are set
		self.assertEqual(wavelet_dict['band_lim'],band_lim)
		self.assertEqual(wavelet_dict['scale_int'],scale_int)
		self.assertEqual(wavelet_dict['j_min'],j_min)
		self.assertEqual(wavelet_dict['j_max'],wavelets_base.calc_j_max(
			band_lim,scale_int))
		self.assertEqual(wavelet_dict['original_nside'],128)
		self.assertEqual(wavelet_dict['input_fwhm'],input_fwhm)
		self.assertEqual(wavelet_dict['n_scales'],wavelets_base.calc_j_max(
			band_lim,scale_int)-j_min