Skip to content

Commit

Permalink
Updated unit tests for ReadPlanck
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasstolker committed Mar 9, 2021
1 parent 2c8f418 commit abff176
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions species/data/blackbody.py
Expand Up @@ -60,11 +60,11 @@ def add_blackbody(input_path: str,
url = 'https://home.strw.leidenuniv.nl/~stolker/species/blackbody.tgz'

if not os.path.isfile(data_file):
print('Downloading blackbody model spectra (46 MB)...', end='', flush=True)
print('Downloading blackbody model spectra (56 MB)...', end='', flush=True)
urllib.request.urlretrieve(url, data_file)
print(' [DONE]')

print('Unpacking blackbody model spectra (46 MB)...', end='', flush=True)
print('Unpacking blackbody model spectra (56 MB)...', end='', flush=True)
tar = tarfile.open(data_file)
tar.extractall(data_folder)
tar.close()
Expand All @@ -90,7 +90,7 @@ def add_blackbody(input_path: str,
continue

print_message = f'Adding blackbody model spectra... {filename}'
print(f'\r{print_message:<62}', end='')
print(f'\r{print_message:<63}', end='')

data_wavel, data_flux = np.loadtxt(os.path.join(data_folder, filename), unpack=True)

Expand Down Expand Up @@ -123,7 +123,7 @@ def add_blackbody(input_path: str,
flux.append(flux_resample) # (W m-2 um-1)

print_message = 'Adding blackbody model spectra... [DONE]'
print(f'\r{print_message:<62}')
print(f'\r{print_message:<63}')

data_sorted = data_util.sort_data(np.asarray(teff),
None,
Expand Down
8 changes: 4 additions & 4 deletions test/test_read/test_planck.py
Expand Up @@ -35,11 +35,11 @@ def test_get_spectrum(self):
modelbox = read_planck.get_spectrum({'teff': 2000., 'radius': 1., 'distance': 10.}, 100.)

assert modelbox.model == 'planck'
assert modelbox.wavelength.shape == (42, )
assert modelbox.flux.shape == (42, )
assert modelbox.wavelength.shape == (204, )
assert modelbox.flux.shape == (204, )

assert np.sum(modelbox.wavelength) == pytest.approx(52.581084870804, rel=self.limit, abs=0.)
assert np.sum(modelbox.flux) == pytest.approx(8.32208902713122e-13, rel=self.limit, abs=0.)
assert np.sum(modelbox.wavelength) == pytest.approx(255.377278282184, rel=self.limit, abs=0.)
assert np.sum(modelbox.flux) == pytest.approx(4.0434750652879004e-12, rel=self.limit, abs=0.)

def test_get_flux(self):
read_planck = species.ReadPlanck(filter_name='MKO/NSFCam.J')
Expand Down

0 comments on commit abff176

Please sign in to comment.