#to run cluster finding on
 rxyz0     = rxyz[keep]
 Rxy0      = Rxy[keep]
 x0        = x[keep]
 y0        = y[keep]
 z0        = z[keep]
 mass0     = mass[keep]
 feh0      = feh[keep]
 id0       = ids[keep]
 id_child0 = id_child[keep]
 age0      = age[keep]
 
 linking_length = 0.004 #4 parsec
 ncut           = 4 #4 star particles
 
 ind, xcm, ycm, zcm, mtot, grpid, r90, r50, rmax =fof.find(x0,y0,z0, b=linking_length, mass=mass0, ncut=ncut)
 ngroup = len(mtot)
 
 export_cluster={}
 for grp_index in range(ngroup):  #iterate over each group
     cluster={}
     ids_in_cluster = id0[ind[grp_index]]  #these are the star particle ids in each cluster
     id_children_in_cluster = id_child0[ind[grp_index]]
     age=age0[ind[grp_index]]
     nstar = len(ids_in_cluster)
     groupid=grpid[grp_index]
     print('------------------------------------------------------------------------------------------------------------------')
     print('grpid, nstar, xcm (kpc), ycm (kpc), zcm (kpc), mtot (msun), rmax (pc)')
     print('%s     %i     %.4f     %.4f    %.4f     %.2e     %.1f ' % (grpid[grp_index], nstar, xcm[grp_index], ycm[grp_index], zcm[grp_index], mtot[grp_index], 1000*rmax[grp_index]))
     print("age os stars in the cluster",age)
     print('ids')
#identifying star clusters/associations
###########################################################################

#select young stars within the disk for star clusters
si = np.where((sage <= .003) & (srxyz < 20) & (abs(sz) < 1.5))

#linking_length = 0.01 #10 parsec
#ncut           = 10 #10 star particles

linking_length = 0.004  #4 parsec
ncut = 5  #10 star particles

#Running fof
ind, xsp, ysp, zsp, msp, grpid, r90, r50, rmax = fof.find(sx[si],
                                                          sy[si],
                                                          sz[si],
                                                          b=linking_length,
                                                          mass=smass[si],
                                                          ncut=ncut)
ngroup = len(msp)
rmax = np.array(rmax)
rmax_parsec = rmax * 1000.

###########################################################################
#gas image (2d histogram)
###########################################################################
#cold (< 10^4 K) gas in the midplane (|z| <= 1.5 kpc within bin_edge
i = np.where((rGas <= bin_edge) & (np.fabs(zGas) <= 1.5) & (tGas <= 1e4))

face, xh, yh = np.histogram2d(
    part['gas'].prop('host.distance.principal.cartesian')[i, 1][0],
    part['gas'].prop('host.distance.principal.cartesian')[i, 0][0],