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 io functions related to txt file imports. #349

Merged
merged 66 commits into from
Nov 27, 2020

Conversation

vinferrer
Copy link
Collaborator

@vinferrer vinferrer commented Nov 13, 2020

Closes nothing

Proposed Changes

  • Reducing code duplicity in io.py
  • merge process_acq and process_txt into process_blueprint_items
  • Create extract_header_items function that gets the header and extracts interval, orig_units, orig_names and gives them to process_blueprint_items

Change Type

  • bugfix (+0.0.1)
  • minor (+0.1.0)
  • major (+1.0.0)
  • refactoring (no version update)
  • test (no version update)
  • infrastructure (no version update)
  • documentation (no version update)
  • other

Checklist before review

  • I added everything I wanted to add to this PR.
  • [Code or tests only] I wrote/updated the necessary docstrings.
  • [Code or tests only] I ran and passed tests locally.
  • [Documentation only] I built the docs locally.
  • My contribution is harmonious with the rest of the code: I'm not introducing repetitions.
  • My code respects the adopted style, especially linting conventions.
  • The title of this PR is explanatory on its own, enough to be understood as part of a changelog.
  • I added or indicated the right labels.
  • I added information regarding the timeline of completion for this PR.
  • Please, comment on my PR while it's a draft and give me feedback on the development!

@vinferrer vinferrer added the Refactoring Improve nonfunctional attributes label Nov 13, 2020
@vinferrer vinferrer changed the title Refractor .txt extension functions Refactor .txt extension functions Nov 13, 2020
@smoia smoia changed the title Refactor .txt extension functions Refactor io functions related to txt file imports. Nov 13, 2020
@codecov
Copy link

codecov bot commented Nov 13, 2020

Codecov Report

Merging #349 (2a8fb9c) into master (ff1456a) will decrease coverage by 0.05%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #349      +/-   ##
==========================================
- Coverage   94.85%   94.80%   -0.06%     
==========================================
  Files           8        8              
  Lines         836      808      -28     
==========================================
- Hits          793      766      -27     
+ Misses         43       42       -1     
Impacted Files Coverage Δ
phys2bids/io.py 99.27% <100.00%> (+0.48%) ⬆️
phys2bids/phys2bids.py 89.59% <100.00%> (ø)

Copy link
Collaborator

@eurunuela eurunuela left a comment

Choose a reason for hiding this comment

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

I'm happy with the changes. Thank you @vinferrer !

@vinferrer
Copy link
Collaborator Author

@smoia @tsalo

Copy link
Member

@smoia smoia left a comment

Choose a reason for hiding this comment

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

One last thing to address (either change or reply to the suggestion), but then it's ready!

phys2bids/io.py Outdated
elif interval[-1] == 'µs':
interval[0] = float(interval[0]) / 1000000
interval[-1] = 's'
elif interval[-1] == 'sec':
Copy link
Member

Choose a reason for hiding this comment

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

Let me try again.
The last moment you use interval[-1] in this function is during this if statement, to see if the value of interval[0] should be "corrected". After this if statement, interval[-1] becomes unused - from what I see, you're adding the unit s in the unit list in the hard way (coherently with your script).
For this reason, every interval[-1]='s' in this elif statement can be removed (unless you're keeping it for testing, but then please write it).
Lines 152-154 are actually superfluous. Line 152 and 154 do exactly what phys2bids.bids.bidsify_unit() does downstream, and line 153 is the same as line 156. The only change you would have to do (that is not wrong) is adding the option in line 131 for interval[-1] != 's' or interval[-1] != 'sec'. Which also makes sense for the message you're giving after in 132. It would be weird, if I know that I set up my labchart to record my sampling interval in seconds, to see that the sampling interval is not second.

You can save almost ten lines, I would do it!

@vinferrer
Copy link
Collaborator Author

Okay, now I understand. It's done

@vinferrer vinferrer requested a review from smoia November 26, 2020 15:08
phys2bids/io.py Outdated Show resolved Hide resolved
Copy link
Member

@smoia smoia left a comment

Choose a reason for hiding this comment

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

Last little suggestion, then it's going to be good on my side.

phys2bids/io.py Outdated Show resolved Hide resolved
@vinferrer vinferrer requested a review from smoia November 27, 2020 13:48
Copy link
Member

@smoia smoia left a comment

Choose a reason for hiding this comment

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

LGTM!

Great job!

@smoia
Copy link
Member

smoia commented Nov 27, 2020

(and yeah, we should find a way to avoid codeconv to protest every time)

@smoia
Copy link
Member

smoia commented Nov 27, 2020

@eurunuela if you're happy you can merge.

@eurunuela eurunuela merged commit 9e29b7a into physiopy:master Nov 27, 2020
@eurunuela
Copy link
Collaborator

Thank you @vinferrer !

@smoia
Copy link
Member

smoia commented Nov 29, 2020

🚀 PR was released in 2.3.0 🚀

@smoia smoia added the released This issue/pull request has been released. label Nov 29, 2020
@vinferrer vinferrer deleted the io_txt branch December 1, 2020 08:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Refactoring Improve nonfunctional attributes released This issue/pull request has been released.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants