Skip to content

Commit

Permalink
Merge pull request yt-project#4844 from cphyc/remove-parenthesis-in-g…
Browse files Browse the repository at this point in the history
…etitem-calls

Remove parenthesis in getitem calls
  • Loading branch information
neutrinoceros authored Mar 18, 2024
2 parents 6ed9cae + 0057a38 commit 192f26b
Show file tree
Hide file tree
Showing 173 changed files with 1,560 additions and 1,606 deletions.
2 changes: 1 addition & 1 deletion doc/source/analyzing/fields.rst
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ following:
density = ad["gas", "density"]
# full field tuple
density = ad[("gas", "density")]
density = ad["gas", "density"]
# through the ds.fields object
density = ad[ds.fields.gas.density]
Expand Down
4 changes: 2 additions & 2 deletions doc/source/analyzing/filtering.rst
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ only the particles with ``particle_type`` (i.e. field = ``('all',
@yt.particle_filter(requires=["particle_type"], filtered_type="all")
def stars(pfilter, data):
filter = data[(pfilter.filtered_type, "particle_type")] == 2
filter = data[pfilter.filtered_type, "particle_type"] == 2
return filter
The :func:`~yt.data_objects.particle_filters.particle_filter` decorator takes a
Expand All @@ -188,7 +188,7 @@ As an alternative syntax, you can also define a new particle filter via the
.. code-block:: python
def stars(pfilter, data):
filter = data[(pfilter.filtered_type, "particle_type")] == 2
filter = data[pfilter.filtered_type, "particle_type"] == 2
return filter
Expand Down
4 changes: 2 additions & 2 deletions doc/source/analyzing/ionization_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
name="IonizedHydrogen", units="", display_name=r"\frac{\rho_{HII}}{\rho_H}"
)
def IonizedHydrogen(field, data):
return data[("gas", "HII_Density")] / (
data[("gas", "HI_Density")] + data[("gas", "HII_Density")]
return data["gas", "HII_Density"] / (
data["gas", "HI_Density"] + data["gas", "HII_Density"]
)


Expand Down
2 changes: 1 addition & 1 deletion doc/source/cookbook/custom_colorbar_tickmarks.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
},
"outputs": [],
"source": [
"plot = slc.plots[(\"gas\", \"density\")]"
"plot = slc.plots[\"gas\", \"density\"]"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion doc/source/cookbook/extract_fixed_resolution_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
f = h5py.File("my_data.h5", mode="w")

# We create a dataset at the root, calling it "density"
f.create_dataset("/density", data=cube[("gas", "density")])
f.create_dataset("/density", data=cube["gas", "density"])

# We close our file
f.close()
Expand Down
12 changes: 6 additions & 6 deletions doc/source/cookbook/hse_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@

def _hse(field, data):
# Remember that g is the negative of the potential gradient
gx = -data[("gas", "density")] * data[("gas", "gravitational_potential_gradient_x")]
gy = -data[("gas", "density")] * data[("gas", "gravitational_potential_gradient_y")]
gz = -data[("gas", "density")] * data[("gas", "gravitational_potential_gradient_z")]
hx = data[("gas", "pressure_gradient_x")] - gx
hy = data[("gas", "pressure_gradient_y")] - gy
hz = data[("gas", "pressure_gradient_z")] - gz
gx = -data["gas", "density"] * data["gas", "gravitational_potential_gradient_x"]
gy = -data["gas", "density"] * data["gas", "gravitational_potential_gradient_y"]
gz = -data["gas", "density"] * data["gas", "gravitational_potential_gradient_z"]
hx = data["gas", "pressure_gradient_x"] - gx
hy = data["gas", "pressure_gradient_y"] - gy
hz = data["gas", "pressure_gradient_z"] - gz
h = np.sqrt((hx * hx + hy * hy + hz * hz) / (gx * gx + gy * gy + gz * gz))
return h

Expand Down
2 changes: 1 addition & 1 deletion doc/source/cookbook/matplotlib-animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
plot = yt.SlicePlot(ts[0], "z", ("gas", "density"))
plot.set_zlim(("gas", "density"), 8e-29, 3e-26)

fig = plot.plots[("gas", "density")].figure
fig = plot.plots["gas", "density"].figure


# animate must accept an integer frame number. We use the frame number
Expand Down
4 changes: 2 additions & 2 deletions doc/source/cookbook/multi_plot_3x2_FRB.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@

# converting our fixed resolution buffers to NDarray so matplotlib can
# render them
dens = np.array(frb[("gas", "density")])
temp = np.array(frb[("gas", "temperature")])
dens = np.array(frb["gas", "density"])
temp = np.array(frb["gas", "temperature"])

plots.append(den_axis.imshow(dens, norm=LogNorm()))
plots[-1].set_clim((5e-32, 1e-29))
Expand Down
12 changes: 6 additions & 6 deletions doc/source/cookbook/multi_plot_slice_and_proj.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@
# Converting our Fixed Resolution Buffers to numpy arrays so that matplotlib
# can render them

slc_dens = np.array(slc_frb[("gas", "density")])
proj_dens = np.array(proj_frb[("gas", "density")])
slc_temp = np.array(slc_frb[("gas", "temperature")])
proj_temp = np.array(proj_frb[("gas", "temperature")])
slc_vel = np.array(slc_frb[("gas", "velocity_magnitude")])
proj_vel = np.array(proj_frb[("gas", "velocity_magnitude")])
slc_dens = np.array(slc_frb["gas", "density"])
proj_dens = np.array(proj_frb["gas", "density"])
slc_temp = np.array(slc_frb["gas", "temperature"])
proj_temp = np.array(proj_frb["gas", "temperature"])
slc_vel = np.array(slc_frb["gas", "velocity_magnitude"])
proj_vel = np.array(proj_frb["gas", "velocity_magnitude"])

plots = [
dens_axes[0].imshow(slc_dens, origin="lower", norm=LogNorm()),
Expand Down
2 changes: 1 addition & 1 deletion doc/source/cookbook/multiplot_2x2_time_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
p.set_zlim(("gas", "density"), 1e-4, 1e-2)

# This forces the ProjectionPlot to redraw itself on the AxesGrid axes.
plot = p.plots[("gas", "density")]
plot = p.plots["gas", "density"]
plot.figure = fig
plot.axes = grid[i].axes
plot.cax = grid.cbar_axes[i]
Expand Down
2 changes: 1 addition & 1 deletion doc/source/cookbook/multiplot_phaseplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
p.set_zlim(("gas", "mass"), 1e42, 1e46)

# This forces the ProjectionPlot to redraw itself on the AxesGrid axes.
plot = p.plots[("gas", "mass")]
plot = p.plots["gas", "mass"]
plot.figure = fig
plot.axes = grid[i].axes
if i == 0:
Expand Down
4 changes: 2 additions & 2 deletions doc/source/cookbook/rad_velocity.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@

ax.plot(
rp0.x.value,
rp0[("gas", "radial_velocity")].in_units("km/s").value,
rp0["gas", "radial_velocity"].in_units("km/s").value,
rp1.x.value,
rp1[("gas", "radial_velocity")].in_units("km/s").value,
rp1["gas", "radial_velocity"].in_units("km/s").value,
)

ax.set_xlabel(r"$\mathrm{r\ (kpc)}$")
Expand Down
2 changes: 1 addition & 1 deletion doc/source/cookbook/radial_profile_styles.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
ax = fig.add_subplot(111)

# Plot the density as a log-log plot using the default settings
dens_plot = ax.loglog(rp.x.value, rp[("gas", "density")].value)
dens_plot = ax.loglog(rp.x.value, rp["gas", "density"].value)

# Here we set the labels of the plot axes

Expand Down
2 changes: 1 addition & 1 deletion doc/source/cookbook/simple_contour_in_slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
)

# This is the plot object.
po = sp.plots[("gas", "density")]
po = sp.plots["gas", "density"]

# Turn off the colormap image, leaving just the contours.
po.axes.images[0].set_visible(False)
Expand Down
4 changes: 2 additions & 2 deletions doc/source/cookbook/simple_slice_matplotlib_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
slc.render()

# Get a reference to the matplotlib axes object for the plot
ax = slc.plots[("gas", "density")].axes
ax = slc.plots["gas", "density"].axes

# Let's adjust the x axis tick labels
for label in ax.xaxis.get_ticklabels():
label.set_color("red")
label.set_fontsize(16)

# Get a reference to the matplotlib figure object for the plot
fig = slc.plots[("gas", "density")].figure
fig = slc.plots["gas", "density"].figure

# And create a mini-panel of a gaussian histogram inside the plot
rect = (0.2, 0.2, 0.2, 0.2)
Expand Down
2 changes: 1 addition & 1 deletion doc/source/cookbook/streamlines_isocontour.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
surface = ds.surface(sphere, ("gas", "density"), 1e-24)

# Color this isodensity surface according to the log of the temperature field
colors = yt.apply_colormap(np.log10(surface[("gas", "temperature")]), cmap_name="hot")
colors = yt.apply_colormap(np.log10(surface["gas", "temperature"]), cmap_name="hot")

# Render this surface
p3dc = Poly3DCollection(surface.triangles, linewidth=0.0)
Expand Down
2 changes: 1 addition & 1 deletion doc/source/cookbook/surface_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
surface = ds.surface(sphere, ("gas", "density"), 1e-24)

# Color this isodensity surface according to the log of the temperature field
colors = yt.apply_colormap(np.log10(surface[("gas", "temperature")]), cmap_name="hot")
colors = yt.apply_colormap(np.log10(surface["gas", "temperature"]), cmap_name="hot")

# Create a 3D matplotlib figure for visualizing the surface
fig = plt.figure()
Expand Down
2 changes: 1 addition & 1 deletion doc/source/cookbook/time_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
# Create a sphere of radius 100 kpc at the center of the dataset volume
sphere = ds.sphere("c", (100.0, "kpc"))
# Calculate the entropy within that sphere
entr = sphere[("gas", "entropy")].sum()
entr = sphere["gas", "entropy"].sum()
# Store the current time and sphere entropy for this dataset in our
# storage dictionary as a tuple
store.result = (ds.current_time.in_units("Gyr"), entr)
Expand Down
8 changes: 4 additions & 4 deletions doc/source/cookbook/yt_gadget_owls_analysis.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
},
"outputs": [],
"source": [
"ad[(\"PartType0\", \"Coordinates\")]"
"ad[\"PartType0\", \"Coordinates\"]"
]
},
{
Expand All @@ -171,7 +171,7 @@
},
"outputs": [],
"source": [
"ad[(\"PartType4\", \"IronFromSNIa\")]"
"ad[\"PartType4\", \"IronFromSNIa\"]"
]
},
{
Expand All @@ -182,7 +182,7 @@
},
"outputs": [],
"source": [
"ad[(\"PartType1\", \"ParticleIDs\")]"
"ad[\"PartType1\", \"ParticleIDs\"]"
]
},
{
Expand All @@ -193,7 +193,7 @@
},
"outputs": [],
"source": [
"ad[(\"PartType0\", \"Hydrogen\")]"
"ad[\"PartType0\", \"Hydrogen\"]"
]
},
{
Expand Down
10 changes: 5 additions & 5 deletions doc/source/examining/loading_data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -648,9 +648,9 @@ to the z direction.
ds.index
ad = ds.all_data()
print(ds.field_info[("raw", "Ex")].nodal_flag)
print(ds.field_info["raw", "Ex"].nodal_flag)
print(ad["raw", "Ex"].shape)
print(ds.field_info[("raw", "Bx")].nodal_flag)
print(ds.field_info["raw", "Bx"].nodal_flag)
print(ad["raw", "Bx"].shape)
print(ds.field_info["raw", "Bx"].nodal_flag)
print(ad["raw", "Bx"].shape)
Expand Down Expand Up @@ -753,11 +753,11 @@ direction.
ds.index
ad = ds.all_data()
print(ds.field_info[("enzo", "Ex")].nodal_flag)
print(ds.field_info["enzo", "Ex"].nodal_flag)
print(ad["enzo", "Ex"].shape)
print(ds.field_info[("enzo", "BxF")].nodal_flag)
print(ds.field_info["enzo", "BxF"].nodal_flag)
print(ad["enzo", "Bx"].shape)
print(ds.field_info[("enzo", "Bx")].nodal_flag)
print(ds.field_info["enzo", "Bx"].nodal_flag)
print(ad["enzo", "Bx"].shape)
Here, the field ``('enzo', 'Ex')`` is nodal in two directions, so four values
Expand Down
6 changes: 3 additions & 3 deletions doc/source/examining/low_level_inspection.rst
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,13 @@ shape is the same, but the number of cells with data is less
level=0, left_edge=[0, 0.0, 0.0], dims=ds.domain_dimensions, data_source=sp
)
print(cg_sp[("gas", "density")].shape)
print(cg_sp["gas", "density"].shape)
(64, 64, 64)
print(cg_sp[("gas", "density")].size)
print(cg_sp["gas", "density"].size)
262144
print(cg_sp[("gas", "density")][cg_sp[("gas", "density")] != 0].size)
print(cg_sp["gas", "density"][cg_sp["gas", "density"] != 0].size)
17256
The ``data_source`` can be any :ref:`3D Data Container <region-reference>`. Also
Expand Down
4 changes: 2 additions & 2 deletions doc/source/visualizing/callbacks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ Clump Finder Callback
ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
data_source = ds.disk([0.5, 0.5, 0.5], [0.0, 0.0, 1.0], (8.0, "kpc"), (1.0, "kpc"))

c_min = 10 ** np.floor(np.log10(data_source[("gas", "density")]).min())
c_max = 10 ** np.floor(np.log10(data_source[("gas", "density")]).max() + 1)
c_min = 10 ** np.floor(np.log10(data_source["gas", "density"]).min())
c_max = 10 ** np.floor(np.log10(data_source["gas", "density"]).max() + 1)

master_clump = Clump(data_source, ("gas", "density"))
master_clump.add_validator("min_cells", 20)
Expand Down
8 changes: 4 additions & 4 deletions doc/source/yt4differences.rst
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,10 @@ method:
plot.save()
arbitrary_grid = ds.arbitrary_grid([0.0, 0.0, 0.0], [25, 25, 25], dims=[16, 16, 16])
ag_density = arbitrary_grid[("gas", "density")]
ag_density = arbitrary_grid["gas", "density"]
covering_grid = ds.covering_grid(4, 0, 16)
cg_density = covering_grid[("gas", "density")]
cg_density = covering_grid["gas", "density"]
In the above example the ``covering_grid`` and the ``arbitrary_grid`` will return
the same data. In fact, these containers are very similar but provide a
Expand Down Expand Up @@ -296,10 +296,10 @@ gather machinery also added.
print(octree.sph_smoothing_style)
# the density will be calculated using SPH scatter
density = octree[("PartType0", "density")]
density = octree["PartType0", "density"]
# this will return the x positions of the octs
x = octree[("index", "x")]
x = octree["index", "x"]
The above code can be modified to use the gather approach by using
``ds.sph_smoothing_style = 'gather'`` before any field access. The octree just
Expand Down
Loading

0 comments on commit 192f26b

Please sign in to comment.