-
Notifications
You must be signed in to change notification settings - Fork 208
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
plot bands with only one kpoint #3798
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @unkcpz for looking into this issue.
Would it be possible to add a test for this to make sure this issue does not come back?
E.g. here:
def test_bandsexport(self): |
Sure I will add test. Now, it serves as an attempt to address the problem, I'll perfect solution for mpl plot and gnuplot both. |
1308fe4
to
637f826
Compare
2a71e34
to
610db31
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @unkcpz !
I've had a quick look through and have some comments
aiida/orm/nodes/data/array/bands.py
Outdated
@@ -825,7 +825,10 @@ def _prepare_mpl_singlefile(self, *args, **kwargs): | |||
|
|||
s_header = matplotlib_header_template.substitute() | |||
s_import = matplotlib_import_data_inline_template.substitute(all_data_json=json.dumps(all_data, indent=2)) | |||
s_body = matplotlib_body_template.substitute() | |||
if len(all_data['paths']) == 1: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seem to me that _prepare_mpl_singlefile
could simply be reusing _prepare_mpl_withjson
in order to avoid code duplication. Is this correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, these two can be combined. I'll try.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried, however, each of _prepare_mpl_*
function is similar but slightly different. I can't think of a better way to combine them at the moment. Using a lone template string and leave all optional string as arguments seems like not a good idea.
@@ -1074,6 +985,115 @@ def show_mpl(self, **kwargs): | |||
""" | |||
exec(*self._exportcontent(fileformat='mpl_singlefile', main_file_name='', **kwargs)) # pylint: disable=exec-used | |||
|
|||
def _prepare_gnuplot(self, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason why you moved _prepare_gnuplot
down in the file?
That makes it harder to spot the changes you made in review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just move all prepare_mpl_*
functions together. _prepare_gnuplot
was inserted in the middle of these _mpl*
functions. I'll move it back for your review, if necessary I'll move mpl functions together at the end.
b664f93
to
d6d7b76
Compare
@unkcpz Just merged the other PR, I guess now it makes sense to continue work on this. |
Codecov Report
@@ Coverage Diff @@
## develop #3798 +/- ##
===========================================
+ Coverage 78.18% 78.20% +0.02%
===========================================
Files 460 460
Lines 33971 33982 +11
===========================================
+ Hits 26559 26575 +16
+ Misses 7412 7407 -5
Continue to review full report at Codecov.
|
@ltalirz Seems working now:smile: After your review, I suggest to move all |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @unkcpz !
Looks good to me, just a few minor comments & requests.
Good to merge afterwards; also feel free to move the functions to the appropriate place now.
tests/cmdline/commands/test_data.py
Outdated
@@ -343,6 +343,31 @@ def test_bandsexport(self): | |||
self.assertEqual(res.exit_code, 0, 'The command did not finish correctly') | |||
self.assertIn(b'[1.0, 3.0]', res.stdout_bytes, 'The string [1.0, 3.0] was not found in the bands' 'export') | |||
|
|||
def test_bandsexport_single_kp(self): | |||
""" | |||
test for issue #2462: plot band on single kpoint case |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test for issue #2462: plot band on single kpoint case | |
Plot band for single k-point (issue #2462). |
tests/cmdline/commands/test_data.py
Outdated
self.cli_runner.invoke(cmd_bands.bands_export, options, catch_exceptions=False) | ||
with open('bands.gnu', 'r') as gnu_file: | ||
res = gnu_file.read() | ||
self.assertIn('vectors nohead', res, 'The string vectors nohead was not found in the gnuplot script') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.assertIn('vectors nohead', res, 'The string vectors nohead was not found in the gnuplot script') | |
self.assertIn('vectors nohead', res, 'The string "vectors nohead" was not found in the gnuplot script') |
aiida/orm/nodes/data/array/bands.py
Outdated
@@ -885,7 +891,10 @@ def _prepare_gnuplot(self, | |||
""" | |||
import os | |||
|
|||
dat_filename = os.path.splitext(main_file_name)[0] + '_data.dat' | |||
if main_file_name is not None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By the way, the default seems to be ''
rather than None
I suggest to change the default of the function argument to None
, and then:
if not main_file_name: # also catches '', just to be safe
main_file_name = 'band.dat' # not sure what a reasonable default is
dat_filename = os.path.splitext(main_file_name)[0] + '_data.dat'
Or even shorter, if you like:
main_file_name = main_file_name or 'band.dat'
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the default filename is not important here, in fact it is not used. Default filename is only used when export gnuplot without specify the extra_file with -o
, if that happened it will throw a command line critical information. Here the file_name is only to make sure os.path.splitext
is working and throw the right Critical information to user.
f01760f
to
68621fc
Compare
Thanks for review! @ltalirz |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, let's go!
Fix #2462 : Support plotting
BandsData
instances with a single kpoint.