-
Notifications
You must be signed in to change notification settings - Fork 25
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
Export data with TXTExport into single file #628
Conversation
Update tests to check new TXTExport
Update tests for new TXTExport
Update tests for new TXTExport
Black format
Black format
Black format
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.
Hey @KulaginVladimir Congrats on your first PR 🚀. It looks great so far, just some minor refactoring things from me. I think @RemDelaporteMathurin has some comments to make too, just to potentially simplify things. Otherwise welcome! Thanks for the contribution, should be able to get this through soon without too much modification
festim/exports/txt_export.py
Outdated
else: | ||
return True if np.isclose(self.times[0], current_time) else False | ||
|
||
def write(self, current_time, nb_iteration, steady): |
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.
Could do with some doc strings here
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.
That's partly on us but yes I agree!
test/system/test_misc.py
Outdated
def test_txt_export_desired_times(tmp_path): | ||
""" | ||
Tests that TXTExport can be exported at all timesteps | ||
""" | ||
my_model = F.Simulation() | ||
|
||
my_model.mesh = F.MeshFromVertices(np.linspace(0, 1)) | ||
my_model.materials = F.Material(1, 1, 0) | ||
my_model.settings = F.Settings(1e-10, 1e-10, final_time=1) | ||
my_model.T = F.Temperature(500) | ||
my_model.dt = F.Stepsize(0.1) | ||
|
||
my_export = F.TXTExport( | ||
"solute", label="mobile_conc", times=[0.2, 0.5], folder=tmp_path | ||
) | ||
my_model.exports = [my_export] | ||
|
||
my_model.initialise() | ||
my_model.run() |
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 a way to test the export without having to make a system test? but I'm not sure on this
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.
There must be a way to just call write()
but I don't know if it's worth it, this does the trick
@@ -105,3 +123,33 @@ def test_there_is_a_next_time(self, my_export): | |||
def test_last(self, my_export): | |||
assert my_export.when_is_next_time(3) is None | |||
assert my_export.when_is_next_time(4) is None | |||
|
|||
|
|||
class TestIsItFirstTimeToExport: |
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.
Could do with some doc strings here
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.
Kinda hard to document a test class, you can document the test functions however.
Co-authored-by: Rémi Delaporte-Mathurin <[email protected]>
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.
Hi @KulaginVladimir thanks for this PR! First of many I hope! 🎉
This is a very good quality of life feature!
I have a few comments, the main one being refactoring this by replacing the is_first_time_to_export
method by a class attribute.
I'll make another PR to your branch that you can then merge to add the changes here ( ie no need to close this PR and make a new one).
festim/exports/txt_export.py
Outdated
else: | ||
return True if np.isclose(self.times[0], current_time) else False | ||
|
||
def write(self, current_time, nb_iteration, steady): |
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.
That's partly on us but yes I agree!
test/system/test_misc.py
Outdated
def test_txt_export_desired_times(tmp_path): | ||
""" | ||
Tests that TXTExport can be exported at all timesteps | ||
""" | ||
my_model = F.Simulation() | ||
|
||
my_model.mesh = F.MeshFromVertices(np.linspace(0, 1)) | ||
my_model.materials = F.Material(1, 1, 0) | ||
my_model.settings = F.Settings(1e-10, 1e-10, final_time=1) | ||
my_model.T = F.Temperature(500) | ||
my_model.dt = F.Stepsize(0.1) | ||
|
||
my_export = F.TXTExport( | ||
"solute", label="mobile_conc", times=[0.2, 0.5], folder=tmp_path | ||
) | ||
my_model.exports = [my_export] | ||
|
||
my_model.initialise() | ||
my_model.run() |
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.
There must be a way to just call write()
but I don't know if it's worth it, this does the trick
@@ -105,3 +123,33 @@ def test_there_is_a_next_time(self, my_export): | |||
def test_last(self, my_export): | |||
assert my_export.when_is_next_time(3) is None | |||
assert my_export.when_is_next_time(4) is None | |||
|
|||
|
|||
class TestIsItFirstTimeToExport: |
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.
Kinda hard to document a test class, you can document the test functions however.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #628 +/- ##
=======================================
Coverage 98.90% 98.91%
=======================================
Files 56 56
Lines 2096 2111 +15
=======================================
+ Hits 2073 2088 +15
Misses 23 23
☔ View full report in Codecov by Sentry. |
Txt export refac
Updated comments
Filename as class property
Filename for TXTExport
single filename for TXTExport
Typo x2
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.
Yay this looks good to me! There are just a few formatting errors like whitespaces and line-length, etc.
I've suggested a couple but there are more (see the linting check failing)
It is super easy to format your code, just run:
python -m black .
This will run the black formatter on all the files and make sure they are correctly formatted.
If you don't have black installed, you can install it with pip.
Co-authored-by: Rémi Delaporte-Mathurin <[email protected]>
Co-authored-by: Rémi Delaporte-Mathurin <[email protected]>
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.
Looks good to me! Congrats @KulaginVladimir on your first PR! 🎉 🚀
Feel free to join the FESTIM slack channel where we discuss about development, but also user support.
On another note, tell me if I'm wrong but by the look of your commit messages, it looks like you made the code modifications directly in github.com?
If that's so, for next time, I think it would be easier for you to clone the repository locally, do the changes, then commit and push the changes to your remote repository on github.com
It will give you more control of what you are doing and it's good practice in general.
If you are still interested in contributing to FESTIM, don't hesitate to take a look at issues tagged with "Good first issues". These are issues that can be easily fixed and that we usually leave open for newcomers!
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.
Looks great to me
Proposed changes
This PR modifies
TXTExport
according to #623.For steady-state simulations, it produces 'FileLabel_steady.txt' with header: 'x,t=steady' in it. For transient simulations, it produces 'FileLabel_transient.txt' with header: 'x,t=Time[0]s,t=Time[1]s,..' where T corresponds either to
times
passed toTXTExport
or all timesteps, iftimes is None
.I also modified previous tests to catch the updated
TXTExport
and added some new.Types of changes
What types of changes does your code introduce to FESTIM?
Checklist