<commit_before>#!/usr/bin/env python2
'''
Sort pmovie files in place. Currently only works on the first record.

Usage:
  pmov-sort.py [options] <input>

Options:
  --help   -h            You know.
  --X=XLIM -x XLIM       Use X with limits. [default: (-30e-4, 5e-4)]
  --Y=YLIM -y YLIM       Use Y with limits. [default: None]
  --Z=ZLIM -z ZLIM       Use Z with limits. [default: (-20e-4,20e-4)]
'''
import lspreader as rd;
import cPickle as pickle
from docopt import docopt;
import numpy as np;
import misc as m;
opts=docopt(__doc__,help=True);
lims = [eval(opts[s]) for s in ["--X","--Y","--Z"]];
if lims == [None,None,None]:
    quit();
dims = [name for i,name in zip(lims,['xi','yi','zi']) if i is not None];
lims  = [lim for lim in lims if lim is not None];
f = m.readfile(opts['<input>'], dumpfull=True)
d = f[0]['data'];
keys=np.array([d[s] for s in dims]);
for i,lim in enumerate(lims):
    keys[i] -= lim[0];
sortedargs = np.lexsort(keys);
f[0]['data'] = d[sortedargs];
with open(opts['<input>'],'w') as outf:
    pickle.dump(f,outf,2);
pass<commit_msg>added pruning to pmov-sort.py to make things unique<commit_after>#!/usr/bin/env python2
'''
Sort pmovie files in place. Currently only works on the first record. By default,
works on x and z.

Usage:
  pmov-sort.py [options] <input>

Options:
  --help -h       You know.
  --X -x          Use X. 
  --Y -y          Use Y.
  --Z -z          Use Z.
'''
import lspreader as rd;
import cPickle as pickle
from docopt import docopt;
import numpy as np;
import misc as m;
from itertools import izip;
opts=docopt(__doc__,help=True);
got = [opts[s] for s in ["--X","--Y","--Z"]];
dims=[label for s,label in zip(got,['xi','yi','zi']) if s];
if dims == []:
    dims = ['xi','zi'];
f = m.readfile(opts['<input>'], dumpfull=True)
d = f[0]['data'];
#first, prune and take only unique particles
_,uniq = np.unique(d[dims],return_index=True);
d=d[uniq];
keys=np.array([d[s] for s in dims]);
sortedargs = np.lexsort(keys);
f[0]['data'] = d[sortedargs];
#with open(opts['<input>'],'w') as outf:
#    pickle.dump(f,outf,2);
{'fraction_non_alphanumeric': 0.1895551257253385, 'fraction_numerical': 0.009671179883945842, 'mean_word_length': 3.517467248908297, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4387155', 'n_tokens_mistral': 820, 'n_tokens_neox': 803, 'n_words': 249}