Last active
August 29, 2015 14:22
-
-
Save ipashchenko/671470d494ffe0b01055 to your computer and use it in GitHub Desktop.
reformat weird txt-files with pulses
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sys | |
| import numpy as np | |
| def reformat_txt(inname, outname): | |
| """ | |
| Function that converts txt-file with dyn. spectra in format: | |
| https://www.dropbox.com/sh/l6kr87oxsxpg367/AACbXZNX4KU1KNEYWjphKbhoa/FRB010724/ascii_files?dl=0 | |
| #ch0 t1 value | |
| #ch0 t2 value | |
| ... | |
| #ch1 t1 value | |
| #ch1 t2 value | |
| ... | |
| #chn t1 value | |
| #chn t2 value | |
| to format with rows - time counts, columns - frequency channels. | |
| :param inname: | |
| Name of txt-file in weird format with dyn. spectra. | |
| :param outname: | |
| Name of output file with dyn. spectra | |
| """ | |
| data = np.loadtxt(inname) | |
| # Number of freq. channels | |
| nchannels = len(np.unique(data[:, 0])) | |
| values = list() | |
| for ch in range(nchannels): | |
| values.append(data[:, 2:][np.where(data[:, 0] == ch)].T) | |
| np.savetxt(outname, np.vstack(values).T) | |
| if __name__ == '__main__': | |
| if len(sys.argv) != 3: | |
| print "Usage: python reformat_txt.py infname outfname" | |
| exit() | |
| reformat_txt(sys.argv[1], sys.argv[2]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment