Issue #1026: yt.load_particles cannot handle multiple types of dictionary fields. (yt_analysis/yt)
New issue 1026: yt.load_particles cannot handle multiple types of dictionary fields. https://bitbucket.org/yt_analysis/yt/issue/1026/ytload_particles-cannot-hand... Benjamin Thompson: yt.load_particles works fine so long as you keep the dictionary fields consistant. For example ``` #!python import numpy as np import yt from yt.units.yt_array import YTArray from yt.units import kiloparsec, Msun, kilometer, second, Gyr n_data = 3000 sim_data_verb = {"particle_mass": YTArray(np.random.rand(n_data) * 1000,"Msun"), "particle_position_x": np.random.rand(n_data), "particle_position_y": np.random.rand(n_data), "particle_position_z": np.random.rand(n_data), "particle_velocity_x": YTArray(np.random.rand(n_data), "kpc/s"), "particle_velocity_y": YTArray(np.random.rand(n_data), "kpc/s"), "particle_velocity_z": YTArray(np.random.rand(n_data), "kpc/s"), "particle_mass_birth_epoch": YTArray(np.random.rand(n_data), "Msun"), "particle_birth_epoch": YTArray(np.random.rand(n_data), "Gyr"), "particle_metallicity": YTArray(np.random.rand(n_data),"dimensionless") } bbox = yt.YTArray(np.array([[0,1],[0,1],[0,1]]),"kpc") ds = yt.load_particles(sim_data_verb, length_unit=kiloparsec, mass_unit=Msun, time_unit=second, bbox=bbox, n_ref=256) ad = ds.all_data() for key in sim_data_verb: print key, ad[key] ``` will work but will return ``` #!python particle_position_z [ 0.2815859 0.38847204 0.22986295 ..., 0.29531876 0.66077444 0.88342952] code_length particle_position_x [ 0.35727259 0.52799574 0.7032232 ..., 0.78598736 0.43919501 0.77617413] code_length particle_position_y [ 0.21314061 0.71663901 0.19971711 ..., 0.41379908 0.20679615 0.26690946] code_length particle_metallicity [ 0.19719678 0.8893857 0.71944182 ..., 0.94147203 0.40978591 0.37535933] dimensionless particle_mass_birth_epoch [ 0.14538698 0.91165767 0.24366002 ..., 0.93701722 0.31856248 0.2815376 ] dimensionless particle_velocity_z [ 1.32970858e+21 2.02143717e+21 8.91082065e+20 ..., 1.45218388e+20 9.72945874e+20 3.02182398e+21] cm/s particle_birth_epoch [ 0.74899177 0.80996651 0.39013562 ..., 0.55047881 0.21678475 0.07351061] dimensionless particle_mass [ 4.94763075e+35 7.77704243e+35 1.12806228e+36 ..., 8.01759848e+35 1.49906294e+36 2.58791744e+35] g particle_velocity_x [ 2.83463595e+21 2.21176517e+21 1.45116224e+21 ..., 1.15946794e+21 2.20856829e+21 1.40417681e+21] cm/s particle_velocity_y [ 3.27195893e+20 1.88669889e+21 3.58577639e+20 ..., 1.01434342e+21 2.92246102e+20 2.07493516e+21] cm/s ``` and e.g particle_mass_birth_epoch will be dimensionless whereas if you were to be consistent with the arrays ``` #!python import numpy as np import yt from yt.units.yt_array import YTArray from yt.units import kiloparsec, Msun, kilometer, second, Gyr n_data = 3000 sim_data_verb = {"particle_mass": YTArray(np.random.rand(n_data) * 1000,"Msun"), "particle_position_x": YTArray(np.random.rand(n_data),"kpc"), "particle_position_y": YTArray(np.random.rand(n_data),"kpc"), "particle_position_z": YTArray(np.random.rand(n_data),"kpc"), "particle_velocity_x": YTArray(np.random.rand(n_data), "kpc/s"), "particle_velocity_y": YTArray(np.random.rand(n_data), "kpc/s"), "particle_velocity_z": YTArray(np.random.rand(n_data), "kpc/s"), "particle_mass_birth_epoch": YTArray(np.random.rand(n_data), "Msun"), "particle_birth_epoch": YTArray(np.random.rand(n_data), "Gyr"), "particle_metallicity": YTArray(np.random.rand(n_data),"dimensionless") } bbox = yt.YTArray(np.array([[0,1],[0,1],[0,1]]),"kpc") ds = yt.load_particles(sim_data_verb, length_unit=kiloparsec, mass_unit=Msun, time_unit=second, bbox=bbox, n_ref=256) ad = ds.all_data() for key in sim_data_verb: print key, ad[key] ``` you get sensible results ``` #!python particle_position_z [ 1.91010138e+21 2.72597553e+21 1.88470277e+20 ..., 1.20441080e+21 2.14680199e+21 5.77431567e+20] cm particle_position_x [ 2.08016250e+21 3.50853505e+20 1.58804046e+21 ..., 1.57472014e+21 3.55352460e+20 2.40592132e+21] cm particle_position_y [ 1.53145514e+21 1.87942152e+21 3.01891288e+21 ..., 1.61942691e+21 1.02154497e+21 2.49263525e+21] cm particle_metallicity [ 0.20026758 0.74414137 0.11611151 ..., 0.71398545 0.9404482 0.12193648] dimensionless particle_mass_birth_epoch [ 0.55149932 0.80309968 0.07713267 ..., 0.16103389 0.85597544 0.55997554] Msun particle_velocity_z [ 1.55542587e+21 2.57960677e+21 2.90400726e+21 ..., 1.90426357e+21 2.94137672e+21 8.78600990e+20] cm/s particle_birth_epoch [ 0.12942072 0.00235603 0.63535871 ..., 0.8858202 0.58461139 0.34462516] Gyr particle_mass [ 1.05296456e+36 1.92696089e+36 3.48006468e+35 ..., 9.26929432e+35 1.86347040e+36 1.21576381e+36] g particle_velocity_x [ 1.01967742e+21 2.38948376e+21 1.83127998e+21 ..., 1.18012037e+20 1.90840829e+21 2.71858174e+21] cm/s particle_velocity_y [ 2.01127183e+20 8.90953057e+20 2.38801554e+21 ..., 1.68662686e+20 3.00596354e+21 4.53271032e+20] cm/s ``` i.e particle_mass_birth_epoch now has dimensions _______________________________________________ yt-dev mailing list yt-dev@lists.spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-dev-spacepope.org
participants (1)
-
Benjamin Thompson