@pimms.calc('<STR_LIT>')<EOL>def save_surface_files(note, error, registrations, subject,<EOL>no_surf_export, no_reg_export, surface_format, surface_path,<EOL>angle_tag, eccen_tag, label_tag, radius_tag, registration_name):
if no_surf_export: return {'<STR_LIT>': ()}<EOL>surface_format = surface_format.lower()<EOL>if surface_format in ['<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>']:<EOL><INDENT>def export(flnm, p):<EOL><INDENT>fsio.write_morph_data(flnm, p)<EOL>return flnm<EOL><DEDENT><DEDENT>elif surface_format in ['<STR_LIT>', '<STR_LIT>']:<EOL><INDENT>def export(flnm, p):<EOL><INDENT>flnm = flnm + '<STR_LIT:.>' + surface_format<EOL>dt = np.int32 if np.issubdtype(p.dtype, np.dtype(int).type) else np.float32<EOL>img = fsmgh.MGHImage(np.asarray([[p]], dtype=dt), np.eye(<NUM_LIT:4>))<EOL>img.to_filename(flnm)<EOL>return flnm<EOL><DEDENT><DEDENT>elif surface_format in ['<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>']:<EOL><INDENT>surface_format = '<STR_LIT>' if surface_format == '<STR_LIT>' else '<STR_LIT>'<EOL>def export(flnm, p):<EOL><INDENT>flnm = flnm + '<STR_LIT:.>' + surface_format<EOL>dt = np.int32 if np.issubdtype(p.dtype, np.dtype(int).type) else np.float32<EOL>img = nib.Nifti1Image(np.asarray([[p]], dtype=dt), np.eye(<NUM_LIT:4>))<EOL>img.to_filename(flnm)<EOL>return flnm<EOL><DEDENT><DEDENT>else:<EOL><INDENT>error('<STR_LIT>' % surface_format)<EOL><DEDENT>path = surface_path if surface_path else os.path.join(subject.path, '<STR_LIT>')<EOL>files = []<EOL>note('<STR_LIT>')<EOL>for h in six.iterkeys(registrations):<EOL><INDENT>hemi = subject.hemis[h]<EOL>reg = registrations[h]<EOL>note('<STR_LIT>' % h.upper())<EOL>pmesh = reg['<STR_LIT>']<EOL>for (pname,tag) in zip(['<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>'],<EOL>[angle_tag, eccen_tag, label_tag, radius_tag]):<EOL><INDENT>flnm = export(os.path.join(path, h + '<STR_LIT:.>' + tag), pmesh.prop(pname))<EOL>files.append(flnm)<EOL><DEDENT>if registration_name and not no_reg_export:<EOL><INDENT>flnm = os.path.join(path, h + '<STR_LIT:.>' + registration_name + '<STR_LIT>')<EOL>fsio.write_geometry(flnm, pmesh.coordinates.T, pmesh.tess.faces.T)<EOL><DEDENT><DEDENT>return {'<STR_LIT>': tuple(files)}<EOL>
save_surface_files is the calculator that saves the registration data out as surface files,
which are put back in the registration as the value 'surface_files'.