Write raw buffer. Parameters ---------- fid : file descriptor an open raw data file. buf : array The buffer to write. cals : array Calibration factors. fmt : str 'short', 'int', 'single', or 'double' for 16/32 bit int or 32/64 bit floa
(fid, buf, cals, fmt)
| 3116 | |
| 3117 | |
| 3118 | def _write_raw_buffer(fid, buf, cals, fmt): |
| 3119 | """Write raw buffer. |
| 3120 | |
| 3121 | Parameters |
| 3122 | ---------- |
| 3123 | fid : file descriptor |
| 3124 | an open raw data file. |
| 3125 | buf : array |
| 3126 | The buffer to write. |
| 3127 | cals : array |
| 3128 | Calibration factors. |
| 3129 | fmt : str |
| 3130 | 'short', 'int', 'single', or 'double' for 16/32 bit int or 32/64 bit |
| 3131 | float for each item. This will be doubled for complex datatypes. Note |
| 3132 | that short and int formats cannot be used for complex data. |
| 3133 | """ |
| 3134 | if buf.shape[0] != len(cals): |
| 3135 | raise ValueError("buffer and calibration sizes do not match") |
| 3136 | |
| 3137 | _check_option("fmt", fmt, ["short", "int", "single", "double"]) |
| 3138 | |
| 3139 | cast_int = False # allow unsafe cast |
| 3140 | if np.isrealobj(buf): |
| 3141 | if fmt == "short": |
| 3142 | write_function = write_dau_pack16 |
| 3143 | cast_int = True |
| 3144 | elif fmt == "int": |
| 3145 | write_function = write_int |
| 3146 | cast_int = True |
| 3147 | elif fmt == "single": |
| 3148 | write_function = write_float |
| 3149 | else: |
| 3150 | write_function = write_double |
| 3151 | else: |
| 3152 | if fmt == "single": |
| 3153 | write_function = write_complex64 |
| 3154 | elif fmt == "double": |
| 3155 | write_function = write_complex128 |
| 3156 | else: |
| 3157 | raise ValueError( |
| 3158 | 'only "single" and "double" supported for writing complex data' |
| 3159 | ) |
| 3160 | |
| 3161 | buf = buf / np.ravel(cals)[:, None] |
| 3162 | if cast_int: |
| 3163 | buf = buf.astype(np.int32) |
| 3164 | write_function(fid, FIFF.FIFF_DATA_BUFFER, buf) |
| 3165 | |
| 3166 | |
| 3167 | def _check_raw_compatibility(raw): |
no test coverage detected