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

MRG: Extract measurement date and age for NIRX files #7891

Merged
merged 8 commits into from
Sep 9, 2020

Conversation

rob-luke
Copy link
Member

What does this implement/fix?

Extract measurement date and birthday for NIRX files.

Additional information

The vendor software only allows saving of age as an integer. So I have taken the measurement date, subtracted the age integer from the years, and stored that as the birthday. Open to alternative suggestions.

@rob-luke
Copy link
Member Author

@larsoner this is failing due to processing of French date strings. Is there any inbuilt multilingual date string parsers in MNE already or do I need to write one?

@rob-luke
Copy link
Member Author

HHmmmm my changes also seem to break other things, Ill fix that. But still curious about the best way to process French dates.

@agramfort
Copy link
Member

what do you mean French dates? like month with letter with accents?

@larsoner
Copy link
Member

Like Travis says:

ValueError: time data '"jeu. 13 févr. 2020""09:08:47.511"' does not match format '"%a, %b %d, %Y""%H:%M:%S.%f"'

@agramfort
Copy link
Member

agramfort commented Jun 12, 2020 via email

@larsoner
Copy link
Member

The docs suggest that locale is used, so indeed if the locale can be extracted from the file header, then we can make a @contextlib.contextmanager to orig = locale.set_locale(locale.LC_something, whatever) and then set_locale(locale.LC_something, orig) afterward. Even if it isn't embedded in the header (which would be sad), we could start making a list of ones to iterate over and try, and always add others later if need be. (Or maybe it won't be so bad to iterate over all of them, if we can get a list?)

@rob-luke
Copy link
Member Author

Thanks for the helpful suggestions. The locale is not embedded in the header. I had started writing a list of locales to iterate over, that's when I stopped and decided to ask here before progressing too far. So it sounds like there is no solution in MNE for this already, so I will continue to code along this path.

@larsoner
Copy link
Member

Indeed AFAIK we have never had to deal with locale when parsing datetime. We can try adding some other LC_ env var to some Travis or Azure run to see if we can get some existing datetime stuff to break. Let's do that after you fix the reading of this particular file, though
-- it will probably tell us which env var(s) are relevant.

@agramfort
Copy link
Member

agramfort commented Jun 13, 2020 via email

@rob-luke
Copy link
Member Author

rob-luke commented Jun 14, 2020

however I had to use fév. and févr. which seems to be the standard.

Thanks for the code snippet. I came up with something very similar and ran in to the same problem. It's the févr that is the problem, datetime.strptime seems to expect fev. I considered some sort of string replace approach for different languages, but this seems unwieldily (how many languages to I then support?). I also considered other packages that are made for dealing with dates, but don't want to add more requirements.

@rob-luke
Copy link
Member Author

Next Im going to check where this févr actually comes from. This may be a problem of our own creating, I have never seen a file from France and don't know if the device will actually save as fev or févr, this seems to have been generated somewhere in _test_raw_reader.

@agramfort
Copy link
Member

agramfort commented Jun 14, 2020 via email

@rob-luke rob-luke force-pushed the nirxdateage branch 2 times, most recently from 5f7f842 to 84ea52f Compare July 8, 2020 04:49
@larsoner
Copy link
Member

@rob-luke will you have time to revisit this in the next couple of weeks? I'll optimistically mark for 0.21

@larsoner larsoner added this to the 0.21 milestone Aug 24, 2020
@rob-luke
Copy link
Member Author

Yes I would like to cross this off. The milestone has sept 15 marked, that should be achievable

@rob-luke
Copy link
Member Author

rob-luke commented Sep 7, 2020

@larsoner I am not sure what to do here with the non standard French encoding of dates.

It seems to me that fév is what datetime expects, yet we have 'févr' in the tests because that was provided in #7313 (I assume, I don't actually have the file).

So if NIRX is providing non standard french date formats, and if I know all the non standard naming, I could create a translation function. But I don't know all the non standard naming and don't have access to a machine at the moment to determine this. Plus this would become quite unwieldy, what other non standard language formats do we then support.

Would it be acceptable to try and parse the dates in the current locale and throw a warning if it doesn't work. For dates that we can't extract it will set them to 0 or something else? This will get English working and downstream usage of the date, and when someone with access to a French system gets some data they can just tweak the French parsing. Thoughts?

@agramfort
Copy link
Member

agramfort commented Sep 7, 2020 via email

@rob-luke
Copy link
Member Author

rob-luke commented Sep 7, 2020

I would reach out to engineers at the company that produces these files to report the issue.

Good idea. But I would like to verify the issue myself first if I am to contact them. Ideally someone could send me some files recorded in France. Failing that, I could set the local of our lab pc to France and record my own file, but Im currently locked out of the lab (at least for the next 3 weeks). So this won't be done by 0.21 release date. I suggest I create an English date PR for 0.21 and raise an issue for the non English dates to be solved when someone sends me some files or I can get in the lab. Acceptable? Or do you prefer I wait and do everything at once?

@agramfort
Copy link
Member

agramfort commented Sep 7, 2020 via email

@rob-luke
Copy link
Member Author

rob-luke commented Sep 8, 2020

@agramfort @larsoner can you please review.

@rob-luke rob-luke changed the title WIP: Extract measurement date and age for NIRX files MRG: Extract measurement date and age for NIRX files Sep 8, 2020
@rob-luke
Copy link
Member Author

rob-luke commented Sep 9, 2020

Thanks for the review. @agramfort and @larsoner could you please review again.
CI fail seems to be a time out error

@agramfort
Copy link
Member

thx @rob-luke

@agramfort agramfort merged commit 0f9cf21 into mne-tools:master Sep 9, 2020
@rob-luke rob-luke deleted the nirxdateage branch September 9, 2020 12:27
larsoner added a commit to libertyh/mne-python that referenced this pull request Sep 9, 2020
* upstream/master: (489 commits)
  MRG, DOC: Fix ICA docstring, add whitening (mne-tools#8227)
  MRG: Extract measurement date and age for NIRX files (mne-tools#7891)
  Nihon Kohden EEG file reader WIP (mne-tools#6017)
  BUG: Fix scaling for src_mri_t in coreg (mne-tools#8223)
  MRG: Set pyvista as default 3d backend (mne-tools#8220)
  MRG: Recreate our helmet graphic (mne-tools#8116)
  [MRG] Adding get_montage for montage to BaseRaw objects (mne-tools#7667)
  ENH: Allow setting tqdm backend (mne-tools#8177)
  [MRG, IO] Persyst reader into Raw object (mne-tools#8176)
  MRG, BUG: Fix errors in IO/loading/projectors (mne-tools#8210)
  MAINT: vectorize _read_annotations_edf (mne-tools#8214)
  FIX : events_from_annotation when annotations.orig_time is None and f… (mne-tools#8209)
  FIX: do not project to sphere; DOC - explain how to get EEGLAB-like topoplots (mne-tools#7455)
  [MRG, DOC] Added linear algebra of transform to doc (mne-tools#7087)
  FIX: Travis failure on python3.8.1 (mne-tools#8207)
  BF: String formatting in exception message (mne-tools#8206)
  BUG: Fix STC limit bug (mne-tools#8202)
  MRG, DOC: fix ica tutorial (mne-tools#8175)
  CSP component order selection (mne-tools#8151)
  MRG, ENH: Add on_missing to plot_events (mne-tools#8198)
  ...
marsipu pushed a commit to marsipu/mne-python that referenced this pull request Oct 14, 2020
* Add meas_date and age to nirx io

* Remove unused import

* Update mne/io/nirx/nirx.py

Co-authored-by: Alexandre Gramfort <[email protected]>

* Update mne/io/nirx/nirx.py

Co-authored-by: Alexandre Gramfort <[email protected]>

* Get date for loop to work

* Shorten tests

* Dont use the word list

* Flake fix

Co-authored-by: Alexandre Gramfort <[email protected]>
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.

3 participants