-
Notifications
You must be signed in to change notification settings - Fork 0
/
analyze_snapshot.py
1582 lines (1423 loc) · 72.7 KB
/
analyze_snapshot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
import os
import h5py
import numpy as np
from scipy import stats
import pickle as pk
import yt
import unyt
class Cloud:
"""
Class for calculating bulk cloud properties.
Parameters:
- M0: initial cloud mass [code_mass].
- R0: initial cloud radius [code_length].
- alpha0: initial cloud turbulent virial parameter.
- G_code: gravitational constant in code units
(default: 4300.17 in [pc * Msun^-1 * (m/s)^2]).
"""
def __init__(self, M, R, alpha, G_code=4300.71):
# Initial cloud mass, radius, and turbulent virial parameter.
# G_code: gravitational constant in code units [default: 4300.71].
self.M = M
self.R = R
self.L = (4.0 * np.pi * self.R**3 / 3.0)**(1.0/3.0)
self.alpha = alpha
self.G_code = G_code
self.rho = self.get_initial_density()
self.Sigma = self.get_initial_surface_density()
self.vrms = self.get_initial_sigma_3D()
self.t_cross = self.get_initial_t_cross()
self.t_ff = self.get_initial_t_ff()
# ----------------------------- FUNCTIONS ---------------------------------
# FROM INITIAL CLOUD PARAMETERS: surface density, R, vrms, Mach number.
def get_initial_density(self, verbose=False):
"""
Calculate the initial cloud density [code_mass/code_length**3].
"""
rho = (3.0 * self.M) / (4.0 * np.pi * self.R**3)
if verbose:
print('Density: {0:.2f} Msun pc^-2'.format(rho))
return rho
def get_initial_surface_density(self, verbose=False):
"""
Calculate the initial cloud surface density [code_mass/code_length**2].
"""
Sigma = self.M / (np.pi * self.R**2)
if verbose:
print('Surface density: {0:.2f} Msun pc^-2'.format(Sigma))
return Sigma
# Initial 3D rms velocity.
def get_initial_sigma_3D(self, verbose=False):
"""
Calculate the initial 3D rms velocity [code_velocity].
"""
sig_3D = np.sqrt((3.0 * self.alpha * self.G_code * self.M) / (5.0 * self.R))
if verbose:
print('sigma_3D = {0:.3f} m s^-1'.format(sig_3D))
return sig_3D
# Initial cloud trubulent crossing time.
def get_initial_t_cross(self, verbose=False):
"""
Calculate the initial turbulent crossing time as R/v_rms [code_time].
"""
sig_3D = self.get_initial_sigma_3D()
t_cross = self.R / sig_3D
if verbose:
print('t_cross = {0:.3g} [code]'.format(t_cross))
return t_cross
# Initial cloud gravitational free-fall time.
def get_initial_t_ff(self, verbose=False):
"""
Calculate the initial freefall time [code_time].
"""
rho = (3.0 * self.M) / (4.0 * np.pi * self.R**3)
t_ff = np.sqrt((3.0 * np.pi) / (32.0 * self.G_code * rho))
if verbose:
print('t_ff = {0:.3g} [code]'.format(t_ff))
return t_ff
class Disk:
"""
Class for analyzing disk properties within Snapshot.
Initialize with HDF5 file created by Snapshot.get_disk().
To-do: disk mass, radius, temperature, ionization fraction, etc.
- USE_IDX: Use stored array indices, not particle IDs, for
tracking disk particles if particle IDs are not unique.
"""
def __init__(self, fname, cloud, USE_IDX=False):
self.fname = fname
self.cloud = cloud
self.USE_IDX = USE_IDX # Use array indices instead of (non-unique) particle IDs.
# Read from saved HDF5 file.
with h5py.File(fname, 'r') as f:
header = f['header']
self.snapshot = header.attrs['snapshot'] # Snapshot number.
self.snapdir = header.attrs['snapdir'] # Snapshot data directory.
self.disk_type = header.attrs['disk_type']
self.disk_name = header.attrs['disk_name']
self.primary_sink = header.attrs['primary_sink']
self.sink_ids = header.attrs['sink_ids']
self.num_sinks = header.attrs['num_sinks']
self.num_gas = header.attrs['num_gas']
self.n_H_min = header.attrs['n_H_min']
self.disk_dm = header.attrs['disk_dm']
self.disk_mass = header.attrs['disk_mass']
self.truncation_radius_AU = header.attrs['truncation_radius_AU']
if header.attrs['truncated_by_neighbor'] == 'True':
self.truncated_by_neighbor = True
else:
self.truncated_by_neighbor = False
if USE_IDX:
self.disk_ids = f.get('disk_idx')[:]
else:
self.disk_ids = f.get('disk_ids')[:]
# Snapshot object.
self.Snapshot = self.get_snapshot(self.cloud)
# Time.
self.time = self.Snapshot.t
# Unit conversions from parent snapshot.
self.G_code = self.Snapshot.G_code
self.l_unit = self.Snapshot.l_unit
self.m_unit = self.Snapshot.m_unit
self.v_unit = self.Snapshot.v_unit
self.B_unit = self.Snapshot.B_unit
self.B_code = self.Snapshot.B_code
self.t_unit = self.Snapshot.t_unit
self.t_unit_myr = self.Snapshot.t_unit_myr
self.rho_unit = self.Snapshot.rho_unit
self.nH_unit = self.Snapshot.nH_unit
self.P_unit = self.Snapshot.P_unit
self.spec_L_unit = self.Snapshot.spec_L_unit
self.L_unit = self.Snapshot.L_unit
self.E_unit = self.Snapshot.E_unit # Internal energy per unit mass.
self.pc_to_au = 206265.0
self.u_to_temp_units = self.Snapshot.u_to_temp_units
#self.gizmo2gauss = self.B_code / self.B_unit
# Get array indices of disk particles from parent snapshot.
if USE_IDX:
self.idx_d = self.disk_ids
else:
self.idx_d = np.isin(self.Snapshot.p0_ids, self.disk_ids)
# Disk particle attributes from parent snapshot.
self.m = self.Snapshot.p0_m[self.idx_d] # Mass [code].
self.x = self.Snapshot.p0_x[self.idx_d] # Coordinates [code].
self.y = self.Snapshot.p0_y[self.idx_d]
self.z = self.Snapshot.p0_z[self.idx_d]
self.u = self.Snapshot.p0_u[self.idx_d] # Velocities [code].
self.v = self.Snapshot.p0_v[self.idx_d]
self.w = self.Snapshot.p0_w[self.idx_d]
self.Bx = self.Snapshot.p0_Bx[self.idx_d] # Magnetic field [code].
self.By = self.Snapshot.p0_By[self.idx_d]
self.Bz = self.Snapshot.p0_Bz[self.idx_d]
self.B_mag = self.Snapshot.p0_B_mag[self.idx_d]
self.rho = self.Snapshot.p0_rho[self.idx_d] # Density [code].
self.hsml = self.Snapshot.p0_hsml[self.idx_d] # Smoothing length.
self.E_int = self.Snapshot.p0_E_int[self.idx_d] # Internal energy per unit mass.
self.P = self.Snapshot.p0_P[self.idx_d] # Pressure.
self.cs = self.Snapshot.p0_cs[self.idx_d] # Sound speed.
self.n_H = self.Snapshot.p0_n_H[self.idx_d] # H number density [cm^-3].
self.Ne = self.Snapshot.p0_Ne[self.idx_d] # Electron abundance.
# Mean molecular weight, temperature, dust temperature.
self.mean_molecular_weight = self.Snapshot.p0_mean_molecular_weight[self.idx_d]
self.temperature = self.Snapshot.p0_temperature[self.idx_d]
self.dust_temp = self.Snapshot.p0_dust_temp[self.idx_d]
# Non-ideal MHD coefficients.
self.eta_O = self.Snapshot.p0_eta_O[self.idx_d]
self.eta_H = self.Snapshot.p0_eta_H[self.idx_d]
self.eta_A = self.Snapshot.p0_eta_A[self.idx_d]
# OLD ATTRIBUTES:
#self.n_He = self.Snapshot.p0_n_He[self.idx_d] # He number density [cm^-3].
#self.H_mass_frac = self.Snapshot.p0_H_mass_frac[self.idx_d]
#self.He_mass_frac = self.Snapshot.p0_He_mass_frac[self.idx_d]
self.neutral_H_abundance = self.Snapshot.p0_neutral_H_abundance[self.idx_d]
self.molecular_mass_frac = self.Snapshot.p0_molecular_mass_frac[self.idx_d]
#self.total_metallicity = self.Snapshot.p0_total_metallicity[self.idx_d]
# Disk + sink center-of-mass, angular momentum.
m_cm, x_cm, v_cm = self.Snapshot.system_center_of_mass(self.disk_ids, self.sink_ids, USE_IDX=USE_IDX)
L_unit_vec, L_mag = self.Snapshot.get_net_ang_mom(self.disk_ids, self.sink_ids, USE_IDX=USE_IDX)
x_hat, y_hat = self.Snapshot._get_orthogonal_vectors(L_unit_vec)
self.x_cm = np.reshape(x_cm, (3, 1))
self.v_cm = np.reshape(v_cm, (3, 1))
self.L_unit_vec = L_unit_vec
self.L_mag = L_mag
# Rotation matrix to Cartesian coordinate frame with z || L_unit_vec.
self.A = self.Snapshot._get_rotation_matrix(x_hat, y_hat, L_unit_vec)
# Cartesian coordinates, velocities in system center-of-mass frame.
self.X_cm = np.matmul(self.A, np.vstack((self.x, self.y, self.z)) - self.x_cm)
self.V_cm = np.matmul(self.A, np.vstack((self.u, self.v, self.w)) - self.v_cm)
# Rotate magnetic field to disk coordinate frame.
self.B_cm = np.matmul(self.A, np.vstack((self.Bx, self.By, self.Bz)))
# Convert to cylindrical coordinates.
disk_r = np.sqrt(self.X_cm[0, :]**2 + self.X_cm[1, :]**2)
disk_t = np.degrees(np.arctan(np.divide(self.X_cm[1, :], self.X_cm[0, :])))
disk_vr = np.divide(np.multiply(self.V_cm[0, :], self.X_cm[0, :]) + \
np.multiply(self.V_cm[1, :], self.X_cm[1, :]), disk_r)
disk_vt = np.divide(np.multiply(self.V_cm[1, :], self.X_cm[0, :]) - \
np.multiply(self.V_cm[0, :], self.X_cm[1, :]), disk_r)
self.X_cyl = np.vstack((disk_r, disk_t, self.X_cm[2, :]))
self.V_cyl = np.vstack((disk_vr, disk_vt, self.V_cm[2, :]))
self.omega = np.divide((np.multiply(self.X_cm[0, :] * self.l_unit, self.V_cm[1, :] * self.v_unit) - \
np.multiply(self.X_cm[1, :] * self.l_unit, self.V_cm[0, :] * self.v_unit)),
(self.X_cm[0, :]**2 + self.X_cm[1, :]**2)* self.l_unit**2)
# Convert magnetic field to cylindrical coordinates.
disk_Br = np.divide(np.multiply(self.B_cm[0, :], self.X_cm[0, :]) + \
np.multiply(self.B_cm[1, :], self.X_cm[1, :]), disk_r)
disk_Bt = np.divide(np.multiply(self.B_cm[1, :], self.X_cm[0, :]) - \
np.multiply(self.B_cm[0, :], self.X_cm[1, :]), disk_r)
self.B_cyl = np.vstack((disk_Br, disk_Bt, self.B_cm[2, :]))
def get_snapshot(self, cloud):
fname_snap = os.path.join(self.snapdir, 'snapshot_{0:03d}.hdf5'.format(self.snapshot))
return Snapshot(fname_snap, cloud)
def get_radial_profile(self, y_vals, num_bins=100, USE_IDX=False):
# Convert radial distance to AU.
r_vals = self.X_cyl[0, :] * self.pc_to_au
# Sort by radial distance.
idx_sort = np.argsort(r_vals)
r_vals, y_vals = r_vals[idx_sort], y_vals[idx_sort]
# Using equal-spaced bins.
y_mean, y_bin_edges, _ = stats.binned_statistic(r_vals, y_vals, statistic='mean', bins=num_bins)
# Bin centers.
x_vals = (y_bin_edges[:-1] + y_bin_edges[1:])/2
return x_vals, y_mean
def write_to_file(self, fname, density_cut=False, n_H_min=1e9, verbose=True):
mask_nH = None
idx_d = np.isin(self.disk_ids, self.disk_ids)
if density_cut:
if verbose:
print('Number of disk particles before density cut: {0:d}'.format(np.sum(idx_d)), flush=True)
mask_nH = (self.n_H >= n_H_min)
#mask_all = np.union1d(idx_d, mask_nH)
mask_all = np.logical_and(idx_d, mask_nH)
idx_d = mask_all
if verbose:
print('Number of disk particles after density cut: {0:d}'.format(np.sum(idx_d)), flush=True)
f = h5py.File(fname, 'w')
header = f.create_dataset('header', (1,))
header.attrs.create('primary_sink', self.primary_sink, dtype=int)
header.attrs.create('sink_ids', self.sink_ids, dtype=int)
header.attrs.create('n_H_min', self.n_H_min, dtype=float)
header.attrs.create('truncation_radius_AU', self.truncation_radius_AU, dtype=float)
header.attrs.create('time', self.time, dtype=float)
header.attrs.create('m_unit', self.m_unit, dtype=float)
header.attrs.create('l_unit', self.l_unit, dtype=float)
header.attrs.create('v_unit', self.v_unit, dtype=float)
header.attrs.create('t_unit', self.t_unit, dtype=float)
header.attrs.create('x_cm', self.x_cm, dtype=float)
header.attrs.create('v_cm', self.v_cm, dtype=float)
header.attrs.create('L_vec', self.L_unit_vec * self.L_mag, dtype=float)
header.attrs.create('rotation_matrix', self.A, dtype=float)
# If USE_IDX, disk_ids are actually disk_idx.
f.create_dataset('disk_ids', data=self.disk_ids[idx_d], dtype=int)
f.create_dataset('mass', data=self.m[idx_d], dtype=float)
f.create_dataset('X_orig', data=np.vstack((self.x, self.y, self.z))[:, idx_d], dtype=float)
f.create_dataset('V_orig', data=np.vstack((self.u, self.v, self.w))[:, idx_d], dtype=float)
f.create_dataset('B_orig', data=np.vstack((self.Bx, self.By, self.Bz))[:, idx_d], dtype=float)
f.create_dataset('X_cm', data=self.X_cm[:, idx_d], dtype=float)
f.create_dataset('V_cm', data=self.V_cm[:, idx_d], dtype=float)
f.create_dataset('B_cm', data=self.B_cm[:, idx_d], dtype=float)
f.create_dataset('X_cyl', data=self.X_cyl[:, idx_d], dtype=float)
f.create_dataset('V_cyl', data=self.V_cyl[:, idx_d], dtype=float)
f.create_dataset('B_cyl', data=self.B_cyl[:, idx_d], dtype=float)
f.create_dataset('B_mag', data=self.B_mag[idx_d], dtype=float)
f.create_dataset('rho', data=self.rho[idx_d], dtype=float)
f.create_dataset('hsml', data=self.hsml[idx_d], dtype=float)
f.create_dataset('E_int', data=self.E_int[idx_d], dtype=float)
f.create_dataset('P', data=self.P[idx_d], dtype=float)
f.create_dataset('cs', data=self.cs[idx_d], dtype=float)
f.create_dataset('n_H', data=self.n_H[idx_d], dtype=float)
f.create_dataset('Ne', data=self.Ne[idx_d], dtype=float)
f.create_dataset('mean_molecular_weight', data=self.mean_molecular_weight[idx_d], dtype=float)
f.create_dataset('temperature', data=self.temperature[idx_d], dtype=float)
f.create_dataset('dust_temp', data=self.dust_temp[idx_d], dtype=float)
f.create_dataset('eta_O', data=self.eta_O[idx_d], dtype=float)
f.create_dataset('eta_H', data=self.eta_H[idx_d], dtype=float)
f.create_dataset('eta_A', data=self.eta_A[idx_d], dtype=float)
f.create_dataset('omega', data=self.omega[idx_d], dtype=float)
f.close()
class Snapshot:
"""
Class for reading gas/sink particle data from HDF5 snapshot files.
Initialize with parent cloud.
- USE_IDX: Use array indices, not particle IDs, for tracking disk
particles if particle IDs are not unique.
"""
def __init__(self, fname, cloud, B_unit=1e4):
# Physical constants.
self.PROTONMASS_CGS = 1.6726e-24
self.ELECTRONMASS_CGS = 9.10953e-28
self.BOLTZMANN_CGS = 1.38066e-16
self.HYDROGEN_MASSFRAC = 0.76
self.ELECTRONCHARGE_CGS = 4.8032e-10
self.C_LIGHT_CGS = 2.9979e10
self.HYDROGEN_MASSFRAC = 0.76
# Initial cloud parameters.
self.fname = fname
self.snapdir = self.get_snapdir()
self.Cloud = cloud
self.M0 = cloud.M # Initial cloud mass, radius.
self.R0 = cloud.R
self.L0 = cloud.L # Volume-equivalent length.
self.alpha0 = cloud.alpha # Initial virial parameter.
# Open HDF5 file.
with h5py.File(fname, 'r') as f:
header = f['Header']
p0 = f['PartType0']
# Do star particles exist in this snapshot?
self.stars_exist = False
if 'PartType5' in f:
self.stars_exist = True
p5 = f['PartType5']
# Header attributes.
self.box_size = header.attrs['BoxSize']
self.num_p0 = header.attrs['NumPart_Total'][0]
self.num_p5 = header.attrs['NumPart_Total'][5]
self.t = header.attrs['Time']
# Unit conversions to cgs; note typo in header for G_code.
self.G_code = header.attrs['Gravitational_Constant_In_Code_Inits']
if 'Internal_UnitB_In_Gauss' in header.attrs:
self.B_code = header.attrs['Internal_UnitB_In_Gauss']
else:
self.B_code = 2.916731267922059e-09
self.l_unit = header.attrs['UnitLength_In_CGS']
self.m_unit = header.attrs['UnitMass_In_CGS']
self.v_unit = header.attrs['UnitVelocity_In_CGS']
self.B_unit = B_unit # Magnetic field unit in Gauss.
self.t_unit = self.l_unit / self.v_unit
self.t_unit_myr = self.t_unit / (3600.0 * 24.0 * 365.0 * 1e6)
self.rho_unit = self.m_unit / self.l_unit**3
self.nH_unit = self.rho_unit/self.PROTONMASS_CGS
self.P_unit = self.m_unit / self.l_unit / self.t_unit**2
self.spec_L_unit = self.l_unit * self.v_unit # Specific angular momentum (get_net_ang_mom).
self.L_unit = self.spec_L_unit * self.m_unit # Angular momentum.
self.E_unit = self.l_unit**2 / self.t_unit**2 # Energy [erg].
self.eta_unit = self.l_unit**2 / self.t_unit # Nonideal MHD diffusivities.
# Convert internal energy to temperature units.
self.u_to_temp_units = (self.PROTONMASS_CGS/self.BOLTZMANN_CGS)*self.E_unit
# Other useful conversion factors.
self.cm_to_AU = 6.6845871226706e-14
self.cm_to_pc = 3.2407792896664e-19
# Critical density for star formation
self.sf_density_threshold = header.attrs['Density_Threshold_For_SF_CodeUnits']
# PartType0 data.
self.p0_ids = p0['ParticleIDs'][()] # Particle IDs.
self.p0_cids = p0['ParticleChildIDsNumber'][()]
self.p0_m = p0['Masses'][()] # Masses.
self.p0_rho = p0['Density'][()] # Density.
self.p0_hsml = p0['SmoothingLength'][()] # Particle smoothing length.
self.p0_E_int = p0['InternalEnergy'][()] # Internal energy.
self.p0_P = p0['Pressure'][()] # Pressure.
self.p0_cs = p0['SoundSpeed'][()] # Sound speed.
self.p0_x = p0['Coordinates'][()][:, 0] # Coordinates.
self.p0_y = p0['Coordinates'][()][:, 1]
self.p0_z = p0['Coordinates'][()][:, 2]
self.p0_u = p0['Velocities'][()][:, 0] # Velocities.
self.p0_v = p0['Velocities'][()][:, 1]
self.p0_w = p0['Velocities'][()][:, 2]
self.p0_Ne = p0['ElectronAbundance'][()] # Electron abundance.
if 'MagneticField' in p0.keys():
self.p0_Bx = p0['MagneticField'][()][:, 0]
self.p0_By = p0['MagneticField'][()][:, 1]
self.p0_Bz = p0['MagneticField'][()][:, 2]
self.p0_B_mag = np.sqrt(self.p0_Bx**2 + self.p0_By**2 + self.p0_Bz**2)
else:
self.p0_Bx = np.zeros(len(self.p0_ids))
self.p0_By = np.zeros(len(self.p0_ids))
self.p0_Bz = np.zeros(len(self.p0_ids))
self.p0_B_mag = np.zeros(len(self.p0_ids))
self.p0_pot = p0['Potential'][()] # Gravitational potential.
# Hydrogen number density and total metallicity.
self.p0_n_H = (1.0 / self.PROTONMASS_CGS) * \
np.multiply(self.p0_rho * self.rho_unit, 1.0 - p0['Metallicity'][()][:, 0])
self.p0_total_metallicity = p0['Metallicity'][()][:, 0]
# Calculate mean molecular weight.
self.p0_mean_molecular_weight = self.get_mean_molecular_weight(self.p0_ids)
# Neutral hydrogen abundance, molecular mass fraction.
self.p0_neutral_H_abundance = p0['NeutralHydrogenAbundance'][()]
self.p0_molecular_mass_frac = p0['MolecularMassFraction'][()]
# Calculate gas adiabatic index and temperature.
fH, f, xe = self.HYDROGEN_MASSFRAC, p0['MolecularMassFraction'][()], self.p0_Ne
f_mono, f_di = fH*(xe + 1.-f) + (1.-fH)/4., fH*f/2.
gamma_mono, gamma_di = 5./3., 7./5.
gamma = 1. + (f_mono + f_di) / (f_mono/(gamma_mono-1.) + f_di/(gamma_di-1.))
self.p0_temperature = (gamma - 1.) * self.p0_mean_molecular_weight * \
self.u_to_temp_units * self.p0_E_int
# Dust temperature.
if 'Dust_Temperature' in p0.keys():
self.p0_dust_temp = p0['Dust_Temperature'][()]
# Get stored coefficients if HDF5 field exists.
if 'MagneticField' in p0.keys():
if 'NonidealDiffusivities' in p0.keys():
self.p0_eta_O = p0['NonidealDiffusivities'][()][:, 0]
self.p0_eta_H = p0['NonidealDiffusivities'][()][:, 1]
self.p0_eta_A = p0['NonidealDiffusivities'][()][:, 2]
# Else, calculate non-ideal MHD coefficients.
else:
if 'Dust_Temperature' in p0.keys():
eta_O, eta_H, eta_A = self.get_nonideal_MHD_coefficients(self.p0_ids)
else:
eta_O, eta_H, eta_A = 0.0, 0.0, 0.0
self.p0_eta_O = eta_O
self.p0_eta_H = eta_H
self.p0_eta_A = eta_A
else:
self.p0_eta_O = np.zeros(len(self.p0_ids))
self.p0_eta_H = np.zeros(len(self.p0_ids))
self.p0_eta_A = np.zeros(len(self.p0_ids))
if 'TimeStep' in p0.keys():
self.p0_timestep = p0['TimeStep'][()]
# For convenience, coordinates and velocities in a (n_gas, 3) array.
self.p0_coord = np.vstack((self.p0_x, self.p0_y, self.p0_z)).T
self.p0_vel = np.vstack((self.p0_u, self.p0_v, self.p0_w)).T
self.p0_mag = np.vstack((self.p0_Bx, self.p0_By, self.p0_Bz)).T
# PartType5 data.
if self.stars_exist:
# Particle IDs.
self.p5_ids = p5['ParticleIDs'][()] # Particle IDs.
self.p5_m = p5['Masses'][()] # Masses.
self.p5_x = p5['Coordinates'][()][:, 0] # Coordinates.
self.p5_y = p5['Coordinates'][()][:, 1]
self.p5_z = p5['Coordinates'][()][:, 2]
self.p5_u = p5['Velocities'][()][:, 0] # Velocities.
self.p5_v = p5['Velocities'][()][:, 1]
self.p5_w = p5['Velocities'][()][:, 2]
self.p5_lx = p5['BH_Specific_AngMom'][()][:, 0] # Specific angular momentum.
self.p5_ly = p5['BH_Specific_AngMom'][()][:, 1]
self.p5_lz = p5['BH_Specific_AngMom'][()][:, 2]
self.p5_coord = np.vstack((self.p5_x, self.p5_y, self.p5_z)).T
self.p5_vel = np.vstack((self.p5_u, self.p5_v, self.p5_w)).T
self.p5_pot = p5['Potential'][()] # Gravitational potential.
self.p5_bhmass = p5['BH_Mass'][()]
self.p5_bhmass_alpha_disk = p5['BH_Mass_AlphaDisk'][()]
self.p5_bhmdot = p5['BH_Mdot'][()]
# Sink particle attributes.
self.p5_sink_radius = p5['SinkRadius'][()]
self.p5_accretion_length = p5['BH_AccretionLength'][()]
self.p5_sf_time = p5['StellarFormationTime'][()]
# Initial t_cross, t_ff, 3D rms velocity, surface density.
self.t_cross0 = cloud.t_cross
self.t_ff0 = cloud.t_ff
self.vrms0 = cloud.vrms
self.rho0 = cloud.rho
self.Sigma0 = cloud.Sigma
# ----------------------------- FUNCTIONS ---------------------------------
# Try to get snapshot number from filename.
def get_i(self):
return int(self.fname.split('snapshot_')[1].split('.hdf5')[0])
# Try to get snapshot datadir from filename.
def get_snapdir(self):
return self.fname.split('snapshot_')[0]
def _get_center_of_mass(self, p_type, p_ids, USE_IDX=False):
"""
Calculates center of mass for (subset of) gas/sink particles.
Parameters:
- p_type: particle type; gas = 'PartType0', sink = 'PartType5'.
- p_ids: particle IDs of particles to include in center of mass
calculation.
- USE_IDX: p_ids are actually array indices of particles.
Returns: M, cm_x, cm_v
- M: total mass (scalar)
- cm_x: center of mass position (array)
- cm_v: center of mass velocity (array)
"""
if p_type == 'PartType0':
if USE_IDX:
idx_p = p_ids
else:
idx_p = np.isin(self.p0_ids, p_ids)
m, M = self.p0_m[idx_p], np.sum(self.p0_m[idx_p])
x, y, z = self.p0_x[idx_p], self.p0_y[idx_p], self.p0_z[idx_p]
u, v, w = self.p0_u[idx_p], self.p0_v[idx_p], self.p0_w[idx_p]
elif p_type == 'PartType5':
if self.num_p5 == 0:
return None
if USE_IDX:
idx_p = p_ids
else:
idx_p = np.isin(self.p5_ids, p_ids)
m, M = self.p5_m[idx_p], np.sum(self.p5_m[idx_p])
x, y, z = self.p5_x[idx_p], self.p5_y[idx_p], self.p5_z[idx_p]
u, v, w = self.p5_u[idx_p], self.p5_v[idx_p], self.p5_w[idx_p]
else:
return None
x_cm = np.sum(np.multiply(m, x))/M; u_cm = np.sum(np.multiply(m, u))/M
y_cm = np.sum(np.multiply(m, y))/M; v_cm = np.sum(np.multiply(m, v))/M
z_cm = np.sum(np.multiply(m, z))/M; w_cm = np.sum(np.multiply(m, w))/M
cm_x = np.asarray([x_cm, y_cm, z_cm])
cm_v = np.asarray([u_cm, v_cm, w_cm])
return M, cm_x, cm_v
def _two_body_center_of_mass(self, m1, x1, v1, m2, x2, v2):
"""
Calculates center of mass for a two-body system.
Parameters:
- m1, m2: masses
- x1, x2: position (array)
- v1, v2" velocity (array)
Returns: M, cm_x, cm_v
- M: total mass (scalar)
- cm_x: center of mass position (array)
- cm_v: center of mass velocity (array)
"""
m = m1 + m2
cm_x = (m1 * x1[0] + m2 * x2[0]) / m
cm_y = (m1 * x1[1] + m2 * x2[1]) / m
cm_z = (m1 * x1[2] + m2 * x2[2]) / m
cm_u = (m1 * v1[0] + m2 * v2[0]) / m
cm_v = (m1 * v1[1] + m2 * v2[1]) / m
cm_w = (m1 * v1[2] + m2 * v2[2]) / m
return m, np.asarray([cm_x, cm_y, cm_z]), np.asarray([cm_u, cm_v, cm_w])
# Get center of mass of (subset of) gas particles.
def gas_center_of_mass(self, gas_ids, USE_IDX=False):
"""
Calculates center of mass for (subset of) gas particles.
Parameters:
- gas_ids: particle IDs of gas particles to include in center of
mass calculation.
Returns: M, cm_x, cm_v
- M: total gas mass (scalar)
- cm_x: gas center of mass position (array)
- cm_v: gas center of mass velocity (array)
"""
M, cm_x, cm_v = self._get_center_of_mass('PartType0', gas_ids, USE_IDX=USE_IDX)
return M, cm_x, cm_v
# Get center of mass of (subset of) sink particles.
def sink_center_of_mass(self, sink_ids):
"""
Calculates center of mass for (subset specified by sink_ids of) sink
particles.
Parameters:
- sink_ids: particle IDs of sink particles to include in center
of mass calculation.
Returns: M, cm_x, cm_v
- M: total sink mass (scalar)
- cm_x: sink center of mass position (array)
- cm_v: sink center of mass velocity (array)
"""
M, cm_x, cm_v = self._get_center_of_mass('PartType5', sink_ids)
return M, cm_x, cm_v
# Get center of mass of combined gas/sink particles system.
def system_center_of_mass(self, gas_ids, sink_ids, USE_IDX=False):
"""
Calculates center of mass for system consisting of both sink and gas
particles.
Parameters:
- gas_ids: particle IDs of gas particles to include in center
of mass calculation.
- sink_ids: particle IDs of sink particles to include in center
of mass calculation.
Returns:
- M: total sink + gas mass (scalar)
- cm_x: sink + gas center of mass position (array)
- cm_v: sink + gas center of mass velocity (array)
"""
M1, x1, v1 = self.gas_center_of_mass(gas_ids, USE_IDX=USE_IDX)
M2, x2, v2 = self.sink_center_of_mass(sink_ids)
M, cm_x, cm_v = self._two_body_center_of_mass(M1, x1, v1, M2, x2, v2)
return M, cm_x, cm_v
# Get particle mass/position/velocity.
def _get_particle_kinematics(self, p_type, p_ids, USE_IDX=False):
"""
Returns masses, positions, and velocities of specified particles.
Parameters:
- p_type: particle type; gas = 'PartType0', sink = 'PartType5'.
- p_ids: particle IDs of specified particles.
- USE_IDX: p_ids are actually array indices of particles.
Returns: m, x, v.
- m: masses of specified particles (1D array)
- x: positions of specified particles (3D array)
- v: velocities of specified particles (3D array)
"""
if p_type == 'PartType0':
if USE_IDX:
idx_p = p_ids
else:
if np.isscalar(p_ids):
idx_p = np.where(self.p0_ids == p_ids)[0][0]
else:
idx_p = np.isin(self.p0_ids, p_ids)
m = self.p0_m[idx_p]
x, y, z = self.p0_x[idx_p], self.p0_y[idx_p], self.p0_z[idx_p]
u, v, w = self.p0_u[idx_p], self.p0_v[idx_p], self.p0_w[idx_p]
elif p_type == 'PartType5':
if USE_IDX:
idx_p = p_ids
else:
if self.num_p5 == 0:
return None
if np.isscalar(p_ids):
idx_p = np.where(self.p5_ids == p_ids)[0][0]
else:
idx_p = np.isin(self.p5_ids, p_ids)
m = self.p5_m[idx_p]
x, y, z = self.p5_x[idx_p], self.p5_y[idx_p], self.p5_z[idx_p]
u, v, w = self.p5_u[idx_p], self.p5_v[idx_p], self.p5_w[idx_p]
else:
return None
if np.isscalar(p_ids):
return m, np.asarray([x, y, z]), np.asarray([u, v, w])
else:
return m, np.vstack((x, y, z)).T, np.vstack((u, v, w)).T
# Get relative particle mass/position/velocity.
def _get_particle_relative_kinematics(self, p_type, p_ids, point_x, point_v, USE_IDX=False):
"""
Returns masses, positions, and velocities of specified particles relative
to the point specified by point_x, point_v.
Parameters:
- p_type: particle type; gas = 'PartType0', sink = 'PartType5'.
- p_ids: particle IDs of specified particles.
- point_x: [array-like] (x, y, z) position specifying origin of
new coordinate system.
- point_v: [array-like] (u, v, w) velocity specifying origin of
new coordinate system.
Returns: m, x, v.
- m: masses of specified particles (1D array)
- x: relative positions of specified particles (3D array)
- v: relative velocities of specified particles (3D array)
"""
x0, y0, z0 = point_x[0], point_x[1], point_x[2]
u0, v0, w0 = point_v[0], point_v[1], point_v[2]
if p_type == 'PartType0':
if USE_IDX:
idx_p = p_ids
else:
if np.isscalar(p_ids):
idx_p = np.where(self.p0_ids == p_ids)[0][0]
else:
idx_p = np.isin(self.p0_ids, p_ids)
m = self.p0_m[idx_p]
x, y, z = self.p0_x[idx_p] - x0, self.p0_y[idx_p] - y0, self.p0_z[idx_p] - z0
u, v, w = self.p0_u[idx_p] - u0, self.p0_v[idx_p] - v0, self.p0_w[idx_p] - w0
elif p_type == 'PartType5':
if USE_IDX:
idx_p = p_ids
else:
if self.num_p5 == 0:
return None
if np.isscalar(p_ids):
idx_p = np.where(self.p5_ids == p_ids)[0][0]
else:
idx_p = np.isin(self.p5_ids, p_ids)
m = self.p5_m[idx_p]
x, y, z = self.p5_x[idx_p] - x0, self.p5_y[idx_p] - y0, self.p5_z[idx_p] - z0
u, v, w = self.p5_u[idx_p] - u0, self.p5_v[idx_p] - v0, self.p5_w[idx_p] - w0
else:
return None
if np.isscalar(p_ids):
return m, np.asarray([x, y, z]), np.asarray([u, v, w])
else:
return m, np.vstack((x, y, z)).T, np.vstack((u, v, w)).T
# Get gas particle mass, position, velocity.
def get_gas_kinematics(self, gas_ids, USE_IDX=False):
"""
Returns masses, positions, and velocities of specified gas particles.
Parameters:
- gas_ids: particle IDs of specified gas particles.
Returns: m, x, v.
- m: masses of specified gas particles (1D array)
- x: positions of specified gas particles (3D array)
- v: velocities of specified gas particles (3D array)
"""
m, x, v = self._get_particle_kinematics('PartType0', gas_ids, USE_IDX=USE_IDX)
return m, x, v
# Get gas particle mass, position, velocity relative to x0, v0.
def get_gas_relative_kinematics(self, gas_ids, x0, v0, USE_IDX=False):
"""
Returns masses, positions, and velocities of specified gas particles
relative to the point specified by point_x, point_v.
Parameters:
- gas_ids: particle IDs of specified gas particles.
- point_x: [array-like] (x, y, z) position specifying origin of
new coordinate system.
- point_v: [array-like] (u, v, w) velocity specifying origin of
new coordinate system.
Returns: m, x, v.
- m: masses of specified gas particles (1D array)
- x: relative positions of specified gas particles (3D array)
- v: relative velocities of specified gas particles (3D array)
"""
m, x, v = self._get_particle_relative_kinematics('PartType0', gas_ids, x0, v0, USE_IDX=USE_IDX)
return m, x, v
# Get sink particle mass, position, velocity.
def get_sink_kinematics(self, sink_ids):
"""
Returns masses, positions, and velocities of specified sink particles.
Parameters:
- sink_ids: particle IDs of specified sink particles.
Returns: m, x, v.
- m: masses of specified sink particles (1D array)
- x: positions of specified sink particles (3D array)
- v: velocities of specified sink particles (3D array)
"""
m, x, v = self._get_particle_kinematics('PartType5', sink_ids)
return m, x, v
# Get sink particle mass, position, velocity relative to x0, v0.
def get_sink_relative_kinematics(self, sink_ids, x0, v0):
"""
Returns masses, positions, and velocities of specified sink particles
relative to the point specified by point_x, point_v.
Parameters:
- sink_ids: particle IDs of specified sink particles.
- point_x: [array-like] (x, y, z) position specifying origin of
new coordinate system.
- point_v: [array-like] (u, v, w) velocity specifying origin of
new coordinate system.
Returns: m, x, v.
- m: masses of specified sink particles (1D array)
- x: relative positions of specified sink particles (3D array)
- v: relative velocities of specified sink particles (3D array)
"""
m, x, v = self._get_particle_relative_kinematics('PartType5', sink_ids, x0, v0)
return m, x, v
# Return particle IDs of gas above density threshhold.
def get_density_cut(self, rho_cut):
"""
Returns particle IDs of gas particles with density above the density
threshhold specified by rho_cut.
Parameters:
- rho_cut: density threshhold [g/cm^3]
Returns:
- particle IDs of gas particles above density threshhold (array).
"""
cut = (self.p0_rho * self.rho_unit) > rho_cut
return self.p0_ids[cut]
# Get 3D rms velocity dispersion of gas_ids.
def get_sigma_3D_gas(self, gas_ids):
"""
Calculates the 3D rms velocity dispersion of the specified gas
particles.
Parameters:
- gas_ids: particle IDs of gas particles to include in the
calculation.
Returns:
- sigma_3D: 3D rms velocity dispersion [code units]
"""
idx_g = np.isin(self.p0_ids, gas_ids)
m = self.p0_m[idx_g]
u, v, w = self.p0_u[idx_g], self.p0_v[idx_g], self.p0_w[idx_g]
sigma_3D = np.sqrt((self.weight_std(u, m)**2.0 + self.weight_std(v, m)**2.0 + \
self.weight_std(w, m)**2.0))
return sigma_3D
# Get 3D rms Mach number (c_s in cm s^-1) of gas_ids.
def get_Mach_gas(self, gas_ids, c_s=2.0e4):
"""
Calculates the Mach number of the specified gas particles, assuming
a constant sound speed c_s. (TO-DO: use actual sound speed.)
Parameters:
- gas_ids: particle IDs of gas particles to include in the
calculation.
- c_s: sound speed [cm/s].
Returns:
- Mach number.
"""
sigma_3D = self.get_sigma_3D_gas(gas_ids)
c_s = c_s / self.v_unit
Mach = sigma_3D / c_s
return Mach
# Get turbulent virial parameter from 3D rms velocity.
def get_alpha_gas(self, gas_ids):
"""
Calculates the turbulent virial parameter of the specified gas
particles.
Parameters:
- gas_ids: particle IDs of gas particles to include in the
calculation.
Returns:
- alpha: turbulent virial parameter = (5*sigma_3D^2*R)/(3*GM)
"""
sigma_3D = self.get_sigma_3D_gas(gas_ids)
alpha = (5.0 * sigma_3D**2 * self.R0) / (3.0 * self.G_code * self.M0)
return alpha
# Get RMS distance to center of mass.
def get_rms_radius(self, gas_ids):
idx_g = np.isin(self.p0_ids, gas_ids)
m_vals = self.p0_m[idx_g]
M_cm, x_cm, v_cm = self.gas_center_of_mass(gas_ids)
x0, y0, z0 = x_cm[0], x_cm[1], x_cm[2]
x_rel, y_rel, z_rel = self.p0_x[idx_g] - x0, self.p0_y[idx_g] - y0, self.p0_z[idx_g] - z0
r_vals = np.sqrt(x_rel**2 + y_rel**2 + z_rel**2)
idx_sort = np.argsort(r_vals)
m_vals, r_vals = m_vals[idx_sort], r_vals[idx_sort]
r_rms = self.weight_std(r_vals, m_vals)
return r_rms
# Get half-mass radius of selected gas particles.
def get_half_mass_radius(self, gas_ids, tol=0.5, verbose=False):
# Initial cloud mass, half-mass radius,
M, R = self.M0, self.R0
m_half = M / 2.0 # Or use M?
r_half = (0.5)**(1.0/3.0) * R # If uniform density.
r_guess = r_half
# Center of mass, indices of selected gas particles.
M_cm, x_cm, v_cm = self.gas_center_of_mass(gas_ids)
idx_g = np.isin(self.p0_ids, gas_ids)
# Center of mass; coordinates of selected gas particles relative to center of mass.
x0, y0, z0 = x_cm[0], x_cm[1], x_cm[2]
x_rel, y_rel, z_rel = self.p0_x[idx_g] - x0, self.p0_y[idx_g] - y0, self.p0_z[idx_g] - z0
# Masses and distances os selected particles.
m_vals = self.p0_m[idx_g]
r_vals = np.sqrt(x_rel**2 + y_rel**2 + z_rel**2)
# Sort gas particles according to distancen from center of mass.
idx_sort = np.argsort(r_vals)
m_vals, r_vals = m_vals[idx_sort], r_vals[idx_sort]
# Get current enclosed mass.
cut = r_vals < r_guess
m_enc = np.sum(m_vals[cut])
while True:
if verbose:
print('Current:\tr_half = {0:.5f} pc\tm_enc = {1:.5f} Msun'.format(r_guess, m_enc))
if m_enc <= m_half + tol and m_enc >= m_half - tol:
if verbose:
print('Found half-mass radius (r = {0:.5f} pc)\t(m_enc = {1:.3f})'.format(r_guess, m_enc))
return r_guess
elif m_enc >= m_half + tol:
r_guess *= 0.9
cut = r_vals < r_guess
m_enc = np.sum(m_vals[cut])
else:
r_guess *= 1.1
cut = r_vals < r_guess
m_enc = np.sum(m_vals[cut])
# Sort particles by distance to specified coordinates.
def _sort_particles_by_distance_to_point(self, p_type, p_ids, point, USE_IDX=False):
"""
Sorts the specified particles according to distance from the specified
point.
Parameters:
- p_type: particle type; gas = 'PartType0', sink = 'PartType5'.
- p_ids: particle IDs of specified particles.
- point: [array-like] (x, y, z) coordinates specifying origin of
new coordinate system.
Returns:
- r_sort: [1D array] sorted distances to specified point, in
increasing order.
- ids_sort: [1D array] sorted particle IDs.
- idx_sort: [1D array] indices corresponding to sort; e.g.
p_ids[idx_sort] = ids_sort.
"""
x0, y0, z0 = point[0], point[1], point[2]
if p_type == 'PartType0':
if USE_IDX:
idx_p = p_ids
else:
idx_p = np.isin(self.p0_ids, p_ids)
ids_p = self.p0_ids[idx_p]
x1, y1, z1 = self.p0_x[idx_p], self.p0_y[idx_p], self.p0_z[idx_p]
elif p_type == 'PartType5':
if self.num_p5 == 0:
return None
if USE_IDX:
idx_p = p_ids
else:
idx_p = np.isin(self.p5_ids, p_ids)
ids_p = self.p5_ids[idx_p]
x1, y1, z1 = self.p5_x[idx_p], self.p5_y[idx_p], self.p5_z[idx_p]
else:
return None
x, y, z = x1 - x0, y1 - y0, z1 - z0
r = np.sqrt(x**2 + y**2 + z**2)
idx_sort = np.argsort(r)
if USE_IDX:
return r[idx_sort], idx_p[idx_sort], idx_sort
else:
return r[idx_sort], ids_p[idx_sort], idx_sort
# Sort gas particles by distance to point (x, y, z).
def sort_gas_by_distance_to_point(self, gas_ids, point, USE_IDX=False):
"""
Sorts the specified gas particles according to distance from the
specified point.
Parameters:
- gas_ids: particle IDs of the specified gas particles.
- point: [array-like] (x, y, z) coordinates specifying origin of
new coordinate system.
Returns:
- r_sort: [1D array] sorted distances to specified point, in
increasing order.
- ids_sort: [1D array] sorted gas particle IDs.
- idx_sort: [1D array] indices corresponding to sort; e.g.
gas_ids[idx_sort] = ids_sort.
"""
r, ids, idx = self._sort_particles_by_distance_to_point('PartType0', gas_ids, point, USE_IDX=USE_IDX)
return r, ids, idx
# Sort sink particles by distance to point (x, y, z).
def sort_sinks_by_distance_to_point(self, sink_ids, point):
"""
Sorts the specified sink particles according to distance from the
specified point.
Parameters:
- sink_ids: particle IDs of the specified sink particles.
- point: [array-like] (x, y, z) coordinates specifying origin of
new coordinate system.
Returns:
- r_sort: [1D array] sorted distances to specified point, in
increasing order.
- ids_sort: [1D array] sorted sink particle IDs.
- idx_sort: [1D array] indices corresponding to sort; e.g.