Skip to content

Commit

Permalink
Fixed splatalogue functionality
Browse files Browse the repository at this point in the history
Assignment procedure works with process_splatalogue again with the new system.
  • Loading branch information
laserkelvin committed Jun 5, 2019
1 parent fb9a8fa commit d834ee5
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 63 deletions.
62 changes: 62 additions & 0 deletions pyspectools/spectra/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,68 @@ def search_center_frequency(frequency, width=0.5):
return None


def calc_line_weighting(
self, frequency, catalog_df, prox=0.00005,
abs=True, freq_col="Frequency", int_col="Intensity"
):
"""
Function for calculating the weighting factor for determining
the likely hood of an assignment. The weighting factor is
determined by the proximity of the catalog frequency to the
observed frequency, as well as the theoretical intensity if it
is available.
Parameters
----------------
frequency : float
Observed frequency in MHz
catalog_df : dataframe
Pandas dataframe containing the catalog data entries
prox: float, optional
Frequency proximity threshold
abs: bool
Specifies whether argument prox is taken as the absolute value
Returns
---------------
None
If nothing matches the frequency, returns None.
dataframe
If matches are found, calculate the weights and return the
candidates in a dataframe.
"""
if abs is False:
lower_freq = frequency * (1 - prox)
upper_freq = frequency * (1 + prox)
else:
lower_freq = frequency - prox
upper_freq = frequency + prox
sliced_catalog = catalog_df.loc[
catalog_df[freq_col].between(lower_freq, upper_freq)
]
nentries = len(sliced_catalog)
if nentries > 0:
if int_col in sliced_catalog:
column = sliced_catalog[int_col]
elif "CDMS/JPL Intensity" in sliced_catalog:
column = sliced_catalog["CDMS/JPL Intensity"]
else:
column = None
# Vectorized function for calculating the line weighting
sliced_catalog["Weighting"] = line_weighting(
frequency, sliced_catalog[freq_col], column
)
# Normalize and sort the weights only if there are more than one
# candidates
if nentries > 1:
sliced_catalog.loc[:, "Weighting"] /= sliced_catalog[
"Weighting"].max()
# Sort by obs-calc
sliced_catalog.sort_values(["Weighting"], ascending=False,
inplace=True)
sliced_catalog.reset_index(drop=True, inplace=True)
return sliced_catalog
else:
return None

def brute_harmonic_search(frequencies, maxJ=10, dev_thres=5., prefilter=False):
"""
Function that will search for possible harmonic candidates
Expand Down
64 changes: 2 additions & 62 deletions pyspectools/spectra/assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,7 @@ def process_splatalogue(self, auto=True, progressbar=True):
splat_df.drop(index, inplace=True)
nitems = len(splat_df)

splat_df = self.calc_line_weighting(
splat_df = analysis.calc_line_weighting(
frequency, splat_df, prox=self.session.freq_prox, abs=self.session.freq_abs
)
if splat_df is not None:
Expand Down Expand Up @@ -1014,7 +1014,7 @@ def process_splatalogue(self, auto=True, progressbar=True):
"deviation": frequency - ass_df["Frequency"][0]
}
# Update the Transition entry
uline.update(**ass_dict)
uline.__dict__.update(**ass_dict)
except ValueError:
# If nothing matches, keep in the U-line
# pile.
Expand All @@ -1024,66 +1024,6 @@ def process_splatalogue(self, auto=True, progressbar=True):
self.logger.info("No species known for {:,.4f}".format(frequency))
self.logger.info("Splatalogue search finished.")

def calc_line_weighting(
self, frequency, catalog_df, prox=0.00005,
abs=True, freq_col="Frequency", int_col="Intensity"
):
"""
Function for calculating the weighting factor for determining
the likely hood of an assignment. The weighting factor is
determined by the proximity of the catalog frequency to the
observed frequency, as well as the theoretical intensity if it
is available.
Parameters
----------------
frequency : float
Observed frequency in MHz
catalog_df : dataframe
Pandas dataframe containing the catalog data entries
prox: float, optional
Frequency proximity threshold
abs: bool
Specifies whether argument prox is taken as the absolute value
Returns
---------------
None
If nothing matches the frequency, returns None.
dataframe
If matches are found, calculate the weights and return the candidates in a dataframe.
"""
if abs is False:
lower_freq = frequency * (1 - prox)
upper_freq = frequency * (1 + prox)
else:
lower_freq = frequency - prox
upper_freq = frequency + prox
sliced_catalog = catalog_df.loc[
catalog_df[freq_col].between(lower_freq, upper_freq)
]
nentries = len(sliced_catalog)
if nentries > 0:
if int_col in sliced_catalog:
column = sliced_catalog[int_col]
elif "CDMS/JPL Intensity" in sliced_catalog:
column = sliced_catalog["CDMS/JPL Intensity"]
else:
column = None
# Vectorized function for calculating the line weighting
sliced_catalog["Weighting"] = analysis.line_weighting(
frequency, sliced_catalog[freq_col], column
)
# Normalize and sort the weights only if there are more than one candidates
if nentries > 1:
sliced_catalog.loc[:, "Weighting"] /= sliced_catalog["Weighting"].max()
# Sort by obs-calc
sliced_catalog.sort_values(["Weighting"], ascending=False, inplace=True)
sliced_catalog.reset_index(drop=True, inplace=True)
return sliced_catalog
else:
return None

def process_linelist(self, name=None, formula=None, filepath=None, linelist=None, auto=True, thres=-10.,
progressbar=True, tol=None, **kwargs,):
"""
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def run(self):

setup(
name="pyspectools",
version="4.0.1",
version="4.0.2",
description="A set of Python tools/routines for spectroscopy",
author="Kelvin Lee",
packages=find_packages(),
Expand Down

0 comments on commit d834ee5

Please sign in to comment.