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

Reformat model information and add link to full channel list #78

Merged
merged 20 commits into from
Jul 31, 2018

Conversation

macedo22
Copy link
Contributor

@macedo22 macedo22 commented Mar 1, 2018

No description provided.

@coveralls
Copy link

coveralls commented Mar 1, 2018

Coverage Status

Coverage remained the same at 7.957% when pulling 6dd7498 on macedo22:small-changes into 1a9c842 on ligovirgo:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 7.957% when pulling 2ba4227 on macedo22:small-changes into b55aa97 on ligovirgo:master.

except(IOError, IndexError):
numpy.savetxt(channelsFile, channels, fmt="%s")
except RuntimeError as e:
if 'latex' in str(e).lower():
Copy link
Member

Choose a reason for hiding this comment

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

@macedo22, why would latex get involved here?

Copy link
Contributor Author

@macedo22 macedo22 Mar 14, 2018

Choose a reason for hiding this comment

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

@duncanmmacleod Not sure. I am not too familiar with Latex and because this exception handling was used for saving all of the plots, I assumed it would go here too. I figured the handling was to account for characters in strings that Latex would get mad at, but it sounds like what you're saying is a Latex exception wouldn't be raised from saving channel names to a text file, as it could for images. I will remove the if/else conditional here and just have
except RuntimeError:
raise

Copy link
Member

Choose a reason for hiding this comment

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

there should be no need for any exception handling here at all, so I recommend you remove all of it, unless you understand a configuration where the file writing should be allowed to fail.

@macedo22
Copy link
Contributor Author

Hi @duncanmmacleod, I removed the error handling you requested as well as a few other things.

  1. process_channel now only iterates through the channels with a non-zero lasso coefficient
  2. The boolean clustering argument was defaulting to True before, but it is now fixed and works as expected.
  3. Non-zero channels and their lasso coefficients are now stored in a dictionary and accessed by key instead of indexed in an array.

@@ -99,20 +100,15 @@ parser.add_argument('-J', '--nproc-plot', type=int, default=None,
parser.add_argument('-o', '--output-dir', default=os.curdir,
help='output directory for plots')
parser.add_argument('-f', '--channel-file', type=os.path.abspath,
help='path for channel file')
help='path for channel file', required=True)
Copy link
Member

Choose a reason for hiding this comment

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

@macedo22, I'm not a fan of required optional arguments, since that makes no sense? Can you have a think about changing this to a positional argument if it really is required?

Copy link
Contributor Author

@macedo22 macedo22 Jun 7, 2018

Choose a reason for hiding this comment

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

@duncanmmacleod Yes, I can! I can just remove it to keep options open, as you say

@@ -128,7 +124,7 @@ psig.add_argument('-x', '--filter-padding', type=float, default=3.,
lsig = parser.add_argument_group('LASSO options')
lsig.add_argument('-a', '--alpha', default=None, type=float,
help='alpha parameter for LASSO fit')
lsig.add_argument('-C', '--cluster', default=True, type=bool,
lsig.add_argument('-C', '--cluster', default='True', type=str,
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand this change, can you explain?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@duncanmmacleod As I discovered from troubleshooting and reading more online, for some reason, boolean arguments will always be True whether you pass in True or False. There are a few different ways to work around this issue, but I found this the simplest and most readable.

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 believe it has something to do with the nature of python or parsing. It will treat any string passed as a boolean as True

Copy link
Member

Choose a reason for hiding this comment

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

in this case you want to use action='store_true' and just give the argument with a value, e.g.

lsig.add_argument('-C', '--cluster', action='store_true', 
                  help='generate clustered channel plots')

the user should then pass just --cluster to enable the clustering.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@duncanmmacleod I'm happy to change this, but our overall usage preference has been to always do clustering by default, and only turn it off if in special cases (e.g. when troubleshooting the code overall to fix bugs). If we would like to keep it as doing clustering by default without the user passing anything, is there another way you would like me to rewrite it? If you still feel this new way you proposed is best, I will make the switch.

Copy link
Member

Choose a reason for hiding this comment

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

@macedo22, you can use the opposite logic and provide something like:

lsig.add_argument('-C', '--no-cluster', action='store_true', default=False,
                  help='do not generate clustered channel plots')

I believe that one of those options using action='store_true' is better than having the user manually pass true or false on the command-line.

Copy link
Contributor Author

@macedo22 macedo22 Jun 13, 2018

Choose a reason for hiding this comment

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

@duncanmmacleod Sounds good to me. I swapped this in and tested it, so it should be good to go with this most recent commit 6dd7498.

auxdata = gooddata
flattab=Table(data = (numpy.asarray(flatdata.keys()),), names = ('Channels',))
Copy link
Member

Choose a reason for hiding this comment

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

@macedo22, please use pep8 white-spacing standards throughout.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@duncanmmacleod will do!

@macedo22
Copy link
Contributor Author

@duncanmmacleod I went ahead and put in your edits. In addition, I have swapped out LassoCV as the default process to use to find the best alpha value when none is given. Jeff and Marissa have been experimenting with information criterion, and it seems to be more useful and informative for our purposes. I replaced LassoCV with using information criterion to find the best alpha to use if none is given.

write_param('Model', 'LASSO')
write_param('Non-zero coefficients', '%d' % numpy.count_nonzero(model.coef_))
write_param('Alpha', '%g' % usedalpha)
write_param('Zero coefficients','%d (%s)' % (len(zeroedtab), "<a href= %s target='_blank'>zeroed channel list</a>" % (zerofile)))
page.p('<br /><br />%s' % df.to_html(index=True))
page.div.close()#model-info
Copy link
Member

Choose a reason for hiding this comment

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

as per pep8, please leave two spaces before inline comments:

page.div.close()  # model-info

@macedo22
Copy link
Contributor Author

macedo22 commented Jul 9, 2018

Hi @duncanmmacleod, I did an overhaul of the code in an attempt to make it more robust. The changes include:
-the large summary plots at the top are generated before the individual auxiliary channel plots
-instead of using pyplot to edit and set features of the plots, the Figure objects themselves are used
-we kept getting TimeoutErrors and LOCKERRORs, and the added config_mpl() function (https://github.com/macedo22/gwdetchar/blob/f0b615b05f456e3efc437ced6d990a3065dc3a8f/bin/gwdetchar-lasso-correlation#L94) is meant to reconfigure matplotlib to store each individual plot's tex cache in its own location, instead of them all sharing the same tex cache folder. This is to avoid two or more plots simultaneously trying to acquire lock with the shared tex cache folder. Since this was added, we are not encountering any of the above errors anymore.

@macedo22
Copy link
Contributor Author

@duncanmmacleod duncanmmacleod self-requested a review July 18, 2018 16:09
Copy link
Member

@duncanmmacleod duncanmmacleod left a comment

Choose a reason for hiding this comment

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

LGTM

return plot7, plot7_legend


if args.cluster is True:
if args.no_cluster is False:
Copy link
Member

Choose a reason for hiding this comment

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

@macedo22, by convention its normally better to use if not args.no_cluster for this (and similarly just if args.cluster for truth testing).

@duncanmmacleod
Copy link
Member

@macedo22, this looks fine to me, the CI failure is from somewhere else and is related to backwards-incompatible gwpy changes that haven't been addressed in gwdetchar yet, I'll get to it soon.

@macedo22
Copy link
Contributor Author

@duncanmmacleod Great! It seemed like the issue was in gwdetchar-scattering, but let me know if there ends up being any unanticipated compatibility issues with gwdetchar-lasso-correlation and I can address them on this branch before merge

@duncanmmacleod
Copy link
Member

@macedo22, I fixed that failure in #87, so if you can rebase your feature branch against the upstream master and force push, you should be able to get past that.

@coveralls
Copy link

coveralls commented Jul 25, 2018

Pull Request Test Coverage Report for Build 236

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 39.372%

Totals Coverage Status
Change from base Build 235: 0.0%
Covered Lines: 426
Relevant Lines: 1082

💛 - Coveralls

@macedo22
Copy link
Contributor Author

@duncanmmacleod Done and done!

@duncanmmacleod duncanmmacleod merged commit 52af2f0 into gwdetchar:master Jul 31, 2018
@macedo22 macedo22 deleted the small-changes branch August 7, 2018 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants