Dear All,
I am quite a beginner with Rpy, but I have started using it in
conjunction with SciPy on the Python side.
Now, I am a bit puzzled since the same code is running without any
problem on my Debian testing laptop whereas it breaks down on my
Fedora Core 5 box.
True, FC5 has a the previous SciPy release, but the problem seems to
be on the R/Rpy side (most likely I am doing something wrong).
The Rpy script I am using relies on the igraph R library to study the
connected components in a graph.
It is not a long script and I include it directly in the following:
#!/usr/bin/R
library(igraph)
distance=function(x){
#f=dist(x,method="euclidean")
f=dist(x,method="euclidean", p=3)
my_dist=as.matrix(f)
return(my_dist)
}
mycluster = function(dist_mat,d){
#where x has to be the distance matrix! I will use it to generate a graph
my_g=graph.adjacency(dist_mat<=d,mode="undirected")
my_g=simplify(my_g)
nc=no.clusters(my_g)
nc=as.matrix(nc)
cluster_comp=clusters(my_g)$csize
cluster_comp=as.matrix(cluster_comp)
cluster_comp=rbind(nc,cluster_comp)
#print("the dimensions are")
#print(dim(cluster_comp))
#I have to turn everything into a matrix for SciPy!!!!!
return(cluster_comp)
}
Then there is the bit in my Python code where the R functions are
called (the R script is saved as cluster_functions.R and there is at
the beginning of the Python code the statement
import scipy as s):
#Now I try loading the R script
r.source("cluster_functions.R")
#I now calculate the number of clusters in each configuration
n_clusters=s.zeros(n_config)
# min_dist=s.zeros(n_config)
dist_mat=s.zeros((n_part,n_part))
for i in xrange(0,n_config):
test_arr=tot_config[i,:]
test_arr=s.reshape(test_arr,(n_part,3))
# if (i==14):
# p.save("test_14.dat",test_arr)
#dist_mat=r.distance(test_arr)
x_pos=x_arr[i,:]
y_pos=y_arr[i,:]
z_pos=z_arr[i,:]
dist_mat=d_calc.distance_calc(x_pos,y_pos,z_pos, box_size)
# if (i==71):
# p.save("distance_matrix_71.dat",dist_mat)
# p.save("x_pos_71.dat",x_pos)
clust_struc= (r.mycluster(dist_mat,threshold))
# print'clust_struct is, ', clust_struc
# n_clusters[i]=r.mycluster(dist_mat,threshold)
n_clusters[i]=clust_struc[0]
# print 'the shape of cluster_struct is, ',s.shape(clust_struc)
#dist_mat=s.where(dist_mat==0.,1000.,dist_mat)
# min_dist[i]=(s.ravel(dist_mat)).min()
#print 'The cluster distribution is, ', clust_struc[1:,0]
#save the cluster size
cluster_name="cluster_dist%05d"%i
p.save(cluster_name,clust_struc[1:,0])
# print 'the evolution of the number of clusters is, ', n_clusters
p.save("number_cluster.dat",n_clusters)
And finally, this is the output I get:
Traceback (most recent call last):
File "./plot_statistics.py", line 749, in ?
clust_struc= (r.mycluster(dist_mat,threshold)) #a cumbersome
rpy.RException: Error in as.matrix(adjmatrix) : (list) object cannot
be coerced to 'double'
Exception in thread Thread-1 (most likely raised during interpreter shutdown):
Traceback (most recent call last):
File "/usr/lib/python2.4/threading.py", line 442, in __bootstrap
File "/usr/lib/python2.4/threading.py", line 422, in run
File "/usr/lib/python2.4/site-packages/rpy.py", line 112, in r_eventloop
exceptions.AttributeError: 'NoneType' object has no attribute 'isSet'
The problems seems to be the matrix I am creating to return the
results of the igraph package.
Basically, nc is a scalar (number of clusters) and
cluster_comp=as.matrix(cluster_comp) is a sequence containing the
number of particles in each cluster e.g.:
nc=4 ---->4 clusters
cluster_comp= 1 5 7 19 ----> number of particles in each cluster
and then I want to stitch them together in a way that can be
manipulated as a scipy array.
Sorry for the long post, but this exception does not exist on my
Debian testing box, so I had to describe it in detail.
Any help is really appreciated.
Many thanks
Lorenzo
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
rpy-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/rpy-list