Created
November 3, 2017 22:50
-
-
Save Yuta-Tarumi/69ed0428db92553cd4f8ef9392429036 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import yt | |
ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030") | |
#yt : [INFO ] 2017-11-03 18:41:25,225 Parameters: current_time = 0.00600002000283 | |
#yt : [INFO ] 2017-11-03 18:41:25,226 Parameters: domain_dimensions = [32 32 32] | |
#yt : [INFO ] 2017-11-03 18:41:25,228 Parameters: domain_left_edge = [ 0. 0. 0.] | |
#yt : [INFO ] 2017-11-03 18:41:25,230 Parameters: domain_right_edge = [ 1. 1. 1.] | |
#yt : [INFO ] 2017-11-03 18:41:25,231 Parameters: cosmological_simulation = 0.0 | |
region1 = ds.sphere([0.5, 0.5, 0.5], (1, 'kpc')) | |
region2 = ds.sphere([0.45, 0.45, 0.45], (1, 'kpc')) | |
#Parsing Hierarchy : 100%|██████████| 173/173 [00:00<00:00, 1275.75it/s] | |
#yt : [INFO ] 2017-11-03 18:41:25,408 Gathering a field list (this may take a moment.) | |
profile1 = yt.create_profile( | |
data_source=region1, | |
bin_fields=["density", "temperature"], | |
fields=["cell_mass"], | |
n_bins=[128, 128], | |
units=dict(), | |
logs=dict(), | |
weight_field=None, | |
extrema=dict(density=(1e-30, 1e-20), temperature=(1e1, 1e8)) | |
) | |
plot1 = yt.PhasePlot.from_profile(profile1) | |
profile_1 = plot1.profile | |
print(profile_1["cell_mass"]) | |
#[[ 0. 0. 0. ..., 0. 0. 0.] | |
# [ 0. 0. 0. ..., 0. 0. 0.] | |
# [ 0. 0. 0. ..., 0. 0. 0.] | |
# ..., | |
# [ 0. 0. 0. ..., 0. 0. 0.] | |
# [ 0. 0. 0. ..., 0. 0. 0.] | |
# [ 0. 0. 0. ..., 0. 0. 0.]] g | |
profile2 = yt.create_profile( | |
data_source=region2, | |
bin_fields=["density", "temperature"], | |
fields=["cell_mass"], | |
n_bins=[128, 128], | |
units=dict(), | |
logs=dict(), | |
weight_field=None, | |
extrema=dict(density=(1e-30, 1e-20), temperature=(1e1, 1e8)) | |
) | |
plot2 = yt.PhasePlot.from_profile(profile2) | |
profile_2 = plot2.profile | |
print(profile_2["cell_mass"]) | |
#[[ 0. 0. 0. ..., 0. 0. 0.] | |
# [ 0. 0. 0. ..., 0. 0. 0.] | |
# [ 0. 0. 0. ..., 0. 0. 0.] | |
# ..., | |
# [ 0. 0. 0. ..., 0. 0. 0.] | |
# [ 0. 0. 0. ..., 0. 0. 0.] | |
# [ 0. 0. 0. ..., 0. 0. 0.]] g | |
profiles_sum = profile_1["cell_mass"] + profile_2["cell_mass"] | |
profiles_sum | |
#YTArray([[ 0., 0., 0., ..., 0., 0., 0.], | |
# [ 0., 0., 0., ..., 0., 0., 0.], | |
# [ 0., 0., 0., ..., 0., 0., 0.], | |
# ..., | |
# [ 0., 0., 0., ..., 0., 0., 0.], | |
# [ 0., 0., 0., ..., 0., 0., 0.], | |
# [ 0., 0., 0., ..., 0., 0., 0.]]) g | |
my_data = {"density": profile_1.x, | |
"temperature": profile_1.y, | |
"cell_mass": profiles_sum} | |
fake_ds_med = {"current_time": yt.YTQuantity(10, "Myr")} | |
yt.save_as_dataset(fake_ds_med, "mydata.h5", my_data) | |
#yt : [INFO ] 2017-11-03 18:41:30,499 Saving field data to yt dataset: mydata.h5. | |
ds = yt.load("mydata.h5") | |
ad = ds.data | |
profile = yt.create_profile(ad, | |
["density", "temperature"], | |
n_bins=[128, 128], | |
fields=["cell_mass"], | |
weight_field=None, | |
extrema=dict(density=(1e-30, 1e-20), temperature=(1e1, 1e8)) | |
) | |
#yt : [INFO ] 2017-11-03 18:41:38,357 Parameters: current_time = 10.0 Myr | |
#yt : [WARNING ] 2017-11-03 18:41:38,359 Geometric data selection not available for this dataset type. | |
# | |
#ValueErrorTraceback (most recent call last) | |
#<ipython-input-8-c94f178c7ab4> in <module>() | |
# 11 fields=["cell_mass"], | |
# 12 weight_field=None, | |
#---> 13 extrema=dict(density=(1e-30, 1e-20), temperature=(1e1, 1e8)) | |
# 14 ) | |
# 15 | |
# | |
#/home/ytarumi/.local/yt/yt/data_objects/profiles.pyc in create_profile(data_source, bin_fields, fields, n_bins, extrema, logs, units, weight_field, accumulation, fractional, deposition) | |
# 1093 setattr(obj, "fractional", fractional) | |
# 1094 if fields is not None: | |
#-> 1095 obj.add_fields([field for field in fields]) | |
# 1096 for field in fields: | |
# 1097 if fractional: | |
# | |
#/home/ytarumi/.local/yt/yt/data_objects/profiles.pyc in add_fields(self, fields) | |
# 125 citer = self.data_source.chunks([], "io") | |
# 126 for chunk in parallel_objects(citer): | |
#--> 127 self._bin_chunk(chunk, fields, temp_storage) | |
# 128 self._finalize_storage(fields, temp_storage) | |
# 129 | |
# | |
#/home/ytarumi/.local/yt/yt/data_objects/profiles.pyc in _bin_chunk(self, chunk, fields, storage) | |
# 565 | |
# 566 def _bin_chunk(self, chunk, fields, storage): | |
#--> 567 rv = self._get_data(chunk, fields) | |
# 568 if rv is None: return | |
# 569 fdata, wdata, (bf_x, bf_y) = rv | |
# | |
#/home/ytarumi/.local/yt/yt/data_objects/profiles.pyc in _get_data(self, chunk, fields) | |
# 253 for i, field in enumerate(fields): | |
# 254 units = chunk.ds.field_info[field].output_units | |
#--> 255 arr[:,i] = chunk[field][filter].in_units(units) | |
# 256 if self.weight_field is not None: | |
# 257 units = chunk.ds.field_info[self.weight_field].output_units | |
# | |
#ValueError: could not broadcast input array from shape (128,128) into shape (128) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment