How to obtain the coordinates of the highest density countour
Hello, I'm trying to obtain the coordinates of the highest density contour level in a region of a simulation. The code I'm using is the following: import yt from yt.units import * loc='/fs/san11/enro/guido/cflows_gg/fixed_mesh_l9_supersonic/' basename='cflows_gg_hdf5_plt_cnt_' out_name='reg1_cg_lines_start_points' n_s=10 n_e=10 d_n=1 nlines=7 # number of lines per plane dimension ## region ## # region 1 # xc=0.0 yc=1.0 zc=4.3 lx=3.0 ly=2.0 lz=2.0 center_r=[xc,yc,zc]*pc left_r =[xc-lx,yc-ly,zc-lz]*pc right_r =[xc+lx,yc+ly,zc+lz]*pc #### connected sets ### levels=3 for i in range(n_s,n_e+1,d_n): print('i: {}'.format(i)) ds=yt.load(loc+basename+str(i).zfill(4)) reg=ds.region(center_r,left_r,right_r) reg_max_rho=reg[('gas','density')].max() reg_min_rho=reg[('gas','density')].min() print("Density : [{0:.4e},{1:.4e}]".format(reg_max_rho,reg_min_rho)) contour_values, connected_sets=reg.extract_connected_sets(('gas','density'),levels,reg_min_rho*100,reg_max_rho,) #print("contour_values: {}".format(contour_values)) So, I wonder if the way to obtain the coordinates that I need is with: connected_sets[levels-1][1].fcoords This is what I obtained: unyt_array([[ 4.82137180e+16, -2.45889962e+18, 7.37669886e+18], [ 4.82137180e+16, -2.45889962e+18, 7.47312629e+18], [ 1.44641154e+17, -2.55532706e+18, 7.18384399e+18], [ 1.44641154e+17, -2.55532706e+18, 7.37669886e+18], [ 1.44641154e+17, -2.45889962e+18, 7.28027142e+18]], 'code_length') This is a (5,3) array, why it has that shape ?? Thanks,
Hi Guido, That means there are five cells in that contour -- which may not be enough for your purposes, so do be careful that you consider that to be a resolved clump, as you may want to bump back a level or two. The first axis of the fcoords array is the cell, and the second is the xyz axis. You should be able to call .center_of_mass() on the contour object to see the center of mass of the object. On Thu, Aug 11, 2022 at 5:35 PM Guido Granda Muñoz <guidogranda@gmail.com> wrote:
Hello, I'm trying to obtain the coordinates of the highest density contour level in a region of a simulation. The code I'm using is the following:
import yt from yt.units import *
loc='/fs/san11/enro/guido/cflows_gg/fixed_mesh_l9_supersonic/' basename='cflows_gg_hdf5_plt_cnt_' out_name='reg1_cg_lines_start_points'
n_s=10 n_e=10 d_n=1
nlines=7 # number of lines per plane dimension ## region ## # region 1 # xc=0.0 yc=1.0 zc=4.3 lx=3.0 ly=2.0 lz=2.0
center_r=[xc,yc,zc]*pc left_r =[xc-lx,yc-ly,zc-lz]*pc right_r =[xc+lx,yc+ly,zc+lz]*pc #### connected sets ### levels=3 for i in range(n_s,n_e+1,d_n): print('i: {}'.format(i)) ds=yt.load(loc+basename+str(i).zfill(4)) reg=ds.region(center_r,left_r,right_r) reg_max_rho=reg[('gas','density')].max() reg_min_rho=reg[('gas','density')].min() print("Density : [{0:.4e},{1:.4e}]".format(reg_max_rho,reg_min_rho)) contour_values, connected_sets=reg.extract_connected_sets(('gas','density'),levels,reg_min_rho*100,reg_max_rho,) #print("contour_values: {}".format(contour_values))
So, I wonder if the way to obtain the coordinates that I need is with: connected_sets[levels-1][1].fcoords This is what I obtained: unyt_array([[ 4.82137180e+16, -2.45889962e+18, 7.37669886e+18], [ 4.82137180e+16, -2.45889962e+18, 7.47312629e+18], [ 1.44641154e+17, -2.55532706e+18, 7.18384399e+18], [ 1.44641154e+17, -2.55532706e+18, 7.37669886e+18], [ 1.44641154e+17, -2.45889962e+18, 7.28027142e+18]], 'code_length') This is a (5,3) array, why it has that shape ?? Thanks, _______________________________________________ yt-users mailing list -- yt-users@python.org To unsubscribe send an email to yt-users-leave@python.org https://mail.python.org/mailman3/lists/yt-users.python.org/ Member address: matthewturk@gmail.com
Hello Matthew, Thanks for answering. I have an additional question about using the center_of_mass(). I didn't find that option, I only found connected_sets[i][j].center which is the center of the region used to get the contours and I'm using the last version of yt. So, I'm using instead : connected_sets[2][1].argmax(('gas','density')) so, I wonder if this will also consider cells that belong to the next contour levels e.g. connected_sets[3][1] and connected_sets[4][1]. I'm asking this because sometimes when doing connected_sets["max level"][1] I get strange coordinates that don't belong to the clump, probably because of the problem of unresolved contours that you mentioned. Cheers,
Hi Guido, Sorry, just seeing this now. That's the center, but I don't think it's what you want. You probably want to access the center_of_mass quantity, which should be available either on the connected set *or* the data object associated with it -- I can't recall which it is, but it's definitely in there. On Tue, Aug 16, 2022 at 12:50 PM Guido Granda Muñoz <guidogranda@gmail.com> wrote:
Hello Matthew, Thanks for answering. I have an additional question about using the center_of_mass(). I didn't find that option, I only found connected_sets[i][j].center which is the center of the region used to get the contours and I'm using the last version of yt. So, I'm using instead :
connected_sets[2][1].argmax(('gas','density'))
so, I wonder if this will also consider cells that belong to the next contour levels e.g. connected_sets[3][1] and connected_sets[4][1]. I'm asking this because sometimes when doing connected_sets["max level"][1] I get strange coordinates that don't belong to the clump, probably because of the problem of unresolved contours that you mentioned.
Cheers, _______________________________________________ yt-users mailing list -- yt-users@python.org To unsubscribe send an email to yt-users-leave@python.org https://mail.python.org/mailman3/lists/yt-users.python.org/ Member address: matthewturk@gmail.com
participants (2)
-
Guido Granda Muñoz
-
Matthew Turk