def METHOD_NAME(self):
    if hasattr(self, "_kdtree"):
        return self._kdtree
    ds = self.ds
    if getattr(ds, "kdtree_filename", None) is None:
        if os.path.exists(ds.parameter_filename):
            fname = ds.parameter_filename + ".kdtree"
        else:
            # we don't want to write to disk for in-memory data
            fname = None
    else:
        fname = ds.kdtree_filename
    self._generate_kdtree(fname)
    return self._kdtree