Commit bd77cb6a authored by Médéric Boquien's avatar Médéric Boquien Committed by Yannick Roehlly

Remove atpy dependency

parent 19b30314
......@@ -20,11 +20,10 @@ and the best fitting model (the one with the least reduced χ²) is given.
"""
import os
import atpy
import json
import numpy as np
from itertools import product
from astropy.table import Table
from astropy.table import Table, Column
from collections import OrderedDict
from datetime import datetime
from copy import deepcopy
......@@ -184,16 +183,20 @@ class Psum(AnalysisModule):
# Read the observation table and complete it by adding error where
# none is provided and by adding the systematic deviation.
obs_table = atpy.Table(data_file, verbose=False)
if data_file[-4:] == 'fits':
obs_table = Table.read(data_file, format='fits')
elif data_file[-3:] == 'vot':
obs_table = Table.read(data_file, format='vot')
else:
obs_table = Table.read(data_file, format='ascii')
for name in filter_list:
name_err = name + '_err'
if name_err not in column_list:
if name_err not in obs_table.columns:
obs_table.add_column(name_err,
np.zeros(obs_table.data.shape),
dtype=float)
obs_table.add_column(Column(name=name_err, data=
np.zeros(np.shape(obs_table))))
else:
obs_table[name_err] = np.zeros(obs_table.data.shape)
obs_table[name_err] = np.zeros(np.shape(obs_table))
obs_table[name_err] = adjust_errors(obs_table[name],
obs_table[name_err])
......@@ -207,7 +210,7 @@ class Psum(AnalysisModule):
# on the analysed variables list + reduced_chi2, probability and
# galaxy_mass at the beginning).
comp_table = np.zeros((len(creation_modules_params),
obs_table.data.shape[0],
np.shape(obs_table)[0],
len(analysed_variables) + 3), dtype=float)
comp_table[:, :, :] = np.nan
......@@ -219,7 +222,7 @@ class Psum(AnalysisModule):
# Compute the reduced Chi-square, the galaxy mass (normalisation
# factor) and probability for each observed SEDs. Add these and
# the values for the analysed variable to the comp_table.
for obs_index in range(obs_table.data.shape[0]):
for obs_index in range(np.shape(obs_table)[0]):
obs_redshift = obs_table['redshift'][obs_index]
obs_fluxes = [obs_table[name][obs_index]
for name in filter_list]
......@@ -263,12 +266,12 @@ class Psum(AnalysisModule):
# We will save the part of the computation table corresponding to
# the model as a FITS file.
fits_table = atpy.Table()
fits_table = Table()
fits_table.table_name = "Analysis computation table"
fits_table.add_column("reduced_chi-square",
comp_table[:, obs_index, 0])
fits_table.add_column("probability",
comp_table[:, obs_index, 1])
fits_table.add_column(Column(name="reduced_chi-square",
data=comp_table[:, obs_index, 0]))
fits_table.add_column(Column(name="probability",
data=comp_table[:, obs_index, 1]))
# Find the model corresponding to the least reduced Chi-square;
# if there more than one model with the minimal chi-square value
......@@ -299,17 +302,17 @@ class Psum(AnalysisModule):
# we develop a way to serialise the SED, we should save the
# complete SED object.
if save_best_sed:
best_sed_table = atpy.Table()
best_sed_table = Table()
best_sed_table.table_name = "Best SED"
best_sed_table.add_column("wavelength",
best_sed.wavelength_grid,
"nm")
best_sed_table.add_column("fnu",
best_norm_factor
best_sed_table.add_column(Column(name="wavelength",
data=best_sed.wavelength_grid,
unit="nm"))
best_sed_table.add_column(Column(name="fnu",
data=best_norm_factor
* best_sed.fnu,
"mJy")
unit="mJy"))
best_sed_table.write(OUT_DIR + obs_name + 'bestSED.fits',
verbose=False)
format='fits')
# Write the SED modules parameters to a file
with open(OUT_DIR + obs_name + "bestSED.params", "w") as f:
f.write(json.dumps(zip(creation_modules, best_params),
......@@ -353,7 +356,7 @@ class Psum(AnalysisModule):
values = comp_table[:, obs_index, idx]
probabilities = comp_table[:, obs_index, 1]
fits_table.add_column(variable, values)
fits_table.add_column(Column(name=variable, data=values))
# We compute the Probability Density Function by binning the
# data into evenly populated bins. To estimate the binning
......@@ -428,18 +431,21 @@ class Psum(AnalysisModule):
plt.close(figure)
if save_pdf:
pdf_table = atpy.Table()
pdf_table = Table()
pdf_table.table_name = "Probability Density Function"
pdf_table.add_column("bin_start",
pdf_bin_boundaries[:-1])
pdf_table.add_column("bin_end",
pdf_bin_boundaries[1:])
pdf_table.add_column("value", pdf_values)
pdf_table.add_column("value_sigma", pdf_value_sigma)
pdf_table.add_column("probability", pdf_probs)
pdf_table.add_column("probability_sigma", pdf_prob_sigma)
pdf_table.add_column(Column(name="bin_start",
data=pdf_bin_boundaries[:-1]))
pdf_table.add_column(Column(name="bin_end",
data=pdf_bin_boundaries[1:]))
pdf_table.add_column(Column(name="value", data=pdf_values))
pdf_table.add_column(Column(name="value_sigma",
data=pdf_value_sigma))
pdf_table.add_column(Column(name="probability",
data=pdf_probs))
pdf_table.add_column(Column(name="probability_sigma",
data=pdf_prob_sigma))
pdf_table.write(OUT_DIR + obs_name + "_" + variable +
"_pdf.fits", verbose=False)
"_pdf.fits", format='fits')
if plot_pdf:
figure = plt.figure()
......@@ -464,17 +470,18 @@ class Psum(AnalysisModule):
plt.close(figure)
# Write the computation table FITS
fits_table.write(OUT_DIR + obs_name + '_comptable.fits', verbose=False)
fits_table.write(OUT_DIR + obs_name + '_comptable.fits', format='fits')
# Write the results to the fits file
result_table = atpy.Table()
result_table = Table()
result_table.table_name = "Analysis results"
result_table.add_column('id', obs_table['id'])
result_table.add_column(Column(name='id', data=obs_table['id']))
for variable in (['galaxy_mass'] + analysed_variables):
result_table.add_column(variable, results[variable])
result_table.add_column(variable + '_err',
results[variable + '_err'])
result_table.write(OUT_DIR + RESULT_FILE, verbose=False)
result_table.add_column(Column(name=variable,
data=results[variable]))
result_table.add_column(Column(name=variable + '_err',
data=results[variable + '_err']))
result_table.write(OUT_DIR + RESULT_FILE)
# Write the best SED table
out_bestsed_table = Table(zip(*out_bestsed_rows),
......
......@@ -11,7 +11,7 @@ This module reads a SED spectrum from a file.
"""
import atpy
from astropy.table import Table
from collections import OrderedDict
from . import CreationModule
......@@ -19,17 +19,13 @@ from . import CreationModule
class LoadSpecFile(CreationModule):
"""Module reading a spectrum from a file and adding it to the SED.
Note that this module uses the atpy module, which is not automatically
installed when one installs pcigale.
"""
parameter_list = OrderedDict([
("filename", (
'str',
"Name of the file to load and to add to the SED table. This "
"file must be loadable with atpy (that depends on other modules "
"being installed).",
"file must be loadable with astropy",
None
)),
("lambda_column", (
......@@ -53,7 +49,7 @@ class LoadSpecFile(CreationModule):
"""
filename = self.parameters['filename']
table = atpy.Table(filename, verbose=False)
table = Table(filename, verbose=False)
sed.add_module(self.name, self.parameters)
......
......@@ -11,7 +11,7 @@ This module reads the star formation history in a file.
"""
import atpy
from astropy.table import Table
import numpy as np
from collections import OrderedDict
from . import CreationModule
......@@ -64,7 +64,12 @@ class SfhFromFile(CreationModule):
"""
filename = self.parameters['filename']
table = atpy.Table(filename, verbose=False)
if filename[-4:] == 'fits':
table = Table.read(filename, format='fits')
elif data_file[-3:] == 'vot':
table = Table.read(filename, format='vot')
else:
table = Table.read(filename, format='ascii')
time_column_name = table.columns.keys[0]
time_grid = table[time_column_name]
......
......@@ -3,7 +3,7 @@
# Licensed under the CeCILL-v2 licence - see Licence_CeCILL_V2-en.txt
# Author: Yannick Roehlly
import atpy
from astropy.table import Table
import configobj
import pkg_resources
import pkgutil
......@@ -149,7 +149,12 @@ class Configuration(object):
filter_list = base.get_filter_list()[0]
# Finding the known filters in the data table
obs_table = atpy.Table(self.config['data_file'], verbose=False)
if self.config['data_file'][-4:] == 'fits':
obs_table = Table.read(self.config['data_file'], format='fits')
elif self.config['data_file'][-3:] == 'vot':
obs_table = Table.read(self.config['data_file'], format='votable')
else:
obs_table = Table.read(self.config['data_file'], format='ascii')
column_list = []
for column in obs_table.columns:
filter_name = column[:-4] if column.endswith('_err') else column
......
......@@ -25,8 +25,8 @@ setup(
version="0.1a",
packages=find_packages(exclude=["database_builder"]),
install_requires=['numpy', 'scipy', 'sqlalchemy', 'atpy', 'matplotlib',
'configobj', 'progressbar', 'pyfits', 'astropy'],
install_requires=['numpy', 'scipy', 'sqlalchemy', 'matplotlib',
'configobj', 'progressbar', 'astropy'],
entry_points=entry_points,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment