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

ENH: Improve Covariance.__repr__ #12181

Merged
merged 2 commits into from
Nov 7, 2023
Merged

ENH: Improve Covariance.__repr__ #12181

merged 2 commits into from
Nov 7, 2023

Conversation

larsoner
Copy link
Member

@larsoner larsoner commented Nov 7, 2023

Improves cov.__repr__. On this branch:

$ python -c 'import mne; cov = mne.read_cov(mne.datasets.sample.data_path() / "MEG"/ "sample" / "sample_audvis-cov.fif"); print(cov); print(cov.as_diag())'
<Covariance | kind : full, shape : (366, 366), range : [-1.3e-11, +5.1e-11], n_samples : 15972>
<Covariance | kind : diagonal, shape : (366,), range : [+6.9e-27, +5.1e-11], n_samples : 15972>

On main:

Too many lines to leave uncollapsed
$ python -c 'import mne; cov = mne.read_cov(mne.datasets.sample.data_path() / "MEG"/ "sample" / "sample_audvis-cov.fif"); print(cov); print(cov.as_diag())'
<Covariance | size : 366 x 366, n_samples : 15972, data : [[ 2.27235589e-23  4.79818505e-24  7.12852747e-25 ...  4.85348042e-18
   2.02846360e-18  8.26727393e-18]
 [ 4.79818505e-24  5.33468523e-24  1.80261790e-25 ...  2.33583009e-19
  -6.93161055e-19  2.35199238e-18]
 [ 7.12852747e-25  1.80261790e-25  5.79073915e-26 ...  1.09498615e-19
   6.16924072e-21  2.93873875e-19]
 ...
 [ 4.85348042e-18  2.33583009e-19  1.09498615e-19 ...  1.40677185e-11
   1.27444183e-11  1.08634620e-11]
 [ 2.02846360e-18 -6.93161055e-19  6.16924072e-21 ...  1.27444183e-11
   1.59818134e-11  8.51070563e-12]
 [ 8.26727393e-18  2.35199238e-18  2.93873875e-19 ...  1.08634620e-11
   8.51070563e-12  1.53708918e-11]]>
<Covariance | diagonal : 366, n_samples : 15972, data : [2.27235589e-23 5.33468523e-24 5.79073915e-26 1.95465404e-23
 9.58056792e-24 3.60094348e-26 1.81981544e-23 1.34520926e-23
 3.06557696e-26 2.96882253e-23 6.52643398e-24 5.74491445e-26
 2.10225446e-23 1.68031534e-23 2.97436798e-26 2.08965492e-23
 1.47060609e-23 2.62781286e-26 1.84361073e-23 1.81840095e-23
 2.19184090e-26 1.88975197e-23 2.68800602e-23 2.56688768e-26
 1.60634828e-23 1.39484233e-23 2.54191786e-26 1.65258130e-23
 1.42576000e-23 2.00152485e-26 1.73383042e-23 1.12707404e-23
 1.34510005e-26 2.02738869e-23 1.53059309e-23 2.90692812e-26
 2.13733254e-23 1.11217011e-23 1.98290428e-26 2.70944458e-23
 1.78858400e-23 1.52557530e-26 2.64442354e-23 1.28272646e-23
 2.27045692e-26 3.46934819e-23 1.70654883e-23 1.85896782e-26
 1.44298685e-23 1.29069385e-23 3.42855070e-26 1.64928823e-23
 1.04175805e-23 4.02816177e-26 9.66863287e-24 9.46040259e-24
 1.90930716e-26 9.76039796e-24 1.21617443e-23 1.67574730e-26
 8.08842821e-24 1.10366280e-23 9.90079362e-27 8.47222561e-24
 1.04417546e-23 6.87284820e-27 1.56952933e-23 1.22422565e-23
 1.38443574e-26 9.06976523e-24 1.28314134e-23 7.89148043e-27
 1.41795962e-23 1.00275767e-23 1.79369674e-26 1.44520077e-23
 1.17242452e-23 1.34091447e-26 1.02101339e-23 1.25942019e-23
 1.60351764e-26 1.26083161e-23 1.24288390e-23 1.58031635e-26
 1.61533781e-23 1.66174099e-23 3.93879618e-26 8.80330006e-24
 1.19775769e-23 1.81498504e-26 1.20684012e-23 1.07447324e-23
 3.96826256e-26 1.53110946e-23 1.12804046e-23 3.90928911e-26
 9.51737790e-24 1.15879749e-23 2.03473655e-26 9.60164914e-24
 1.14775185e-23 1.91527343e-26 9.77051683e-24 7.94056985e-24
 8.06730973e-27 1.07205920e-23 1.06563938e-23 8.60452824e-27
 2.66759665e-23 1.14294496e-23 7.01913862e-27 1.11140408e-23
 1.33951591e-23 9.92666593e-27 1.15522707e-23 1.34748856e-23
 1.15535462e-26 2.57075256e-23 1.40793007e-23 1.91549544e-26
 4.44182123e-23 2.50852702e-23 2.05577502e-26 1.88341733e-23
 1.58766384e-23 1.90660610e-26 2.32487656e-23 1.89694885e-23
 3.84577952e-26 3.29702610e-23 2.70901160e-23 4.50967172e-26
 1.97317217e-23 2.06014306e-23 2.29262428e-26 1.26589795e-23
 1.01506374e-23 1.18397451e-26 2.84475248e-23 2.01558167e-23
 3.12330680e-26 4.11777497e-23 2.94863676e-23 5.22395589e-26
 4.04883675e-23 4.01645698e-23 5.33299607e-26 3.98333983e-23
 2.88954151e-23 3.61355111e-26 2.13251321e-23 2.13260049e-23
 6.53681021e-26 2.06448813e-23 1.18678977e-23 8.18099107e-26
 1.79164523e-23 7.99025128e-24 6.28559688e-26 3.29289026e-23
 2.66545764e-23 5.83210397e-26 1.92143364e-23 1.25128638e-23
 1.97820678e-26 1.86141666e-23 1.05965310e-23 1.49124722e-26
 3.07531948e-23 1.21717025e-23 3.74736702e-26 3.11432402e-23
 5.90914647e-24 5.08300212e-26 1.50432059e-23 1.37741819e-23
 1.70907723e-26 1.90390030e-23 1.51353470e-23 1.59813520e-26
 1.26679370e-23 1.49294939e-23 1.21404813e-26 1.43215951e-23
 1.36811407e-23 1.34896798e-26 2.11682650e-23 1.10600072e-23
 3.29344993e-26 1.47704577e-23 9.48508943e-24 1.32499375e-26
 1.85902422e-23 1.13719095e-23 1.36570334e-26 2.49742296e-23
 1.82463414e-23 3.75035273e-26 2.07192036e-23 1.51333343e-23
 1.52132764e-26 1.34277815e-23 1.43432359e-23 1.74776828e-26
 1.03640201e-23 1.33215187e-23 1.23183089e-26 1.24307318e-23
 1.71055637e-23 1.05631508e-26 1.18568342e-23 1.25064528e-23
 9.45748562e-27 1.24103074e-23 1.11783168e-23 9.02247199e-27
 1.02141965e-23 1.14414665e-23 1.36421611e-26 1.20537935e-23
 1.27582590e-23 1.07555351e-26 9.17105764e-24 1.15111691e-23
 1.03820558e-26 1.18822559e-23 1.10870049e-23 1.12114279e-26
 1.40472554e-23 1.76900917e-23 1.01033403e-26 9.39314172e-24
 1.17814092e-23 8.85552267e-27 1.05553795e-23 1.16473732e-23
 9.16817054e-27 1.02556966e-23 1.04110946e-23 1.40684113e-26
 1.06373568e-23 1.31516056e-23 3.11993751e-26 1.73027975e-23
 1.61627027e-23 3.35937930e-26 1.34457157e-23 1.53938581e-23
 2.68660533e-26 2.88153439e-23 1.65107911e-23 2.47188432e-26
 1.46573512e-23 1.20043915e-23 1.59628878e-26 1.04428034e-23
 1.26146874e-23 1.50780650e-26 1.62005957e-23 1.75270416e-23
 1.23058472e-26 1.58176594e-23 1.56502976e-23 1.66838549e-26
 8.85306033e-24 1.07419750e-23 1.56103041e-26 1.17222664e-23
 1.37992484e-23 1.15396367e-26 3.05725969e-23 2.49504696e-23
 2.46473048e-26 3.85142274e-23 3.81192233e-23 3.31308020e-26
 2.05499333e-23 2.29652922e-23 2.31463611e-26 2.00285688e-23
 5.62879134e-21 1.81510535e-26 1.29122625e-23 1.17373699e-23
 1.69234769e-26 2.12782241e-23 1.82214290e-23 1.97655972e-26
 1.27401062e-23 9.98869402e-24 3.05980071e-26 1.15566687e-23
 8.09567634e-24 2.85829350e-26 3.06247746e-23 3.04050683e-23
 4.06232188e-26 1.82968558e-23 6.31686724e-24 4.99394932e-26
 1.63062431e-23 7.97657806e-24 3.58499059e-26 2.74788033e-23
 1.68643895e-23 2.87265789e-26 4.25632261e-11 2.56714374e-11
 2.80009384e-11 4.73974461e-11 2.78251821e-11 2.97043910e-11
 5.12006519e-11 4.11697974e-11 3.57716900e-11 2.68798113e-11
 2.06795721e-11 2.33334334e-11 2.18510993e-11 2.30691316e-11
 4.64078722e-11 2.61682510e-11 1.65090413e-11 3.67974301e-11
 1.56722083e-11 9.28091398e-12 1.35143133e-11 1.61401951e-11
 3.87212846e-11 2.27794861e-11 1.90371447e-11 1.36402798e-11
 9.46929978e-12 1.01404904e-11 8.28679654e-12 1.11831172e-11
 9.72002932e-12 1.11577470e-11 9.68316782e-12 2.24701862e-11
 1.28517682e-11 1.70748987e-11 1.16799324e-11 1.07175316e-11
 1.06492206e-11 1.16511789e-11 1.17076548e-11 9.23804355e-12
 1.30048508e-11 1.57250678e-11 1.38694547e-11 1.44601708e-11
 1.44986466e-11 1.55456033e-11 1.44021899e-11 1.29703160e-11
 1.15298093e-11 1.09026952e-11 2.22903113e-13 1.83683640e-11
 1.64163453e-11 1.46454142e-11 1.62477060e-11 1.40677185e-11
 1.59818134e-11 1.53708918e-11]>

</details>

@larsoner larsoner added this to the 1.6 milestone Nov 7, 2023

def _array_repr(x):
"""Produce compact info about float ndarray x."""
assert isinstance(x, np.ndarray), type(x)
Copy link
Member

Choose a reason for hiding this comment

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

I think bandit will complain about assert appearing outside a test file (but maybe not?)

Copy link
Member

Choose a reason for hiding this comment

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

never mind, bandit does complain but it's considered "low" severity so the job still passes. And I don't mind having this kind of assert usage in our code anyway.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think we ignore that rule because we do this so often

@larsoner larsoner merged commit b55df63 into mne-tools:main Nov 7, 2023
28 checks passed
@larsoner larsoner deleted the cov-repr branch November 7, 2023 18:19
larsoner added a commit to pablomainar/mne-python that referenced this pull request Nov 8, 2023
* upstream/main:
  BUG: Fix bug with spectrum warning (mne-tools#12186)
  Add argument splash to disable splash-screen from Qt-browser (mne-tools#12185)
  BUG: Fix bug with logging and n_jobs>1 (mne-tools#12154)
  Use gray logo (works in light and dark modes) (mne-tools#12184)
  Tweak logo for dark mode (mne-tools#12176)
  ENH: Improve Covariance.__repr__ (mne-tools#12181)
  ENH: Enable sensor-specific OPM coregistration in mne coreg (mne-tools#11405)
  Tweak README.rst (mne-tools#12166)
  [pre-commit.ci] pre-commit autoupdate (mne-tools#12177)
  MAINT: Add branch coverage (mne-tools#12174)
  OpenSSF (mne-tools#12175)
  fix docstring in 60_sleep.py (mne-tools#12171)
  FIX: skip empty lines in read_raw_eyelink (mne-tools#12172)
  FIX: Fix bug with coreg scalars (mne-tools#12164)
  Changed casting rule in np.clip to allow reading of raw GDF files (mne-tools#12168)
  [DOC] Add documentation for setting montage order (mne-tools#12160)
  Fix inferring fiducials from EEGLAB (mne-tools#12165)
larsoner added a commit to hoechenberger/mne-python that referenced this pull request Nov 8, 2023
…o-pyproject.toml

* upstream/main:
  MAINT: Fix CIs (mne-tools#12188)
  BUG: Fix bug with default alpha and axes (mne-tools#12187)
  BUG: Fix bug with spectrum warning (mne-tools#12186)
  Add argument splash to disable splash-screen from Qt-browser (mne-tools#12185)
  BUG: Fix bug with logging and n_jobs>1 (mne-tools#12154)
  Use gray logo (works in light and dark modes) (mne-tools#12184)
  Tweak logo for dark mode (mne-tools#12176)
  ENH: Improve Covariance.__repr__ (mne-tools#12181)
  ENH: Enable sensor-specific OPM coregistration in mne coreg (mne-tools#11405)
  Tweak README.rst (mne-tools#12166)
snwnde pushed a commit to snwnde/mne-python that referenced this pull request Mar 20, 2024
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.

2 participants