def dummy_test(infile, expfile, simple=True): ifile = open(infile, "br") Din = pickle.load(ifile) ifile.close() Y = Din["Y"] M = Din["M"] # assign slm params slm = SLM(M, FixedEffect(1)) if "tri" in Din: slm.surf = {"tri": Din["tri"]} if "lat" in Din: slm.surf = {"lat": Din["lat"]} # here we go --> run the linear model slm.linear_model(Y) ofile = open(expfile, "br") Dout = pickle.load(ofile) ofile.close() # compare... testout = [] for makey_ in Dout.keys(): comp = np.allclose(getattr(slm, makey_), Dout[makey_], rtol=1e-05, equal_nan=True) testout.append(comp) assert all(flag == True for (flag) in testout)
def get_linmod_output(Y, M, foutname, tri=None, lat=None): """Runs linmod and returns all relevant output.""" slm = SLM(M, FixedEffect(1)) if tri is not None: slm.surf = {"tri": tri} if lat is not None: slm.lat = {"lat": lat} slm.linear_model(Y) keys = [ "cluster_threshold", "coef", "df", "drlim", "niter", "resl", "SSE", "thetalim", "X", "tri", ] D = {} for key in keys: if getattr(slm, key) is not None: D[key] = getattr(slm, key) with open(foutname, "wb") as handle: pickle.dump(D, handle, protocol=4) return D