def test_mean(): tr = get_rand_traj() st_mean = crys.mean(tr) attrs_only_traj = ['time', 'timestep', 'nstep'] for attr_name in tr.attr_lst: attr = getattr(st_mean, attr_name) if attr_name in attrs_only_traj: assert attr is None, "%s is not None" %attr_name elif attr_name in tr.attrs_nstep: assert np.allclose(attr, getattr(tr, attr_name).mean(axis=tr.timeaxis))
def test_mean(): tr = get_rand_traj() st_mean = crys.mean(tr) attrs_only_traj = ['time', 'timestep', 'nstep'] for attr_name in tr.attr_lst: attr = getattr(st_mean, attr_name) if attr_name in attrs_only_traj: assert attr is None, "%s is not None" % attr_name elif attr_name in tr.attrs_nstep: assert np.allclose(attr, getattr(tr, attr_name).mean(axis=tr.timeaxis))
{st} only in Trajectory: {onlytr} only in Structure: {onlyst} Attributes which are None w.r.t. the Trajectory API after the following operation, starting with a fully populated struct or traj (all attrs not None): """.format(st=st.attr_lst, tr=tr.attr_lst, onlytr=list(onlytr), onlyst=list(onlyst)) items = [\ ('tr', tr), ('tr.copy', tr.copy()), ('tr[0:5]', tr[0:5]), ('st', st), ('st.copy', st.copy()), ('tr[0]', tr[0]), ('mean(tr)', crys.mean(tr)), ('concatenate([st,st])', crys.concatenate([st,st])), ('concatenate([st,tr])', crys.concatenate([st,tr])), ('concatenate([tr,tr])', crys.concatenate([tr,tr])), ] for name,obj in items: none_attrs = set.difference(set(tr.attr_lst), crys.populated_attrs([obj])) typ = 'traj' if obj.is_traj else 'struct' print "{:25} {:7} {}".format(name, typ, list(none_attrs))
{st} only in Trajectory: {onlytr} only in Structure: {onlyst} Attributes which are None w.r.t. the Trajectory API after the following operation, starting with a fully populated struct or traj (all attrs not None): """.format(st=st.attr_lst, tr=tr.attr_lst, onlytr=list(onlytr), onlyst=list(onlyst))) items = [\ ('tr', tr), ('tr.copy', tr.copy()), ('tr[0:5]', tr[0:5]), ('st', st), ('st.copy', st.copy()), ('tr[0]', tr[0]), ('mean(tr)', crys.mean(tr)), ('concatenate([st,st])', crys.concatenate([st,st])), ('concatenate([st,tr])', crys.concatenate([st,tr])), ('concatenate([tr,tr])', crys.concatenate([tr,tr])), ] for name,obj in items: none_attrs = set.difference(set(tr.attr_lst), crys.populated_attrs([obj])) typ = 'traj' if obj.is_traj else 'struct' print("{:25} {:7} {}".format(name, typ, list(none_attrs)))