Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
cigale
CIGALE
Commits
030d68d6
Commit
030d68d6
authored
Feb 14, 2014
by
Yannick Roehlly
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create an utility function to read table files
parent
387c9f25
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
51 additions
and
13 deletions
+51
-13
pcigale/analysis_modules/psum.py
pcigale/analysis_modules/psum.py
+2
-4
pcigale/creation_modules/loadfile.py
pcigale/creation_modules/loadfile.py
+2
-1
pcigale/creation_modules/sfhfromfile.py
pcigale/creation_modules/sfhfromfile.py
+2
-4
pcigale/session/configuration.py
pcigale/session/configuration.py
+2
-4
pcigale/utils.py
pcigale/utils.py
+43
-0
No files found.
pcigale/analysis_modules/psum.py
View file @
030d68d6
...
...
@@ -30,6 +30,7 @@ from copy import deepcopy
from
scipy
import
stats
from
progressbar
import
ProgressBar
from
matplotlib
import
pyplot
as
plt
from
..utils
import
read_table
from
.
import
AnalysisModule
from
..creation_modules
import
get_module
from
..warehouse
import
SedWarehouse
...
...
@@ -183,10 +184,7 @@ class Psum(AnalysisModule):
# Read the observation table and complete it by adding error where
# none is provided and by adding the systematic deviation.
if
data_file
.
endswith
((
'fits'
,
'vot'
,
'xml'
)):
obs_table
=
Table
.
read
(
data_file
)
else
:
obs_table
=
Table
.
read
(
data_file
,
format
=
'ascii'
)
obs_table
=
read_table
(
data_file
)
for
name
in
filter_list
:
name_err
=
name
+
'_err'
if
name_err
not
in
column_list
:
...
...
pcigale/creation_modules/loadfile.py
View file @
030d68d6
...
...
@@ -13,6 +13,7 @@ This module reads a SED spectrum from a file.
from
astropy.table
import
Table
from
collections
import
OrderedDict
from
..utils
import
read_table
from
.
import
CreationModule
...
...
@@ -49,7 +50,7 @@ class LoadSpecFile(CreationModule):
"""
filename
=
self
.
parameters
[
'filename'
]
table
=
T
able
(
filename
,
verbose
=
False
)
table
=
read_t
able
(
filename
)
sed
.
add_module
(
self
.
name
,
self
.
parameters
)
...
...
pcigale/creation_modules/sfhfromfile.py
View file @
030d68d6
...
...
@@ -14,6 +14,7 @@ This module reads the star formation history in a file.
from
astropy.table
import
Table
import
numpy
as
np
from
collections
import
OrderedDict
from
..utils
import
read_table
from
.
import
CreationModule
...
...
@@ -64,10 +65,7 @@ class SfhFromFile(CreationModule):
"""
filename
=
self
.
parameters
[
'filename'
]
if
filename
.
endswith
((
'fits'
,
'vot'
,
'xml'
)):
table
=
Table
.
read
(
filename
)
else
:
table
=
Table
.
read
(
filename
,
format
=
'ascii'
)
table
=
read_table
(
filename
)
time_column_name
=
table
.
columns
.
keys
[
0
]
time_grid
=
table
[
time_column_name
]
...
...
pcigale/session/configuration.py
View file @
030d68d6
...
...
@@ -14,6 +14,7 @@ from glob import glob # To allow the use of glob() in "eval..."
from
textwrap
import
wrap
from
.tools
import
param_dict_combine
from
..data
import
Database
from
..utils
import
read_table
from
..
import
creation_modules
from
..
import
analysis_modules
...
...
@@ -149,10 +150,7 @@ class Configuration(object):
filter_list
=
base
.
get_filter_list
()[
0
]
# Finding the known filters in the data table
if
self
.
config
[
'data_file'
].
endswith
((
'fits'
,
'vot'
,
'xml'
)):
obs_table
=
Table
.
read
(
self
.
config
[
'data_file'
])
else
:
obs_table
=
Table
.
read
(
self
.
config
[
'data_file'
],
format
=
'ascii'
)
obs_table
=
read_table
(
self
.
config
[
'data_file'
])
column_list
=
[]
for
column
in
obs_table
.
columns
:
filter_name
=
column
[:
-
4
]
if
column
.
endswith
(
'_err'
)
else
column
...
...
pcigale/utils.py
0 → 100644
View file @
030d68d6
# -*- coding: utf-8 -*-
# Copyright (C) 2014 Yannick Roehlly
# Licensed under the CeCILL-v2 licence - see Licence_CeCILL_V2-en.txt
# Author: Yannick Roehlly
"""
Various utility function for pcigale
"""
from
astropy.table
import
Table
from
astropy.io.ascii.core
import
InconsistentTableError
def
read_table
(
file_
):
"""Read a data table using astropy
This function first tries to automatically read the table with astropy,
if that fails, it tries with the ascii format.
Parameters
----------
file_ : string
Name of the file to read.
Return
------
an astropy.table.Table object
Raise
-----
An error is raised when the table can not be parsed.
"""
try
:
table
=
Table
.
read
(
file_
)
except
Exception
:
# astropy should raise a specific exception
try
:
table
=
Table
.
read
(
file_
,
format
=
"ascii"
)
except
InconsistentTableError
:
raise
StandardError
(
"The file <{}> can not be parsed as a data "
"table."
.
format
(
file_
))
return
table
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment