@@ -1173,10 +1173,10 @@ class Info(ValidatedDict, SetChannelsMixin, MontageMixin, ContainsMixin):
11731173
11741174 .. warning::
11751175 The only entries that should be manually changed by the user are:
1176- ``info['bads']``, ``info['description']``, ``info['device_info']``
1177- ``info['dev_head_t ']``, ``info['experimenter ']``,
1178- ``info['helium_info ']``, ``info['line_freq']``, ``info['temp ']``,
1179- and ``info['subject_info']``.
1176+ ``info['bads']``, ``info['description']``, ``info['device_info']``,
1177+ ``info['proj_id ']``, ``info['proj_name']``, ``info['dev_head_t ']``,
1178+ ``info['experimenter ']``, ``info['helium_info ']``,
1179+ ``info['line_freq']``, ``info['temp']``, and ``info['subject_info']``.
11801180
11811181 All other entries should be considered read-only, though they can be
11821182 modified by various MNE-Python functions or methods (which have
@@ -1634,8 +1634,8 @@ class Info(ValidatedDict, SetChannelsMixin, MontageMixin, ContainsMixin):
16341634 "Please use methods inst.add_channels(), "
16351635 "inst.drop_channels(), and inst.pick() instead." ,
16361636 "proc_history" : "proc_history cannot be set directly." ,
1637- "proj_id" : "proj_id cannot be set directly." ,
1638- "proj_name" : "proj_name cannot be set directly." ,
1637+ "proj_id" : partial ( _check_types , name = "proj_id" , types = ( int , None ), cast = int ) ,
1638+ "proj_name" : partial ( _check_types , name = "proj_name" , types = ( str , None )) ,
16391639 "projs" : "projs cannot be set directly. "
16401640 "Please use methods inst.add_proj() and inst.del_proj() "
16411641 "instead." ,
@@ -2206,7 +2206,7 @@ def read_meas_info(fid, tree, clean_bads=False, verbose=None):
22062206 description = tag .data
22072207 elif kind == FIFF .FIFF_PROJ_ID :
22082208 tag = read_tag (fid , pos )
2209- proj_id = tag .data
2209+ proj_id = int ( tag .data . item ())
22102210 elif kind == FIFF .FIFF_PROJ_NAME :
22112211 tag = read_tag (fid , pos )
22122212 proj_name = tag .data
@@ -3009,6 +3009,21 @@ def _where_isinstance(values, kind):
30093009 return values [int (idx )]
30103010 elif len (idx ) > 1 :
30113011 raise RuntimeError (msg )
3012+ # proj_id
3013+ elif _check_isinstance (values , (int , type (None )), all ) and key == "proj_id" :
3014+ unique_values = set (values )
3015+ if len (unique_values ) != 1 :
3016+ logger .info ("Found multiple proj_ids, using the first one." )
3017+ return list (unique_values )[0 ]
3018+
3019+ elif key == "experimenter" or key == "proj_name" :
3020+ if _check_isinstance (values , (str , type (None )), all ):
3021+ unique_values = set (values )
3022+ unique_values .discard (None )
3023+ if len (unique_values ) == 1 :
3024+ return list (unique_values )[0 ]
3025+ else :
3026+ return None
30123027 # other
30133028 else :
30143029 unique_values = set (values )
@@ -3018,7 +3033,7 @@ def _where_isinstance(values, kind):
30183033 logger .info ("Found multiple StringIO instances. Setting value to `None`" )
30193034 return None
30203035 elif isinstance (list (unique_values )[0 ], str ):
3021- logger .info ("Found multiple filenames . Setting value to `None`" )
3036+ logger .info (f "Found multiple { key } . Setting value to `None`" )
30223037 return None
30233038 else :
30243039 raise RuntimeError (msg )
@@ -3498,7 +3513,7 @@ def anonymize_info(info, daysback=None, keep_his=False, verbose=None):
34983513 info ["description" ] = default_desc
34993514 with info ._unlock ():
35003515 if info ["proj_id" ] is not None :
3501- info ["proj_id" ] = np . zeros_like ( info [ "proj_id" ])
3516+ info ["proj_id" ] = 0
35023517 if info ["proj_name" ] is not None :
35033518 info ["proj_name" ] = default_str
35043519 if info ["utc_offset" ] is not None :
0 commit comments