Commit 6e3c22b6 authored by Médéric Boquien's avatar Médéric Boquien
Browse files

To verify whether a variable is among the keys of a dictionary there is...

To verify whether a variable is among the keys of a dictionary there is actually no need to call the keys() function. A dictionary has a __contains__() member which is called when the “in” keyword is used.
parent 380b7c96
......@@ -95,7 +95,7 @@ class Casey2012(CreationModule):
sed: pcigale.sed.SED object
"""
if 'dust.luminosity' not in sed.info.keys():
if 'dust.luminosity' not in sed.info:
sed.add_info('dust.luminosity', 1., True)
luminosity = sed.info['dust.luminosity']
......
......@@ -80,7 +80,7 @@ class Dale2014(CreationModule):
parameters: dictionary containing the parameters
"""
if 'dust.luminosity' not in sed.info.keys():
if 'dust.luminosity' not in sed.info:
sed.add_info('dust.luminosity', 1., True)
luminosity = sed.info['dust.luminosity']
......
......@@ -104,7 +104,7 @@ class DL2007(CreationModule):
parameters: dictionary containing the parameters
"""
if 'dust.luminosity' not in sed.info.keys():
if 'dust.luminosity' not in sed.info:
sed.add_info('dust.luminosity', 1., True)
luminosity = sed.info['dust.luminosity']
......
......@@ -108,7 +108,7 @@ class DL2014(CreationModule):
parameters: dictionary containing the parameters
"""
if 'dust.luminosity' not in sed.info.keys():
if 'dust.luminosity' not in sed.info:
sed.add_info('dust.luminosity', 1., True)
luminosity = sed.info['dust.luminosity']
......
......@@ -117,7 +117,7 @@ class Fritz2006(CreationModule):
"""
if 'dust.luminosity' not in sed.info.keys():
if 'dust.luminosity' not in sed.info:
sed.add_info('dust.luminosity', 1., True)
luminosity = sed.info['dust.luminosity']
......
......@@ -98,7 +98,7 @@ class MBB(CreationModule):
sed: pcigale.sed.SED object
"""
if 'dust.luminosity' not in sed.info.keys():
if 'dust.luminosity' not in sed.info:
sed.add_info('dust.luminosity', 1., True)
luminosity = sed.info['dust.luminosity']
......
......@@ -78,7 +78,7 @@ class Radio(CreationModule):
sed: pcigale.sed.SED object
"""
if 'dust.luminosity' not in sed.info.keys():
if 'dust.luminosity' not in sed.info:
sed.add_info('dust.luminosity', 1., True)
luminosity = sed.info['dust.luminosity']
......
......@@ -179,7 +179,7 @@ class Redshifting(CreationModule):
redshift = self.redshift
# If the SED is already redshifted, raise an error.
if 'redshift' in sed.info.keys() and sed.info['redshift'] > 0.:
if 'redshift' in sed.info and sed.info['redshift'] > 0.:
raise Exception("The SED is already redshifted <z={}>."
.format(sed.info['redshift']))
......@@ -207,7 +207,7 @@ class Redshifting(CreationModule):
# This is the case for instance if some but not all models have an AGN
# fraction of 0.
key = sed.wavelength_grid.size
if key not in self.igm_attenuation.keys():
if key not in self.igm_attenuation:
self.igm_attenuation[key] = igm_transmission(sed.wavelength_grid,
redshift) - 1.
sed.add_contribution('igm', sed.wavelength_grid,
......
......@@ -315,7 +315,7 @@ class SED(object):
l_lambda_r = np.interp(wavelength_r, wavelength, self.luminosity)
if 'universe.luminosity_distance' in self.info.keys():
if 'universe.luminosity_distance' in self.info:
dist = self.info['universe.luminosity_distance']
else:
dist = 10. * parsec
......
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