Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor of LineList tables #409

Merged
merged 24 commits into from
Sep 15, 2017
Merged

Refactor of LineList tables #409

merged 24 commits into from
Sep 15, 2017

Conversation

profxj
Copy link
Contributor

@profxj profxj commented Sep 6, 2017

This started as a branch to convert fk5 coords to icrs (fk5 only
uses float32 precision!) and became a refactor of LineList tables.

I also sped up some of the methods.

Note that I've turned off the 'extra' columns as the default
when initializing LineList but I can be convinced to have
this be on by default.

I imagine there will be some issues raised in pyigm and/or GUIs.

Copy link
Collaborator

@jnburchett jnburchett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There appear to be some recurring bugs dealing with calls to LineList._data, and I suspect these are symptomatic of a data table error that will rear its ugly head in several applications (e.g., instantiating AbsLines, AbsComponents, etc.)

@@ -37,6 +37,7 @@ def ion_name(ion, flg=0, nspace=None):
-------

"""
import pdb; pdb.set_trace()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why drop into the debugger here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this method is now deprecated. I could just remove it I guess.

Just did.

@@ -103,7 +103,7 @@ def gaussian_ew(spec, ltype, initial_guesses=None):
# Use only good values (i.e. with meaningful errors)
cond = (sig > 0.) & (np.isfinite(sig))
# Actual fit
g = fit_g(g_init, wv[cond], fx[cond], weights=1./sig[cond])
g = fit_g(g_init, wv[cond].value, fx[cond].value, weights=1./sig[cond].value)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 65: I think this function is actually tested through test_gaussew_absline

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It isn't passing astropy 2.0.1 without this change.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, my comment should have been inserted much higher and has nothing to do with your committed change. I was referring to your comment just below the docstring: "Note: Tested in test_absline_anly"

@@ -593,48 +621,46 @@ def all_transitions(self, line):
if line == 'unknown':
return self.unknown_line()
if self.list in ['H2']:

cond = self._data['ion_name'] == line.split('(')[0]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the self._data['ion_name'] does not exist. Should be self._data['name'].

else: # this should be always len(tbl)==1 because Z is not None
return self.from_table_to_dict(tbl)
else:
indices = np.where(self._data['ion_name'] == line)[0]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above also: self._data['ion_name'] does not exist; should be self._data['name']. Calling, e.g., LineList.all_transitions('HI') fails currently. However, it appears that self._data['ion_name'] is set in LineList. set_extra_columns_to_datatable()? Either way, all_transitions() doesn't work with or without 'extras'.


def strongest_transitions(self, line, wvlims, n_max=3, verbose=False):
""" Find the strongest transition for an ion
def strongest_transitions(self, line, wvlims, n_max=3, verbose=False,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method doesn't work either, also due to _data['ion_name'] KeyError.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comment below

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works as expected now.

@profxj
Copy link
Contributor Author

profxj commented Sep 6, 2017

Several of the methods in LineList(), e.g. all_transitions
require that the set_extra_columns_to_datatable() has been run.

Previously, this was the default but I've turned that off. This will
give folks trouble, I suppose. And, as I think more carefully, I really
don't like adding these extra columns. Better to carry around a
separate table. Giving that a try now @jnburchett and @ntejos

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 7a77e02 on fk5_refactor into ** on master**.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling e7d3c9d on fk5_refactor into ** on master**.

@jnburchett
Copy link
Collaborator

This guy ready to look at again?

@profxj
Copy link
Contributor Author

profxj commented Sep 7, 2017

yes, please

Copy link
Collaborator

@jnburchett jnburchett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good news: available_transitions, all_transitions, etc., seem to be working well now that the table keys are straightened out.

I spot checked a few VP fits with joebvp, which accesses atomic data through linetools, and all seems to be well there.

Bad news: I tested igmguesses and some odd behavior is now occurring. For one, when I start up igmguesses, the gui shows an odd assortment of lines in the various panels (beginning with MgI and PbII). When I switch to the 'strong' linelist with the 'T' key, I then get the normal suite of lines I usually see starting with Ly-alpha. Things get weirder when I try to add a component, as the list of added components shows the wrong ion!

I suspect that @ntejos will be able to track down the source of the problem fairly easily. Lines 240-262 of pyigm.guis.igmguesses initialize the linelists to be used by igmguesses and 311 and 326-355 set the list for use.


def strongest_transitions(self, line, wvlims, n_max=3, verbose=False):
""" Find the strongest transition for an ion
def strongest_transitions(self, line, wvlims, n_max=3, verbose=False,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works as expected now.

@@ -103,7 +103,7 @@ def gaussian_ew(spec, ltype, initial_guesses=None):
# Use only good values (i.e. with meaningful errors)
cond = (sig > 0.) & (np.isfinite(sig))
# Actual fit
g = fit_g(g_init, wv[cond], fx[cond], weights=1./sig[cond])
g = fit_g(g_init, wv[cond].value, fx[cond].value, weights=1./sig[cond].value)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, my comment should have been inserted much higher and has nothing to do with your committed change. I was referring to your comment just below the docstring: "Note: Tested in test_absline_anly"

@profxj
Copy link
Contributor Author

profxj commented Sep 8, 2017

I am pretty sure the changes to igmguesses will be straightforward enough.
And I'm happy doing them. I just don't want to do so until @ntejos indicates
he is ok with the overall refactoring.

@ntejos
Copy link
Contributor

ntejos commented Sep 8, 2017

I'm aware of this, but I may need some extra time before I can start looking closer (still traveling). Regarding igmguesses, we can leave that for the very end and I agree changes there will be relatively easy.

Copy link
Contributor

@ntejos ntejos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good, specially the handling of available transitions and (hopefully) strongest transitions, if my "head compilation" was done right the later may need extra work to ensure the original sortening. Left some comments for your consideration...

@@ -359,12 +359,15 @@ def add_abslines_from_linelist(self, llist='ISM', init_name=None, wvlim=None, mi

# unify output to be always QTable
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update inline comment QTable -> Table

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

@@ -65,7 +67,7 @@ class LineList(object):
sort_by : str or list of str, optional
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove use_ISM_table from docstring as it is removed below from code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checked that the docs (linelist.rst) is up to date too

data_file = resource_filename('linetools', 'data/lines/linelist.ascii')
# Read
self._fulltable = Table.read(data_file, format='ascii.ecsv')

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thus, we are not making the table from scratch anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct.

@@ -247,21 +260,25 @@ def set_lines(self, verbose=True, use_cache=True, use_ISM_table=True):
use_ISM_table : bool, optional
For speed, use a saved ISM table instead of reading from original source files.
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove use_ISM_table as it seems is not used anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

return

if self.list not in ['HI', 'ISM', 'EUV', 'Strong', 'H2']:
warnings.warn('Not implemented: will not set relative strength for LineList: {}.'.format(self.list))
return

# Set ion_name column
ion_name = np.array([' '*20]*len(self.name)).astype(str)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may be a good time to set up a naming convention that is valid for atoms and molecules alike? Instead of having different ones as currently.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, I'm not sure we have a convention at all.
Only 2 different prescriptions to generate them.

It might be good to have one method that does them.
But I think we are ok for now.

@@ -912,51 +933,123 @@ def update_wrest(table, verbose=True):
table['Ek'][mt[0]] = 52330.33 / u.cm
'''
#
def load_datasets(datasets, tol=1e-3, use_cache=True):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make tol lower? 1e-4?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would require quite a bit of fussing.
Let's stick with 1e-3 for now.


Parameters
----------
use_ISM_table : bool, optional
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove use_ISM_table from docstring

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed


Parameters
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

define datasets in docstring

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

def test_ism_read_source_catalogues():
ism = LineList('ISM', use_ISM_table=False)
ism = LineList('ISM')#, use_ISM_table=False)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove for good

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

#with pytest.raises(ValueError) as tmp: # This is failing Python 2.7 for reasons unbenknownst to me
# ism.set_extra_columns_to_datatable(abundance_type='incorrect_one')
#ism = LineList('ISM')
#with pytest.raises(ValueError):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do we test for expected errors now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fussed with this for quite awhile. I can't
get it to work on 2.7 (it is fine on 3.6).

…tools/linetools into fk5_refactor

# Conflicts:
#	linetools/isgm/abssystem.py
#	linetools/scripts/lt_xabssys.py
@profxj
Copy link
Contributor Author

profxj commented Sep 12, 2017

@ntejos , @jnburchett -- I think we are there (but let's see if this
passes Travis).

Am going to fuss with igmguesses to make sure that works.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling fe60a20 on fk5_refactor into ** on master**.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling fe60a20 on fk5_refactor into ** on master**.

@profxj
Copy link
Contributor Author

profxj commented Sep 13, 2017

@jnburchett -- if you are happy and you know it, approve this PR.

Thanks.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling bf9d89e on fk5_refactor into ** on master**.

@jnburchett
Copy link
Collaborator

Tested IGMguesses and problems seem to have been fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants