From 23947fc711b2ec120edd2c9f46ae5ec4d6dd95cf Mon Sep 17 00:00:00 2001 From: Tomas Stolker Date: Thu, 30 Jan 2020 12:38:49 +0100 Subject: [PATCH] Replaced wget with urllib.request, updated tutorials, errors and warnings in get_model, bug fix get_data with petitCODE, smooth parameter in get_model --- docs/tutorials/atmospheric_models.ipynb | 6 +- .../tutorials/color_magnitude_broadband.ipynb | 33 ++-- .../color_magnitude_narrowband.ipynb | 30 ++-- docs/tutorials/data_model.ipynb | 4 +- docs/tutorials/fitting_photometry.ipynb | 4 +- docs/tutorials/flux_magnitude.ipynb | 6 +- docs/tutorials/photometric_calibration.ipynb | 6 +- docs/tutorials/synthetic_photometry.ipynb | 42 +++-- requirements.txt | 1 - species/analysis/fit_model.py | 2 +- species/core/setup.py | 8 +- species/data/ames_cond.py | 41 ++--- species/data/ames_dusty.py | 41 ++--- species/data/btnextgen.py | 51 +++--- species/data/btsettl.py | 48 +++-- species/data/database.py | 132 +++++++++----- species/data/drift_phoenix.py | 14 +- species/data/filters.py | 8 +- species/data/irtf.py | 6 +- species/data/isochrones.py | 4 +- species/data/leggett.py | 14 +- species/data/petitcode.py | 96 +++------- species/data/queries.py | 2 +- species/data/spex.py | 8 +- species/data/vega.py | 10 +- species/data/vlm_plx.py | 10 +- species/plot/plot_color.py | 4 +- species/plot/plot_mcmc.py | 6 +- species/plot/plot_spectrum.py | 2 +- species/read/read_model.py | 169 +++++++++++++----- species/util/data_util.py | 14 +- species/util/phot_util.py | 6 +- species/util/read_util.py | 4 +- test/test_read/test_isochrone.py | 18 +- test/test_read/test_model.py | 37 ++-- 35 files changed, 492 insertions(+), 395 deletions(-) diff --git a/docs/tutorials/atmospheric_models.ipynb b/docs/tutorials/atmospheric_models.ipynb index 0d7f0951..123669dc 100644 --- a/docs/tutorials/atmospheric_models.ipynb +++ b/docs/tutorials/atmospheric_models.ipynb @@ -97,9 +97,9 @@ ], "source": [ "database.add_model(model='drift-phoenix',\n", - " wavel_range=(0.5, 10.),\n", - " teff_range=None,\n", - " spec_res=None)" + " wavel_range=None,\n", + " spec_res=None,\n", + " teff_range=None)" ] }, { diff --git a/docs/tutorials/color_magnitude_broadband.ipynb b/docs/tutorials/color_magnitude_broadband.ipynb index 22c34290..9b8bddaf 100644 --- a/docs/tutorials/color_magnitude_broadband.ipynb +++ b/docs/tutorials/color_magnitude_broadband.ipynb @@ -27,9 +27,9 @@ "metadata": {}, "outputs": [], "source": [ - "import species\n", - "import wget\n", - "import numpy as np" + "import urllib.request\n", + "import numpy as np\n", + "import species" ] }, { @@ -201,7 +201,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "The isochrones from the AMES-Cond and AMES-Dusty evolutionary models are downloaded with `wget`." + "The isochrones from the AMES-Cond and AMES-Dusty evolutionary models are downloaded with `urllib.request`." ] }, { @@ -221,11 +221,18 @@ } ], "source": [ - "wget.download('https://phoenix.ens-lyon.fr/Grids/AMES-Cond/ISOCHRONES/model.AMES-Cond-2000.M-0.0.NaCo.Vega',\n", - " out='data/model.AMES-Cond-2000.M-0.0.NaCo.Vega')\n", - "\n", - "wget.download('https://phoenix.ens-lyon.fr/Grids/AMES-Dusty/ISOCHRONES/model.AMES-dusty.M-0.0.NaCo.Vega',\n", - " out='data/model.AMES-dusty.M-0.0.NaCo.Vega')" + "urllib.request.urlretrieve('https://phoenix.ens-lyon.fr/Grids/AMES-Cond/ISOCHRONES/model.AMES-Cond-2000.M-0.0.NaCo.Vega',\n", + " 'data/model.AMES-Cond-2000.M-0.0.NaCo.Vega')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "urllib.request.urlretrieve('https://phoenix.ens-lyon.fr/Grids/AMES-Dusty/ISOCHRONES/model.AMES-dusty.M-0.0.NaCo.Vega',\n", + " 'data/model.AMES-dusty.M-0.0.NaCo.Vega')" ] }, { @@ -295,13 +302,13 @@ "source": [ "database.add_model(model='ames-cond',\n", " wavel_range=(0.5, 10.),\n", - " teff_range=(100., 4000.),\n", - " spec_res=1000.)\n", + " spec_res=1000.,\n", + " teff_range=(100., 4000.))\n", "\n", "database.add_model(model='ames-dusty',\n", " wavel_range=(0.5, 10.),\n", - " teff_range=(100., 4000.),\n", - " spec_res=1000.)" + " spec_res=1000.,\n", + " teff_range=(100., 4000.))" ] }, { diff --git a/docs/tutorials/color_magnitude_narrowband.ipynb b/docs/tutorials/color_magnitude_narrowband.ipynb index 2a5084db..930aa97e 100644 --- a/docs/tutorials/color_magnitude_narrowband.ipynb +++ b/docs/tutorials/color_magnitude_narrowband.ipynb @@ -27,9 +27,9 @@ "metadata": {}, "outputs": [], "source": [ - "import species\n", - "import wget\n", - "import numpy as np" + "import urllib.request\n", + "import numpy as np\n", + "import species" ] }, { @@ -1060,8 +1060,8 @@ "source": [ "database.add_model(model='ames-cond',\n", " wavel_range=(0.5, 10.),\n", - " teff_range=(100., 4000.),\n", - " spec_res=1000.)" + " spec_res=1000.\n", + " teff_range=(100., 4000.))" ] }, { @@ -1090,8 +1090,8 @@ "source": [ "database.add_model(model='ames-dusty',\n", " wavel_range=(0.5, 10.),\n", - " teff_range=(100., 4000.),\n", - " spec_res=1000.)" + " spec_res=1000.\n", + " teff_range=(100., 4000.))" ] }, { @@ -1118,10 +1118,18 @@ } ], "source": [ - "wget.download('https://phoenix.ens-lyon.fr/Grids/AMES-Cond/ISOCHRONES/model.AMES-Cond-2000.M-0.0.NaCo.Vega',\n", - " out='data/model.AMES-Cond-2000.M-0.0.NaCo.Vega')\n", - "wget.download('https://phoenix.ens-lyon.fr/Grids/AMES-Dusty/ISOCHRONES/model.AMES-dusty.M-0.0.NaCo.Vega',\n", - " out='data/model.AMES-dusty.M-0.0.NaCo.Vega')" + "urllib.request.urlretrieve('https://phoenix.ens-lyon.fr/Grids/AMES-Cond/ISOCHRONES/model.AMES-Cond-2000.M-0.0.NaCo.Vega',\n", + " 'data/model.AMES-Cond-2000.M-0.0.NaCo.Vega')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "urllib.request.urlretrieve('https://phoenix.ens-lyon.fr/Grids/AMES-Dusty/ISOCHRONES/model.AMES-dusty.M-0.0.NaCo.Vega',\n", + " 'data/model.AMES-dusty.M-0.0.NaCo.Vega')" ] }, { diff --git a/docs/tutorials/data_model.ipynb b/docs/tutorials/data_model.ipynb index ca1f1269..773242fe 100644 --- a/docs/tutorials/data_model.ipynb +++ b/docs/tutorials/data_model.ipynb @@ -113,8 +113,8 @@ "source": [ "database.add_model(model='ames-cond',\n", " wavel_range=(0.1, 6.),\n", - " teff_range=(2800., 3000.),\n", - " spec_res=1000.)" + " spec_res=1000.\n", + " teff_range=(2800., 3000.))" ] }, { diff --git a/docs/tutorials/fitting_photometry.ipynb b/docs/tutorials/fitting_photometry.ipynb index 0914c3b9..36cd51d3 100644 --- a/docs/tutorials/fitting_photometry.ipynb +++ b/docs/tutorials/fitting_photometry.ipynb @@ -74,8 +74,8 @@ "source": [ "database.add_model(model='drift-phoenix',\n", " wavel_range=None,\n", - " teff_range=None,\n", - " spec_res=None)" + " spec_res=None\n", + " teff_range=None)" ] }, { diff --git a/docs/tutorials/flux_magnitude.ipynb b/docs/tutorials/flux_magnitude.ipynb index 99e7de31..eced53c6 100644 --- a/docs/tutorials/flux_magnitude.ipynb +++ b/docs/tutorials/flux_magnitude.ipynb @@ -16,7 +16,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "Initiating species v0.1.0... [DONE]\n", + "Initiating species v0.1.2... [DONE]\n", "Creating species_config.ini... [DONE]\n", "Database: /Users/tomasstolker/applications/species/docs/tutorials/species_database.hdf5\n", "Data folder: /Users/tomasstolker/applications/species/docs/tutorials/data\n", @@ -28,7 +28,7 @@ { "data": { "text/plain": [ - "" + "" ] }, "execution_count": 1, @@ -61,7 +61,7 @@ "text": [ "Adding filter: JWST/NIRCam.F115W... [DONE]\n", "Downloading Vega spectrum (270 kB)... [DONE]\n", - "Adding Vega spectrum...[DONE]\n", + "Adding Vega spectrum... [DONE]\n", "Flux density [W m-2 micron-1] = 4.15e-15 +/- 7.69e-16\n" ] } diff --git a/docs/tutorials/photometric_calibration.ipynb b/docs/tutorials/photometric_calibration.ipynb index 8983a8e1..b834d08b 100644 --- a/docs/tutorials/photometric_calibration.ipynb +++ b/docs/tutorials/photometric_calibration.ipynb @@ -34,8 +34,8 @@ "metadata": {}, "outputs": [], "source": [ + "import urllib.request\n", "import species\n", - "import wget\n", "from IPython.display import Image" ] }, @@ -187,8 +187,8 @@ } ], "source": [ - "wget.download('http://irtfweb.ifa.hawaii.edu/~spex/IRTF_Spectral_Library/Data/G8V_HD75732.txt',\n", - " out='data/G8V_HD75732.txt')" + "urllib.request.urlretrieve('http://irtfweb.ifa.hawaii.edu/~spex/IRTF_Spectral_Library/Data/G8V_HD75732.txt',\n", + " 'data/G8V_HD75732.txt')" ] }, { diff --git a/docs/tutorials/synthetic_photometry.ipynb b/docs/tutorials/synthetic_photometry.ipynb index 8082c203..0ed473e4 100644 --- a/docs/tutorials/synthetic_photometry.ipynb +++ b/docs/tutorials/synthetic_photometry.ipynb @@ -13,9 +13,9 @@ "metadata": {}, "outputs": [], "source": [ - "import species\n", - "import wget\n", - "import numpy as np" + "import urllib.request\n", + "import numpy as np\n", + "import species" ] }, { @@ -27,7 +27,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "Initiating species v0.1.0... [DONE]\n", + "Initiating species v0.1.2... [DONE]\n", "Creating species_config.ini... [DONE]\n", "Database: /Users/tomasstolker/applications/species/docs/tutorials/species_database.hdf5\n", "Data folder: /Users/tomasstolker/applications/species/docs/tutorials/data\n", @@ -39,7 +39,7 @@ { "data": { "text/plain": [ - "" + "" ] }, "execution_count": 2, @@ -55,17 +55,35 @@ "cell_type": "code", "execution_count": 3, "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "('data/plnt_Jupiter.txt', )" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "urllib.request.urlretrieve('http://irtfweb.ifa.hawaii.edu/~spex/IRTF_Spectral_Library/Data/plnt_Jupiter.txt',\n", + " 'data/plnt_Jupiter.txt')" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, "outputs": [], "source": [ - "wget.download('http://irtfweb.ifa.hawaii.edu/~spex/IRTF_Spectral_Library/Data/plnt_Jupiter.txt',\n", - " out='data/plnt_Jupiter.txt')\n", - "\n", "wavelength, flux, error = np.loadtxt('data/plnt_Jupiter.txt', unpack=True)" ] }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -74,7 +92,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 6, "metadata": {}, "outputs": [ { @@ -83,7 +101,7 @@ "text": [ "Adding filter: JWST/NIRCam.F115W... [DONE]\n", "Downloading Vega spectrum (270 kB)... [DONE]\n", - "Adding Vega spectrum...[DONE]\n" + "Adding Vega spectrum... [DONE]\n" ] } ], @@ -94,7 +112,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 7, "metadata": {}, "outputs": [ { diff --git a/requirements.txt b/requirements.txt index a9bd7d8c..d845994e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,4 +10,3 @@ scipy ~= 1.4 spectres ~= 2.0 tqdm ~= 4.42 xlrd ~= 1.2 -wget ~= 3.2 diff --git a/species/analysis/fit_model.py b/species/analysis/fit_model.py index cc748702..74da1d90 100644 --- a/species/analysis/fit_model.py +++ b/species/analysis/fit_model.py @@ -121,7 +121,7 @@ def lnlike(param, chisq += (item[0]-flux)**2 / item[1]**2 if spectrum is not None: - model = modelspec.get_model(paramdict, None) + model = modelspec.get_model(paramdict) flux_new = spectres.spectres(new_spec_wavs=spectrum[:, 0], old_spec_wavs=model.wavelength, diff --git a/species/core/setup.py b/species/core/setup.py index 4b9ea9d1..d41ba409 100644 --- a/species/core/setup.py +++ b/species/core/setup.py @@ -23,7 +23,7 @@ def __init__(self): None """ - print(f'Initiating species v{species.__version__}...', end='') + print(f'Initiating species v{species.__version__}...', end='', flush=True) working_folder = os.path.abspath(os.getcwd()) @@ -33,7 +33,7 @@ def __init__(self): if not os.path.isfile(config_file): - print('Creating species_config.ini...', end='') + print('Creating species_config.ini...', end='', flush=True) with open(config_file, 'w') as file_obj: file_obj.write('[species]\n') @@ -53,12 +53,12 @@ def __init__(self): print(f'Working folder: {working_folder}') if not os.path.isfile(database_file): - print('Creating species_database.hdf5...', end='') + print('Creating species_database.hdf5...', end='', flush=True) h5_file = h5py.File(database_file, 'w') h5_file.close() print(' [DONE]') if not os.path.exists(data_folder): - print('Creating data folder...', end='') + print('Creating data folder...', end='', flush=True) os.makedirs(data_folder) print(' [DONE]') diff --git a/species/data/ames_cond.py b/species/data/ames_cond.py index b45fd274..86f38cf4 100644 --- a/species/data/ames_cond.py +++ b/species/data/ames_cond.py @@ -1,12 +1,12 @@ """ -Module for AMES-Cond atmospheric models. +Module for AMES-Cond atmospheric model spectra. """ import os import gzip import tarfile +import urllib.request -import wget import numpy as np from scipy.interpolate import interp1d @@ -16,9 +16,9 @@ def add_ames_cond(input_path, database, - wl_bound, - teff_bound, - specres): + wavel_range, + teff_range, + spec_res): """ Function for adding the AMES-Cond atmospheric models to the database. @@ -28,11 +28,11 @@ def add_ames_cond(input_path, Folder where the data is located. database : h5py._hl.files.File Database. - wl_bound : tuple(float, float) + wavel_range : tuple(float, float) Wavelength range (micron). - teff_bound : tuple(float, float), None + teff_range : tuple(float, float), None Effective temperature range (K). - specres : float + spec_res : float Spectral resolution. Returns @@ -41,9 +41,6 @@ def add_ames_cond(input_path, None """ - if not wl_bound: - wl_bound = (1e-2, 1e2) - if not os.path.exists(input_path): os.makedirs(input_path) @@ -60,16 +57,14 @@ def add_ames_cond(input_path, data_file = os.path.join(data_folder, input_file) if not os.path.isfile(data_file): - print(f'Downloading AMES-Cond model spectra {label}...', end='') - wget.download(url, out=data_file, bar=None) + print(f'Downloading AMES-Cond model spectra {label}...', end='', flush=True) + urllib.request.urlretrieve(url, data_file) print(' [DONE]') - print(f'Unpacking AMES-Cond model spectra {label}...', end='') - + print(f'Unpacking AMES-Cond model spectra {label}...', end='', flush=True) tar = tarfile.open(data_file) tar.extractall(data_folder) tar.close() - print(' [DONE]') data_folder += 'SPECTRA/' @@ -78,10 +73,10 @@ def add_ames_cond(input_path, logg = [] flux = [] - wavelength = [wl_bound[0]] + wavelength = [wavel_range[0]] - while wavelength[-1] <= wl_bound[1]: - wavelength.append(wavelength[-1] + wavelength[-1]/specres) + while wavelength[-1] <= wavel_range[1]: + wavelength.append(wavelength[-1] + wavelength[-1]/spec_res) wavelength = np.asarray(wavelength[:-1]) @@ -99,8 +94,8 @@ def add_ames_cond(input_path, if feh_val != 0.: continue - if teff_bound is not None: - if teff_val < teff_bound[0] or teff_val > teff_bound[1]: + if teff_range is not None: + if teff_val < teff_range[0] or teff_val > teff_range[1]: continue data_wavel = [] @@ -169,8 +164,8 @@ def add_ames_cond(input_path, if np.all(np.diff(data[:, 0]) < 0): raise ValueError('The wavelengths are not all sorted by increasing value.') - indices = np.where((data[:, 0] >= wl_bound[0]) & - (data[:, 0] <= wl_bound[1]))[0] + indices = np.where((data[:, 0] >= wavel_range[0]) & + (data[:, 0] <= wavel_range[1]))[0] if indices.size > 0: teff.append(teff_val) diff --git a/species/data/ames_dusty.py b/species/data/ames_dusty.py index 86f5530c..be6bf061 100644 --- a/species/data/ames_dusty.py +++ b/species/data/ames_dusty.py @@ -1,12 +1,12 @@ """ -Module for AMES-Dusty atmospheric models. +Module for AMES-Dusty atmospheric model spectra. """ import os import gzip import tarfile +import urllib.request -import wget import numpy as np from scipy.interpolate import interp1d @@ -16,9 +16,9 @@ def add_ames_dusty(input_path, database, - wl_bound, - teff_bound, - specres): + wavel_range, + teff_range, + spec_res): """ Function for adding the AMES-Dusty atmospheric models to the database. @@ -28,11 +28,11 @@ def add_ames_dusty(input_path, Folder where the data is located. database : h5py._hl.files.File Database. - wl_bound : tuple(float, float) + wavel_range : tuple(float, float) Wavelength range (micron). - teff_bound : tuple(float, float), None + teff_range : tuple(float, float), None Effective temperature range (K). - specres : float + spec_res : float Spectral resolution. Returns @@ -41,9 +41,6 @@ def add_ames_dusty(input_path, None """ - if not wl_bound: - wl_bound = (1e-2, 1e2) - if not os.path.exists(input_path): os.makedirs(input_path) @@ -60,16 +57,14 @@ def add_ames_dusty(input_path, data_file = os.path.join(data_folder, input_file) if not os.path.isfile(data_file): - print(f'Downloading AMES-Dusty model spectra {label}...', end='') - wget.download(url, out=data_file, bar=None) + print(f'Downloading AMES-Dusty model spectra {label}...', end='', flush=True) + urllib.request.urlretrieve(url, data_file) print(' [DONE]') - print(f'Unpacking AMES-Dusty model spectra {label}...', end='') - + print(f'Unpacking AMES-Dusty model spectra {label}...', end='', flush=True) tar = tarfile.open(data_file) tar.extractall(data_folder) tar.close() - print(' [DONE]') data_folder += 'SPECTRA/' @@ -78,10 +73,10 @@ def add_ames_dusty(input_path, logg = [] flux = [] - wavelength = [wl_bound[0]] + wavelength = [wavel_range[0]] - while wavelength[-1] <= wl_bound[1]: - wavelength.append(wavelength[-1] + wavelength[-1]/specres) + while wavelength[-1] <= wavel_range[1]: + wavelength.append(wavelength[-1] + wavelength[-1]/spec_res) wavelength = np.asarray(wavelength[:-1]) @@ -99,8 +94,8 @@ def add_ames_dusty(input_path, if feh_val != 0.: continue - if teff_bound is not None: - if teff_val < teff_bound[0] or teff_val > teff_bound[1]: + if teff_range is not None: + if teff_val < teff_range[0] or teff_val > teff_range[1]: continue data_wavel = [] @@ -139,8 +134,8 @@ def add_ames_dusty(input_path, if np.all(np.diff(data[:, 0]) < 0): raise ValueError('The wavelengths are not all sorted by increasing value.') - indices = np.where((data[:, 0] >= wl_bound[0]) & - (data[:, 0] <= wl_bound[1]))[0] + indices = np.where((data[:, 0] >= wavel_range[0]) & + (data[:, 0] <= wavel_range[1]))[0] if indices.size > 0: teff.append(teff_val) diff --git a/species/data/btnextgen.py b/species/data/btnextgen.py index 9d4963df..17750de9 100644 --- a/species/data/btnextgen.py +++ b/species/data/btnextgen.py @@ -1,11 +1,11 @@ """ -Module for BT-NextGen atmospheric models. +Module for BT-NextGen atmospheric model spectra. """ import os import tarfile +import urllib.request -import wget import numpy as np import pandas as pd @@ -16,9 +16,9 @@ def add_btnextgen(input_path, database, - wl_bound, - teff_bound, - specres): + wavel_range, + teff_range, + spec_res): """ Function for adding the BT-NextGen atmospheric models to the database. @@ -28,11 +28,11 @@ def add_btnextgen(input_path, Folder where the data is located. database : h5py._hl.files.File Database. - wl_bound : tuple(float, float) + wavel_range : tuple(float, float) Wavelength range (micron). - teff_bound : tuple(float, float), None + teff_range : tuple(float, float), None Effective temperature range (K). - specres : float + spec_res : float Spectral resolution. Returns @@ -41,9 +41,6 @@ def add_btnextgen(input_path, None """ - if not wl_bound: - wl_bound = (1e-2, 1e2) - if not os.path.exists(input_path): os.makedirs(input_path) @@ -65,16 +62,14 @@ def add_btnextgen(input_path, data_file = os.path.join(input_path, item) if not os.path.isfile(data_file): - print(f'Downloading BT-NextGen model spectra {labels[i]}...', end='') - wget.download(urls[i], out=data_file, bar=None) + print(f'Downloading BT-NextGen model spectra {labels[i]}...', end='', flush=True) + urllib.request.urlretrieve(urls[i], data_file) print(' [DONE]') - print(f'Unpacking BT-NextGen model spectra {labels[i]}...', end='') - + print(f'Unpacking BT-NextGen model spectra {labels[i]}...', end='', flush=True) tar = tarfile.open(data_file) tar.extractall(data_folder) tar.close() - print(' [DONE]') teff = [] @@ -82,10 +77,10 @@ def add_btnextgen(input_path, feh = [] flux = [] - wavelength = [wl_bound[0]] + wavelength = [wavel_range[0]] - while wavelength[-1] <= wl_bound[1]: - wavelength.append(wavelength[-1] + wavelength[-1]/specres) + while wavelength[-1] <= wavel_range[1]: + wavelength.append(wavelength[-1] + wavelength[-1]/spec_res) wavelength = np.asarray(wavelength[:-1]) @@ -98,16 +93,14 @@ def add_btnextgen(input_path, teff_val = float(filename[3:6])*100. - if teff_bound is not None: - - if teff_bound[0] <= teff_val <= teff_bound[1]: - teff.append(teff_val) - logg.append(float(filename[7:9])) - feh.append(float(filename[11:14])) - - else: + if teff_range is not None: + if teff_val < teff_range[0] or teff_val > teff_range[1]: continue + teff.append(teff_val) + logg.append(float(filename[7:9])) + feh.append(float(filename[11:14])) + dataf = pd.pandas.read_csv(data_folder+filename, usecols=[0, 1], names=['wavelength', 'flux'], @@ -139,8 +132,8 @@ def add_btnextgen(input_path, if np.all(np.diff(data[0, :]) < 0): raise ValueError('The wavelengths are not all sorted by increasing value.') - indices = np.where((data[0, :] >= wl_bound[0]) & - (data[0, :] <= wl_bound[1]))[0] + indices = np.where((data[0, :] >= wavel_range[0]) & + (data[0, :] <= wavel_range[1]))[0] data = data[:, indices] diff --git a/species/data/btsettl.py b/species/data/btsettl.py index 4468c6b0..bb2ff31a 100644 --- a/species/data/btsettl.py +++ b/species/data/btsettl.py @@ -1,11 +1,11 @@ """ -Module for BT-Settl atmospheric models. +Module for BT-Settl atmospheric model spectra. """ import os import tarfile +import urllib.request -import wget import numpy as np import pandas as pd @@ -16,9 +16,9 @@ def add_btsettl(input_path, database, - wl_bound, - teff_bound, - specres): + wavel_range, + teff_range, + spec_res): """ Function for adding the BT-Settl atmospheric models to the database. @@ -28,11 +28,11 @@ def add_btsettl(input_path, Folder where the data is located. database : h5py._hl.files.File Database. - wl_bound : tuple(float, float) + wavel_range : tuple(float, float) Wavelength range (micron). - teff_bound : tuple(float, float), None + teff_range : tuple(float, float), None Effective temperature range (K). - specres : float + spec_res : float Spectral resolution. Returns @@ -41,42 +41,36 @@ def add_btsettl(input_path, None """ - if not wl_bound: - wl_bound = (1e-2, 1e2) - if not os.path.exists(input_path): os.makedirs(input_path) data_folder = os.path.join(input_path, 'bt-settl/') input_file = 'BT-Settl_M-0.0_a+0.0.tar' - label = '(5.8 GB)' url = 'https://phoenix.ens-lyon.fr/Grids/BT-Settl/CIFIST2011/SPECTRA/BT-Settl_M-0.0_a+0.0.tar' data_file = os.path.join(input_path, input_file) if not os.path.isfile(data_file): - print(f'Downloading BT-Settl model spectra {label}...', end='') - wget.download(url, out=data_file, bar=None) + print('Downloading BT-Settl model spectra (5.8 GB)...', end='', flush=True) + urllib.request.urlretrieve(url, data_file) print(' [DONE]') - print(f'Unpacking BT-Settl model spectra {label}...', end='') - + print('Unpacking BT-Settl model spectra (5.8 GB)...', end='', flush=True) tar = tarfile.open(data_file) tar.extractall(data_folder) tar.close() - print(' [DONE]') teff = [] logg = [] flux = [] - wavelength = [wl_bound[0]] + wavelength = [wavel_range[0]] - while wavelength[-1] <= wl_bound[1]: - wavelength.append(wavelength[-1] + wavelength[-1]/specres) + while wavelength[-1] <= wavel_range[1]: + wavelength.append(wavelength[-1] + wavelength[-1]/spec_res) wavelength = np.asarray(wavelength[:-1]) @@ -97,8 +91,12 @@ def add_btsettl(input_path, logg_val = float(filename[9:12]) feh_val = float(filename[13:16]) - if teff_bound is not None: - if teff_val < teff_bound[0] or teff_val > teff_bound[1]: + else: + raise ValueError('The length of the filename is not compatible for reading ' + 'the parameter values.') + + if teff_range is not None: + if teff_val < teff_range[0] or teff_val > teff_range[1]: continue if feh_val != 0.: @@ -135,8 +133,8 @@ def add_btsettl(input_path, if np.all(np.diff(data[:, 0]) < 0): raise ValueError('The wavelengths are not all sorted by increasing value.') - indices = np.where((data[:, 0] >= wl_bound[0]) & - (data[:, 0] <= wl_bound[1]))[0] + indices = np.where((data[:, 0] >= wavel_range[0]) & + (data[:, 0] <= wavel_range[1]))[0] if indices.size > 0: teff.append(teff_val) @@ -160,7 +158,7 @@ def add_btsettl(input_path, wavelength, np.asarray(flux)) - data_util.write_data('bt-settl', ('teff', 'logg'), database, data_sorted) + data_util.write_data('bt-settl', ['teff', 'logg'], database, data_sorted) print_message = 'Adding BT-Settl model spectra... [DONE]' print(f'\r{print_message:<80}') diff --git a/species/data/database.py b/species/data/database.py index 66fa09ff..a2ffcc46 100644 --- a/species/data/database.py +++ b/species/data/database.py @@ -157,7 +157,7 @@ def add_filter(self, if 'filters/'+filter_name in h5_file: del h5_file['filters/'+filter_name] - print(f'Adding filter: {filter_name}...', end='') + print(f'Adding filter: {filter_name}...', end='', flush=True) if filename: data = np.loadtxt(filename) @@ -218,8 +218,8 @@ def add_isochrones(self, def add_model(self, model, wavel_range=None, + spec_res=None, teff_range=None, - spec_res=1000., data_folder=None): """ Parameters @@ -229,11 +229,15 @@ def add_model(self, 'petitcode-cool-clear', 'petitcode-cool-cloudy', 'petitcode-hot-clear', or 'petitcode-hot-cloudy'). wavel_range : tuple(float, float), None - Wavelength range (micron). + Wavelength range (micron). Not required for the DRIFT-PHOENIX and petitCODE models, in + which case the argument can be set to None. + spec_res : float, None + Spectral resolution. Not required for the DRIFT-PHOENIX and petitCODE models, in which + case the argument can be set to None. teff_range : tuple(float, float), None - Effective temperature range (K). - spec_res : float - Spectral resolution. + Effective temperature range (K). Not required for the DRIFT-PHOENIX and petitCODE + models, in which case the argument can be set to None. Setting the value to None for + the other models will add all available temperatures. data_folder : str, None Folder with input data. Only required for the petitCODE hot models which are not publically available. @@ -244,52 +248,85 @@ def add_model(self, None """ + if model in ['petitcode-hot-clear', 'petitcode-hot-cloudy'] and data_folder is None: + raise ValueError('The petitCODE hot models are not publicly available and should ' + 'be imported by setting the \'data_folder\' parameter. Please ' + 'contact Paul Mollière (molliere@mpia.de) for the model spectra.') + + if (model[0:9] == 'petitcode' or model == 'drift-phoenix') and wavel_range is not None: + warnings.warn('The \'wavel_range\' parameter is not required for the DRIFT-PHOENIX ' + 'and petitCODE model spectra because they are sampled on a fixed ' + 'wavelength grid.') + + if (model[0:9] == 'petitcode' or model == 'drift-phoenix') and spec_res is not None: + warnings.warn('The \'spec_res\' parameter is not required for the DRIFT-PHOENIX and ' + 'petitCODE model spectra because they are sampled on a fixed wavelength ' + 'grid.') + + if model in ['ames-cond', 'ames-dusty', 'bt-sett', 'bt-nextgen'] and wavel_range is None: + raise ValueError('The \'wavel_range\' should be set for the \'{model}\' models to ' + 'resample the original spectra on a fixed wavelength grid.') + + if model in ['ames-cond', 'ames-dusty', 'bt-sett', 'bt-nextgen'] and spec_res is None: + raise ValueError('The \'spec_res\' should be set for the \'{model}\' models to ' + 'resample the original spectra on a fixed wavelength grid.') + + if (model[0:9] == 'petitcode' or model == 'drift-phoenix') and teff_range is not None: + warnings.warn('The \'teff_range\' parameter is ignored for the DRIFT-PHOENIX and ' + 'petitCODE model spectra.') + + if model in ['bt-settl', 'bt-nextgen'] and teff_range is None: + warnings.warn('The temperature range is not restricted with the \'teff_range\'' + 'parameter. Therefore, adding the BT-Settl or BT-NextGen spectra ' + 'will be very slow.') + h5_file = h5py.File(self.database, 'a') if 'models' not in h5_file: h5_file.create_group('models') - if model[0:13] == 'drift-phoenix': - drift_phoenix.add_drift_phoenix(self.input_path, h5_file) - data_util.add_missing(model, ('teff', 'logg', 'feh'), h5_file) + if model == 'ames-cond': + ames_cond.add_ames_cond(self.input_path, h5_file, wavel_range, teff_range, spec_res) + data_util.add_missing(model, ['teff', 'logg'], h5_file) + + elif model == 'ames-dusty': + ames_dusty.add_ames_dusty(self.input_path, h5_file, wavel_range, teff_range, spec_res) + data_util.add_missing(model, ['teff', 'logg'], h5_file) - elif model[0:8] == 'bt-settl': + elif model == 'bt-settl': btsettl.add_btsettl(self.input_path, h5_file, wavel_range, teff_range, spec_res) - data_util.add_missing(model, ('teff', 'logg'), h5_file) + data_util.add_missing(model, ['teff', 'logg'], h5_file) - elif model[0:10] == 'bt-nextgen': + elif model == 'bt-nextgen': btnextgen.add_btnextgen(self.input_path, h5_file, wavel_range, teff_range, spec_res) - data_util.add_missing(model, ('teff', 'logg', 'feh'), h5_file) - - elif model[0:10] == 'ames-dusty': - ames_dusty.add_ames_dusty(self.input_path, h5_file, wavel_range, teff_range, spec_res) - data_util.add_missing(model, ('teff', 'logg'), h5_file) + data_util.add_missing(model, ['teff', 'logg', 'feh'], h5_file) - elif model[0:9] == 'ames-cond': - ames_cond.add_ames_cond(self.input_path, h5_file, wavel_range, teff_range, spec_res) - data_util.add_missing(model, ('teff', 'logg'), h5_file) + elif model == 'drift-phoenix': + drift_phoenix.add_drift_phoenix(self.input_path, h5_file) + data_util.add_missing(model, ['teff', 'logg', 'feh'], h5_file) - elif model[0:9] == 'ames-cond': - ames_cond.add_ames_cond(self.input_path, h5_file, wavel_range, teff_range, spec_res) - data_util.add_missing(model, ('teff', 'logg'), h5_file) + elif model == 'petitcode-cool-clear': + petitcode.add_petitcode_cool_clear(self.input_path, h5_file) + data_util.add_missing(model, ['teff', 'logg', 'feh'], h5_file) - elif model[0:20] == 'petitcode-cool-clear': - petitcode.add_petitcode_cool_clear(self.input_path, h5_file, wavel_range, teff_range, spec_res) - data_util.add_missing(model, ('teff', 'logg', 'feh'), h5_file) + elif model == 'petitcode-cool-cloudy': + petitcode.add_petitcode_cool_cloudy(self.input_path, h5_file) + data_util.add_missing(model, ['teff', 'logg', 'feh', 'fsed'], h5_file) - elif model[0:21] == 'petitcode-cool-cloudy': - petitcode.add_petitcode_cool_cloudy(self.input_path, h5_file, wavel_range, teff_range, spec_res) - data_util.add_missing(model, ('teff', 'logg', 'feh', 'fsed'), h5_file) + elif model == 'petitcode-hot-clear': + petitcode.add_petitcode_hot_clear(self.input_path, h5_file, data_folder) + data_util.add_missing(model, ['teff', 'logg', 'feh', 'co'], h5_file) - elif model[0:19] == 'petitcode-hot-clear': - petitcode.add_petitcode_hot_clear(self.input_path, h5_file, wavel_range, teff_range, - spec_res, data_folder) - data_util.add_missing(model, ('teff', 'logg', 'feh', 'co'), h5_file) + elif model == 'petitcode-hot-cloudy': + petitcode.add_petitcode_hot_cloudy(self.input_path, h5_file, data_folder) + data_util.add_missing(model, ['teff', 'logg', 'feh', 'co', 'fsed'], h5_file) - elif model[0:20] == 'petitcode-hot-cloudy': - petitcode.add_petitcode_hot_cloudy(self.input_path, h5_file, wavel_range, teff_range, - spec_res, data_folder) - data_util.add_missing(model, ('teff', 'logg', 'feh', 'co', 'fsed'), h5_file) + else: + raise ValueError(f'The {model} atmospheric model does not exist. Please choose from ' + f'\'ames-cond\', \'ames-dusty\', \'bt-settl\', \'bt-nextgen\', ' + f'\'drift-phoexnix\', \'petitcode-cool-clear\', ' + f'\'petitcode-cool-cloudy\', \'petitcode-hot-clear\', ' + f'\'petitcode-hot-cloudy\'.') h5_file.close() @@ -366,7 +403,7 @@ def add_object(self, data=data, dtype='f') - print(f'Adding object: {object_name}...', end='') + print(f'Adding object: {object_name}...', end='', flush=True) if spectrum is not None: @@ -494,7 +531,7 @@ def add_calibration(self, else: error = np.repeat(0., wavelength.size) - print(f'Adding calibration spectrum: {tag}...', end='') + print(f'Adding calibration spectrum: {tag}...', end='', flush=True) h5_file.create_dataset('spectra/calibration/'+tag, data=np.vstack((wavelength, flux, error)), @@ -650,7 +687,7 @@ def get_probable_sample(self, max_sample = samples[index_max] # print(f'Maximum probability: {max_prob:.2f}') - # print(f'Most probable sample:', end='') + # print(f'Most probable sample:', end='', flush=True) prob_sample = {} @@ -696,7 +733,7 @@ def get_median_sample(self, samples = samples[:, burnin:, :] samples = np.reshape(samples, (-1, nparam)) - # print(f'Median sample:', end='') + # print(f'Median sample:', end='', flush=True) median_sample = {} @@ -705,7 +742,7 @@ def get_median_sample(self, par_value = np.percentile(samples[:, i], 50.) median_sample[par_key] = par_value - # print(f' {par_key}={par_value:.2f}', end='') + # print(f' {par_key}={par_value:.2f}', end='', flush=True) if dset.attrs.__contains__('distance'): median_sample['distance'] = dset.attrs['distance'] @@ -735,7 +772,8 @@ def get_mcmc_spectra(self, Wavelength range (micron) or filter name. Full spectrum if set to None. spec_res : float Spectral resolution, achieved by smoothing with a Gaussian kernel. The original - wavelength points are used if set to None. + wavelength points are used if set to None. Note that this requires equally-spaced + wavelength bins. Returns ------- @@ -793,7 +831,7 @@ def get_mcmc_spectra(self, if spectrum_name == 'planck': specbox = readmodel.get_spectrum(model_param, spec_res) else: - specbox = readmodel.get_model(model_param, spec_res) + specbox = readmodel.get_model(model_param, spec_res=spec_res, smooth=True) elif spectrum_type == 'calibration': specbox = readcalib.get_spectrum(model_param) @@ -881,8 +919,8 @@ def get_object(self, object_name : str Object name in the database. filters : list(str, ) - Filter names for which the photometry is selected. All available photometry of the object - is selected if set to None. + Filter names for which the photometry is selected. All available photometry of the + object is selected if set to None. inc_phot : bool Include photometry in the box. inc_spec : bool @@ -894,7 +932,7 @@ def get_object(self, Box with the object's data. """ - print(f'Getting object: {object_name}...', end='') + print(f'Getting object: {object_name}...', end='', flush=True) h5_file = h5py.File(self.database, 'r') dset = h5_file['objects/'+object_name] diff --git a/species/data/drift_phoenix.py b/species/data/drift_phoenix.py index a488decb..0dc37a9e 100644 --- a/species/data/drift_phoenix.py +++ b/species/data/drift_phoenix.py @@ -1,11 +1,11 @@ """ -Module for DRIFT-PHOENIX atmospheric models. +Module for DRIFT-PHOENIX atmospheric model spectra. """ import os import tarfile +import urllib.request -import wget import numpy as np from species.util import data_util @@ -19,7 +19,9 @@ def add_drift_phoenix(input_path, Parameters ---------- input_path : str + Folder where the data is located. database : h5py._hl.files.File + Database. Returns ------- @@ -36,16 +38,14 @@ def add_drift_phoenix(input_path, url = 'https://people.phys.ethz.ch/~stolkert/species/drift-phoenix.tgz' if not os.path.isfile(data_file): - print('Downloading DRIFT-PHOENIX model spectra (151 MB)...', end='') - wget.download(url, out=data_file, bar=None) + print('Downloading DRIFT-PHOENIX model spectra (151 MB)...', end='', flush=True) + urllib.request.urlretrieve(url, data_file) print(' [DONE]') - print('Unpacking DRIFT-PHOENIX model spectra...', end='') - + print('Unpacking DRIFT-PHOENIX model spectra...', end='', flush=True) tar = tarfile.open(data_file) tar.extractall(input_path) tar.close() - print(' [DONE]') teff = [] diff --git a/species/data/filters.py b/species/data/filters.py index cb639de8..2daecb2b 100644 --- a/species/data/filters.py +++ b/species/data/filters.py @@ -3,8 +3,8 @@ """ import os +import urllib.request -import wget import numpy as np @@ -25,8 +25,7 @@ def download_filter(filter_id): if filter_id == 'LCO/VisAO.Ys': url = 'https://xwcl.science/magao/visao/VisAO_Ys_filter_curve.dat' - - wget.download(url, out='VisAO_Ys_filter_curve.dat', bar=None) + urllib.request.urlretrieve(url, 'VisAO_Ys_filter_curve.dat') wavelength, transmission, _, _ = np.loadtxt('VisAO_Ys_filter_curve.dat', unpack=True) @@ -37,8 +36,7 @@ def download_filter(filter_id): else: url = 'http://svo2.cab.inta-csic.es/svo/theory/fps/getdata.php?format=ascii&id='+filter_id - - wget.download(url, out='filter.dat', bar=None) + urllib.request.urlretrieve(url, 'filter.dat') if os.stat('filter.dat').st_size == 0: raise ValueError(f'Filter {filter_id} not found on the SVO Filter Profile Service.') diff --git a/species/data/irtf.py b/species/data/irtf.py index 20dfa983..c1ec1748 100644 --- a/species/data/irtf.py +++ b/species/data/irtf.py @@ -4,8 +4,8 @@ import os import tarfile +import urllib.request -import wget import numpy as np from astropy.io import fits @@ -73,10 +73,10 @@ def add_irtf(input_path, for item in sptypes: if not os.path.isfile(data_file[item]): print(f'Downloading IRTF Spectral Library - {data_type[item]}...', end='') - wget.download(url[item], out=data_file[item], bar=None) + urllib.request.urlretrieve(url[item], data_file[item]) print(' [DONE]') - print('Unpacking IRTF Spectral Library...', end='') + print('Unpacking IRTF Spectral Library...', end='', flush=True) for item in sptypes: tar = tarfile.open(data_file[item]) diff --git a/species/data/isochrones.py b/species/data/isochrones.py index 59355719..00bd0ae1 100644 --- a/species/data/isochrones.py +++ b/species/data/isochrones.py @@ -63,7 +63,7 @@ def add_baraffe(database, index_sort = np.argsort(isochrones[:, 0]) isochrones = isochrones[index_sort, :] - print(f'Adding isochrones: {tag}...', end='') + print(f'Adding isochrones: {tag}...', end='', flush=True) bytes_type = h5py.special_dtype(vlen=bytes) @@ -120,7 +120,7 @@ def add_marleau(database, logg = np.log10(1e3 * constants.GRAVITY * mass_cgs / radius_cgs**2) - print(f'Adding isochrones: {tag}...', end='') + print(f'Adding isochrones: {tag}...', end='', flush=True) isochrones = np.vstack((age, mass, teff, luminosity, logg)) isochrones = np.transpose(isochrones) diff --git a/species/data/leggett.py b/species/data/leggett.py index 7d6e9807..93cd2a69 100644 --- a/species/data/leggett.py +++ b/species/data/leggett.py @@ -3,8 +3,8 @@ """ import os +import urllib.request -import wget import h5py import numpy as np import pandas as pd @@ -37,16 +37,16 @@ def add_leggett(input_path, url2 = 'http://staff.gemini.edu/~sleggett/datafile8.txt' if not os.path.isfile(data_file1): - print('Downloading Leggett L and T Dwarf Data (88 kB)...', end='') - wget.download(url1, out=data_file1, bar=None) + print('Downloading Leggett L and T Dwarf Data (88 kB)...', end='', flush=True) + urllib.request.urlretrieve(url1, data_file1) print(' [DONE]') if not os.path.isfile(data_file2): - print('Downloading Leggett T6+ and Y Dwarf Data (44 kB)...', end='') - wget.download(url2, out=data_file2, bar=None) + print('Downloading Leggett T6+ and Y Dwarf Data (44 kB)...', end='', flush=True) + urllib.request.urlretrieve(url2, data_file2) print(' [DONE]') - print('Adding Leggett L and T Dwarf Data...', end='') + print('Adding Leggett L and T Dwarf Data...', end='', flush=True) group = 'photometry/leggett' @@ -79,7 +79,7 @@ def add_leggett(input_path, mag_w4 = np.repeat(np.nan, np.size(name)) print(' [DONE]') - print('Adding Leggett T6+ and Y Dwarf Data...', end='') + print('Adding Leggett T6+ and Y Dwarf Data...', end='', flush=True) file_io = open(data_file2, 'r') lines = file_io.readlines()[69:] diff --git a/species/data/petitcode.py b/species/data/petitcode.py index 4a2b802f..b02d8bac 100644 --- a/species/data/petitcode.py +++ b/species/data/petitcode.py @@ -1,11 +1,11 @@ """ -Module for petitCODE atmospheric models. +Module for petitCODE atmospheric model spectra. """ import os import zipfile +import urllib.request -import wget import numpy as np from species.core import constants @@ -13,10 +13,7 @@ def add_petitcode_cool_clear(input_path, - database, - wl_bound, - teff_bound, - specres): + database): """ Function for adding the petitCODE cool clear atmospheric models to the database. @@ -26,12 +23,6 @@ def add_petitcode_cool_clear(input_path, Folder where the data is located. database : h5py._hl.files.File Database. - wl_bound : tuple(float, float) - Wavelength range (micron). - teff_bound : tuple(float, float), None - Effective temperature range (K). - specres : float - Spectral resolution. Returns ------- @@ -39,26 +30,21 @@ def add_petitcode_cool_clear(input_path, None """ - if not wl_bound: - wl_bound = (1e-2, 1e2) - if not os.path.exists(input_path): os.makedirs(input_path) data_folder = os.path.join(input_path, 'linder_molliere_grid/clear/specs/') - input_file = 'linder_molliere_grid.zip' - url = 'http://mpia.de/~molliere/online_data/linder_molliere_grid.zip' - data_file = os.path.join(input_path, input_file) + data_file = os.path.join(input_path, 'linder_molliere_grid.zip') if not os.path.isfile(data_file): - print('Downloading petitCODE cool clear model spectra...', end='') - wget.download(url, out=data_file, bar=None) + print('Downloading petitCODE cool clear model spectra (3.7 GB)...', end='', flush=True) + urllib.request.urlretrieve(url, data_file) print(' [DONE]') - print('Unpacking petitCODE cool clear model spectra...', end='') + print('Unpacking petitCODE cool clear model spectra...', end='', flush=True) with zipfile.ZipFile(data_file, 'r') as zip_ref: zip_ref.extractall(input_path) @@ -102,17 +88,17 @@ def add_petitcode_cool_clear(input_path, wavelength, np.asarray(flux)) - data_util.write_data('petitcode-cool-clear', ('teff', 'logg', 'feh'), database, data_sorted) + data_util.write_data('petitcode-cool-clear', + ['teff', 'logg', 'feh'], + database, + data_sorted) print_message = 'Adding petitCODE cool clear model spectra... [DONE]' print(f'\r{print_message:<110}') def add_petitcode_cool_cloudy(input_path, - database, - wl_bound, - teff_bound, - specres): + database): """ Function for adding the petitCODE cool cloudy atmospheric models to the database. @@ -122,12 +108,6 @@ def add_petitcode_cool_cloudy(input_path, Folder where the data is located. database : h5py._hl.files.File Database. - wl_bound : tuple(float, float) - Wavelength range (micron). - teff_bound : tuple(float, float), None - Effective temperature range (K). - specres : float - Spectral resolution. Returns ------- @@ -135,26 +115,21 @@ def add_petitcode_cool_cloudy(input_path, None """ - if not wl_bound: - wl_bound = (1e-2, 1e2) - if not os.path.exists(input_path): os.makedirs(input_path) data_folder = os.path.join(input_path, 'linder_molliere_grid/cloudy/specs/') - input_file = 'linder_molliere_grid.zip' - url = 'http://mpia.de/~molliere/online_data/linder_molliere_grid.zip' - data_file = os.path.join(input_path, input_file) + data_file = os.path.join(input_path, 'linder_molliere_grid.zip') if not os.path.isfile(data_file): - print('Downloading petitCODE cool cloudy model spectra...', end='') - wget.download(url, out=data_file, bar=None) + print('Downloading petitCODE cool cloudy model spectra (3.7 GB)...', end='', flush=True) + urllib.request.urlretrieve(url, data_file) print(' [DONE]') - print('Unpacking petitCODE cool cloudy model spectra...', end='') + print('Unpacking petitCODE cool cloudy model spectra...', end='', flush=True) with zipfile.ZipFile(data_file, 'r') as zip_ref: zip_ref.extractall(input_path) @@ -200,7 +175,10 @@ def add_petitcode_cool_cloudy(input_path, wavelength, np.asarray(flux)) - data_util.write_data('petitcode-cool-cloudy', ('teff', 'logg', 'feh', 'fsed'), database, data_sorted) + data_util.write_data('petitcode-cool-cloudy', + ['teff', 'logg', 'feh', 'fsed'], + database, + data_sorted) print_message = 'Adding petitCODE cool cloudy model spectra... [DONE]' print(f'\r{print_message:<110}') @@ -208,9 +186,6 @@ def add_petitcode_cool_cloudy(input_path, def add_petitcode_hot_clear(input_path, database, - wl_bound, - teff_bound, - specres, data_folder): """ Function for adding the petitCODE hot clear atmospheric models to the database. @@ -221,12 +196,6 @@ def add_petitcode_hot_clear(input_path, Folder where the data is located. database : h5py._hl.files.File Database. - wl_bound : tuple(float, float) - Wavelength range (micron). - teff_bound : tuple(float, float), None - Effective temperature range (K). - specres : float - Spectral resolution. data_folder : str Path with input data. @@ -236,9 +205,6 @@ def add_petitcode_hot_clear(input_path, None """ - if not wl_bound: - wl_bound = (1e-2, 1e2) - if not os.path.exists(input_path): os.makedirs(input_path) @@ -279,7 +245,10 @@ def add_petitcode_hot_clear(input_path, wavelength, np.asarray(flux)) - data_util.write_data('petitcode-hot-clear', ('teff', 'logg', 'feh', 'co'), database, data_sorted) + data_util.write_data('petitcode-hot-clear', + ['teff', 'logg', 'feh', 'co'], + database, + data_sorted) print_message = 'Adding petitCODE hot clear model spectra... [DONE]' print(f'\r{print_message:<110}') @@ -287,9 +256,6 @@ def add_petitcode_hot_clear(input_path, def add_petitcode_hot_cloudy(input_path, database, - wl_bound, - teff_bound, - specres, data_folder): """ Function for adding the petitCODE hot cloudy atmospheric models to the database. @@ -300,12 +266,6 @@ def add_petitcode_hot_cloudy(input_path, Folder where the data is located. database : h5py._hl.files.File Database. - wl_bound : tuple(float, float) - Wavelength range (micron). - teff_bound : tuple(float, float), None - Effective temperature range (K). - specres : float - Spectral resolution. data_folder : str Path with input data. @@ -315,9 +275,6 @@ def add_petitcode_hot_cloudy(input_path, None """ - if not wl_bound: - wl_bound = (1e-2, 1e2) - if not os.path.exists(input_path): os.makedirs(input_path) @@ -360,7 +317,10 @@ def add_petitcode_hot_cloudy(input_path, wavelength, np.asarray(flux)) - data_util.write_data('petitcode-hot-cloudy', ('teff', 'logg', 'feh', 'co', 'fsed'), database, data_sorted) + data_util.write_data('petitcode-hot-cloudy', + ['teff', 'logg', 'feh', 'co', 'fsed'], + database, + data_sorted) print_message = 'Adding petitCODE hot cloudy model spectra... [DONE]' print(f'\r{print_message:<110}') diff --git a/species/data/queries.py b/species/data/queries.py index 9f428605..e35f5563 100644 --- a/species/data/queries.py +++ b/species/data/queries.py @@ -162,7 +162,7 @@ def get_distance(target): # search VizieR catalogs if ma.is_masked(parallax): - + for _, item in enumerate(catalogs): result = Vizier.query_object(target, catalog=item) diff --git a/species/data/spex.py b/species/data/spex.py index fb23a501..c9bcae3e 100644 --- a/species/data/spex.py +++ b/species/data/spex.py @@ -4,8 +4,8 @@ import os import warnings +import urllib.request -import wget import numpy as np from astropy.io.votable import parse_single_table @@ -45,7 +45,7 @@ def add_spex(input_path, database): xml_file = os.path.join(data_path, 'spex.xml') - wget.download(url_all, out=xml_file, bar=None) + urllib.request.urlretrieve(url_all, xml_file) table = parse_single_table(xml_file) name = table.array['name'] @@ -59,7 +59,7 @@ def add_spex(input_path, database): for i, item in enumerate(url): if twomass[i] not in unique_id: xml_file = os.path.join(data_path, twomass[i].decode('utf-8')+'.xml') - wget.download(item.decode('utf-8'), out=xml_file, bar=None) + urllib.request.urlretrieve(item.decode('utf-8'), xml_file) table = parse_single_table(xml_file) name = table.array['ID'] @@ -72,7 +72,7 @@ def add_spex(input_path, database): os.remove(xml_file) xml_file = os.path.join(data_path, name+'.xml') - wget.download(url[0].decode('utf-8'), out=xml_file, bar=None) + urllib.request.urlretrieve(url[0].decode('utf-8'), xml_file) unique_id.append(twomass[i]) diff --git a/species/data/vega.py b/species/data/vega.py index 1c19e4f0..e70e22b9 100644 --- a/species/data/vega.py +++ b/species/data/vega.py @@ -3,8 +3,8 @@ """ import os +import urllib.request -import wget import numpy as np from astropy.io import fits @@ -31,10 +31,8 @@ def add_vega(input_path, database): url = 'http://ssb.stsci.edu/cdbs/calspec/alpha_lyr_stis_008.fits' if not os.path.isfile(data_file): - print('Downloading Vega spectrum (270 kB)...', end='') - - wget.download(url, out=data_file, bar=None) - + print('Downloading Vega spectrum (270 kB)...', end='', flush=True) + urllib.request.urlretrieve(url, data_file) print(' [DONE]') if 'spectra/calibration' not in database: @@ -56,7 +54,7 @@ def add_vega(input_path, database): error_stat *= 1.e-3*1e4 # [erg s-1 cm-2 A-1] -> [W m-2 micron-1] error_sys *= 1.e-3*1e4 # [erg s-1 cm-2 A-1] -> [W m-2 micron-1] - print('Adding Vega spectrum...', end='') + print('Adding Vega spectrum...', end='', flush=True) database.create_dataset('spectra/calibration/vega', data=np.vstack((wavelength, flux, error_stat)), diff --git a/species/data/vlm_plx.py b/species/data/vlm_plx.py index bc91a6b6..c60e91c7 100644 --- a/species/data/vlm_plx.py +++ b/species/data/vlm_plx.py @@ -3,8 +3,8 @@ """ import os +import urllib.request -import wget import h5py import numpy as np @@ -36,13 +36,11 @@ def add_vlm_plx(input_path, 'Database_of_Ultracool_Parallaxes_files/vlm-plx-all.fits' if not os.path.isfile(data_file): - print('Downloading Database of Ultracool Parallaxes (307 kB)...', end='') - - wget.download(url, out=data_file, bar=None) - + print('Downloading Database of Ultracool Parallaxes (307 kB)...', end='', flush=True) + urllib.request.urlretrieve(url, data_file) print(' [DONE]') - print('Adding Database of Ultracool Parallaxes...', end='') + print('Adding Database of Ultracool Parallaxes...', end='', flush=True) group = 'photometry/vlm-plx' diff --git a/species/plot/plot_color.py b/species/plot/plot_color.py index aa4694f2..774b932e 100644 --- a/species/plot/plot_color.py +++ b/species/plot/plot_color.py @@ -80,7 +80,7 @@ def plot_color_magnitude(boxes, """ - print(f'Plotting color-magnitude diagram: {output}... ', end='') + print(f'Plotting color-magnitude diagram: {output}... ', end='', flush=True) model_color = ('#234398', '#f6a432') model_linestyle = ('-', '--', ':', '-.') @@ -401,7 +401,7 @@ def plot_color_color(boxes, None """ - print(f'Plotting color-color diagram: {output}... ', end='') + print(f'Plotting color-color diagram: {output}... ', end='', flush=True) model_color = ('#234398', '#f6a432') model_linestyle = ('-', '--', ':', '-.') diff --git a/species/plot/plot_mcmc.py b/species/plot/plot_mcmc.py index 90596f46..93038b8e 100644 --- a/species/plot/plot_mcmc.py +++ b/species/plot/plot_mcmc.py @@ -42,7 +42,7 @@ def plot_walkers(tag, None """ - print(f'Plotting walkers: {output}...', end='') + print(f'Plotting walkers: {output}...', end='', flush=True) species_db = database.Database() box = species_db.get_samples(tag) @@ -137,7 +137,7 @@ def plot_posteriors(tag, None """ - print(f'Plotting posteriors: {output}...', end='') + print(f'Plotting posteriors: {output}...', end='', flush=True) species_db = database.Database() box = species_db.get_samples(tag, burnin=burnin) @@ -229,7 +229,7 @@ def plot_photometry(tag, samples = species_db.get_mcmc_photometry(tag, burnin, filter_id) - print(f'Plotting photometry samples: {output}...', end='') + print(f'Plotting photometry samples: {output}...', end='', flush=True) fig = corner.corner(samples, labels=['Magnitude'], quantiles=[0.16, 0.5, 0.84], label_kwargs={'fontsize': 13}, show_titles=True, diff --git a/species/plot/plot_spectrum.py b/species/plot/plot_spectrum.py index 85481ecb..ba09eda3 100644 --- a/species/plot/plot_spectrum.py +++ b/species/plot/plot_spectrum.py @@ -427,7 +427,7 @@ def plot_spectrum(boxes, if filters: ax2.set_ylim(0., 1.1) - print(f'Plotting spectrum: {output}...', end='') + print(f'Plotting spectrum: {output}...', end='', flush=True) if title: if filters: diff --git a/species/read/read_model.py b/species/read/read_model.py index bac7574c..8a912762 100644 --- a/species/read/read_model.py +++ b/species/read/read_model.py @@ -10,7 +10,7 @@ import spectres import numpy as np -from scipy.interpolate import RegularGridInterpolator +from scipy.interpolate import RegularGridInterpolator, interp1d from species.analysis import photometry from species.core import box, constants @@ -141,23 +141,23 @@ def interpolate_model(self): h5_file = self.open_database() - flux = np.asarray(h5_file['models/'+self.model+'/flux']) - teff = np.asarray(h5_file['models/'+self.model+'/teff']) - logg = np.asarray(h5_file['models/'+self.model+'/logg']) + flux = np.asarray(h5_file[f'models/{self.model}/flux']) + teff = np.asarray(h5_file[f'models/{self.model}/teff']) + logg = np.asarray(h5_file[f'models/{self.model}/logg']) if self.wl_points is None: self.wl_points, self.wl_index = self.wavelength_points(h5_file) - if self.model in ('drift-phoenix', 'bt-nextgen', 'petitcode-cool-clear'): + if self.model in ['ames-cond', 'ames-dusty', 'bt-settl']: + points = (teff, logg) + flux = flux[:, :, self.wl_index] + + if self.model in ['bt-nextgen', 'drift-phoenix', 'petitcode-cool-clear']: feh = np.asarray(h5_file['models/'+self.model+'/feh']) points = (teff, logg, feh) flux = flux[:, :, :, self.wl_index] - elif self.model in ('bt-settl', 'ames-dusty', 'ames-cond'): - points = (teff, logg) - flux = flux[:, :, self.wl_index] - elif self.model == 'petitcode-cool-cloudy': feh = np.asarray(h5_file['models/petitcode-cool-cloudy/feh']) fsed = np.asarray(h5_file['models/petitcode-cool-cloudy/fsed']) @@ -191,7 +191,8 @@ def interpolate_model(self): def get_model(self, model_param, spec_res=None, - magnitude=False): + magnitude=False, + smooth=False): """ Function for extracting a model spectrum by linearly interpolating the model grid. The parameters values should lie within the boundaries of the grid points that are stored @@ -208,6 +209,11 @@ def get_model(self, magnitude : bool Normalize the spectrum with a flux calibrated spectrum of Vega and return the magnitude instead of flux density. + smooth : bool + If True, the spectral resolution is changed by smoothing with a Gaussian kernel. In + that case the original wavelength grid is maintained. Note that this requires + equally-spaced wavelength bins. If False, the spectrum is resampled by linearly + interpolating the extracted spectrum. Only used if ``spec_res`` is not None. Returns ------- @@ -227,14 +233,14 @@ def get_model(self, wl_points = self.get_wavelengths() self.wavel_range = (wl_points[0], wl_points[-1]) - if self.model in ('drift-phoenix', 'bt-nextgen', 'petitcode-cool-clear'): + if self.model in ['ames-cond', 'ames-dusty', 'bt-settl']: parameters = [model_param['teff'], - model_param['logg'], - model_param['feh']] + model_param['logg']] - elif self.model in ('bt-settl', 'ames-dusty', 'ames-cond'): + elif self.model in ['bt-nextgen', 'drift-phoenix', 'petitcode-cool-clear']: parameters = [model_param['teff'], - model_param['logg']] + model_param['logg'], + model_param['feh']] elif self.model == 'petitcode-cool-cloudy': parameters = [model_param['teff'], @@ -274,10 +280,26 @@ def get_model(self, 'the parameter values and the wavelength range are within ' 'the grid boundaries as stored in the database.') - flux = read_util.smooth_spectrum(wavelength=self.wl_points, - flux=flux, - spec_res=spec_res, - size=11) + if smooth: + flux = read_util.smooth_spectrum(wavelength=self.wl_points, + flux=flux, + spec_res=spec_res, + size=11) + + else: + wavel_resample = [self.wl_points[0]] + while wavel_resample[-1] <= self.wl_points[-1]: + wavel_resample.append(wavel_resample[-1] + wavel_resample[-1]/spec_res) + + wavel_resample = np.asarray(wavel_resample[:-1]) + + flux_interp = interp1d(self.wl_points, + flux, + kind='linear', + bounds_error=False, + fill_value=1e-100) + + flux = flux_interp(wavel_resample) if magnitude: quantity = 'magnitude' @@ -307,12 +329,17 @@ def get_model(self, is_finite = np.where(np.isfinite(flux))[0] - return box.create_box(boxtype='model', - model=self.model, - wavelength=self.wl_points[is_finite], - flux=flux[is_finite], - parameters=model_param, - quantity=quantity) + if not smooth and spec_res is not None: + wavelength = wavel_resample[is_finite] + else: + wavelength = self.wl_points[is_finite] + + return box.create_box(boxtype='model', + model=self.model, + wavelength=wavelength, + flux=flux[is_finite], + parameters=model_param, + quantity=quantity) def get_data(self, model_param): @@ -337,75 +364,106 @@ def get_data(self, wl_points, wl_index = self.wavelength_points(h5_file) - flux = np.asarray(h5_file['models/'+self.model+'/flux']) - teff = np.asarray(h5_file['models/'+self.model+'/teff']) - logg = np.asarray(h5_file['models/'+self.model+'/logg']) + flux = np.asarray(h5_file[f'models/{self.model}/flux']) + teff = np.asarray(h5_file[f'models/{self.model}/teff']) + logg = np.asarray(h5_file[f'models/{self.model}/logg']) - if self.model in ('bt-settl', 'ames-cond', 'ames-dusty'): + if self.model in ['ames-cond', 'ames-dusty', 'bt-settl']: teff_index = np.argwhere(teff == model_param['teff'])[0] - if not teff_index: + if len(teff_index) == 0: raise ValueError('Temperature value not found.') teff_index = teff_index[0] logg_index = np.argwhere(logg == model_param['logg'])[0] - if not logg_index: + if len(logg_index) == 0: raise ValueError('Surface gravity value not found.') logg_index = logg_index[0] flux = flux[teff_index, logg_index, wl_index] - elif self.model in ('drift-phoenix', 'bt-nextgen'): + elif self.model in ['bt-nextgen', 'drift-phoenix', 'petitcode-cool-clear']: feh = np.asarray(h5_file['models/'+self.model+'/feh']) teff_index = np.argwhere(teff == model_param['teff'])[0] - if not teff_index: + if len(teff_index) == 0: raise ValueError('Temperature value not found.') teff_index = teff_index[0] logg_index = np.argwhere(logg == model_param['logg'])[0] - if not logg_index: + if len(logg_index) == 0: raise ValueError('Surface gravity value not found.') logg_index = logg_index[0] feh_index = np.argwhere(feh == model_param['feh'])[0] - if not feh_index: + if len(feh_index) == 0: raise ValueError('Metallicity value not found.') feh_index = feh_index[0] flux = flux[teff_index, logg_index, feh_index, wl_index] + elif self.model == 'petitcode-cool-cloudy': + feh = np.asarray(h5_file['models/'+self.model+'/feh']) + fsed = np.asarray(h5_file['models/'+self.model+'/fsed']) + + teff_index = np.argwhere(teff == model_param['teff'])[0] + + if len(teff_index) == 0: + raise ValueError('Temperature value not found.') + + teff_index = teff_index[0] + logg_index = np.argwhere(logg == model_param['logg'])[0] + + if len(logg_index) == 0: + raise ValueError('Surface gravity value not found.') + + logg_index = logg_index[0] + feh_index = np.argwhere(feh == model_param['feh'])[0] + + if len(feh_index) == 0: + raise ValueError('Metallicity value not found.') + + feh_index = feh_index[0] + fsed_index = np.argwhere(fsed == model_param['fsed'])[0] + + if len(fsed_index) == 0: + raise ValueError('f_sed value not found.') + + fsed_index = fsed_index[0] + + flux = flux[teff_index, logg_index, feh_index, fsed_index, wl_index] + elif self.model == 'petitcode-hot-clear': feh = np.asarray(h5_file['models/'+self.model+'/feh']) co_ratio = np.asarray(h5_file['models/'+self.model+'/co']) teff_index = np.argwhere(teff == model_param['teff'])[0] - if not teff_index: + if len(teff_index) == 0: raise ValueError('Temperature value not found.') teff_index = teff_index[0] logg_index = np.argwhere(logg == model_param['logg'])[0] - if not logg_index: + if len(logg_index) == 0: raise ValueError('Surface gravity value not found.') logg_index = logg_index[0] feh_index = np.argwhere(feh == model_param['feh'])[0] - if not feh_index: + if len(feh_index) == 0: raise ValueError('Metallicity value not found.') feh_index = feh_index[0] co_index = np.argwhere(co_ratio == model_param['co'])[0] - if not co_index: + if len(co_index) == 0: raise ValueError('C/O value not found.') co_index = co_index[0] @@ -419,31 +477,31 @@ def get_data(self, teff_index = np.argwhere(teff == model_param['teff'])[0] - if not teff_index: + if len(teff_index) == 0: raise ValueError('Temperature value not found.') teff_index = teff_index[0] logg_index = np.argwhere(logg == model_param['logg'])[0] - if not logg_index: + if len(logg_index) == 0: raise ValueError('Surface gravity value not found.') logg_index = logg_index[0] feh_index = np.argwhere(feh == model_param['feh'])[0] - if not feh_index: + if len(feh_index) == 0: raise ValueError('Metallicity value not found.') feh_index = feh_index[0] co_index = np.argwhere(co_ratio == model_param['co'])[0] - if not co_index: + if len(co_index) == 0: raise ValueError('C/O value not found.') co_index = co_index[0] fsed_index = np.argwhere(fsed == model_param['fsed'])[0] - if not fsed_index: + if len(fsed_index) == 0: raise ValueError('f_sed value not found.') fsed_index = fsed_index[0] @@ -624,16 +682,31 @@ def get_points(self): h5_file = self.open_database() - teff = h5_file['models/'+self.model+'/teff'] - logg = h5_file['models/'+self.model+'/logg'] + teff = h5_file[f'models/{self.model}/teff'] + logg = h5_file[f'models/{self.model}/logg'] points['teff'] = np.asarray(teff) points['logg'] = np.asarray(logg) - if self.model in ('drift-phoenix', 'bt-nextgen'): - feh = h5_file['models/'+self.model+'/feh'] + feh_models = ['drift-phoenix', + 'bt-nextgen', + 'petitcode-cool-clear', + 'petitcode-cool-cloudy', + 'petitcode-hot-clear', + 'petitcode-hot-cloudy'] + + if self.model in feh_models: + feh = h5_file[f'models/{self.model}/feh'] points['feh'] = np.asarray(feh) + if self.model in ['petitcode-cool-cloudy', 'petitcode-hot-cloudy']: + fsed = h5_file[f'models/{self.model}/fsed'] + points['fsed'] = np.asarray(fsed) + + if self.model in ['petitcode-hot-clear', 'petitcode-hot-cloudy']: + co_ratio = h5_file[f'models/{self.model}/co'] + points['co'] = np.asarray(co_ratio) + h5_file.close() return points diff --git a/species/util/data_util.py b/species/util/data_util.py index 1f7325a2..0dfa0a1f 100644 --- a/species/util/data_util.py +++ b/species/util/data_util.py @@ -173,15 +173,19 @@ def sort_data(teff, spectrum[index_teff, index_logg, index_feh, index_co, index_fsed, :] = flux[i] if feh is None and co is None and fsed is None: - sorted_data = (teff_unique, logg_unique, wavelength, spectrum) + sorted_data = [teff_unique, logg_unique, wavelength, spectrum] + elif feh is not None and co is None and fsed is None: - sorted_data = (teff_unique, logg_unique, feh_unique, wavelength, spectrum) + sorted_data = [teff_unique, logg_unique, feh_unique, wavelength, spectrum] + elif feh is not None and co is not None and fsed is None: - sorted_data = (teff_unique, logg_unique, feh_unique, co_unique, wavelength, spectrum) + sorted_data = [teff_unique, logg_unique, feh_unique, co_unique, wavelength, spectrum] + elif feh is not None and co is None and fsed is not None: - sorted_data = (teff_unique, logg_unique, feh_unique, fsed_unique, wavelength, spectrum) + sorted_data = [teff_unique, logg_unique, feh_unique, fsed_unique, wavelength, spectrum] + else: - sorted_data = (teff_unique, logg_unique, feh_unique, co_unique, fsed_unique, wavelength, spectrum) + sorted_data = [teff_unique, logg_unique, feh_unique, co_unique, fsed_unique, wavelength, spectrum] return sorted_data diff --git a/species/util/phot_util.py b/species/util/phot_util.py index 6c224839..2ae655bf 100644 --- a/species/util/phot_util.py +++ b/species/util/phot_util.py @@ -31,7 +31,7 @@ def multi_photometry(datatype, Box with synthetic photometry. """ - print('Calculating synthetic photometry...', end='') + print('Calculating synthetic photometry...', end='', flush=True) flux = {} @@ -124,7 +124,7 @@ def get_residuals(datatype, else: res_phot = None - print('Calculating residuals...', end='') + print('Calculating residuals...', end='', flush=True) if inc_spec: wavel_range = (0.9*objectbox.spectrum[0, 0], 1.1*objectbox.spectrum[-1, 0]) @@ -135,7 +135,7 @@ def get_residuals(datatype, else: readmodel = read_model.ReadModel(spectrum, wavel_range=wavel_range) - model = readmodel.get_model(model_param=parameters, spec_res=1000.) + model = readmodel.get_model(parameters, spec_res=None) wl_new = objectbox.spectrum[:, 0] diff --git a/species/util/read_util.py b/species/util/read_util.py index 183d61cd..51b4bbf8 100644 --- a/species/util/read_util.py +++ b/species/util/read_util.py @@ -58,8 +58,8 @@ def add_luminosity(modelbox): fullspec = readmodel.get_spectrum(model_param=modelbox.parameters, spec_res=1000.) else: - readmodel = read_model.ReadModel(model=modelbox.model) - fullspec = readmodel.get_model(model_param=modelbox.parameters) + readmodel = read_model.ReadModel(modelbox.model) + fullspec = readmodel.get_model(modelbox.parameters) flux = simps(fullspec.flux, fullspec.wavelength) diff --git a/test/test_read/test_isochrone.py b/test/test_read/test_isochrone.py index b6bb0643..239c40f3 100644 --- a/test/test_read/test_isochrone.py +++ b/test/test_read/test_isochrone.py @@ -1,7 +1,7 @@ import os import shutil +import urllib.request -import wget import numpy as np import species @@ -19,7 +19,7 @@ def setup_class(self): url = 'https://phoenix.ens-lyon.fr/Grids/AMES-Cond/ISOCHRONES/' \ 'model.AMES-Cond-2000.M-0.0.NaCo.Vega' - wget.download(url, out=filename, bar=None) + urllib.request.urlretrieve(url, filename) def teardown_class(self): os.remove('species_database.hdf5') @@ -33,7 +33,11 @@ def test_species_init(self): def test_read_isochrone(self): database = species.Database() database.add_isochrones('model.AMES-Cond-2000.M-0.0.NaCo.Vega', 'ames-cond_isochrone') - database.add_model('ames-cond', teff_range=(2000., 2500)) + + database.add_model('ames-cond', + wavel_range=(1., 5.), + spec_res=100., + teff_range=(2000., 2500)) read_isochrone = species.ReadIsochrone('ames-cond_isochrone') assert read_isochrone.tag == 'ames-cond_isochrone' @@ -74,10 +78,10 @@ def test_get_color_magnitude(self): assert colormag_box.color.shape == (10, ) assert colormag_box.magnitude.shape == (10, ) - assert np.allclose(np.sum(colormag_box.color), 2.6331156719128295, + assert np.allclose(np.sum(colormag_box.color), 1.4008303791405279, rtol=self.limit, atol=0.) - assert np.allclose(np.sum(colormag_box.magnitude), 109.7461532106704, + assert np.allclose(np.sum(colormag_box.magnitude), 109.04012329375813, rtol=self.limit, atol=0.) assert np.allclose(np.sum(colormag_box.sptype), 400., @@ -96,10 +100,10 @@ def test_get_color_color(self): assert colorcolor_box.color1.shape == (10, ) assert colorcolor_box.color2.shape == (10, ) - assert np.allclose(np.sum(colorcolor_box.color1), 2.6331156719128295, + assert np.allclose(np.sum(colorcolor_box.color1), 1.4008303791405279, rtol=self.limit, atol=0.) - assert np.allclose(np.sum(colorcolor_box.color2), 3.5341201019561055, + assert np.allclose(np.sum(colorcolor_box.color2), 3.3543215260896577, rtol=self.limit, atol=0.) assert np.allclose(np.sum(colorcolor_box.sptype), 400., diff --git a/test/test_read/test_model.py b/test/test_read/test_model.py index 7560d641..b02174a8 100644 --- a/test/test_read/test_model.py +++ b/test/test_read/test_model.py @@ -25,42 +25,53 @@ def test_species_init(self): def test_read_model(self): database = species.Database() - database.add_model('ames-cond', teff_range=(2000., 2500)) + + database.add_model('ames-cond', + wavel_range=(1., 5.), + spec_res=100., + teff_range=(2000., 2500)) read_model = species.ReadModel('ames-cond') assert read_model.model == 'ames-cond' def test_get_model(self): read_model = species.ReadModel('ames-cond', filter_name='Paranal/NACO.H') - model_box = read_model.get_model(self.model_param, spec_res=100., magnitude=False) - assert np.allclose(np.sum(model_box.wavelength), 410.47345, rtol=1e-8, atol=0.) - assert np.allclose(np.sum(model_box.flux), 8.032991225624241e-12, rtol=self.limit, atol=0.) + model_box = read_model.get_model(self.model_param, + spec_res=100., + magnitude=False, + smooth=True) + + assert np.allclose(np.sum(model_box.wavelength), 45.969303, rtol=1e-8, atol=0.) + assert np.allclose(np.sum(model_box.flux), 8.282984147434914e-13, rtol=self.limit, atol=0.) - model_box = read_model.get_model(self.model_param, spec_res=100., magnitude=True) + model_box = read_model.get_model(self.model_param, + spec_res=100., + magnitude=True, + smooth=True) - assert np.allclose(np.sum(model_box.wavelength), 410.47345, rtol=1e-8, atol=0.) - assert np.allclose(np.sum(model_box.flux), 2860.100473487432, rtol=self.limit, atol=0.) + assert np.allclose(np.sum(model_box.wavelength), 45.969303, rtol=1e-8, atol=0.) + assert np.allclose(np.sum(model_box.flux), 325.94157665022743, rtol=self.limit, atol=0.) def test_get_data(self): read_model = species.ReadModel('ames-cond', filter_name='Paranal/NACO.H') model_box = read_model.get_data(self.model_param) - assert np.allclose(np.sum(model_box.wavelength), 444.07788, rtol=1e-8, atol=0.) - assert np.allclose(np.sum(model_box.flux), 8.2915255e-12, rtol=1e-8, atol=0.) + assert np.allclose(np.sum(model_box.wavelength), 47.859764, rtol=1e-8, atol=0.) + assert np.allclose(np.sum(model_box.flux), 8.396668e-13, rtol=1e-6, atol=0.) def test_get_flux(self): read_model = species.ReadModel('ames-cond', filter_name='Paranal/NACO.H') flux = read_model.get_flux(self.model_param) - assert np.allclose(flux, 3.4948402850252455e-14, rtol=self.limit, atol=0.) + assert np.allclose(flux, 3.451203668214645e-14, rtol=self.limit, atol=0.) def test_get_magnitude(self): read_model = species.ReadModel('ames-cond', filter_name='Paranal/NACO.H') magnitude = read_model.get_magnitude(self.model_param) - assert np.allclose(magnitude[0], 11.306912946044667, rtol=self.limit, atol=0.) - assert np.allclose(magnitude[1], 11.306912946044667, rtol=self.limit, atol=0.) + assert np.allclose(magnitude[0], 11.320554805593877, rtol=self.limit, atol=0.) + assert np.allclose(magnitude[1], 11.320554805593877, rtol=self.limit, atol=0.) def test_get_bounds(self): read_model = species.ReadModel('ames-cond', filter_name='Paranal/NACO.H') @@ -73,7 +84,7 @@ def test_get_wavelengths(self): read_model = species.ReadModel('ames-cond', filter_name='Paranal/NACO.H') wavelengths = read_model.get_wavelengths() - assert np.allclose(np.sum(wavelengths), 99995.52, rtol=1e-7, atol=0.) + assert np.allclose(np.sum(wavelengths), 401.2594, rtol=1e-7, atol=0.) def test_get_points(self): read_model = species.ReadModel('ames-cond', filter_name='Paranal/NACO.H')