From 717016a39339cb1efdf47d83350e03e9c6291a58 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 20 May 2021 09:26:58 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../analyzing/Particle_Trajectories.ipynb | 42 +++-- .../domain_analysis/XrayEmissionFields.ipynb | 59 +++++-- doc/source/analyzing/mesh_filter.ipynb | 64 ++++--- doc/source/analyzing/particle_filter.ipynb | 34 ++-- .../cookbook/custom_colorbar_tickmarks.ipynb | 8 +- doc/source/cookbook/fits_radio_cubes.ipynb | 37 ++-- doc/source/cookbook/fits_xray_images.ipynb | 155 ++++++++++------ .../geographic_xforms_and_projections.ipynb | 116 ++++++------ doc/source/cookbook/tipsy_and_yt.ipynb | 26 +-- doc/source/cookbook/yt_gadget_analysis.ipynb | 56 +++--- .../cookbook/yt_gadget_owls_analysis.ipynb | 14 +- .../Loading_Generic_Array_Data.ipynb | 167 ++++++++++++------ .../Loading_Generic_Particle_Data.ipynb | 56 +++--- .../examining/Loading_Spherical_Data.ipynb | 35 ++-- .../quickstart/2)_Data_Inspection.ipynb | 33 ++-- .../quickstart/3)_Simple_Visualization.ipynb | 2 +- .../4)_Data_Objects_and_Time_Series.ipynb | 45 ++--- .../5)_Derived_Fields_and_Profiles.ipynb | 46 ++--- .../quickstart/6)_Volume_Rendering.ipynb | 11 +- doc/source/visualizing/FITSImageData.ipynb | 83 ++++++--- .../TransferFunctionHelper_Tutorial.ipynb | 55 ++++-- .../Volume_Rendering_Tutorial.ipynb | 37 ++-- 22 files changed, 724 insertions(+), 457 deletions(-) diff --git a/doc/source/analyzing/Particle_Trajectories.ipynb b/doc/source/analyzing/Particle_Trajectories.ipynb index dcdb5e91e71..d7794883206 100644 --- a/doc/source/analyzing/Particle_Trajectories.ipynb +++ b/doc/source/analyzing/Particle_Trajectories.ipynb @@ -80,7 +80,7 @@ "ds = yt.load(my_fns[0])\n", "dd = ds.all_data()\n", "indices = dd[\"particle_index\"].astype(\"int\")\n", - "print (indices)" + "print(indices)" ] }, { @@ -118,8 +118,8 @@ }, "outputs": [], "source": [ - "print (trajs[\"particle_position_x\"])\n", - "print (trajs[\"particle_position_x\"].shape)" + "print(trajs[\"particle_position_x\"])\n", + "print(trajs[\"particle_position_x\"].shape)" ] }, { @@ -219,7 +219,9 @@ "outputs": [], "source": [ "ds = yt.load(\"enzo_tiny_cosmology/DD0046/DD0046\")\n", - "slc = yt.SlicePlot(ds, \"x\", [\"density\",\"dark_matter_density\"], center=\"max\", width=(3.0, \"Mpc\"))\n", + "slc = yt.SlicePlot(\n", + " ds, \"x\", [\"density\", \"dark_matter_density\"], center=\"max\", width=(3.0, \"Mpc\")\n", + ")\n", "slc.show()" ] }, @@ -279,10 +281,22 @@ "outputs": [], "source": [ "fig = plt.figure(figsize=(8.0, 8.0))\n", - "ax = fig.add_subplot(111, projection='3d')\n", - "ax.plot(trajs[\"particle_position_x\"][100], trajs[\"particle_position_y\"][100], trajs[\"particle_position_z\"][100])\n", - "ax.plot(trajs[\"particle_position_x\"][8], trajs[\"particle_position_y\"][8], trajs[\"particle_position_z\"][8])\n", - "ax.plot(trajs[\"particle_position_x\"][25], trajs[\"particle_position_y\"][25], trajs[\"particle_position_z\"][25])" + "ax = fig.add_subplot(111, projection=\"3d\")\n", + "ax.plot(\n", + " trajs[\"particle_position_x\"][100],\n", + " trajs[\"particle_position_y\"][100],\n", + " trajs[\"particle_position_z\"][100],\n", + ")\n", + "ax.plot(\n", + " trajs[\"particle_position_x\"][8],\n", + " trajs[\"particle_position_y\"][8],\n", + " trajs[\"particle_position_z\"][8],\n", + ")\n", + "ax.plot(\n", + " trajs[\"particle_position_x\"][25],\n", + " trajs[\"particle_position_y\"][25],\n", + " trajs[\"particle_position_z\"][25],\n", + ")" ] }, { @@ -300,7 +314,7 @@ }, "outputs": [], "source": [ - "plt.figure(figsize=(6,6))\n", + "plt.figure(figsize=(6, 6))\n", "plt.plot(trajs[\"particle_time\"], trajs[\"particle_position_x\"][100])\n", "plt.plot(trajs[\"particle_time\"], trajs[\"particle_position_x\"][8])\n", "plt.plot(trajs[\"particle_time\"], trajs[\"particle_position_x\"][25])" @@ -339,7 +353,7 @@ }, "outputs": [], "source": [ - "plt.figure(figsize=(6,6))\n", + "plt.figure(figsize=(6, 6))\n", "plt.plot(trajs[\"particle_time\"], trajs[\"density\"][100])\n", "plt.plot(trajs[\"particle_time\"], trajs[\"density\"][8])\n", "plt.plot(trajs[\"particle_time\"], trajs[\"density\"][25])\n", @@ -361,8 +375,12 @@ }, "outputs": [], "source": [ - "trajs.write_out(\"halo_trajectories\") # This will write a separate file for each trajectory\n", - "trajs.write_out_h5(\"halo_trajectories.h5\") # This will write all trajectories to a single file" + "trajs.write_out(\n", + " \"halo_trajectories\"\n", + ") # This will write a separate file for each trajectory\n", + "trajs.write_out_h5(\n", + " \"halo_trajectories.h5\"\n", + ") # This will write all trajectories to a single file" ] } ], diff --git a/doc/source/analyzing/domain_analysis/XrayEmissionFields.ipynb b/doc/source/analyzing/domain_analysis/XrayEmissionFields.ipynb index 39a9429cb6f..0e2b02eb3e2 100644 --- a/doc/source/analyzing/domain_analysis/XrayEmissionFields.ipynb +++ b/doc/source/analyzing/domain_analysis/XrayEmissionFields.ipynb @@ -43,7 +43,9 @@ "\n", "ds = yt.load(\"GasSloshing/sloshing_nomag2_hdf5_plt_cnt_0150\")\n", "\n", - "xray_fields = yt.add_xray_emissivity_field(ds, 0.5, 7.0, table_type='apec', metallicity=0.3)" + "xray_fields = yt.add_xray_emissivity_field(\n", + " ds, 0.5, 7.0, table_type=\"apec\", metallicity=0.3\n", + ")" ] }, { @@ -69,7 +71,7 @@ "metadata": {}, "outputs": [], "source": [ - "print (xray_fields)" + "print(xray_fields)" ] }, { @@ -86,7 +88,7 @@ "outputs": [], "source": [ "sp = ds.sphere(\"c\", (2.0, \"Mpc\"))\n", - "print (sp.quantities.total_quantity((\"gas\",\"xray_luminosity_0.5_7.0_keV\")))" + "print(sp.quantities.total_quantity((\"gas\", \"xray_luminosity_0.5_7.0_keV\")))" ] }, { @@ -104,9 +106,15 @@ }, "outputs": [], "source": [ - "slc = yt.SlicePlot(ds, 'z', [('gas', 'xray_emissivity_0.5_7.0_keV'),\n", - " ('gas', 'xray_photon_emissivity_0.5_7.0_keV')],\n", - " width=(0.75, \"Mpc\"))\n", + "slc = yt.SlicePlot(\n", + " ds,\n", + " \"z\",\n", + " [\n", + " (\"gas\", \"xray_emissivity_0.5_7.0_keV\"),\n", + " (\"gas\", \"xray_photon_emissivity_0.5_7.0_keV\"),\n", + " ],\n", + " width=(0.75, \"Mpc\"),\n", + ")\n", "slc.show()" ] }, @@ -129,10 +137,17 @@ "source": [ "ds2 = yt.load(\"D9p_500/10MpcBox_HartGal_csf_a0.500.d\")\n", "\n", - "# In this case, use the redshift and cosmology from the dataset, \n", + "# In this case, use the redshift and cosmology from the dataset,\n", "# but in theory you could put in something different\n", - "xray_fields2 = yt.add_xray_emissivity_field(ds2, 0.5, 2.0, redshift=ds2.current_redshift, cosmology=ds2.cosmology,\n", - " metallicity=(\"gas\", \"metallicity\"), table_type='cloudy')" + "xray_fields2 = yt.add_xray_emissivity_field(\n", + " ds2,\n", + " 0.5,\n", + " 2.0,\n", + " redshift=ds2.current_redshift,\n", + " cosmology=ds2.cosmology,\n", + " metallicity=(\"gas\", \"metallicity\"),\n", + " table_type=\"cloudy\",\n", + ")" ] }, { @@ -148,7 +163,7 @@ "metadata": {}, "outputs": [], "source": [ - "print (xray_fields2)" + "print(xray_fields2)" ] }, { @@ -166,8 +181,9 @@ }, "outputs": [], "source": [ - "prj = yt.ProjectionPlot(ds2, \"x\", (\"gas\",\"xray_intensity_0.5_2.0_keV\"),\n", - " center=\"max\", width=(40, \"kpc\"))\n", + "prj = yt.ProjectionPlot(\n", + " ds2, \"x\", (\"gas\", \"xray_intensity_0.5_2.0_keV\"), center=\"max\", width=(40, \"kpc\")\n", + ")\n", "prj.set_zlim(\"xray_intensity_0.5_2.0_keV\", 1.0e-32, 5.0e-24)\n", "prj.show()" ] @@ -197,8 +213,14 @@ "metadata": {}, "outputs": [], "source": [ - "xray_fields3 = yt.add_xray_emissivity_field(ds2, 0.5, 2.0, dist=(1.0,\"Mpc\"), metallicity=(\"gas\", \"metallicity\"), \n", - " table_type='cloudy')" + "xray_fields3 = yt.add_xray_emissivity_field(\n", + " ds2,\n", + " 0.5,\n", + " 2.0,\n", + " dist=(1.0, \"Mpc\"),\n", + " metallicity=(\"gas\", \"metallicity\"),\n", + " table_type=\"cloudy\",\n", + ")" ] }, { @@ -209,8 +231,13 @@ }, "outputs": [], "source": [ - "prj = yt.ProjectionPlot(ds2, \"x\", (\"gas\", \"xray_photon_intensity_0.5_2.0_keV\"),\n", - " center=\"max\", width=(40, \"kpc\"))\n", + "prj = yt.ProjectionPlot(\n", + " ds2,\n", + " \"x\",\n", + " (\"gas\", \"xray_photon_intensity_0.5_2.0_keV\"),\n", + " center=\"max\",\n", + " width=(40, \"kpc\"),\n", + ")\n", "prj.set_zlim(\"xray_photon_intensity_0.5_2.0_keV\", 1.0e-24, 5.0e-16)\n", "prj.show()" ] diff --git a/doc/source/analyzing/mesh_filter.ipynb b/doc/source/analyzing/mesh_filter.ipynb index 5f9f9a10ed8..11b00a9ea13 100644 --- a/doc/source/analyzing/mesh_filter.ipynb +++ b/doc/source/analyzing/mesh_filter.ipynb @@ -14,6 +14,7 @@ "outputs": [], "source": [ "import yt\n", + "\n", "ds = yt.load(\"Enzo_64/DD0042/data0042\")" ] }, @@ -38,7 +39,9 @@ "\n", "# you can chain cut regions in two ways:\n", "dense_and_cool_ad = dense_ad.cut_region([\"obj['temperature'] < 1e5\"])\n", - "overpressure_and_fast_ad = ad.cut_region(['(obj[\"pressure\"] > 1e-14) & (obj[\"velocity_magnitude\"].in_units(\"km/s\") > 1e2)'])" + "overpressure_and_fast_ad = ad.cut_region(\n", + " ['(obj[\"pressure\"] > 1e-14) & (obj[\"velocity_magnitude\"].in_units(\"km/s\") > 1e2)']\n", + ")" ] }, { @@ -55,13 +58,15 @@ "outputs": [], "source": [ "ad = ds.all_data()\n", - "hot_ad = ad.include_above('temperature', 1e6)\n", - "dense_ad = ad.include_above('density', 5e-30)\n", + "hot_ad = ad.include_above(\"temperature\", 1e6)\n", + "dense_ad = ad.include_above(\"density\", 5e-30)\n", "\n", "# These can be chained as well\n", - "dense_and_cool_ad = dense_ad.include_below('temperature', 1e5)\n", - "overpressure_and_fast_ad = ad.include_above('pressure', 1e-14)\n", - "overpressure_and_fast_ad = overpressure_and_fast_ad.include_above('velocity_magnitude', 1e2, 'km/s')" + "dense_and_cool_ad = dense_ad.include_below(\"temperature\", 1e5)\n", + "overpressure_and_fast_ad = ad.include_above(\"pressure\", 1e-14)\n", + "overpressure_and_fast_ad = overpressure_and_fast_ad.include_above(\n", + " \"velocity_magnitude\", 1e2, \"km/s\"\n", + ")" ] }, { @@ -77,8 +82,11 @@ "metadata": {}, "outputs": [], "source": [ - "print (\"Temperature of all cells:\\n ad['temperature'] = \\n%s\\n\" % ad[\"temperature\"])\n", - "print (\"Temperatures of all \\\"hot\\\" cells:\\n hot_ad['temperature'] = \\n%s\" % hot_ad['temperature'])" + "print(\"Temperature of all cells:\\n ad['temperature'] = \\n%s\\n\" % ad[\"temperature\"])\n", + "print(\n", + " \"Temperatures of all \\\"hot\\\" cells:\\n hot_ad['temperature'] = \\n%s\"\n", + " % hot_ad[\"temperature\"]\n", + ")" ] }, { @@ -87,8 +95,14 @@ "metadata": {}, "outputs": [], "source": [ - "print (\"Density of dense, cool material:\\n dense_and_cool_ad['density'] = \\n%s\\n\" % dense_and_cool_ad['density'])\n", - "print (\"Temperature of dense, cool material:\\n dense_and_cool_ad['temperature'] = \\n%s\" % dense_and_cool_ad['temperature'])" + "print(\n", + " \"Density of dense, cool material:\\n dense_and_cool_ad['density'] = \\n%s\\n\"\n", + " % dense_and_cool_ad[\"density\"]\n", + ")\n", + "print(\n", + " \"Temperature of dense, cool material:\\n dense_and_cool_ad['temperature'] = \\n%s\"\n", + " % dense_and_cool_ad[\"temperature\"]\n", + ")" ] }, { @@ -106,13 +120,15 @@ "metadata": {}, "outputs": [], "source": [ - "proj1 = yt.ProjectionPlot(ds, 'x', \"density\", weight_field=\"density\")\n", - "proj1.annotate_title('No Cuts')\n", + "proj1 = yt.ProjectionPlot(ds, \"x\", \"density\", weight_field=\"density\")\n", + "proj1.annotate_title(\"No Cuts\")\n", "proj1.set_figure_size(5)\n", "proj1.show()\n", "\n", - "proj2 = yt.ProjectionPlot(ds, 'x', \"density\", weight_field=\"density\", data_source=hot_ad)\n", - "proj2.annotate_title('Hot Gas')\n", + "proj2 = yt.ProjectionPlot(\n", + " ds, \"x\", \"density\", weight_field=\"density\", data_source=hot_ad\n", + ")\n", + "proj2.annotate_title(\"Hot Gas\")\n", "proj2.set_zlim(\"density\", 3e-31, 3e-27)\n", "proj2.set_figure_size(5)\n", "proj2.show()" @@ -136,15 +152,15 @@ "metadata": {}, "outputs": [], "source": [ - "slc1 = yt.SlicePlot(ds, 'x', \"density\", center='m')\n", - "slc1.set_zlim('density', 3e-31, 3e-27)\n", - "slc1.annotate_title('No Cuts')\n", + "slc1 = yt.SlicePlot(ds, \"x\", \"density\", center=\"m\")\n", + "slc1.set_zlim(\"density\", 3e-31, 3e-27)\n", + "slc1.annotate_title(\"No Cuts\")\n", "slc1.set_figure_size(5)\n", "slc1.show()\n", "\n", - "slc2 = yt.SlicePlot(ds, 'x', \"density\", center='m', data_source=dense_ad)\n", - "slc2.set_zlim('density', 3e-31, 3e-27)\n", - "slc2.annotate_title('Dense Gas')\n", + "slc2 = yt.SlicePlot(ds, \"x\", \"density\", center=\"m\", data_source=dense_ad)\n", + "slc2.set_zlim(\"density\", 3e-31, 3e-27)\n", + "slc2.annotate_title(\"Dense Gas\")\n", "slc2.set_figure_size(5)\n", "slc2.show()" ] @@ -155,15 +171,15 @@ "metadata": {}, "outputs": [], "source": [ - "ph1 = yt.PhasePlot(ad, 'density', 'temperature', 'mass', weight_field=None)\n", + "ph1 = yt.PhasePlot(ad, \"density\", \"temperature\", \"mass\", weight_field=None)\n", "ph1.set_xlim(3e-31, 3e-27)\n", - "ph1.annotate_title('No Cuts')\n", + "ph1.annotate_title(\"No Cuts\")\n", "ph1.set_figure_size(5)\n", "ph1.show()\n", "\n", - "ph1 = yt.PhasePlot(dense_ad, 'density', 'temperature', 'mass', weight_field=None)\n", + "ph1 = yt.PhasePlot(dense_ad, \"density\", \"temperature\", \"mass\", weight_field=None)\n", "ph1.set_xlim(3e-31, 3e-27)\n", - "ph1.annotate_title('Dense Gas')\n", + "ph1.annotate_title(\"Dense Gas\")\n", "ph1.set_figure_size(5)\n", "ph1.show()" ] diff --git a/doc/source/analyzing/particle_filter.ipynb b/doc/source/analyzing/particle_filter.ipynb index 0b07af9c9c0..8506ddfb0e8 100644 --- a/doc/source/analyzing/particle_filter.ipynb +++ b/doc/source/analyzing/particle_filter.ipynb @@ -23,8 +23,8 @@ "\n", "ds = yt.load(\"TipsyGalaxy/galaxy.00300\")\n", "for field in ds.derived_field_list:\n", - " if field[0] == 'Stars':\n", - " print (field)" + " if field[0] == \"Stars\":\n", + " print(field)" ] }, { @@ -52,12 +52,13 @@ "source": [ "def young_stars(pfilter, data):\n", " age = data.ds.current_time - data[pfilter.filtered_type, \"creation_time\"]\n", - " filter = np.logical_and(age.in_units('Myr') <= 5, age >= 0)\n", + " filter = np.logical_and(age.in_units(\"Myr\") <= 5, age >= 0)\n", " return filter\n", "\n", + "\n", "def old_stars(pfilter, data):\n", " age = data.ds.current_time - data[pfilter.filtered_type, \"creation_time\"]\n", - " filter = np.logical_or(age.in_units('Myr') >= 5, age < 0)\n", + " filter = np.logical_or(age.in_units(\"Myr\") >= 5, age < 0)\n", " return filter" ] }, @@ -77,9 +78,16 @@ }, "outputs": [], "source": [ - "yt.add_particle_filter(\"young_stars\", function=young_stars, filtered_type='Stars', requires=[\"creation_time\"])\n", + "yt.add_particle_filter(\n", + " \"young_stars\",\n", + " function=young_stars,\n", + " filtered_type=\"Stars\",\n", + " requires=[\"creation_time\"],\n", + ")\n", "\n", - "yt.add_particle_filter(\"old_stars\", function=old_stars, filtered_type='Stars', requires=[\"creation_time\"])" + "yt.add_particle_filter(\n", + " \"old_stars\", function=old_stars, filtered_type=\"Stars\", requires=[\"creation_time\"]\n", + ")" ] }, { @@ -99,12 +107,12 @@ }, "outputs": [], "source": [ - "ds.add_particle_filter('young_stars')\n", - "ds.add_particle_filter('old_stars')\n", + "ds.add_particle_filter(\"young_stars\")\n", + "ds.add_particle_filter(\"old_stars\")\n", "\n", "for field in ds.derived_field_list:\n", " if \"young_stars\" in field or \"young_stars\" in field[1]:\n", - " print (field)" + " print(field)" ] }, { @@ -122,7 +130,13 @@ }, "outputs": [], "source": [ - "p = yt.ProjectionPlot(ds, 'z', [('deposit', 'young_stars_cic'), ('deposit', 'old_stars_cic')], width=(40, 'kpc'), center='m')\n", + "p = yt.ProjectionPlot(\n", + " ds,\n", + " \"z\",\n", + " [(\"deposit\", \"young_stars_cic\"), (\"deposit\", \"old_stars_cic\")],\n", + " width=(40, \"kpc\"),\n", + " center=\"m\",\n", + ")\n", "p.set_figure_size(5)\n", "p.show()" ] diff --git a/doc/source/cookbook/custom_colorbar_tickmarks.ipynb b/doc/source/cookbook/custom_colorbar_tickmarks.ipynb index f88a9418ef1..9363d5b1f17 100644 --- a/doc/source/cookbook/custom_colorbar_tickmarks.ipynb +++ b/doc/source/cookbook/custom_colorbar_tickmarks.ipynb @@ -19,8 +19,8 @@ }, "outputs": [], "source": [ - "ds = yt.load('IsolatedGalaxy/galaxy0030/galaxy0030')\n", - "slc = yt.SlicePlot(ds, 'x', 'density')\n", + "ds = yt.load(\"IsolatedGalaxy/galaxy0030/galaxy0030\")\n", + "slc = yt.SlicePlot(ds, \"x\", \"density\")\n", "slc" ] }, @@ -39,7 +39,7 @@ }, "outputs": [], "source": [ - "plot = slc.plots['density']" + "plot = slc.plots[\"density\"]" ] }, { @@ -94,7 +94,7 @@ "outputs": [], "source": [ "colorbar.set_ticks([1e-28])\n", - "colorbar.set_ticklabels(['$10^{-28}$'])\n", + "colorbar.set_ticklabels([\"$10^{-28}$\"])\n", "slc" ] } diff --git a/doc/source/cookbook/fits_radio_cubes.ipynb b/doc/source/cookbook/fits_radio_cubes.ipynb index 46d363f6406..b0279f86374 100644 --- a/doc/source/cookbook/fits_radio_cubes.ipynb +++ b/doc/source/cookbook/fits_radio_cubes.ipynb @@ -81,7 +81,8 @@ "outputs": [], "source": [ "from yt.frontends.fits.misc import PlotWindowWCS\n", - "PlotWindowWCS(slc)\n" + "\n", + "PlotWindowWCS(slc)" ] }, { @@ -118,8 +119,9 @@ "outputs": [], "source": [ "import yt.units as u\n", + "\n", "new_center = ds.domain_center\n", - "new_center[2] = ds.spec2pixel(-250000.*u.m/u.s)" + "new_center[2] = ds.spec2pixel(-250000.0 * u.m / u.s)" ] }, { @@ -156,7 +158,7 @@ }, "outputs": [], "source": [ - "new_center[2] = ds.spec2pixel(-100000.*u.m/u.s)\n", + "new_center[2] = ds.spec2pixel(-100000.0 * u.m / u.s)\n", "slc = yt.SlicePlot(ds, \"z\", [\"intensity\"], center=new_center, origin=\"native\")\n", "slc.show()" ] @@ -169,7 +171,7 @@ }, "outputs": [], "source": [ - "new_center[2] = ds.spec2pixel(-150000.*u.m/u.s)\n", + "new_center[2] = ds.spec2pixel(-150000.0 * u.m / u.s)\n", "slc = yt.SlicePlot(ds, \"z\", [\"intensity\"], center=new_center, origin=\"native\")\n", "slc.show()" ] @@ -215,7 +217,7 @@ }, "outputs": [], "source": [ - "slc = yt.SlicePlot(ds, \"x\", [\"intensity\"], origin=\"native\", window_size=(8,8))\n", + "slc = yt.SlicePlot(ds, \"x\", [\"intensity\"], origin=\"native\", window_size=(8, 8))\n", "slc.show()" ] }, @@ -227,7 +229,7 @@ }, "outputs": [], "source": [ - "slc = yt.SlicePlot(ds, \"y\", [\"intensity\"], origin=\"native\", window_size=(8,8))\n", + "slc = yt.SlicePlot(ds, \"y\", [\"intensity\"], origin=\"native\", window_size=(8, 8))\n", "slc.show()" ] }, @@ -278,9 +280,9 @@ }, "outputs": [], "source": [ - "dd = ds.all_data() # A region containing the entire dataset\n", + "dd = ds.all_data() # A region containing the entire dataset\n", "extrema = dd.quantities.extrema(\"temperature\")\n", - "print (extrema)" + "print(extrema)" ] }, { @@ -298,8 +300,9 @@ }, "outputs": [], "source": [ - "prj = yt.ProjectionPlot(ds, \"z\", [\"temperature\"], origin=\"native\", \n", - " weight_field=\"ones\") # \"ones\" weights each cell by 1\n", + "prj = yt.ProjectionPlot(\n", + " ds, \"z\", [\"temperature\"], origin=\"native\", weight_field=\"ones\"\n", + ") # \"ones\" weights each cell by 1\n", "prj.set_log(\"temperature\", True)\n", "prj.show()" ] @@ -356,7 +359,7 @@ }, "outputs": [], "source": [ - "print (fc.quantities.extrema(\"temperature\"))" + "print(fc.quantities.extrema(\"temperature\"))" ] }, { @@ -392,8 +395,9 @@ }, "outputs": [], "source": [ - "prj = yt.ProjectionPlot(ds, \"z\", [\"temperature\"], data_source=fc, origin=\"native\", \n", - " weight_field=\"ones\") # \"ones\" weights each cell by 1\n", + "prj = yt.ProjectionPlot(\n", + " ds, \"z\", [\"temperature\"], data_source=fc, origin=\"native\", weight_field=\"ones\"\n", + ") # \"ones\" weights each cell by 1\n", "prj.set_log(\"temperature\", True)\n", "prj.show()" ] @@ -450,7 +454,7 @@ }, "outputs": [], "source": [ - "print (box_reg.quantities.extrema(\"temperature\"))" + "print(box_reg.quantities.extrema(\"temperature\"))" ] }, { @@ -468,8 +472,9 @@ }, "outputs": [], "source": [ - "prj = yt.ProjectionPlot(ds, \"z\", [\"temperature\"], origin=\"native\", \n", - " data_source=box_reg, weight_field=\"ones\") # \"ones\" weights each cell by 1\n", + "prj = yt.ProjectionPlot(\n", + " ds, \"z\", [\"temperature\"], origin=\"native\", data_source=box_reg, weight_field=\"ones\"\n", + ") # \"ones\" weights each cell by 1\n", "prj.set_zlim(\"temperature\", 1.0e-2, 1.5)\n", "prj.set_log(\"temperature\", True)\n", "prj.show()" diff --git a/doc/source/cookbook/fits_xray_images.ipynb b/doc/source/cookbook/fits_xray_images.ipynb index 30461087474..83def8db2dd 100644 --- a/doc/source/cookbook/fits_xray_images.ipynb +++ b/doc/source/cookbook/fits_xray_images.ipynb @@ -42,8 +42,10 @@ }, "outputs": [], "source": [ - "ds = yt.load(\"xray_fits/A2052_merged_0.3-2_match-core_tmap_bgecorr.fits\", \n", - " auxiliary_files=[\"xray_fits/A2052_core_tmap_b1_m2000_.fits\"])" + "ds = yt.load(\n", + " \"xray_fits/A2052_merged_0.3-2_match-core_tmap_bgecorr.fits\",\n", + " auxiliary_files=[\"xray_fits/A2052_core_tmap_b1_m2000_.fits\"],\n", + ")" ] }, { @@ -70,16 +72,42 @@ "source": [ "def _counts(field, data):\n", " exposure_time = data.get_field_parameter(\"exposure_time\")\n", - " return data[\"flux\"]*data[\"pixel\"]*exposure_time\n", - "ds.add_field((\"gas\",\"counts\"), function=_counts, sampling_type=\"cell\", units=\"counts\", take_log=False)\n", + " return data[\"flux\"] * data[\"pixel\"] * exposure_time\n", + "\n", + "\n", + "ds.add_field(\n", + " (\"gas\", \"counts\"),\n", + " function=_counts,\n", + " sampling_type=\"cell\",\n", + " units=\"counts\",\n", + " take_log=False,\n", + ")\n", + "\n", "\n", "def _pp(field, data):\n", - " return np.sqrt(data[\"counts\"])*data[\"projected_temperature\"]\n", - "ds.add_field((\"gas\",\"pseudo_pressure\"), function=_pp, sampling_type=\"cell\", units=\"sqrt(counts)*keV\", take_log=False)\n", + " return np.sqrt(data[\"counts\"]) * data[\"projected_temperature\"]\n", + "\n", + "\n", + "ds.add_field(\n", + " (\"gas\", \"pseudo_pressure\"),\n", + " function=_pp,\n", + " sampling_type=\"cell\",\n", + " units=\"sqrt(counts)*keV\",\n", + " take_log=False,\n", + ")\n", + "\n", "\n", "def _pe(field, data):\n", - " return data[\"projected_temperature\"]*data[\"counts\"]**(-1./3.)\n", - "ds.add_field((\"gas\",\"pseudo_entropy\"), function=_pe, sampling_type=\"cell\", units=\"keV*(counts)**(-1/3)\", take_log=False)" + " return data[\"projected_temperature\"] * data[\"counts\"] ** (-1.0 / 3.0)\n", + "\n", + "\n", + "ds.add_field(\n", + " (\"gas\", \"pseudo_entropy\"),\n", + " function=_pe,\n", + " sampling_type=\"cell\",\n", + " units=\"keV*(counts)**(-1/3)\",\n", + " take_log=False,\n", + ")" ] }, { @@ -115,13 +143,17 @@ }, "outputs": [], "source": [ - "slc = yt.SlicePlot(ds, \"z\", \n", - " [\"flux\",\"projected_temperature\",\"pseudo_pressure\",\"pseudo_entropy\"], \n", - " origin=\"native\", field_parameters={\"exposure_time\":exposure_time})\n", - "slc.set_log(\"flux\",True)\n", - "slc.set_log(\"pseudo_pressure\",False)\n", - "slc.set_log(\"pseudo_entropy\",False)\n", - "slc.set_width(250.)\n", + "slc = yt.SlicePlot(\n", + " ds,\n", + " \"z\",\n", + " [\"flux\", \"projected_temperature\", \"pseudo_pressure\", \"pseudo_entropy\"],\n", + " origin=\"native\",\n", + " field_parameters={\"exposure_time\": exposure_time},\n", + ")\n", + "slc.set_log(\"flux\", True)\n", + "slc.set_log(\"pseudo_pressure\", False)\n", + "slc.set_log(\"pseudo_entropy\", False)\n", + "slc.set_width(250.0)\n", "slc.show()" ] }, @@ -141,6 +173,7 @@ "outputs": [], "source": [ "from yt.frontends.fits.misc import PlotWindowWCS\n", + "\n", "wcs_slc = PlotWindowWCS(slc)\n", "wcs_slc.show()" ] @@ -160,8 +193,8 @@ }, "outputs": [], "source": [ - "v, c = ds.find_max(\"flux\") # Find the maximum flux and its center\n", - "my_sphere = ds.sphere(c, (100.,\"code_length\")) # Radius of 150 pixels\n", + "v, c = ds.find_max(\"flux\") # Find the maximum flux and its center\n", + "my_sphere = ds.sphere(c, (100.0, \"code_length\")) # Radius of 150 pixels\n", "my_sphere.set_field_parameter(\"exposure_time\", exposure_time)" ] }, @@ -180,13 +213,17 @@ }, "outputs": [], "source": [ - "radial_profile = yt.ProfilePlot(my_sphere, \"radius\", \n", - " [\"counts\",\"pseudo_pressure\",\"pseudo_entropy\"], \n", - " n_bins=30, weight_field=\"ones\")\n", + "radial_profile = yt.ProfilePlot(\n", + " my_sphere,\n", + " \"radius\",\n", + " [\"counts\", \"pseudo_pressure\", \"pseudo_entropy\"],\n", + " n_bins=30,\n", + " weight_field=\"ones\",\n", + ")\n", "radial_profile.set_log(\"counts\", True)\n", "radial_profile.set_log(\"pseudo_pressure\", True)\n", "radial_profile.set_log(\"pseudo_entropy\", True)\n", - "radial_profile.set_xlim(3,100.)\n", + "radial_profile.set_xlim(3, 100.0)\n", "radial_profile.show()" ] }, @@ -205,7 +242,9 @@ }, "outputs": [], "source": [ - "phase_plot = yt.PhasePlot(my_sphere, \"pseudo_pressure\", \"pseudo_entropy\", [\"counts\"], weight_field=None)\n", + "phase_plot = yt.PhasePlot(\n", + " my_sphere, \"pseudo_pressure\", \"pseudo_entropy\", [\"counts\"], weight_field=None\n", + ")\n", "phase_plot.show()" ] }, @@ -225,13 +264,18 @@ "outputs": [], "source": [ "from yt.frontends.fits.misc import ds9_region\n", - "reg_file = [\"# Region file format: DS9 version 4.1\\n\",\n", - " \"global color=green dashlist=8 3 width=3 include=1 source=1 fk5\\n\",\n", - " \"circle(15:16:44.817,+7:01:19.62,34.6256\\\")\"]\n", - "f = open(\"circle.reg\",\"w\")\n", + "\n", + "reg_file = [\n", + " \"# Region file format: DS9 version 4.1\\n\",\n", + " \"global color=green dashlist=8 3 width=3 include=1 source=1 fk5\\n\",\n", + " 'circle(15:16:44.817,+7:01:19.62,34.6256\")',\n", + "]\n", + "f = open(\"circle.reg\", \"w\")\n", "f.writelines(reg_file)\n", "f.close()\n", - "circle_reg = ds9_region(ds, \"circle.reg\", field_parameters={\"exposure_time\":exposure_time})" + "circle_reg = ds9_region(\n", + " ds, \"circle.reg\", field_parameters={\"exposure_time\": exposure_time}\n", + ")" ] }, { @@ -249,7 +293,9 @@ }, "outputs": [], "source": [ - "print (circle_reg.quantities.weighted_average_quantity(\"projected_temperature\", \"counts\"))" + "print(\n", + " circle_reg.quantities.weighted_average_quantity(\"projected_temperature\", \"counts\")\n", + ")" ] }, { @@ -267,15 +313,19 @@ }, "outputs": [], "source": [ - "prj = yt.ProjectionPlot(ds, \"z\", \n", - " [\"flux\",\"projected_temperature\",\"pseudo_pressure\",\"pseudo_entropy\"], \n", - " origin=\"native\", field_parameters={\"exposure_time\":exposure_time},\n", - " data_source=circle_reg,\n", - " method=\"sum\")\n", - "prj.set_log(\"flux\",True)\n", - "prj.set_log(\"pseudo_pressure\",False)\n", - "prj.set_log(\"pseudo_entropy\",False)\n", - "prj.set_width(250.)\n", + "prj = yt.ProjectionPlot(\n", + " ds,\n", + " \"z\",\n", + " [\"flux\", \"projected_temperature\", \"pseudo_pressure\", \"pseudo_entropy\"],\n", + " origin=\"native\",\n", + " field_parameters={\"exposure_time\": exposure_time},\n", + " data_source=circle_reg,\n", + " method=\"sum\",\n", + ")\n", + "prj.set_log(\"flux\", True)\n", + "prj.set_log(\"pseudo_pressure\", False)\n", + "prj.set_log(\"pseudo_entropy\", False)\n", + "prj.set_width(250.0)\n", "prj.show()" ] }, @@ -319,7 +369,7 @@ }, "outputs": [], "source": [ - "ds2 = yt.load(\"xray_fits/acisf05356N003_evt2.fits.gz\", parameters={\"reblock\":2})" + "ds2 = yt.load(\"xray_fits/acisf05356N003_evt2.fits.gz\", parameters={\"reblock\": 2})" ] }, { @@ -337,7 +387,7 @@ }, "outputs": [], "source": [ - "ebounds = [(0.1,2.0),(2.0,5.0)]\n", + "ebounds = [(0.1, 2.0), (2.0, 5.0)]\n", "setup_counts_fields(ds2, ebounds)" ] }, @@ -357,8 +407,8 @@ "outputs": [], "source": [ "dd = ds2.all_data()\n", - "print (dd[\"event_x\"])\n", - "print (dd[\"event_y\"])" + "print(dd[\"event_x\"])\n", + "print(dd[\"event_y\"])" ] }, { @@ -376,9 +426,9 @@ }, "outputs": [], "source": [ - "slc = yt.SlicePlot(ds2, \"z\", [\"counts_0.1-2.0\",\"counts_2.0-5.0\"], origin=\"native\")\n", - "slc.pan((100.,100.))\n", - "slc.set_width(500.)\n", + "slc = yt.SlicePlot(ds2, \"z\", [\"counts_0.1-2.0\", \"counts_2.0-5.0\"], origin=\"native\")\n", + "slc.pan((100.0, 100.0))\n", + "slc.set_width(500.0)\n", "slc.show()" ] }, @@ -397,12 +447,17 @@ }, "outputs": [], "source": [ - "slc = yt.SlicePlot(ds2, \"z\", [\"counts_0.1-2.0\",\"counts_2.0-5.0\"], origin=\"native\",\n", - " field_parameters={\"sigma\":2.}) # This value is in pixel scale\n", - "slc.pan((100.,100.))\n", - "slc.set_width(500.)\n", - "slc.set_zlim(\"counts_0.1-2.0\", 0.01, 100.)\n", - "slc.set_zlim(\"counts_2.0-5.0\", 0.01, 50.)\n", + "slc = yt.SlicePlot(\n", + " ds2,\n", + " \"z\",\n", + " [\"counts_0.1-2.0\", \"counts_2.0-5.0\"],\n", + " origin=\"native\",\n", + " field_parameters={\"sigma\": 2.0},\n", + ") # This value is in pixel scale\n", + "slc.pan((100.0, 100.0))\n", + "slc.set_width(500.0)\n", + "slc.set_zlim(\"counts_0.1-2.0\", 0.01, 100.0)\n", + "slc.set_zlim(\"counts_2.0-5.0\", 0.01, 50.0)\n", "slc.show()" ] } diff --git a/doc/source/cookbook/geographic_xforms_and_projections.ipynb b/doc/source/cookbook/geographic_xforms_and_projections.ipynb index c302acfdda0..7f863f23dbb 100644 --- a/doc/source/cookbook/geographic_xforms_and_projections.ipynb +++ b/doc/source/cookbook/geographic_xforms_and_projections.ipynb @@ -76,14 +76,13 @@ "for dim in n.dimensions.keys():\n", " size = n.variables[dim].size\n", " if size > 1:\n", - " bbox.append([n.variables[dim][:].min(),\n", - " n.variables[dim][:].max()])\n", + " bbox.append([n.variables[dim][:].min(), n.variables[dim][:].max()])\n", " dims.append(n.variables[dim].long_name)\n", " sizes.append(size)\n", - "dims.reverse() # Fortran ordering\n", + "dims.reverse() # Fortran ordering\n", "sizes.reverse()\n", "bbox.reverse()\n", - "dims = [f.replace('vertical level', 'altitude') for f in dims]\n", + "dims = [f.replace(\"vertical level\", \"altitude\") for f in dims]\n", "bbox = np.array(bbox)" ] }, @@ -100,7 +99,9 @@ "metadata": {}, "outputs": [], "source": [ - "w_regex = re.compile(r'([a-zA-Z]+)(.*)')\n", + "w_regex = re.compile(r\"([a-zA-Z]+)(.*)\")\n", + "\n", + "\n", "def regex_parser(s):\n", " try:\n", " return \"**\".join(filter(None, w_regex.search(s).groups()))\n", @@ -120,7 +121,7 @@ " if d.ndim != ndims:\n", " continue\n", " units = n.variables[field].units\n", - " units = \" * \".join(map(regex_parser, units.split())) \n", + " units = \" * \".join(map(regex_parser, units.split()))\n", " data[field] = (np.squeeze(d), str(units))\n", " names[field] = n.variables[field].long_name.replace(\"_\", \" \")" ] @@ -138,8 +139,7 @@ "metadata": {}, "outputs": [], "source": [ - "ds = yt.load_uniform_grid(data, sizes, 1.0, geometry=(\"geographic\", dims),\n", - " bbox=bbox)" + "ds = yt.load_uniform_grid(data, sizes, 1.0, geometry=(\"geographic\", dims), bbox=bbox)" ] }, { @@ -162,7 +162,7 @@ "metadata": {}, "outputs": [], "source": [ - "p = yt.SlicePlot(ds, \"altitude\", 'AIRDENS')\n", + "p = yt.SlicePlot(ds, \"altitude\", \"AIRDENS\")\n", "p.show()" ] }, @@ -179,10 +179,10 @@ "metadata": {}, "outputs": [], "source": [ - "p = yt.SlicePlot(ds, \"altitude\", 'AIRDENS')\n", + "p = yt.SlicePlot(ds, \"altitude\", \"AIRDENS\")\n", "p._setup_plots()\n", - "p.plots['AIRDENS'].axes.set_global()\n", - "p.plots['AIRDENS'].axes.coastlines()\n", + "p.plots[\"AIRDENS\"].axes.set_global()\n", + "p.plots[\"AIRDENS\"].axes.coastlines()\n", "p.show()" ] }, @@ -206,11 +206,11 @@ "metadata": {}, "outputs": [], "source": [ - "p = yt.SlicePlot(ds, \"altitude\", 'AIRDENS')\n", + "p = yt.SlicePlot(ds, \"altitude\", \"AIRDENS\")\n", "p.set_mpl_projection(\"Robinson\")\n", "p._setup_plots()\n", - "p.plots['AIRDENS'].axes.set_global()\n", - "p.plots['AIRDENS'].axes.coastlines()\n", + "p.plots[\"AIRDENS\"].axes.set_global()\n", + "p.plots[\"AIRDENS\"].axes.coastlines()\n", "p.show()" ] }, @@ -227,11 +227,11 @@ "metadata": {}, "outputs": [], "source": [ - "p = yt.SlicePlot(ds, \"altitude\", 'AIRDENS')\n", - "p.set_mpl_projection((\"Robinson\",(37.5,)))\n", + "p = yt.SlicePlot(ds, \"altitude\", \"AIRDENS\")\n", + "p.set_mpl_projection((\"Robinson\", (37.5,)))\n", "p._setup_plots()\n", - "p.plots['AIRDENS'].axes.set_global()\n", - "p.plots['AIRDENS'].axes.coastlines()\n", + "p.plots[\"AIRDENS\"].axes.set_global()\n", + "p.plots[\"AIRDENS\"].axes.coastlines()\n", "p.show()" ] }, @@ -248,10 +248,10 @@ "metadata": {}, "outputs": [], "source": [ - "p.set_mpl_projection('Orthographic')\n", + "p.set_mpl_projection(\"Orthographic\")\n", "p._setup_plots()\n", - "p.plots['AIRDENS'].axes.set_global()\n", - "p.plots['AIRDENS'].axes.coastlines()\n", + "p.plots[\"AIRDENS\"].axes.set_global()\n", + "p.plots[\"AIRDENS\"].axes.coastlines()\n", "p.show()" ] }, @@ -284,10 +284,10 @@ "metadata": {}, "outputs": [], "source": [ - "p.set_mpl_projection(('Orthographic', (90, 45)))\n", + "p.set_mpl_projection((\"Orthographic\", (90, 45)))\n", "p._setup_plots()\n", - "p.plots['AIRDENS'].axes.set_global()\n", - "p.plots['AIRDENS'].axes.coastlines()\n", + "p.plots[\"AIRDENS\"].axes.set_global()\n", + "p.plots[\"AIRDENS\"].axes.coastlines()\n", "p.show()" ] }, @@ -304,10 +304,12 @@ "metadata": {}, "outputs": [], "source": [ - "p.set_mpl_projection(('Orthographic', (), {'central_latitude':-45, 'central_longitude':275}))\n", + "p.set_mpl_projection(\n", + " (\"Orthographic\", (), {\"central_latitude\": -45, \"central_longitude\": 275})\n", + ")\n", "p._setup_plots()\n", - "p.plots['AIRDENS'].axes.set_global()\n", - "p.plots['AIRDENS'].axes.coastlines()\n", + "p.plots[\"AIRDENS\"].axes.set_global()\n", + "p.plots[\"AIRDENS\"].axes.coastlines()\n", "p.show()" ] }, @@ -331,10 +333,10 @@ "metadata": {}, "outputs": [], "source": [ - "p.set_mpl_projection(('RotatedPole', (177.5, 37.5)))\n", + "p.set_mpl_projection((\"RotatedPole\", (177.5, 37.5)))\n", "p._setup_plots()\n", - "p.plots['AIRDENS'].axes.set_global()\n", - "p.plots['AIRDENS'].axes.coastlines()\n", + "p.plots[\"AIRDENS\"].axes.set_global()\n", + "p.plots[\"AIRDENS\"].axes.coastlines()\n", "p.show()" ] }, @@ -344,10 +346,12 @@ "metadata": {}, "outputs": [], "source": [ - "p.set_mpl_projection(('RotatedPole', (), {'pole_latitude':37.5, 'pole_longitude':177.5}))\n", + "p.set_mpl_projection(\n", + " (\"RotatedPole\", (), {\"pole_latitude\": 37.5, \"pole_longitude\": 177.5})\n", + ")\n", "p._setup_plots()\n", - "p.plots['AIRDENS'].axes.set_global()\n", - "p.plots['AIRDENS'].axes.coastlines()\n", + "p.plots[\"AIRDENS\"].axes.set_global()\n", + "p.plots[\"AIRDENS\"].axes.coastlines()\n", "p.show()" ] }, @@ -357,10 +361,10 @@ "metadata": {}, "outputs": [], "source": [ - "p.set_mpl_projection('NorthPolarStereo')\n", + "p.set_mpl_projection(\"NorthPolarStereo\")\n", "p._setup_plots()\n", - "p.plots['AIRDENS'].axes.set_global()\n", - "p.plots['AIRDENS'].axes.coastlines()\n", + "p.plots[\"AIRDENS\"].axes.set_global()\n", + "p.plots[\"AIRDENS\"].axes.coastlines()\n", "p.show()" ] }, @@ -370,10 +374,10 @@ "metadata": {}, "outputs": [], "source": [ - "p.set_mpl_projection('AlbersEqualArea')\n", + "p.set_mpl_projection(\"AlbersEqualArea\")\n", "p._setup_plots()\n", - "p.plots['AIRDENS'].axes.set_global()\n", - "p.plots['AIRDENS'].axes.coastlines()\n", + "p.plots[\"AIRDENS\"].axes.set_global()\n", + "p.plots[\"AIRDENS\"].axes.coastlines()\n", "p.show()" ] }, @@ -383,10 +387,10 @@ "metadata": {}, "outputs": [], "source": [ - "p.set_mpl_projection('InterruptedGoodeHomolosine')\n", + "p.set_mpl_projection(\"InterruptedGoodeHomolosine\")\n", "p._setup_plots()\n", - "p.plots['AIRDENS'].axes.set_global()\n", - "p.plots['AIRDENS'].axes.coastlines()\n", + "p.plots[\"AIRDENS\"].axes.set_global()\n", + "p.plots[\"AIRDENS\"].axes.coastlines()\n", "p.show()" ] }, @@ -396,10 +400,10 @@ "metadata": {}, "outputs": [], "source": [ - "p.set_mpl_projection('Robinson')\n", + "p.set_mpl_projection(\"Robinson\")\n", "p._setup_plots()\n", - "p.plots['AIRDENS'].axes.set_global()\n", - "p.plots['AIRDENS'].axes.coastlines()\n", + "p.plots[\"AIRDENS\"].axes.set_global()\n", + "p.plots[\"AIRDENS\"].axes.coastlines()\n", "p.show()" ] }, @@ -409,10 +413,10 @@ "metadata": {}, "outputs": [], "source": [ - "p.set_mpl_projection('Gnomonic')\n", + "p.set_mpl_projection(\"Gnomonic\")\n", "p._setup_plots()\n", - "p.plots['AIRDENS'].axes.set_global()\n", - "p.plots['AIRDENS'].axes.coastlines()\n", + "p.plots[\"AIRDENS\"].axes.set_global()\n", + "p.plots[\"AIRDENS\"].axes.coastlines()\n", "p.show()" ] }, @@ -436,10 +440,10 @@ "metadata": {}, "outputs": [], "source": [ - "ds.coordinates.data_transform[\"altitude\"]=\"Miller\"\n", - "p = yt.SlicePlot(ds, \"altitude\", 'AIRDENS')\n", - "p.plots['AIRDENS'].axes.set_global()\n", - "p.plots['AIRDENS'].axes.coastlines()\n", + "ds.coordinates.data_transform[\"altitude\"] = \"Miller\"\n", + "p = yt.SlicePlot(ds, \"altitude\", \"AIRDENS\")\n", + "p.plots[\"AIRDENS\"].axes.set_global()\n", + "p.plots[\"AIRDENS\"].axes.coastlines()\n", "p.show()" ] }, @@ -456,10 +460,10 @@ "metadata": {}, "outputs": [], "source": [ - "p.set_mpl_projection('Robinson')\n", + "p.set_mpl_projection(\"Robinson\")\n", "p._setup_plots()\n", - "p.plots['AIRDENS'].axes.set_global()\n", - "p.plots['AIRDENS'].axes.coastlines()\n", + "p.plots[\"AIRDENS\"].axes.set_global()\n", + "p.plots[\"AIRDENS\"].axes.coastlines()\n", "p.show()" ] } diff --git a/doc/source/cookbook/tipsy_and_yt.ipynb b/doc/source/cookbook/tipsy_and_yt.ipynb index 50d83a000df..8d5c44fe888 100644 --- a/doc/source/cookbook/tipsy_and_yt.ipynb +++ b/doc/source/cookbook/tipsy_and_yt.ipynb @@ -47,7 +47,7 @@ }, "outputs": [], "source": [ - "ds = yt.load('TipsyGalaxy/galaxy.00300', n_ref=8)" + "ds = yt.load(\"TipsyGalaxy/galaxy.00300\", n_ref=8)" ] }, { @@ -115,15 +115,17 @@ "outputs": [], "source": [ "dd = ds.all_data()\n", - "xcoord = dd['Gas','Coordinates'][:,0].v\n", - "ycoord = dd['Gas','Coordinates'][:,1].v\n", - "logT = np.log10(dd['Gas','Temperature'])\n", - "plt.scatter(xcoord, ycoord, c=logT, s=2*logT, marker='o', edgecolor='none', vmin=2, vmax=6)\n", - "plt.xlim(-20,20)\n", - "plt.ylim(-20,20)\n", + "xcoord = dd[\"Gas\", \"Coordinates\"][:, 0].v\n", + "ycoord = dd[\"Gas\", \"Coordinates\"][:, 1].v\n", + "logT = np.log10(dd[\"Gas\", \"Temperature\"])\n", + "plt.scatter(\n", + " xcoord, ycoord, c=logT, s=2 * logT, marker=\"o\", edgecolor=\"none\", vmin=2, vmax=6\n", + ")\n", + "plt.xlim(-20, 20)\n", + "plt.ylim(-20, 20)\n", "cb = plt.colorbar()\n", - "cb.set_label('$\\log_{10}$ Temperature')\n", - "plt.gcf().set_size_inches(15,10)" + "cb.set_label(\"$\\log_{10}$ Temperature\")\n", + "plt.gcf().set_size_inches(15, 10)" ] }, { @@ -148,7 +150,7 @@ }, "outputs": [], "source": [ - "yt.SlicePlot(ds, 'z', ('gas','density'), width=(40, 'kpc'), center='m')" + "yt.SlicePlot(ds, \"z\", (\"gas\", \"density\"), width=(40, \"kpc\"), center=\"m\")" ] }, { @@ -159,7 +161,7 @@ }, "outputs": [], "source": [ - "yt.ProjectionPlot(ds, 'z', ('gas','density'), width=(40, 'kpc'), center='m')" + "yt.ProjectionPlot(ds, \"z\", (\"gas\", \"density\"), width=(40, \"kpc\"), center=\"m\")" ] }, { @@ -177,7 +179,7 @@ }, "outputs": [], "source": [ - "yt.SlicePlot(ds, 'z', ('gas', 'Fe_fraction'), width=(40, 'kpc'), center='m')" + "yt.SlicePlot(ds, \"z\", (\"gas\", \"Fe_fraction\"), width=(40, \"kpc\"), center=\"m\")" ] } ], diff --git a/doc/source/cookbook/yt_gadget_analysis.ipynb b/doc/source/cookbook/yt_gadget_analysis.ipynb index a9e6ca7d3ab..b08e71f7bea 100644 --- a/doc/source/cookbook/yt_gadget_analysis.ipynb +++ b/doc/source/cookbook/yt_gadget_analysis.ipynb @@ -50,21 +50,21 @@ }, "outputs": [], "source": [ - "fname = 'GadgetDiskGalaxy/snapshot_200.hdf5'\n", + "fname = \"GadgetDiskGalaxy/snapshot_200.hdf5\"\n", "\n", - "unit_base = {'UnitLength_in_cm' : 3.08568e+21,\n", - " 'UnitMass_in_g' : 1.989e+43,\n", - " 'UnitVelocity_in_cm_per_s' : 100000}\n", + "unit_base = {\n", + " \"UnitLength_in_cm\": 3.08568e21,\n", + " \"UnitMass_in_g\": 1.989e43,\n", + " \"UnitVelocity_in_cm_per_s\": 100000,\n", + "}\n", "\n", - "bbox_lim = 1e5 #kpc\n", + "bbox_lim = 1e5 # kpc\n", "\n", - "bbox = [[-bbox_lim,bbox_lim],\n", - " [-bbox_lim,bbox_lim],\n", - " [-bbox_lim,bbox_lim]]\n", - " \n", - "ds = yt.load(fname,unit_base=unit_base,bounding_box=bbox)\n", + "bbox = [[-bbox_lim, bbox_lim], [-bbox_lim, bbox_lim], [-bbox_lim, bbox_lim]]\n", + "\n", + "ds = yt.load(fname, unit_base=unit_base, bounding_box=bbox)\n", "ds.index\n", - "ad= ds.all_data()" + "ad = ds.all_data()" ] }, { @@ -82,7 +82,7 @@ }, "outputs": [], "source": [ - "px = yt.ProjectionPlot(ds, 'x', ('gas', 'density'))\n", + "px = yt.ProjectionPlot(ds, \"x\", (\"gas\", \"density\"))\n", "px.show()" ] }, @@ -101,9 +101,9 @@ }, "outputs": [], "source": [ - "print ('left edge: ',ds.domain_left_edge)\n", - "print ('right edge: ',ds.domain_right_edge)\n", - "print ('center: ',ds.domain_center)" + "print(\"left edge: \", ds.domain_left_edge)\n", + "print(\"right edge: \", ds.domain_right_edge)\n", + "print(\"center: \", ds.domain_center)" ] }, { @@ -142,7 +142,7 @@ "ad = ds.all_data()\n", "\n", "# total_mass returns a list, representing the total gas and dark matter + stellar mass, respectively\n", - "print ([tm.in_units('Msun') for tm in ad.quantities.total_mass()])" + "print([tm.in_units(\"Msun\") for tm in ad.quantities.total_mass()])" ] }, { @@ -160,11 +160,11 @@ }, "outputs": [], "source": [ - "density = ad[(\"PartType0\",\"density\")]\n", + "density = ad[(\"PartType0\", \"density\")]\n", "wdens = np.where(density == np.max(density))\n", - "coordinates = ad[(\"PartType0\",\"Coordinates\")]\n", + "coordinates = ad[(\"PartType0\", \"Coordinates\")]\n", "center = coordinates[wdens][0]\n", - "print ('center = ',center)" + "print(\"center = \", center)" ] }, { @@ -182,14 +182,14 @@ }, "outputs": [], "source": [ - "new_box_size = ds.quan(250,'code_length')\n", + "new_box_size = ds.quan(250, \"code_length\")\n", "\n", - "left_edge = center - new_box_size/2\n", - "right_edge = center + new_box_size/2\n", + "left_edge = center - new_box_size / 2\n", + "right_edge = center + new_box_size / 2\n", "\n", - "print (new_box_size.in_units('Mpc'))\n", - "print (left_edge.in_units('Mpc'))\n", - "print (right_edge.in_units('Mpc'))" + "print(new_box_size.in_units(\"Mpc\"))\n", + "print(left_edge.in_units(\"Mpc\"))\n", + "print(right_edge.in_units(\"Mpc\"))" ] }, { @@ -200,7 +200,7 @@ }, "outputs": [], "source": [ - "ad2= ds.region(center=center, left_edge=left_edge, right_edge=right_edge)" + "ad2 = ds.region(center=center, left_edge=left_edge, right_edge=right_edge)" ] }, { @@ -218,7 +218,7 @@ }, "outputs": [], "source": [ - "print ([tm.in_units('Msun') for tm in ad.quantities.total_mass()])" + "print([tm.in_units(\"Msun\") for tm in ad.quantities.total_mass()])" ] }, { @@ -236,7 +236,7 @@ }, "outputs": [], "source": [ - "px = yt.ProjectionPlot(ds, 'x', ('gas', 'density'), center=center, width=new_box_size)\n", + "px = yt.ProjectionPlot(ds, \"x\", (\"gas\", \"density\"), center=center, width=new_box_size)\n", "px.show()" ] }, diff --git a/doc/source/cookbook/yt_gadget_owls_analysis.ipynb b/doc/source/cookbook/yt_gadget_owls_analysis.ipynb index 82c2a719864..eb873e9599f 100644 --- a/doc/source/cookbook/yt_gadget_owls_analysis.ipynb +++ b/doc/source/cookbook/yt_gadget_owls_analysis.ipynb @@ -82,7 +82,7 @@ }, "outputs": [], "source": [ - "fname = 'snapshot_033/snap_033.0.hdf5'\n", + "fname = \"snapshot_033/snap_033.0.hdf5\"\n", "ds = yt.load(fname, n_ref=64, over_refine_factor=1)" ] }, @@ -169,7 +169,7 @@ }, "outputs": [], "source": [ - "ad['PartType0', 'Coordinates']" + "ad[\"PartType0\", \"Coordinates\"]" ] }, { @@ -180,7 +180,7 @@ }, "outputs": [], "source": [ - "ad['PartType4', 'IronFromSNIa']" + "ad[\"PartType4\", \"IronFromSNIa\"]" ] }, { @@ -191,7 +191,7 @@ }, "outputs": [], "source": [ - "ad['PartType1', 'ParticleIDs']" + "ad[\"PartType1\", \"ParticleIDs\"]" ] }, { @@ -202,7 +202,7 @@ }, "outputs": [], "source": [ - "ad['PartType0', 'Hydrogen']" + "ad[\"PartType0\", \"Hydrogen\"]" ] }, { @@ -227,7 +227,7 @@ }, "outputs": [], "source": [ - "pz = yt.ProjectionPlot(ds, 'z', ('gas', 'H_density'))" + "pz = yt.ProjectionPlot(ds, \"z\", (\"gas\", \"H_density\"))" ] }, { @@ -249,7 +249,7 @@ }, "outputs": [], "source": [ - "pz = yt.ProjectionPlot(ds, 'z', ('gas', 'H_p0_density'))" + "pz = yt.ProjectionPlot(ds, \"z\", (\"gas\", \"H_p0_density\"))" ] }, { diff --git a/doc/source/examining/Loading_Generic_Array_Data.ipynb b/doc/source/examining/Loading_Generic_Array_Data.ipynb index 5c95aab0d27..32cf83f0361 100644 --- a/doc/source/examining/Loading_Generic_Array_Data.ipynb +++ b/doc/source/examining/Loading_Generic_Array_Data.ipynb @@ -65,7 +65,7 @@ }, "outputs": [], "source": [ - "arr = np.random.random(size=(64,64,64))" + "arr = np.random.random(size=(64, 64, 64))" ] }, { @@ -83,7 +83,7 @@ }, "outputs": [], "source": [ - "data = dict(density = (arr, \"g/cm**3\"))\n", + "data = dict(density=(arr, \"g/cm**3\"))\n", "bbox = np.array([[-1.5, 1.5], [-1.5, 1.5], [-1.5, 1.5]])\n", "ds = yt.load_uniform_grid(data, arr.shape, length_unit=\"Mpc\", bbox=bbox, nprocs=64)" ] @@ -154,13 +154,21 @@ "posx_arr = np.random.uniform(low=-1.5, high=1.5, size=10000)\n", "posy_arr = np.random.uniform(low=-1.5, high=1.5, size=10000)\n", "posz_arr = np.random.uniform(low=-1.5, high=1.5, size=10000)\n", - "data = dict(density = (np.random.random(size=(64,64,64)), \"Msun/kpc**3\"), \n", - " particle_position_x = (posx_arr, 'code_length'), \n", - " particle_position_y = (posy_arr, 'code_length'),\n", - " particle_position_z = (posz_arr, 'code_length'))\n", + "data = dict(\n", + " density=(np.random.random(size=(64, 64, 64)), \"Msun/kpc**3\"),\n", + " particle_position_x=(posx_arr, \"code_length\"),\n", + " particle_position_y=(posy_arr, \"code_length\"),\n", + " particle_position_z=(posz_arr, \"code_length\"),\n", + ")\n", "bbox = np.array([[-1.5, 1.5], [-1.5, 1.5], [-1.5, 1.5]])\n", - "ds = yt.load_uniform_grid(data, data[\"density\"][0].shape, length_unit=(1.0, \"Mpc\"), mass_unit=(1.0,\"Msun\"), \n", - " bbox=bbox, nprocs=4)" + "ds = yt.load_uniform_grid(\n", + " data,\n", + " data[\"density\"][0].shape,\n", + " length_unit=(1.0, \"Mpc\"),\n", + " mass_unit=(1.0, \"Msun\"),\n", + " bbox=bbox,\n", + " nprocs=4,\n", + ")" ] }, { @@ -209,9 +217,13 @@ "from os.path import join\n", "import h5py\n", "from yt.config import ytcfg\n", - "data_dir = ytcfg.get('yt','test_data_dir')\n", + "\n", + "data_dir = ytcfg.get(\"yt\", \"test_data_dir\")\n", "from yt.utilities.physical_ratios import cm_per_kpc\n", - "f = h5py.File(join(data_dir, \"UnigridData\", \"turb_vels.h5\"), \"r\") # Read-only access to the file" + "\n", + "f = h5py.File(\n", + " join(data_dir, \"UnigridData\", \"turb_vels.h5\"), \"r\"\n", + ") # Read-only access to the file" ] }, { @@ -229,7 +241,7 @@ }, "outputs": [], "source": [ - "print (f.keys())" + "print(f.keys())" ] }, { @@ -247,8 +259,20 @@ }, "outputs": [], "source": [ - "units = [\"gauss\",\"gauss\",\"gauss\", \"g/cm**3\", \"erg/cm**3\", \"K\", \n", - " \"cm/s\", \"cm/s\", \"cm/s\", \"cm/s\", \"cm/s\", \"cm/s\"]" + "units = [\n", + " \"gauss\",\n", + " \"gauss\",\n", + " \"gauss\",\n", + " \"g/cm**3\",\n", + " \"erg/cm**3\",\n", + " \"K\",\n", + " \"cm/s\",\n", + " \"cm/s\",\n", + " \"cm/s\",\n", + " \"cm/s\",\n", + " \"cm/s\",\n", + " \"cm/s\",\n", + "]" ] }, { @@ -266,7 +290,7 @@ }, "outputs": [], "source": [ - "data = {k:(v.value,u) for (k,v), u in zip(f.items(),units)}\n", + "data = {k: (v.value, u) for (k, v), u in zip(f.items(), units)}\n", "bbox = np.array([[-0.5, 0.5], [-0.5, 0.5], [-0.5, 0.5]])" ] }, @@ -278,8 +302,14 @@ }, "outputs": [], "source": [ - "ds = yt.load_uniform_grid(data, data[\"Density\"][0].shape, length_unit=250.*cm_per_kpc, bbox=bbox, nprocs=8, \n", - " periodicity=(False,False,False))" + "ds = yt.load_uniform_grid(\n", + " data,\n", + " data[\"Density\"][0].shape,\n", + " length_unit=250.0 * cm_per_kpc,\n", + " bbox=bbox,\n", + " nprocs=8,\n", + " periodicity=(False, False, False),\n", + ")" ] }, { @@ -297,7 +327,9 @@ }, "outputs": [], "source": [ - "prj = yt.ProjectionPlot(ds, \"z\", [\"z-velocity\",\"Temperature\",\"Bx\"], weight_field=\"Density\")\n", + "prj = yt.ProjectionPlot(\n", + " ds, \"z\", [\"z-velocity\", \"Temperature\", \"Bx\"], weight_field=\"Density\"\n", + ")\n", "prj.set_log(\"z-velocity\", False)\n", "prj.set_log(\"Bx\", False)\n", "prj.show()" @@ -325,9 +357,9 @@ }, "outputs": [], "source": [ - "#Find the min and max of the field\n", - "mi, ma = ds.all_data().quantities.extrema('Temperature')\n", - "#Reduce the dynamic range\n", + "# Find the min and max of the field\n", + "mi, ma = ds.all_data().quantities.extrema(\"Temperature\")\n", + "# Reduce the dynamic range\n", "mi = mi.value + 1.5e7\n", "ma = ma.value - 0.81e7" ] @@ -352,7 +384,7 @@ "# Define the center of the camera to be the domain center\n", "c = ds.domain_center[0]\n", "# Define the width of the image\n", - "W = 1.5*ds.domain_width[0]\n", + "W = 1.5 * ds.domain_width[0]\n", "# Define the number of pixels to render\n", "Npixels = 512" ] @@ -372,7 +404,7 @@ }, "outputs": [], "source": [ - "sc = yt.create_scene(ds, 'Temperature')\n", + "sc = yt.create_scene(ds, \"Temperature\")\n", "dd = ds.all_data()\n", "\n", "source = sc[0]\n", @@ -380,7 +412,7 @@ "source.log_field = False\n", "\n", "tf = yt.ColorTransferFunction((mi, ma), grey_opacity=False)\n", - "tf.map_to_colormap(mi, ma, scale=15.0, colormap='algae')\n", + "tf.map_to_colormap(mi, ma, scale=15.0, colormap=\"algae\")\n", "\n", "source.set_transfer_function(tf)\n", "\n", @@ -427,6 +459,7 @@ "outputs": [], "source": [ "import astropy.io.fits as pyfits\n", + "\n", "# Or, just import pyfits if that's what you have installed" ] }, @@ -467,8 +500,8 @@ "data = {}\n", "for hdu in f:\n", " name = hdu.name.lower()\n", - " data[name] = (hdu.data,\"km/s\")\n", - "print (data.keys())" + " data[name] = (hdu.data, \"km/s\")\n", + "print(data.keys())" ] }, { @@ -506,8 +539,8 @@ }, "outputs": [], "source": [ - "ds = yt.load_uniform_grid(data, data[\"velocity_x\"][0].shape, length_unit=(1.0,\"Mpc\"))\n", - "slc = yt.SlicePlot(ds, \"x\", [\"velocity_x\",\"velocity_y\",\"velocity_z\"])\n", + "ds = yt.load_uniform_grid(data, data[\"velocity_x\"][0].shape, length_unit=(1.0, \"Mpc\"))\n", + "slc = yt.SlicePlot(ds, \"x\", [\"velocity_x\", \"velocity_y\", \"velocity_z\"])\n", "for ax in \"xyz\":\n", " slc.set_log(\"velocity_%s\" % (ax), False)\n", "slc.annotate_velocity()\n", @@ -537,15 +570,19 @@ "outputs": [], "source": [ "grid_data = [\n", - " dict(left_edge = [0.0, 0.0, 0.0],\n", - " right_edge = [1.0, 1.0, 1.0],\n", - " level = 0,\n", - " dimensions = [32, 32, 32]), \n", - " dict(left_edge = [0.25, 0.25, 0.25],\n", - " right_edge = [0.75, 0.75, 0.75],\n", - " level = 1,\n", - " dimensions = [32, 32, 32])\n", - " ]" + " dict(\n", + " left_edge=[0.0, 0.0, 0.0],\n", + " right_edge=[1.0, 1.0, 1.0],\n", + " level=0,\n", + " dimensions=[32, 32, 32],\n", + " ),\n", + " dict(\n", + " left_edge=[0.25, 0.25, 0.25],\n", + " right_edge=[0.75, 0.75, 0.75],\n", + " level=1,\n", + " dimensions=[32, 32, 32],\n", + " ),\n", + "]" ] }, { @@ -563,8 +600,8 @@ }, "outputs": [], "source": [ - "for g in grid_data: \n", - " g[\"density\"] = (np.random.random(g[\"dimensions\"]) * 2**g[\"level\"], \"g/cm**3\")" + "for g in grid_data:\n", + " g[\"density\"] = (np.random.random(g[\"dimensions\"]) * 2 ** g[\"level\"], \"g/cm**3\")" ] }, { @@ -582,12 +619,24 @@ }, "outputs": [], "source": [ - "grid_data[0][\"particle_position_x\"] = (np.array([]), \"code_length\") # No particles, so set empty arrays\n", + "grid_data[0][\"particle_position_x\"] = (\n", + " np.array([]),\n", + " \"code_length\",\n", + ") # No particles, so set empty arrays\n", "grid_data[0][\"particle_position_y\"] = (np.array([]), \"code_length\")\n", "grid_data[0][\"particle_position_z\"] = (np.array([]), \"code_length\")\n", - "grid_data[1][\"particle_position_x\"] = (np.random.uniform(low=0.25, high=0.75, size=1000), \"code_length\")\n", - "grid_data[1][\"particle_position_y\"] = (np.random.uniform(low=0.25, high=0.75, size=1000), \"code_length\")\n", - "grid_data[1][\"particle_position_z\"] = (np.random.uniform(low=0.25, high=0.75, size=1000), \"code_length\")" + "grid_data[1][\"particle_position_x\"] = (\n", + " np.random.uniform(low=0.25, high=0.75, size=1000),\n", + " \"code_length\",\n", + ")\n", + "grid_data[1][\"particle_position_y\"] = (\n", + " np.random.uniform(low=0.25, high=0.75, size=1000),\n", + " \"code_length\",\n", + ")\n", + "grid_data[1][\"particle_position_z\"] = (\n", + " np.random.uniform(low=0.25, high=0.75, size=1000),\n", + " \"code_length\",\n", + ")" ] }, { @@ -654,16 +703,24 @@ "posxb_arr = np.random.uniform(low=-1.5, high=1.5, size=20000)\n", "posyb_arr = np.random.uniform(low=-1.5, high=1.5, size=20000)\n", "poszb_arr = np.random.uniform(low=-1.5, high=1.5, size=20000)\n", - "data = {\"density\": (np.random.random(size=(64,64,64)), \"Msun/kpc**3\"), \n", - " (\"red\", \"particle_position_x\"): (posxr_arr, 'code_length'), \n", - " (\"red\", \"particle_position_y\"): (posyr_arr, 'code_length'),\n", - " (\"red\", \"particle_position_z\"): (poszr_arr, 'code_length'),\n", - " (\"blue\", \"particle_position_x\"): (posxb_arr, 'code_length'), \n", - " (\"blue\", \"particle_position_y\"): (posyb_arr, 'code_length'),\n", - " (\"blue\", \"particle_position_z\"): (poszb_arr, 'code_length')}\n", + "data = {\n", + " \"density\": (np.random.random(size=(64, 64, 64)), \"Msun/kpc**3\"),\n", + " (\"red\", \"particle_position_x\"): (posxr_arr, \"code_length\"),\n", + " (\"red\", \"particle_position_y\"): (posyr_arr, \"code_length\"),\n", + " (\"red\", \"particle_position_z\"): (poszr_arr, \"code_length\"),\n", + " (\"blue\", \"particle_position_x\"): (posxb_arr, \"code_length\"),\n", + " (\"blue\", \"particle_position_y\"): (posyb_arr, \"code_length\"),\n", + " (\"blue\", \"particle_position_z\"): (poszb_arr, \"code_length\"),\n", + "}\n", "bbox = np.array([[-1.5, 1.5], [-1.5, 1.5], [-1.5, 1.5]])\n", - "ds = yt.load_uniform_grid(data, data[\"density\"][0].shape, length_unit=(1.0, \"Mpc\"), mass_unit=(1.0,\"Msun\"), \n", - " bbox=bbox, nprocs=4)" + "ds = yt.load_uniform_grid(\n", + " data,\n", + " data[\"density\"][0].shape,\n", + " length_unit=(1.0, \"Mpc\"),\n", + " mass_unit=(1.0, \"Msun\"),\n", + " bbox=bbox,\n", + " nprocs=4,\n", + ")" ] }, { @@ -680,10 +737,10 @@ "outputs": [], "source": [ "dd = ds.all_data()\n", - "print (ds.particle_types)\n", - "print (dd[\"red\", \"particle_position_x\"].size)\n", - "print (dd[\"blue\", \"particle_position_x\"].size)\n", - "print (dd[\"all\", \"particle_position_x\"].size)" + "print(ds.particle_types)\n", + "print(dd[\"red\", \"particle_position_x\"].size)\n", + "print(dd[\"blue\", \"particle_position_x\"].size)\n", + "print(dd[\"all\", \"particle_position_x\"].size)" ] }, { diff --git a/doc/source/examining/Loading_Generic_Particle_Data.ipynb b/doc/source/examining/Loading_Generic_Particle_Data.ipynb index 024a4b08f44..3f4d7dab2fb 100644 --- a/doc/source/examining/Loading_Generic_Particle_Data.ipynb +++ b/doc/source/examining/Loading_Generic_Particle_Data.ipynb @@ -21,7 +21,7 @@ "\n", "n_particles = 5000000\n", "\n", - "ppx, ppy, ppz = 1e6*np.random.normal(size=[3, n_particles])\n", + "ppx, ppy, ppz = 1e6 * np.random.normal(size=[3, n_particles])\n", "\n", "ppm = np.ones(n_particles)" ] @@ -41,10 +41,12 @@ }, "outputs": [], "source": [ - "data = {'particle_position_x': ppx,\n", - " 'particle_position_y': ppy,\n", - " 'particle_position_z': ppz,\n", - " 'particle_mass': ppm}" + "data = {\n", + " \"particle_position_x\": ppx,\n", + " \"particle_position_y\": ppy,\n", + " \"particle_position_z\": ppz,\n", + " \"particle_mass\": ppm,\n", + "}" ] }, { @@ -72,9 +74,13 @@ "import yt\n", "from yt.units import parsec, Msun\n", "\n", - "bbox = 1.1*np.array([[min(ppx), max(ppx)], [min(ppy), max(ppy)], [min(ppz), max(ppz)]])\n", + "bbox = 1.1 * np.array(\n", + " [[min(ppx), max(ppx)], [min(ppy), max(ppy)], [min(ppz), max(ppz)]]\n", + ")\n", "\n", - "ds = yt.load_particles(data, length_unit=parsec, mass_unit=1e8*Msun, n_ref=256, bbox=bbox)" + "ds = yt.load_particles(\n", + " data, length_unit=parsec, mass_unit=1e8 * Msun, n_ref=256, bbox=bbox\n", + ")" ] }, { @@ -142,8 +148,8 @@ "metadata": {}, "outputs": [], "source": [ - "slc = yt.SlicePlot(ds, 2, ('deposit', 'all_cic'))\n", - "slc.set_width((8, 'Mpc'))" + "slc = yt.SlicePlot(ds, 2, (\"deposit\", \"all_cic\"))\n", + "slc.set_width((8, \"Mpc\"))" ] }, { @@ -162,22 +168,26 @@ "n_star_particles = 1000000\n", "n_dm_particles = 2000000\n", "\n", - "ppxd, ppyd, ppzd = 1e6*np.random.normal(size=[3, n_dm_particles])\n", + "ppxd, ppyd, ppzd = 1e6 * np.random.normal(size=[3, n_dm_particles])\n", "ppmd = np.ones(n_dm_particles)\n", "\n", - "ppxs, ppys, ppzs = 5e5*np.random.normal(size=[3, n_star_particles])\n", - "ppms = 0.1*np.ones(n_star_particles)\n", + "ppxs, ppys, ppzs = 5e5 * np.random.normal(size=[3, n_star_particles])\n", + "ppms = 0.1 * np.ones(n_star_particles)\n", "\n", - "data2 = {('dm', 'particle_position_x'): ppxd,\n", - " ('dm', 'particle_position_y'): ppyd,\n", - " ('dm', 'particle_position_z'): ppzd,\n", - " ('dm', 'particle_mass'): ppmd,\n", - " ('star', 'particle_position_x'): ppxs,\n", - " ('star', 'particle_position_y'): ppys,\n", - " ('star', 'particle_position_z'): ppzs,\n", - " ('star', 'particle_mass'): ppms}\n", + "data2 = {\n", + " (\"dm\", \"particle_position_x\"): ppxd,\n", + " (\"dm\", \"particle_position_y\"): ppyd,\n", + " (\"dm\", \"particle_position_z\"): ppzd,\n", + " (\"dm\", \"particle_mass\"): ppmd,\n", + " (\"star\", \"particle_position_x\"): ppxs,\n", + " (\"star\", \"particle_position_y\"): ppys,\n", + " (\"star\", \"particle_position_z\"): ppzs,\n", + " (\"star\", \"particle_mass\"): ppms,\n", + "}\n", "\n", - "ds2 = yt.load_particles(data2, length_unit=parsec, mass_unit=1e8*Msun, n_ref=256, bbox=bbox)" + "ds2 = yt.load_particles(\n", + " data2, length_unit=parsec, mass_unit=1e8 * Msun, n_ref=256, bbox=bbox\n", + ")" ] }, { @@ -195,8 +205,8 @@ }, "outputs": [], "source": [ - "slc = yt.SlicePlot(ds2, 2, [('deposit', 'dm_cic'), ('deposit', 'star_cic')])\n", - "slc.set_width((8, 'Mpc'))" + "slc = yt.SlicePlot(ds2, 2, [(\"deposit\", \"dm_cic\"), (\"deposit\", \"star_cic\")])\n", + "slc.set_width((8, \"Mpc\"))" ] } ], diff --git a/doc/source/examining/Loading_Spherical_Data.ipynb b/doc/source/examining/Loading_Spherical_Data.ipynb index 4b02e2708f0..ba5efd5fb96 100644 --- a/doc/source/examining/Loading_Spherical_Data.ipynb +++ b/doc/source/examining/Loading_Spherical_Data.ipynb @@ -40,18 +40,26 @@ }, "outputs": [], "source": [ - "@yt.derived_field(name = \"sphx\", units = \"cm\", take_log=False)\n", + "@yt.derived_field(name=\"sphx\", units=\"cm\", take_log=False)\n", "def sphx(field, data):\n", - " return np.cos(data[\"phi\"]) * np.sin(data[\"theta\"])*data[\"r\"]\n", - "@yt.derived_field(name = \"sphy\", units = \"cm\", take_log=False)\n", + " return np.cos(data[\"phi\"]) * np.sin(data[\"theta\"]) * data[\"r\"]\n", + "\n", + "\n", + "@yt.derived_field(name=\"sphy\", units=\"cm\", take_log=False)\n", "def sphy(field, data):\n", - " return np.sin(data[\"phi\"]) * np.sin(data[\"theta\"])*data[\"r\"]\n", - "@yt.derived_field(name = \"sphz\", units = \"cm\", take_log=False)\n", + " return np.sin(data[\"phi\"]) * np.sin(data[\"theta\"]) * data[\"r\"]\n", + "\n", + "\n", + "@yt.derived_field(name=\"sphz\", units=\"cm\", take_log=False)\n", "def sphz(field, data):\n", - " return np.cos(data[\"theta\"])*data[\"r\"]\n", - "@yt.derived_field(name = \"funfield\", units=\"cm\", take_log=False)\n", + " return np.cos(data[\"theta\"]) * data[\"r\"]\n", + "\n", + "\n", + "@yt.derived_field(name=\"funfield\", units=\"cm\", take_log=False)\n", "def funfield(field, data):\n", - " return (np.sin(data[\"phi\"])**2 + np.cos(data[\"theta\"])**2) * (1.0*data[\"r\"].uq+data[\"r\"])" + " return (np.sin(data[\"phi\"]) ** 2 + np.cos(data[\"theta\"]) ** 2) * (\n", + " 1.0 * data[\"r\"].uq + data[\"r\"]\n", + " )" ] }, { @@ -73,9 +81,12 @@ }, "outputs": [], "source": [ - "ds = yt.load_uniform_grid({}, [128, 128, 128],\n", - " bbox=np.array([[0.0, 1.0], [0.0, np.pi], [0.0, 2*np.pi]]),\n", - " geometry=\"spherical\")" + "ds = yt.load_uniform_grid(\n", + " {},\n", + " [128, 128, 128],\n", + " bbox=np.array([[0.0, 1.0], [0.0, np.pi], [0.0, 2 * np.pi]]),\n", + " geometry=\"spherical\",\n", + ")" ] }, { @@ -97,7 +108,7 @@ }, "outputs": [], "source": [ - "s = ds.slice(2, np.pi/2)\n", + "s = ds.slice(2, np.pi / 2)\n", "p = s.to_pw(\"funfield\", origin=\"native\")\n", "p.set_zlim(\"all\", 0.0, 4.0)\n", "p.show()" diff --git a/doc/source/quickstart/2)_Data_Inspection.ipynb b/doc/source/quickstart/2)_Data_Inspection.ipynb index baf00f0c513..7dfc110c358 100644 --- a/doc/source/quickstart/2)_Data_Inspection.ipynb +++ b/doc/source/quickstart/2)_Data_Inspection.ipynb @@ -169,9 +169,9 @@ }, "outputs": [], "source": [ - "print (ds.domain_width.in_units(\"kpc\"))\n", - "print (ds.domain_width.in_units(\"au\"))\n", - "print (ds.domain_width.in_units(\"mile\"))" + "print(ds.domain_width.in_units(\"kpc\"))\n", + "print(ds.domain_width.in_units(\"au\"))\n", + "print(ds.domain_width.in_units(\"mile\"))" ] }, { @@ -192,9 +192,9 @@ }, "outputs": [], "source": [ - "print (ds.particle_types)\n", - "print (ds.particle_types_raw)\n", - "print (ds.particle_type_counts)" + "print(ds.particle_types)\n", + "print(ds.particle_types_raw)\n", + "print(ds.particle_type_counts)" ] }, { @@ -226,7 +226,7 @@ }, "outputs": [], "source": [ - "print (ds.index.grid_left_edge)" + "print(ds.index.grid_left_edge)" ] }, { @@ -365,9 +365,9 @@ "outputs": [], "source": [ "g2 = gs[0]\n", - "print (g2)\n", - "print (g2.Parent)\n", - "print (g2.get_global_startindex())" + "print(g2)\n", + "print(g2.Parent)\n", + "print(g2.get_global_startindex())" ] }, { @@ -381,7 +381,7 @@ }, "outputs": [], "source": [ - "g2[\"density\"][:,:,0]" + "g2[\"density\"][:, :, 0]" ] }, { @@ -395,8 +395,8 @@ }, "outputs": [], "source": [ - "print ((g2.Parent.child_mask == 0).sum() * 8)\n", - "print (g2.ActiveDimensions.prod())" + "print((g2.Parent.child_mask == 0).sum() * 8)\n", + "print(g2.ActiveDimensions.prod())" ] }, { @@ -412,8 +412,9 @@ "source": [ "for f in ds.field_list:\n", " fv = g[f]\n", - " if fv.size == 0: continue\n", - " print (f, fv.min(), fv.max())" + " if fv.size == 0:\n", + " continue\n", + " print(f, fv.min(), fv.max())" ] }, { @@ -438,7 +439,7 @@ }, "outputs": [], "source": [ - "sp = ds.sphere(\"max\", (10, 'kpc'))" + "sp = ds.sphere(\"max\", (10, \"kpc\"))" ] }, { diff --git a/doc/source/quickstart/3)_Simple_Visualization.ipynb b/doc/source/quickstart/3)_Simple_Visualization.ipynb index 0a08ce3b800..2d1daddf6a4 100644 --- a/doc/source/quickstart/3)_Simple_Visualization.ipynb +++ b/doc/source/quickstart/3)_Simple_Visualization.ipynb @@ -42,7 +42,7 @@ "outputs": [], "source": [ "ds = yt.load_sample(\"enzo_tiny_cosmology\", \"DD0046/DD0046\")\n", - "print (\"Redshift =\", ds.current_redshift)" + "print(\"Redshift =\", ds.current_redshift)" ] }, { diff --git a/doc/source/quickstart/4)_Data_Objects_and_Time_Series.ipynb b/doc/source/quickstart/4)_Data_Objects_and_Time_Series.ipynb index c93484399ee..a3637c83923 100644 --- a/doc/source/quickstart/4)_Data_Objects_and_Time_Series.ipynb +++ b/doc/source/quickstart/4)_Data_Objects_and_Time_Series.ipynb @@ -75,7 +75,7 @@ "rho_ex = []\n", "times = []\n", "for ds in ts:\n", - " print (ds)\n", + " print(ds)\n", " dd = ds.all_data()\n", " rho_ex.append(dd.quantities.extrema(\"density\"))\n", " times.append(ds.current_time.in_units(\"Gyr\"))\n", @@ -100,8 +100,8 @@ }, "outputs": [], "source": [ - "pylab.semilogy(times, rho_ex[:,0], '-xk', label='Minimum')\n", - "pylab.semilogy(times, rho_ex[:,1], '-xr', label='Maximum')\n", + "pylab.semilogy(times, rho_ex[:, 0], \"-xk\", label=\"Minimum\")\n", + "pylab.semilogy(times, rho_ex[:, 1], \"-xr\", label=\"Maximum\")\n", "pylab.ylabel(\"Density ($g/cm^3$)\")\n", "pylab.xlabel(\"Time (Gyr)\")\n", "pylab.legend()\n", @@ -141,11 +141,11 @@ " halos = HaloFinder(ds)\n", " dd = ds.all_data()\n", " total_mass = dd.quantities.total_quantity(\"mass\").in_units(\"Msun\")\n", - " total_in_baryons = 0.0*Msun\n", + " total_in_baryons = 0.0 * Msun\n", " for halo in halos:\n", " sp = halo.get_sphere()\n", " total_in_baryons += sp.quantities.total_quantity(\"mass\").in_units(\"Msun\")\n", - " mass.append(total_in_baryons/total_mass)\n", + " mass.append(total_in_baryons / total_mass)\n", " zs.append(ds.current_redshift)" ] }, @@ -167,11 +167,11 @@ }, "outputs": [], "source": [ - "pylab.semilogx(zs, mass, '-xb')\n", + "pylab.semilogx(zs, mass, \"-xb\")\n", "pylab.xlabel(\"Redshift\")\n", "pylab.ylabel(\"Mass in halos / Total mass\")\n", "pylab.xlim(right=max(zs))\n", - "pylab.ylim(-0.01, .18)" + "pylab.ylim(-0.01, 0.18)" ] }, { @@ -217,7 +217,7 @@ }, "outputs": [], "source": [ - "print (ray[\"dts\"])" + "print(ray[\"dts\"])" ] }, { @@ -231,7 +231,7 @@ }, "outputs": [], "source": [ - "print (ray[\"t\"])" + "print(ray[\"t\"])" ] }, { @@ -245,7 +245,7 @@ }, "outputs": [], "source": [ - "print (ray[\"x\"])" + "print(ray[\"x\"])" ] }, { @@ -271,10 +271,10 @@ "ds = yt.load_sample(\"IsolatedGalaxy\")\n", "v, c = ds.find_max(\"density\")\n", "sl = ds.slice(2, c[0])\n", - "print (sl[\"index\", \"x\"])\n", - "print (sl[\"index\", \"z\"])\n", - "print (sl[\"pdx\"])\n", - "print (sl[\"gas\", \"density\"].shape)" + "print(sl[\"index\", \"x\"])\n", + "print(sl[\"index\", \"z\"])\n", + "print(sl[\"pdx\"])\n", + "print(sl[\"gas\", \"density\"].shape)" ] }, { @@ -295,8 +295,8 @@ }, "outputs": [], "source": [ - "frb = sl.to_frb((50.0, 'kpc'), 1024)\n", - "print (frb[\"gas\", \"density\"].shape)" + "frb = sl.to_frb((50.0, \"kpc\"), 1024)\n", + "print(frb[\"gas\", \"density\"].shape)" ] }, { @@ -319,6 +319,7 @@ "source": [ "yt.write_image(np.log10(frb[\"gas\", \"density\"]), \"temp.png\")\n", "from IPython.display import Image\n", + "\n", "Image(filename=\"temp.png\")" ] }, @@ -402,8 +403,8 @@ "outputs": [], "source": [ "pws = sl.to_pw(fields=[\"density\"])\n", - "#pws.show()\n", - "print (list(pws.plots.keys()))" + "# pws.show()\n", + "print(list(pws.plots.keys()))" ] }, { @@ -430,8 +431,8 @@ }, "outputs": [], "source": [ - "cg = ds.covering_grid(2, [0.0, 0.0, 0.0], ds.domain_dimensions * 2**2)\n", - "print (cg[\"density\"].shape)" + "cg = ds.covering_grid(2, [0.0, 0.0, 0.0], ds.domain_dimensions * 2 ** 2)\n", + "print(cg[\"density\"].shape)" ] }, { @@ -452,8 +453,8 @@ }, "outputs": [], "source": [ - "scg = ds.smoothed_covering_grid(2, [0.0, 0.0, 0.0], ds.domain_dimensions * 2**2)\n", - "print (scg[\"density\"].shape)" + "scg = ds.smoothed_covering_grid(2, [0.0, 0.0, 0.0], ds.domain_dimensions * 2 ** 2)\n", + "print(scg[\"density\"].shape)" ] } ], diff --git a/doc/source/quickstart/5)_Derived_Fields_and_Profiles.ipynb b/doc/source/quickstart/5)_Derived_Fields_and_Profiles.ipynb index 0e17517b236..15ce85f1fd7 100644 --- a/doc/source/quickstart/5)_Derived_Fields_and_Profiles.ipynb +++ b/doc/source/quickstart/5)_Derived_Fields_and_Profiles.ipynb @@ -72,7 +72,7 @@ "source": [ "ds = yt.load_sample(\"IsolatedGalaxy\")\n", "dd = ds.all_data()\n", - "print (list(dd.quantities.keys()))" + "print(list(dd.quantities.keys()))" ] }, { @@ -93,7 +93,7 @@ }, "outputs": [], "source": [ - "print (dd.quantities.extrema(\"dinosaurs\"))" + "print(dd.quantities.extrema(\"dinosaurs\"))" ] }, { @@ -114,7 +114,7 @@ }, "outputs": [], "source": [ - "print (dd.quantities.weighted_average_quantity(\"dinosaurs\", weight=\"temperature\"))" + "print(dd.quantities.weighted_average_quantity(\"dinosaurs\", weight=\"temperature\"))" ] }, { @@ -137,13 +137,13 @@ }, "outputs": [], "source": [ - "sp = ds.sphere(\"max\", (10.0, 'kpc'))\n", + "sp = ds.sphere(\"max\", (10.0, \"kpc\"))\n", "bv = sp.quantities.bulk_velocity()\n", "L = sp.quantities.angular_momentum_vector()\n", "rho_min, rho_max = sp.quantities.extrema(\"density\")\n", - "print (bv)\n", - "print (L)\n", - "print (rho_min, rho_max)" + "print(bv)\n", + "print(L)\n", + "print(rho_min, rho_max)" ] }, { @@ -171,10 +171,10 @@ "outputs": [], "source": [ "prof = yt.Profile1D(sp, \"density\", 32, rho_min, rho_max, True, weight_field=\"mass\")\n", - "prof.add_fields([\"temperature\",\"dinosaurs\"])\n", + "prof.add_fields([\"temperature\", \"dinosaurs\"])\n", "pylab.loglog(np.array(prof.x), np.array(prof[\"temperature\"]), \"-x\")\n", - "pylab.xlabel('Density $(g/cm^3)$')\n", - "pylab.ylabel('Temperature $(K)$')" + "pylab.xlabel(\"Density $(g/cm^3)$\")\n", + "pylab.ylabel(\"Temperature $(K)$\")" ] }, { @@ -195,9 +195,9 @@ }, "outputs": [], "source": [ - "pylab.loglog(np.array(prof.x), np.array(prof[\"dinosaurs\"]), '-x')\n", - "pylab.xlabel('Density $(g/cm^3)$')\n", - "pylab.ylabel('Dinosaurs $(K cm / s)$')" + "pylab.loglog(np.array(prof.x), np.array(prof[\"dinosaurs\"]), \"-x\")\n", + "pylab.xlabel(\"Density $(g/cm^3)$\")\n", + "pylab.ylabel(\"Dinosaurs $(K cm / s)$\")" ] }, { @@ -220,9 +220,9 @@ "source": [ "prof = yt.Profile1D(sp, \"density\", 32, rho_min, rho_max, True, weight_field=None)\n", "prof.add_fields([\"mass\"])\n", - "pylab.loglog(np.array(prof.x), np.array(prof[\"mass\"].in_units(\"Msun\")), '-x')\n", - "pylab.xlabel('Density $(g/cm^3)$')\n", - "pylab.ylabel('Cell mass $(M_\\odot)$')" + "pylab.loglog(np.array(prof.x), np.array(prof[\"mass\"].in_units(\"Msun\")), \"-x\")\n", + "pylab.xlabel(\"Density $(g/cm^3)$\")\n", + "pylab.ylabel(\"Cell mass $(M_\\odot)$\")" ] }, { @@ -243,8 +243,8 @@ }, "outputs": [], "source": [ - "prof = yt.ProfilePlot(sp, 'density', 'mass', weight_field=None)\n", - "prof.set_unit('mass', 'Msun')\n", + "prof = yt.ProfilePlot(sp, \"density\", \"mass\", weight_field=None)\n", + "prof.set_unit(\"mass\", \"Msun\")\n", "prof.show()" ] }, @@ -268,19 +268,19 @@ }, "outputs": [], "source": [ - "sp_small = ds.sphere(\"max\", (50.0, 'kpc'))\n", + "sp_small = ds.sphere(\"max\", (50.0, \"kpc\"))\n", "bv = sp_small.quantities.bulk_velocity()\n", "\n", - "sp = ds.sphere(\"max\", (0.1, 'Mpc'))\n", + "sp = ds.sphere(\"max\", (0.1, \"Mpc\"))\n", "rv1 = sp.quantities.extrema(\"radial_velocity\")\n", "\n", "sp.clear_data()\n", "sp.set_field_parameter(\"bulk_velocity\", bv)\n", "rv2 = sp.quantities.extrema(\"radial_velocity\")\n", "\n", - "print (bv)\n", - "print (rv1)\n", - "print (rv2)" + "print(bv)\n", + "print(rv1)\n", + "print(rv2)" ] } ], diff --git a/doc/source/quickstart/6)_Volume_Rendering.ipynb b/doc/source/quickstart/6)_Volume_Rendering.ipynb index 581b8358a13..0a067457e98 100644 --- a/doc/source/quickstart/6)_Volume_Rendering.ipynb +++ b/doc/source/quickstart/6)_Volume_Rendering.ipynb @@ -21,6 +21,7 @@ "outputs": [], "source": [ "import yt\n", + "\n", "ds = yt.load_sample(\"IsolatedGalaxy\")" ] }, @@ -48,9 +49,9 @@ "source": [ "sc = yt.create_scene(ds)\n", "\n", - "sc.camera.set_width(ds.quan(20, 'kpc'))\n", + "sc.camera.set_width(ds.quan(20, \"kpc\"))\n", "\n", - "source = sc.sources['source_00']\n", + "source = sc.sources[\"source_00\"]\n", "\n", "tf = yt.ColorTransferFunction((-28, -24))\n", "tf.add_layers(4, w=0.01)\n", @@ -101,11 +102,11 @@ "source": [ "sc = yt.create_scene(ds)\n", "\n", - "sc.camera.set_width(ds.quan(20, 'kpc'))\n", + "sc.camera.set_width(ds.quan(20, \"kpc\"))\n", "\n", - "source = sc.sources['source_00']\n", + "source = sc.sources[\"source_00\"]\n", "\n", - "source.field = 'density'\n", + "source.field = \"density\"\n", "\n", "tf = yt.ColorTransferFunction((-28, -25))\n", "tf.add_layers(4, w=0.03)\n", diff --git a/doc/source/visualizing/FITSImageData.ipynb b/doc/source/visualizing/FITSImageData.ipynb index b0a2912397d..e82e796f13e 100644 --- a/doc/source/visualizing/FITSImageData.ipynb +++ b/doc/source/visualizing/FITSImageData.ipynb @@ -22,9 +22,11 @@ "metadata": {}, "outputs": [], "source": [ - "units_override = {\"length_unit\": (1.0, \"Mpc\"),\n", - " \"mass_unit\": (1.0e14, \"Msun\"),\n", - " \"time_unit\": (1.0, \"Myr\")}\n", + "units_override = {\n", + " \"length_unit\": (1.0, \"Mpc\"),\n", + " \"mass_unit\": (1.0e14, \"Msun\"),\n", + " \"time_unit\": (1.0, \"Myr\"),\n", + "}\n", "ds = yt.load(\"MHDSloshing/virgo_low_res.0054.vtk\", units_override=units_override)" ] }, @@ -48,8 +50,13 @@ "metadata": {}, "outputs": [], "source": [ - "prj = yt.ProjectionPlot(ds, \"z\", (\"gas\", \"temperature\"), \n", - " weight_field=(\"gas\", \"density\"), width=(500., \"kpc\"))\n", + "prj = yt.ProjectionPlot(\n", + " ds,\n", + " \"z\",\n", + " (\"gas\", \"temperature\"),\n", + " weight_field=(\"gas\", \"density\"),\n", + " width=(500.0, \"kpc\"),\n", + ")\n", "prj.show()" ] }, @@ -66,7 +73,9 @@ "metadata": {}, "outputs": [], "source": [ - "prj_fits = yt.FITSProjection(ds, \"z\", (\"gas\", \"temperature\"), weight_field=(\"gas\", \"density\"))" + "prj_fits = yt.FITSProjection(\n", + " ds, \"z\", (\"gas\", \"temperature\"), weight_field=(\"gas\", \"density\")\n", + ")" ] }, { @@ -89,8 +98,13 @@ "metadata": {}, "outputs": [], "source": [ - "prj_fits = yt.FITSProjection(ds, \"z\", (\"gas\", \"temperature\"), \n", - " weight_field=(\"gas\", \"density\"), width=(500., \"kpc\"))" + "prj_fits = yt.FITSProjection(\n", + " ds,\n", + " \"z\",\n", + " (\"gas\", \"temperature\"),\n", + " weight_field=(\"gas\", \"density\"),\n", + " width=(500.0, \"kpc\"),\n", + ")" ] }, { @@ -187,7 +201,9 @@ "source": [ "# length_unit defaults to that from the dataset\n", "# image_res defaults to 512\n", - "slc_fits = yt.FITSSlice(ds, \"z\", (\"gas\", \"density\"), width=(500,\"kpc\"), length_unit=\"ly\", image_res=256)" + "slc_fits = yt.FITSSlice(\n", + " ds, \"z\", (\"gas\", \"density\"), width=(500, \"kpc\"), length_unit=\"ly\", image_res=256\n", + ")" ] }, { @@ -258,7 +274,7 @@ "metadata": {}, "outputs": [], "source": [ - "slc2 = yt.SlicePlot(ds2, \"z\", (\"gas\", \"temperature\"), width=(500.,\"kpc\"))\n", + "slc2 = yt.SlicePlot(ds2, \"z\", (\"gas\", \"temperature\"), width=(500.0, \"kpc\"))\n", "slc2.set_log(\"temperature\", True)\n", "slc2.show()" ] @@ -284,8 +300,10 @@ "outputs": [], "source": [ "slc3 = ds.slice(0, 0.0)\n", - "frb = slc3.to_frb((500.,\"kpc\"), 800)\n", - "fid_frb = frb.to_fits_data(fields=[(\"gas\", \"density\"), (\"gas\", \"temperature\")], length_unit=\"pc\")" + "frb = slc3.to_frb((500.0, \"kpc\"), 800)\n", + "fid_frb = frb.to_fits_data(\n", + " fields=[(\"gas\", \"density\"), (\"gas\", \"temperature\")], length_unit=\"pc\"\n", + ")" ] }, { @@ -301,8 +319,9 @@ "metadata": {}, "outputs": [], "source": [ - "fid_pw = prj.to_fits_data(fields=[(\"gas\", \"density\"), (\"gas\", \"temperature\")], \n", - " length_unit=\"pc\")" + "fid_pw = prj.to_fits_data(\n", + " fields=[(\"gas\", \"density\"), (\"gas\", \"temperature\")], length_unit=\"pc\"\n", + ")" ] }, { @@ -318,10 +337,14 @@ "metadata": {}, "outputs": [], "source": [ - "grid = ds.r[(-0.5, \"Mpc\"):(0.5, \"Mpc\"):64j,\n", - " (-0.5, \"Mpc\"):(0.5, \"Mpc\"):64j,\n", - " (-0.5, \"Mpc\"):(0.5, \"Mpc\"):64j]\n", - "fid_grid = grid.to_fits_data(fields=[(\"gas\", \"density\"), (\"gas\", \"temperature\")], length_unit=\"Mpc\")" + "grid = ds.r[\n", + " (-0.5, \"Mpc\"):(0.5, \"Mpc\"):64j,\n", + " (-0.5, \"Mpc\"):(0.5, \"Mpc\"):64j,\n", + " (-0.5, \"Mpc\"):(0.5, \"Mpc\"):64j,\n", + "]\n", + "fid_grid = grid.to_fits_data(\n", + " fields=[(\"gas\", \"density\"), (\"gas\", \"temperature\")], length_unit=\"Mpc\"\n", + ")" ] }, { @@ -459,9 +482,9 @@ "metadata": {}, "outputs": [], "source": [ - "sky_center = [30.,45.] # in degrees\n", - "sky_scale = (2.5, \"arcsec/kpc\") # could also use a YTQuantity\n", - "prj_fits.create_sky_wcs(sky_center, sky_scale, ctype=[\"RA---TAN\",\"DEC--TAN\"])" + "sky_center = [30.0, 45.0] # in degrees\n", + "sky_scale = (2.5, \"arcsec/kpc\") # could also use a YTQuantity\n", + "prj_fits.create_sky_wcs(sky_center, sky_scale, ctype=[\"RA---TAN\", \"DEC--TAN\"])" ] }, { @@ -495,7 +518,9 @@ }, "outputs": [], "source": [ - "prj_fits3.create_sky_wcs(sky_center, sky_scale, ctype=[\"RA---TAN\",\"DEC--TAN\"], replace_old_wcs=False)" + "prj_fits3.create_sky_wcs(\n", + " sky_center, sky_scale, ctype=[\"RA---TAN\", \"DEC--TAN\"], replace_old_wcs=False\n", + ")" ] }, { @@ -541,8 +566,8 @@ "metadata": {}, "outputs": [], "source": [ - "fid_frb.update_header(\"all\", \"time\", 0.1) # Update all the fields\n", - "fid_frb.update_header(\"temperature\", \"scale\", \"Rankine\") # Update just one field" + "fid_frb.update_header(\"all\", \"time\", 0.1) # Update all the fields\n", + "fid_frb.update_header(\"temperature\", \"scale\", \"Rankine\") # Update just one field" ] }, { @@ -551,8 +576,8 @@ "metadata": {}, "outputs": [], "source": [ - "print (fid_frb[\"density\"].header[\"time\"])\n", - "print (fid_frb[\"temperature\"].header[\"scale\"])" + "print(fid_frb[\"density\"].header[\"time\"])\n", + "print(fid_frb[\"temperature\"].header[\"scale\"])" ] }, { @@ -576,7 +601,7 @@ "outputs": [], "source": [ "fid_frb.change_image_name(\"density\", \"mass_per_volume\")\n", - "fid_frb.info() # now \"density\" should be gone and \"mass_per_volume\" should be in its place" + "fid_frb.info() # now \"density\" should be gone and \"mass_per_volume\" should be in its place" ] }, { @@ -628,7 +653,7 @@ "metadata": {}, "outputs": [], "source": [ - "slc3 = yt.SlicePlot(ds0, \"z\", (\"gas\", \"density\"), width=(500.,\"kpc\"))\n", + "slc3 = yt.SlicePlot(ds0, \"z\", (\"gas\", \"density\"), width=(500.0, \"kpc\"))\n", "slc3.set_log(\"density\", True)\n", "slc3.show()" ] @@ -639,7 +664,7 @@ "metadata": {}, "outputs": [], "source": [ - "slc4 = yt.SlicePlot(dsc, \"z\", (\"gas\", \"density\"), width=(500.,\"kpc\"))\n", + "slc4 = yt.SlicePlot(dsc, \"z\", (\"gas\", \"density\"), width=(500.0, \"kpc\"))\n", "slc4.set_log(\"density\", True)\n", "slc4.show()" ] diff --git a/doc/source/visualizing/TransferFunctionHelper_Tutorial.ipynb b/doc/source/visualizing/TransferFunctionHelper_Tutorial.ipynb index aa8c09779c0..d15bf6e2d78 100644 --- a/doc/source/visualizing/TransferFunctionHelper_Tutorial.ipynb +++ b/doc/source/visualizing/TransferFunctionHelper_Tutorial.ipynb @@ -20,13 +20,16 @@ "import yt\n", "import numpy as np\n", "from IPython.core.display import Image\n", - "from yt.visualization.volume_rendering.transfer_function_helper import TransferFunctionHelper\n", + "from yt.visualization.volume_rendering.transfer_function_helper import (\n", + " TransferFunctionHelper,\n", + ")\n", "from yt.visualization.volume_rendering.render_source import VolumeSource\n", "\n", + "\n", "def showme(im):\n", " # screen out NaNs\n", " im[im != im] = 0.0\n", - " \n", + "\n", " # Create an RGBA bitmap to display\n", " imb = yt.write_bitmap(im, None)\n", " return Image(imb)" @@ -47,7 +50,7 @@ }, "outputs": [], "source": [ - "ds = yt.load('Enzo_64/DD0043/data0043')" + "ds = yt.load(\"Enzo_64/DD0043/data0043\")" ] }, { @@ -85,7 +88,7 @@ "source": [ "# Build a transfer function that is a multivariate gaussian in temperature\n", "tfh = TransferFunctionHelper(ds)\n", - "tfh.set_field('temperature')\n", + "tfh.set_field(\"temperature\")\n", "tfh.set_log(True)\n", "tfh.set_bounds()\n", "tfh.build_transfer_function()\n", @@ -108,7 +111,7 @@ }, "outputs": [], "source": [ - "tfh.plot(profile_field='mass')" + "tfh.plot(profile_field=\"mass\")" ] }, { @@ -127,15 +130,23 @@ "outputs": [], "source": [ "tfh = TransferFunctionHelper(ds)\n", - "tfh.set_field('temperature')\n", + "tfh.set_field(\"temperature\")\n", "tfh.set_bounds()\n", "tfh.set_log(True)\n", "tfh.build_transfer_function()\n", - "tfh.tf.add_layers(8, w=0.01, mi=4.0, ma=8.0, col_bounds=[4.,8.], alpha=np.logspace(-1,2,7), colormap='RdBu_r')\n", - "tfh.tf.map_to_colormap(6.0, 8.0, colormap='Reds')\n", - "tfh.tf.map_to_colormap(-1.0, 6.0, colormap='Blues_r')\n", + "tfh.tf.add_layers(\n", + " 8,\n", + " w=0.01,\n", + " mi=4.0,\n", + " ma=8.0,\n", + " col_bounds=[4.0, 8.0],\n", + " alpha=np.logspace(-1, 2, 7),\n", + " colormap=\"RdBu_r\",\n", + ")\n", + "tfh.tf.map_to_colormap(6.0, 8.0, colormap=\"Reds\")\n", + "tfh.tf.map_to_colormap(-1.0, 6.0, colormap=\"Blues_r\")\n", "\n", - "tfh.plot(profile_field='mass')" + "tfh.plot(profile_field=\"mass\")" ] }, { @@ -153,13 +164,13 @@ }, "outputs": [], "source": [ - "im, sc = yt.volume_render(ds, ['temperature'])\n", + "im, sc = yt.volume_render(ds, [\"temperature\"])\n", "\n", "source = sc.get_source()\n", "source.set_transfer_function(tfh.tf)\n", "im2 = sc.render()\n", "\n", - "showme(im2[:,:,:3])" + "showme(im2[:, :, :3])" ] }, { @@ -178,15 +189,23 @@ "outputs": [], "source": [ "tfh2 = TransferFunctionHelper(ds)\n", - "tfh2.set_field('temperature')\n", + "tfh2.set_field(\"temperature\")\n", "tfh2.set_bounds()\n", "tfh2.set_log(True)\n", "tfh2.build_transfer_function()\n", - "tfh2.tf.add_layers(8, w=0.01, mi=4.0, ma=8.0, col_bounds=[4.,8.], alpha=np.logspace(-1,2,7), colormap='RdBu_r')\n", - "tfh2.tf.map_to_colormap(6.0, 8.0, colormap='Reds', scale=5.0)\n", - "tfh2.tf.map_to_colormap(-1.0, 6.0, colormap='Blues_r', scale=1.0)\n", + "tfh2.tf.add_layers(\n", + " 8,\n", + " w=0.01,\n", + " mi=4.0,\n", + " ma=8.0,\n", + " col_bounds=[4.0, 8.0],\n", + " alpha=np.logspace(-1, 2, 7),\n", + " colormap=\"RdBu_r\",\n", + ")\n", + "tfh2.tf.map_to_colormap(6.0, 8.0, colormap=\"Reds\", scale=5.0)\n", + "tfh2.tf.map_to_colormap(-1.0, 6.0, colormap=\"Blues_r\", scale=1.0)\n", "\n", - "tfh2.plot(profile_field='mass')" + "tfh2.plot(profile_field=\"mass\")" ] }, { @@ -207,7 +226,7 @@ "source.set_transfer_function(tfh2.tf)\n", "im3 = sc.render()\n", "\n", - "showme(im3[:,:,:3])" + "showme(im3[:, :, :3])" ] }, { diff --git a/doc/source/visualizing/Volume_Rendering_Tutorial.ipynb b/doc/source/visualizing/Volume_Rendering_Tutorial.ipynb index d2a8ffc9df3..5250dc2bfdc 100644 --- a/doc/source/visualizing/Volume_Rendering_Tutorial.ipynb +++ b/doc/source/visualizing/Volume_Rendering_Tutorial.ipynb @@ -34,7 +34,9 @@ "source": [ "import yt\n", "import numpy as np\n", - "from yt.visualization.volume_rendering.transfer_function_helper import TransferFunctionHelper\n", + "from yt.visualization.volume_rendering.transfer_function_helper import (\n", + " TransferFunctionHelper,\n", + ")\n", "from yt.visualization.volume_rendering.api import Scene, VolumeSource\n", "\n", "ds = yt.load(\"IsolatedGalaxy/galaxy0030/galaxy0030\")\n", @@ -56,7 +58,7 @@ "metadata": {}, "outputs": [], "source": [ - "print (sc)" + "print(sc)" ] }, { @@ -72,7 +74,7 @@ "metadata": {}, "outputs": [], "source": [ - "print (sc.get_source())" + "print(sc.get_source())" ] }, { @@ -122,7 +124,7 @@ "metadata": {}, "outputs": [], "source": [ - "print (sc)" + "print(sc)" ] }, { @@ -205,7 +207,7 @@ "metadata": {}, "outputs": [], "source": [ - "sc.camera.zoom(1./3.0)" + "sc.camera.zoom(1.0 / 3.0)" ] }, { @@ -223,15 +225,15 @@ "metadata": {}, "outputs": [], "source": [ - "# Set up a custom transfer function using the TransferFunctionHelper. \n", + "# Set up a custom transfer function using the TransferFunctionHelper.\n", "# We use 10 Gaussians evenly spaced logarithmically between the min and max\n", "# field values.\n", "tfh = TransferFunctionHelper(ds)\n", - "tfh.set_field('density')\n", + "tfh.set_field(\"density\")\n", "tfh.set_log(True)\n", "tfh.set_bounds()\n", "tfh.build_transfer_function()\n", - "tfh.tf.add_layers(10, colormap='gist_rainbow')\n", + "tfh.tf.add_layers(10, colormap=\"gist_rainbow\")\n", "\n", "# Grab the first render source and set it to use the new transfer function\n", "render_source = sc.get_source()\n", @@ -254,21 +256,20 @@ "metadata": {}, "outputs": [], "source": [ - "cam = sc.add_camera(ds, lens_type='perspective')\n", + "cam = sc.add_camera(ds, lens_type=\"perspective\")\n", "\n", "# Standing at (x=0.05, y=0.5, z=0.5), we look at the area of x>0.05 (with some open angle\n", "# specified by camera width) along the positive x direction.\n", - "cam.position = ds.arr([0.05, 0.5, 0.5], 'code_length')\n", + "cam.position = ds.arr([0.05, 0.5, 0.5], \"code_length\")\n", "\n", - "normal_vector = [1., 0., 0.]\n", - "north_vector = [0., 0., 1.]\n", - "cam.switch_orientation(normal_vector=normal_vector,\n", - " north_vector=north_vector)\n", + "normal_vector = [1.0, 0.0, 0.0]\n", + "north_vector = [0.0, 0.0, 1.0]\n", + "cam.switch_orientation(normal_vector=normal_vector, north_vector=north_vector)\n", "\n", "# The width determines the opening angle\n", "cam.set_width(ds.domain_width * 0.5)\n", "\n", - "print (sc.camera)" + "print(sc.camera)" ] }, { @@ -303,7 +304,7 @@ "metadata": {}, "outputs": [], "source": [ - "sc.save('volume_render.png',render=False)" + "sc.save(\"volume_render.png\", render=False)" ] }, { @@ -321,7 +322,7 @@ "metadata": {}, "outputs": [], "source": [ - "sc.save('volume_render_clip4.png',sigma_clip=4.0,render=False)" + "sc.save(\"volume_render_clip4.png\", sigma_clip=4.0, render=False)" ] }, { @@ -340,7 +341,7 @@ "outputs": [], "source": [ "# set the lens type back to plane-parallel\n", - "sc.camera.set_lens('plane-parallel')\n", + "sc.camera.set_lens(\"plane-parallel\")\n", "\n", "# move the camera to the left edge of the domain\n", "sc.camera.set_position(ds.domain_left_edge)\n",