diff --git a/notebooks/chapter_1_introduction/tutorial_0_visualization.ipynb b/notebooks/chapter_1_introduction/tutorial_0_visualization.ipynb index a1f4ecd..6f5c37a 100644 --- a/notebooks/chapter_1_introduction/tutorial_0_visualization.ipynb +++ b/notebooks/chapter_1_introduction/tutorial_0_visualization.ipynb @@ -153,15 +153,9 @@ "cell_type": "code", "metadata": {}, "source": [ - "if al.util.dataset.should_simulate(str(dataset_path)):\n", - " import subprocess\n", - " import sys\n", - "\n", - " # Use the same Python interpreter as this tutorial.\n", - " subprocess.run(\n", - " [sys.executable, \"scripts/simulator/no_lens_light.py\"],\n", - " check=True,\n", - " )" + "al.util.dataset.simulate_if_needed(\n", + " dataset_path, simulator=\"scripts/simulator/no_lens_light.py\"\n", + ")" ], "outputs": [], "execution_count": null diff --git a/notebooks/chapter_1_introduction/tutorial_5_data.ipynb b/notebooks/chapter_1_introduction/tutorial_5_data.ipynb index 23bd35b..306aea9 100644 --- a/notebooks/chapter_1_introduction/tutorial_5_data.ipynb +++ b/notebooks/chapter_1_introduction/tutorial_5_data.ipynb @@ -883,14 +883,9 @@ "source": [ "dataset_path = Path(\"dataset\") / \"interferometer\" / \"simple\"\n", "\n", - "if al.util.dataset.should_simulate(str(dataset_path)):\n", - " import subprocess\n", - " import sys\n", - "\n", - " subprocess.run(\n", - " [sys.executable, \"scripts/simulator/interferometer.py\"],\n", - " check=True,\n", - " )\n", + "al.util.dataset.simulate_if_needed(\n", + " dataset_path, simulator=\"scripts/simulator/interferometer.py\"\n", + ")\n", "\n", "real_space_mask = al.Mask2D.circular(\n", " shape_native=(100, 100),\n", @@ -956,14 +951,9 @@ "source": [ "dataset_path = Path(\"dataset\") / \"weak_lensing\" / \"simple\"\n", "\n", - "if al.util.dataset.should_simulate(str(dataset_path)):\n", - " import subprocess\n", - " import sys\n", - "\n", - " subprocess.run(\n", - " [sys.executable, \"scripts/simulator/weak_lensing.py\"],\n", - " check=True,\n", - " )\n", + "al.util.dataset.simulate_if_needed(\n", + " dataset_path, simulator=\"scripts/simulator/weak_lensing.py\"\n", + ")\n", "\n", "dataset = al.from_json(file_path=dataset_path / \"dataset.json\")\n", "\n", @@ -1011,14 +1001,9 @@ "source": [ "group_dataset_path = Path(\"dataset\") / \"group\" / \"simple\"\n", "\n", - "if al.util.dataset.should_simulate(str(group_dataset_path)):\n", - " import subprocess\n", - " import sys\n", - "\n", - " subprocess.run(\n", - " [sys.executable, \"scripts/simulator/group.py\"],\n", - " check=True,\n", - " )\n", + "al.util.dataset.simulate_if_needed(\n", + " group_dataset_path, simulator=\"scripts/simulator/group.py\"\n", + ")\n", "\n", "group_dataset = al.Imaging.from_fits(\n", " data_path=group_dataset_path / \"data.fits\",\n", diff --git a/notebooks/chapter_1_introduction/tutorial_6_fitting.ipynb b/notebooks/chapter_1_introduction/tutorial_6_fitting.ipynb index 6564ed2..7b5c1f6 100644 --- a/notebooks/chapter_1_introduction/tutorial_6_fitting.ipynb +++ b/notebooks/chapter_1_introduction/tutorial_6_fitting.ipynb @@ -134,14 +134,9 @@ "cell_type": "code", "metadata": {}, "source": [ - "if al.util.dataset.should_simulate(str(dataset_path)):\n", - " import subprocess\n", - " import sys\n", - "\n", - " subprocess.run(\n", - " [sys.executable, \"scripts/chapter_1_introduction/tutorial_5_data.py\"],\n", - " check=True,\n", - " )\n", + "al.util.dataset.simulate_if_needed(\n", + " dataset_path, simulator=\"scripts/chapter_1_introduction/tutorial_5_data.py\"\n", + ")\n", "\n", "dataset = al.Imaging.from_fits(\n", " data_path=dataset_path / \"data.fits\",\n", @@ -1094,14 +1089,9 @@ "dataset_name = \"simple__no_lens_light__mass_sis\"\n", "dataset_path = Path(\"dataset\") / \"imaging\" / dataset_name\n", "\n", - "if al.util.dataset.should_simulate(str(dataset_path)):\n", - " import subprocess\n", - " import sys\n", - "\n", - " subprocess.run(\n", - " [sys.executable, \"scripts/simulator/no_lens_light__mass_sis.py\"],\n", - " check=True,\n", - " )\n", + "al.util.dataset.simulate_if_needed(\n", + " dataset_path, simulator=\"scripts/simulator/no_lens_light__mass_sis.py\"\n", + ")\n", "\n", "dataset = al.Imaging.from_fits(\n", " data_path=dataset_path / \"data.fits\",\n", diff --git a/notebooks/chapter_2_lens_modeling/tutorial_10_prior_passing.ipynb b/notebooks/chapter_2_lens_modeling/tutorial_10_prior_passing.ipynb index 90f204a..3d5dc13 100644 --- a/notebooks/chapter_2_lens_modeling/tutorial_10_prior_passing.ipynb +++ b/notebooks/chapter_2_lens_modeling/tutorial_10_prior_passing.ipynb @@ -124,14 +124,9 @@ "cell_type": "code", "metadata": {}, "source": [ - "if al.util.dataset.should_simulate(str(dataset_path)):\n", - " import subprocess\n", - " import sys\n", - "\n", - " subprocess.run(\n", - " [sys.executable, \"scripts/simulator/lens_sersic.py\"],\n", - " check=True,\n", - " )\n", + "al.util.dataset.simulate_if_needed(\n", + " dataset_path, simulator=\"scripts/simulator/lens_sersic.py\"\n", + ")\n", "\n", "dataset = al.Imaging.from_fits(\n", " data_path=dataset_path / \"data.fits\",\n", diff --git a/notebooks/chapter_2_lens_modeling/tutorial_1_non_linear_search.ipynb b/notebooks/chapter_2_lens_modeling/tutorial_1_non_linear_search.ipynb index 1b030e1..f74112f 100644 --- a/notebooks/chapter_2_lens_modeling/tutorial_1_non_linear_search.ipynb +++ b/notebooks/chapter_2_lens_modeling/tutorial_1_non_linear_search.ipynb @@ -246,11 +246,9 @@ "metadata": {}, "source": [ "\n", - "if al.util.dataset.should_simulate(str(dataset_path)):\n", - " import subprocess\n", - " import sys\n", - "\n", - " subprocess.run([sys.executable, \"scripts/simulator/no_lens_light__mass_sis.py\"], check=True)\n", + "al.util.dataset.simulate_if_needed(\n", + " dataset_path, simulator=\"scripts/simulator/no_lens_light__mass_sis.py\"\n", + ")\n", "\n", "dataset = al.Imaging.from_fits(\n", " data_path=dataset_path / \"data.fits\",\n", diff --git a/notebooks/chapter_2_lens_modeling/tutorial_2_practicalities.ipynb b/notebooks/chapter_2_lens_modeling/tutorial_2_practicalities.ipynb index b644ca4..5b61c86 100644 --- a/notebooks/chapter_2_lens_modeling/tutorial_2_practicalities.ipynb +++ b/notebooks/chapter_2_lens_modeling/tutorial_2_practicalities.ipynb @@ -117,11 +117,9 @@ "dataset_name = \"lens_sersic\"\n", "dataset_path = Path(\"dataset\") / \"imaging\" / dataset_name\n", "\n", - "if al.util.dataset.should_simulate(str(dataset_path)):\n", - " import subprocess\n", - " import sys\n", - "\n", - " subprocess.run([sys.executable, \"scripts/simulator/lens_sersic.py\"], check=True)\n", + "al.util.dataset.simulate_if_needed(\n", + " dataset_path, simulator=\"scripts/simulator/lens_sersic.py\"\n", + ")\n", "\n", "dataset = al.Imaging.from_fits(\n", " data_path=dataset_path / \"data.fits\",\n", diff --git a/notebooks/chapter_2_lens_modeling/tutorial_3_why_modeling_is_hard.ipynb b/notebooks/chapter_2_lens_modeling/tutorial_3_why_modeling_is_hard.ipynb index a259117..9709780 100644 --- a/notebooks/chapter_2_lens_modeling/tutorial_3_why_modeling_is_hard.ipynb +++ b/notebooks/chapter_2_lens_modeling/tutorial_3_why_modeling_is_hard.ipynb @@ -142,11 +142,9 @@ "dataset_name = \"lens_sersic\"\n", "dataset_path = Path(\"dataset\") / \"imaging\" / dataset_name\n", "\n", - "if al.util.dataset.should_simulate(str(dataset_path)):\n", - " import subprocess\n", - " import sys\n", - "\n", - " subprocess.run([sys.executable, \"scripts/simulator/lens_sersic.py\"], check=True)\n", + "al.util.dataset.simulate_if_needed(\n", + " dataset_path, simulator=\"scripts/simulator/lens_sersic.py\"\n", + ")\n", "\n", "dataset = al.Imaging.from_fits(\n", " data_path=dataset_path / \"data.fits\",\n", diff --git a/notebooks/chapter_2_lens_modeling/tutorial_4_linear_profiles.ipynb b/notebooks/chapter_2_lens_modeling/tutorial_4_linear_profiles.ipynb index 7b2464f..71171c6 100644 --- a/notebooks/chapter_2_lens_modeling/tutorial_4_linear_profiles.ipynb +++ b/notebooks/chapter_2_lens_modeling/tutorial_4_linear_profiles.ipynb @@ -135,11 +135,9 @@ "dataset_name = \"lens_sersic\"\n", "dataset_path = Path(\"dataset\") / \"imaging\" / dataset_name\n", "\n", - "if al.util.dataset.should_simulate(str(dataset_path)):\n", - " import subprocess\n", - " import sys\n", - "\n", - " subprocess.run([sys.executable, \"scripts/simulator/lens_sersic.py\"], check=True)\n", + "al.util.dataset.simulate_if_needed(\n", + " dataset_path, simulator=\"scripts/simulator/lens_sersic.py\"\n", + ")\n", "\n", "dataset = al.Imaging.from_fits(\n", " data_path=dataset_path / \"data.fits\",\n", diff --git a/notebooks/chapter_2_lens_modeling/tutorial_6_masking_and_positions.ipynb b/notebooks/chapter_2_lens_modeling/tutorial_6_masking_and_positions.ipynb index 0cda41e..4fb896a 100644 --- a/notebooks/chapter_2_lens_modeling/tutorial_6_masking_and_positions.ipynb +++ b/notebooks/chapter_2_lens_modeling/tutorial_6_masking_and_positions.ipynb @@ -115,14 +115,9 @@ "cell_type": "code", "metadata": {}, "source": [ - "if al.util.dataset.should_simulate(str(dataset_path)):\n", - " import subprocess\n", - " import sys\n", - "\n", - " subprocess.run(\n", - " [sys.executable, \"scripts/simulator/no_lens_light__mass_sis.py\"],\n", - " check=True,\n", - " )\n", + "al.util.dataset.simulate_if_needed(\n", + " dataset_path, simulator=\"scripts/simulator/no_lens_light__mass_sis.py\"\n", + ")\n", "\n", "dataset = al.Imaging.from_fits(\n", " data_path=dataset_path / \"data.fits\",\n", diff --git a/notebooks/chapter_2_lens_modeling/tutorial_7_results.ipynb b/notebooks/chapter_2_lens_modeling/tutorial_7_results.ipynb index 52e0a4d..17fd2b3 100644 --- a/notebooks/chapter_2_lens_modeling/tutorial_7_results.ipynb +++ b/notebooks/chapter_2_lens_modeling/tutorial_7_results.ipynb @@ -109,14 +109,9 @@ "cell_type": "code", "metadata": {}, "source": [ - "if al.util.dataset.should_simulate(str(dataset_path)):\n", - " import subprocess\n", - " import sys\n", - "\n", - " subprocess.run(\n", - " [sys.executable, \"scripts/simulator/no_lens_light__mass_sis.py\"],\n", - " check=True,\n", - " )\n", + "al.util.dataset.simulate_if_needed(\n", + " dataset_path, simulator=\"scripts/simulator/no_lens_light__mass_sis.py\"\n", + ")\n", "\n", "dataset = al.Imaging.from_fits(\n", " data_path=dataset_path / \"data.fits\",\n", diff --git a/notebooks/chapter_2_lens_modeling/tutorial_9_search_chaining.ipynb b/notebooks/chapter_2_lens_modeling/tutorial_9_search_chaining.ipynb index a17e42e..a860cd3 100644 --- a/notebooks/chapter_2_lens_modeling/tutorial_9_search_chaining.ipynb +++ b/notebooks/chapter_2_lens_modeling/tutorial_9_search_chaining.ipynb @@ -153,14 +153,9 @@ "cell_type": "code", "metadata": {}, "source": [ - "if al.util.dataset.should_simulate(str(dataset_path)):\n", - " import subprocess\n", - " import sys\n", - "\n", - " subprocess.run(\n", - " [sys.executable, \"scripts/simulator/lens_sersic.py\"],\n", - " check=True,\n", - " )\n", + "al.util.dataset.simulate_if_needed(\n", + " dataset_path, simulator=\"scripts/simulator/lens_sersic.py\"\n", + ")\n", "\n", "dataset = al.Imaging.from_fits(\n", " data_path=dataset_path / \"data.fits\",\n", diff --git a/notebooks/chapter_3_pixelizations/tutorial_11_brightness_adaption.ipynb b/notebooks/chapter_3_pixelizations/tutorial_11_brightness_adaption.ipynb index e832b37..9d913c3 100644 --- a/notebooks/chapter_3_pixelizations/tutorial_11_brightness_adaption.ipynb +++ b/notebooks/chapter_3_pixelizations/tutorial_11_brightness_adaption.ipynb @@ -132,14 +132,9 @@ "cell_type": "code", "metadata": {}, "source": [ - "if al.util.dataset.should_simulate(str(dataset_path)):\n", - " import subprocess\n", - " import sys\n", - "\n", - " subprocess.run(\n", - " [sys.executable, \"scripts/simulator/no_lens_light.py\"],\n", - " check=True,\n", - " )\n", + "al.util.dataset.simulate_if_needed(\n", + " dataset_path, simulator=\"scripts/simulator/no_lens_light.py\"\n", + ")\n", "\n", "dataset = al.Imaging.from_fits(\n", " data_path=dataset_path / \"data.fits\",\n", diff --git a/notebooks/chapter_3_pixelizations/tutorial_12_adaptive_regularization.ipynb b/notebooks/chapter_3_pixelizations/tutorial_12_adaptive_regularization.ipynb index 1f88f0d..6fa4b3b 100644 --- a/notebooks/chapter_3_pixelizations/tutorial_12_adaptive_regularization.ipynb +++ b/notebooks/chapter_3_pixelizations/tutorial_12_adaptive_regularization.ipynb @@ -113,14 +113,9 @@ "cell_type": "code", "metadata": {}, "source": [ - "if al.util.dataset.should_simulate(str(dataset_path)):\n", - " import subprocess\n", - " import sys\n", - "\n", - " subprocess.run(\n", - " [sys.executable, \"scripts/simulator/no_lens_light.py\"],\n", - " check=True,\n", - " )\n", + "al.util.dataset.simulate_if_needed(\n", + " dataset_path, simulator=\"scripts/simulator/no_lens_light.py\"\n", + ")\n", "\n", "dataset = al.Imaging.from_fits(\n", " data_path=dataset_path / \"data.fits\",\n", diff --git a/notebooks/chapter_3_pixelizations/tutorial_1_pixelizations.ipynb b/notebooks/chapter_3_pixelizations/tutorial_1_pixelizations.ipynb index 03b292f..fb2413d 100644 --- a/notebooks/chapter_3_pixelizations/tutorial_1_pixelizations.ipynb +++ b/notebooks/chapter_3_pixelizations/tutorial_1_pixelizations.ipynb @@ -114,11 +114,9 @@ "\n", "dataset_path = Path(\"dataset\") / \"imaging\" / \"source_complex\"\n", "\n", - "if al.util.dataset.should_simulate(str(dataset_path)):\n", - " subprocess.run(\n", - " [sys.executable, \"scripts/simulator/source_complex.py\"],\n", - " check=True,\n", - " )\n", + "al.util.dataset.simulate_if_needed(\n", + " dataset_path, simulator=\"scripts/simulator/source_complex.py\"\n", + ")\n", "\n", "dataset = al.Imaging.from_fits(\n", " data_path=dataset_path / \"data.fits\",\n", diff --git a/notebooks/chapter_3_pixelizations/tutorial_2_bayesian_regularization.ipynb b/notebooks/chapter_3_pixelizations/tutorial_2_bayesian_regularization.ipynb index c22c51b..97be03e 100644 --- a/notebooks/chapter_3_pixelizations/tutorial_2_bayesian_regularization.ipynb +++ b/notebooks/chapter_3_pixelizations/tutorial_2_bayesian_regularization.ipynb @@ -98,11 +98,9 @@ "\n", "dataset_path = Path(\"dataset\") / \"imaging\" / \"source_complex\"\n", "\n", - "if al.util.dataset.should_simulate(str(dataset_path)):\n", - " subprocess.run(\n", - " [sys.executable, \"scripts/simulator/source_complex.py\"],\n", - " check=True,\n", - " )\n", + "al.util.dataset.simulate_if_needed(\n", + " dataset_path, simulator=\"scripts/simulator/source_complex.py\"\n", + ")\n", "\n", "dataset = al.Imaging.from_fits(\n", " data_path=dataset_path / \"data.fits\",\n", diff --git a/notebooks/chapter_3_pixelizations/tutorial_3_borders.ipynb b/notebooks/chapter_3_pixelizations/tutorial_3_borders.ipynb index f7fd667..75d43ed 100644 --- a/notebooks/chapter_3_pixelizations/tutorial_3_borders.ipynb +++ b/notebooks/chapter_3_pixelizations/tutorial_3_borders.ipynb @@ -92,11 +92,9 @@ "\n", "dataset_path = Path(\"dataset\") / \"imaging\" / \"simple__no_lens_light\"\n", "\n", - "if al.util.dataset.should_simulate(str(dataset_path)):\n", - " subprocess.run(\n", - " [sys.executable, \"scripts/simulator/no_lens_light.py\"],\n", - " check=True,\n", - " )\n", + "al.util.dataset.simulate_if_needed(\n", + " dataset_path, simulator=\"scripts/simulator/no_lens_light.py\"\n", + ")\n", "\n", "dataset_unmasked = al.Imaging.from_fits(\n", " data_path=dataset_path / \"data.fits\",\n", diff --git a/notebooks/chapter_3_pixelizations/tutorial_4_lens_modeling.ipynb b/notebooks/chapter_3_pixelizations/tutorial_4_lens_modeling.ipynb index 70cd985..755a810 100644 --- a/notebooks/chapter_3_pixelizations/tutorial_4_lens_modeling.ipynb +++ b/notebooks/chapter_3_pixelizations/tutorial_4_lens_modeling.ipynb @@ -103,11 +103,9 @@ "\n", "dataset_path = Path(\"dataset\") / \"imaging\" / \"simple__no_lens_light\"\n", "\n", - "if al.util.dataset.should_simulate(str(dataset_path)):\n", - " subprocess.run(\n", - " [sys.executable, \"scripts/simulator/no_lens_light.py\"],\n", - " check=True,\n", - " )\n", + "al.util.dataset.simulate_if_needed(\n", + " dataset_path, simulator=\"scripts/simulator/no_lens_light.py\"\n", + ")\n", "\n", "dataset = al.Imaging.from_fits(\n", " data_path=dataset_path / \"data.fits\",\n", @@ -786,11 +784,9 @@ "\n", "foreground_dataset_path = Path(\"dataset\") / \"imaging\" / \"lens_sersic\"\n", "\n", - "if al.util.dataset.should_simulate(str(foreground_dataset_path)):\n", - " subprocess.run(\n", - " [sys.executable, \"scripts/simulator/lens_sersic.py\"],\n", - " check=True,\n", - " )\n", + "al.util.dataset.simulate_if_needed(\n", + " foreground_dataset_path, simulator=\"scripts/simulator/lens_sersic.py\"\n", + ")\n", "\n", "foreground_dataset = al.Imaging.from_fits(\n", " data_path=foreground_dataset_path / \"data.fits\",\n", diff --git a/notebooks/chapter_3_pixelizations/tutorial_8_adaptive_pixelization.ipynb b/notebooks/chapter_3_pixelizations/tutorial_8_adaptive_pixelization.ipynb index 26ef768..0327b82 100644 --- a/notebooks/chapter_3_pixelizations/tutorial_8_adaptive_pixelization.ipynb +++ b/notebooks/chapter_3_pixelizations/tutorial_8_adaptive_pixelization.ipynb @@ -124,14 +124,9 @@ "cell_type": "code", "metadata": {}, "source": [ - "if al.util.dataset.should_simulate(str(dataset_path)):\n", - " import subprocess\n", - " import sys\n", - "\n", - " subprocess.run(\n", - " [sys.executable, \"scripts/simulator/no_lens_light.py\"],\n", - " check=True,\n", - " )\n", + "al.util.dataset.simulate_if_needed(\n", + " dataset_path, simulator=\"scripts/simulator/no_lens_light.py\"\n", + ")\n", "\n", "dataset = al.Imaging.from_fits(\n", " data_path=dataset_path / \"data.fits\",\n", diff --git a/notebooks/chapter_4_scaling_up_lensing/tutorial_1_extra_galaxies.ipynb b/notebooks/chapter_4_scaling_up_lensing/tutorial_1_extra_galaxies.ipynb index 46b0203..58c7144 100644 --- a/notebooks/chapter_4_scaling_up_lensing/tutorial_1_extra_galaxies.ipynb +++ b/notebooks/chapter_4_scaling_up_lensing/tutorial_1_extra_galaxies.ipynb @@ -153,14 +153,9 @@ "cell_type": "code", "metadata": {}, "source": [ - "if al.util.dataset.should_simulate(str(dataset_path)):\n", - " import subprocess\n", - " import sys\n", - "\n", - " subprocess.run(\n", - " [sys.executable, \"scripts/simulator/lens_extra_galaxy.py\"],\n", - " check=True,\n", - " )\n", + "al.util.dataset.simulate_if_needed(\n", + " dataset_path, simulator=\"scripts/simulator/lens_extra_galaxy.py\"\n", + ")\n", "\n", "dataset = al.Imaging.from_fits(\n", " data_path=dataset_path / \"data.fits\",\n", diff --git a/notebooks/chapter_4_scaling_up_lensing/tutorial_2_multi_galaxy.ipynb b/notebooks/chapter_4_scaling_up_lensing/tutorial_2_multi_galaxy.ipynb index 09320f8..ee3b92a 100644 --- a/notebooks/chapter_4_scaling_up_lensing/tutorial_2_multi_galaxy.ipynb +++ b/notebooks/chapter_4_scaling_up_lensing/tutorial_2_multi_galaxy.ipynb @@ -130,14 +130,9 @@ "dataset_name = \"x2_lens_galaxies\"\n", "dataset_path = Path(\"dataset\") / \"imaging\" / dataset_name\n", "\n", - "if al.util.dataset.should_simulate(str(dataset_path)):\n", - " import subprocess\n", - " import sys\n", - "\n", - " subprocess.run(\n", - " [sys.executable, \"scripts/simulator/lens_x2.py\"],\n", - " check=True,\n", - " )\n", + "al.util.dataset.simulate_if_needed(\n", + " dataset_path, simulator=\"scripts/simulator/lens_x2.py\"\n", + ")\n", "\n", "dataset = al.Imaging.from_fits(\n", " data_path=dataset_path / \"data.fits\",\n", @@ -601,14 +596,9 @@ "dataset_name = \"x3_lens_galaxies\"\n", "dataset_path = Path(\"dataset\") / \"imaging\" / dataset_name\n", "\n", - "if al.util.dataset.should_simulate(str(dataset_path)):\n", - " import subprocess\n", - " import sys\n", - "\n", - " subprocess.run(\n", - " [sys.executable, \"scripts/simulator/lens_x3.py\"],\n", - " check=True,\n", - " )\n", + "al.util.dataset.simulate_if_needed(\n", + " dataset_path, simulator=\"scripts/simulator/lens_x3.py\"\n", + ")\n", "\n", "dataset = al.Imaging.from_fits(\n", " data_path=dataset_path / \"data.fits\",\n", diff --git a/notebooks/chapter_4_scaling_up_lensing/tutorial_3_scaling_relation.ipynb b/notebooks/chapter_4_scaling_up_lensing/tutorial_3_scaling_relation.ipynb index e8dbca9..d65f706 100644 --- a/notebooks/chapter_4_scaling_up_lensing/tutorial_3_scaling_relation.ipynb +++ b/notebooks/chapter_4_scaling_up_lensing/tutorial_3_scaling_relation.ipynb @@ -198,14 +198,9 @@ "cell_type": "code", "metadata": {}, "source": [ - "if al.util.dataset.should_simulate(str(dataset_path)):\n", - " import subprocess\n", - " import sys\n", - "\n", - " subprocess.run(\n", - " [sys.executable, \"scripts/simulator/lens_x2.py\"],\n", - " check=True,\n", - " )\n", + "al.util.dataset.simulate_if_needed(\n", + " dataset_path, simulator=\"scripts/simulator/lens_x2.py\"\n", + ")\n", "\n", "dataset = al.Imaging.from_fits(\n", " data_path=dataset_path / \"data.fits\",\n", diff --git a/notebooks/chapter_4_scaling_up_lensing/tutorial_4_group_scale.ipynb b/notebooks/chapter_4_scaling_up_lensing/tutorial_4_group_scale.ipynb index 3d463c4..74adc2c 100644 --- a/notebooks/chapter_4_scaling_up_lensing/tutorial_4_group_scale.ipynb +++ b/notebooks/chapter_4_scaling_up_lensing/tutorial_4_group_scale.ipynb @@ -165,14 +165,7 @@ "cell_type": "code", "metadata": {}, "source": [ - "if al.util.dataset.should_simulate(str(dataset_path)):\n", - " import subprocess\n", - " import sys\n", - "\n", - " subprocess.run(\n", - " [sys.executable, \"scripts/simulator/group.py\"],\n", - " check=True,\n", - " )\n", + "al.util.dataset.simulate_if_needed(dataset_path, simulator=\"scripts/simulator/group.py\")\n", "\n", "dataset = al.Imaging.from_fits(\n", " data_path=dataset_path / \"data.fits\",\n", diff --git a/notebooks/chapter_4_scaling_up_lensing/tutorial_5_cluster_scale.ipynb b/notebooks/chapter_4_scaling_up_lensing/tutorial_5_cluster_scale.ipynb index 3403eae..9b10972 100644 --- a/notebooks/chapter_4_scaling_up_lensing/tutorial_5_cluster_scale.ipynb +++ b/notebooks/chapter_4_scaling_up_lensing/tutorial_5_cluster_scale.ipynb @@ -195,14 +195,9 @@ "cell_type": "code", "metadata": {}, "source": [ - "if al.util.dataset.should_simulate(str(dataset_path)):\n", - " import subprocess\n", - " import sys\n", - "\n", - " subprocess.run(\n", - " [sys.executable, \"scripts/simulator/cluster.py\"],\n", - " check=True,\n", - " )" + "al.util.dataset.simulate_if_needed(\n", + " dataset_path, simulator=\"scripts/simulator/cluster.py\"\n", + ")" ], "outputs": [], "execution_count": null diff --git a/notebooks/chapter_optional/tutorial_searches.ipynb b/notebooks/chapter_optional/tutorial_searches.ipynb index 8f96184..0298c0a 100644 --- a/notebooks/chapter_optional/tutorial_searches.ipynb +++ b/notebooks/chapter_optional/tutorial_searches.ipynb @@ -110,14 +110,9 @@ "cell_type": "code", "metadata": {}, "source": [ - "if al.util.dataset.should_simulate(str(dataset_path)):\n", - " import subprocess\n", - " import sys\n", - "\n", - " subprocess.run(\n", - " [sys.executable, \"scripts/simulator/lens_sersic.py\"],\n", - " check=True,\n", - " )\n", + "al.util.dataset.simulate_if_needed(\n", + " dataset_path, simulator=\"scripts/simulator/lens_sersic.py\"\n", + ")\n", "\n", "dataset = al.Imaging.from_fits(\n", " data_path=dataset_path / \"data.fits\",\n", diff --git a/scripts/chapter_1_introduction/tutorial_0_visualization.py b/scripts/chapter_1_introduction/tutorial_0_visualization.py index 12ae756..d3ce9dd 100644 --- a/scripts/chapter_1_introduction/tutorial_0_visualization.py +++ b/scripts/chapter_1_introduction/tutorial_0_visualization.py @@ -62,15 +62,9 @@ The next cell runs the simulator if the example dataset needs to be generated. You do not need to run the simulator separately. """ -if al.util.dataset.should_simulate(str(dataset_path)): - import subprocess - import sys - - # Use the same Python interpreter as this tutorial. - subprocess.run( - [sys.executable, "scripts/simulator/no_lens_light.py"], - check=True, - ) +al.util.dataset.simulate_if_needed( + dataset_path, simulator="scripts/simulator/no_lens_light.py" +) """ We now load three FITS files into an `Imaging` object: the image, its noise map and the point-spread function diff --git a/scripts/chapter_1_introduction/tutorial_5_data.py b/scripts/chapter_1_introduction/tutorial_5_data.py index 55d81e1..4ad21eb 100644 --- a/scripts/chapter_1_introduction/tutorial_5_data.py +++ b/scripts/chapter_1_introduction/tutorial_5_data.py @@ -563,14 +563,9 @@ """ dataset_path = Path("dataset") / "interferometer" / "simple" -if al.util.dataset.should_simulate(str(dataset_path)): - import subprocess - import sys - - subprocess.run( - [sys.executable, "scripts/simulator/interferometer.py"], - check=True, - ) +al.util.dataset.simulate_if_needed( + dataset_path, simulator="scripts/simulator/interferometer.py" +) real_space_mask = al.Mask2D.circular( shape_native=(100, 100), @@ -622,14 +617,9 @@ """ dataset_path = Path("dataset") / "weak_lensing" / "simple" -if al.util.dataset.should_simulate(str(dataset_path)): - import subprocess - import sys - - subprocess.run( - [sys.executable, "scripts/simulator/weak_lensing.py"], - check=True, - ) +al.util.dataset.simulate_if_needed( + dataset_path, simulator="scripts/simulator/weak_lensing.py" +) dataset = al.from_json(file_path=dataset_path / "dataset.json") @@ -663,14 +653,9 @@ """ group_dataset_path = Path("dataset") / "group" / "simple" -if al.util.dataset.should_simulate(str(group_dataset_path)): - import subprocess - import sys - - subprocess.run( - [sys.executable, "scripts/simulator/group.py"], - check=True, - ) +al.util.dataset.simulate_if_needed( + group_dataset_path, simulator="scripts/simulator/group.py" +) group_dataset = al.Imaging.from_fits( data_path=group_dataset_path / "data.fits", diff --git a/scripts/chapter_1_introduction/tutorial_6_fitting.py b/scripts/chapter_1_introduction/tutorial_6_fitting.py index 6f57aed..3d7f344 100644 --- a/scripts/chapter_1_introduction/tutorial_6_fitting.py +++ b/scripts/chapter_1_introduction/tutorial_6_fitting.py @@ -64,14 +64,9 @@ The pixel scale is 0.1 arcseconds, matching the simulation. """ -if al.util.dataset.should_simulate(str(dataset_path)): - import subprocess - import sys - - subprocess.run( - [sys.executable, "scripts/chapter_1_introduction/tutorial_5_data.py"], - check=True, - ) +al.util.dataset.simulate_if_needed( + dataset_path, simulator="scripts/chapter_1_introduction/tutorial_5_data.py" +) dataset = al.Imaging.from_fits( data_path=dataset_path / "data.fits", @@ -688,14 +683,9 @@ dataset_name = "simple__no_lens_light__mass_sis" dataset_path = Path("dataset") / "imaging" / dataset_name -if al.util.dataset.should_simulate(str(dataset_path)): - import subprocess - import sys - - subprocess.run( - [sys.executable, "scripts/simulator/no_lens_light__mass_sis.py"], - check=True, - ) +al.util.dataset.simulate_if_needed( + dataset_path, simulator="scripts/simulator/no_lens_light__mass_sis.py" +) dataset = al.Imaging.from_fits( data_path=dataset_path / "data.fits", diff --git a/scripts/chapter_2_lens_modeling/tutorial_10_prior_passing.py b/scripts/chapter_2_lens_modeling/tutorial_10_prior_passing.py index 2f8c78f..43f4b74 100644 --- a/scripts/chapter_2_lens_modeling/tutorial_10_prior_passing.py +++ b/scripts/chapter_2_lens_modeling/tutorial_10_prior_passing.py @@ -55,14 +55,9 @@ If the dataset does not already exist on your system, it will be created by running the corresponding simulator script. This ensures that all example scripts can be run without manually simulating data first. """ -if al.util.dataset.should_simulate(str(dataset_path)): - import subprocess - import sys - - subprocess.run( - [sys.executable, "scripts/simulator/lens_sersic.py"], - check=True, - ) +al.util.dataset.simulate_if_needed( + dataset_path, simulator="scripts/simulator/lens_sersic.py" +) dataset = al.Imaging.from_fits( data_path=dataset_path / "data.fits", diff --git a/scripts/chapter_2_lens_modeling/tutorial_1_non_linear_search.py b/scripts/chapter_2_lens_modeling/tutorial_1_non_linear_search.py index 0dbcd6d..faaf01d 100644 --- a/scripts/chapter_2_lens_modeling/tutorial_1_non_linear_search.py +++ b/scripts/chapter_2_lens_modeling/tutorial_1_non_linear_search.py @@ -154,11 +154,9 @@ object will use later. """ -if al.util.dataset.should_simulate(str(dataset_path)): - import subprocess - import sys - - subprocess.run([sys.executable, "scripts/simulator/no_lens_light__mass_sis.py"], check=True) +al.util.dataset.simulate_if_needed( + dataset_path, simulator="scripts/simulator/no_lens_light__mass_sis.py" +) dataset = al.Imaging.from_fits( data_path=dataset_path / "data.fits", diff --git a/scripts/chapter_2_lens_modeling/tutorial_2_practicalities.py b/scripts/chapter_2_lens_modeling/tutorial_2_practicalities.py index 54166b7..0dcd6f2 100755 --- a/scripts/chapter_2_lens_modeling/tutorial_2_practicalities.py +++ b/scripts/chapter_2_lens_modeling/tutorial_2_practicalities.py @@ -67,11 +67,9 @@ dataset_name = "lens_sersic" dataset_path = Path("dataset") / "imaging" / dataset_name -if al.util.dataset.should_simulate(str(dataset_path)): - import subprocess - import sys - - subprocess.run([sys.executable, "scripts/simulator/lens_sersic.py"], check=True) +al.util.dataset.simulate_if_needed( + dataset_path, simulator="scripts/simulator/lens_sersic.py" +) dataset = al.Imaging.from_fits( data_path=dataset_path / "data.fits", diff --git a/scripts/chapter_2_lens_modeling/tutorial_3_why_modeling_is_hard.py b/scripts/chapter_2_lens_modeling/tutorial_3_why_modeling_is_hard.py index f74b7c3..c963277 100644 --- a/scripts/chapter_2_lens_modeling/tutorial_3_why_modeling_is_hard.py +++ b/scripts/chapter_2_lens_modeling/tutorial_3_why_modeling_is_hard.py @@ -89,11 +89,9 @@ dataset_name = "lens_sersic" dataset_path = Path("dataset") / "imaging" / dataset_name -if al.util.dataset.should_simulate(str(dataset_path)): - import subprocess - import sys - - subprocess.run([sys.executable, "scripts/simulator/lens_sersic.py"], check=True) +al.util.dataset.simulate_if_needed( + dataset_path, simulator="scripts/simulator/lens_sersic.py" +) dataset = al.Imaging.from_fits( data_path=dataset_path / "data.fits", diff --git a/scripts/chapter_2_lens_modeling/tutorial_4_linear_profiles.py b/scripts/chapter_2_lens_modeling/tutorial_4_linear_profiles.py index 1c7619b..2520b8a 100644 --- a/scripts/chapter_2_lens_modeling/tutorial_4_linear_profiles.py +++ b/scripts/chapter_2_lens_modeling/tutorial_4_linear_profiles.py @@ -82,11 +82,9 @@ dataset_name = "lens_sersic" dataset_path = Path("dataset") / "imaging" / dataset_name -if al.util.dataset.should_simulate(str(dataset_path)): - import subprocess - import sys - - subprocess.run([sys.executable, "scripts/simulator/lens_sersic.py"], check=True) +al.util.dataset.simulate_if_needed( + dataset_path, simulator="scripts/simulator/lens_sersic.py" +) dataset = al.Imaging.from_fits( data_path=dataset_path / "data.fits", diff --git a/scripts/chapter_2_lens_modeling/tutorial_6_masking_and_positions.py b/scripts/chapter_2_lens_modeling/tutorial_6_masking_and_positions.py index 56fcba1..3783a20 100644 --- a/scripts/chapter_2_lens_modeling/tutorial_6_masking_and_positions.py +++ b/scripts/chapter_2_lens_modeling/tutorial_6_masking_and_positions.py @@ -46,14 +46,9 @@ If the dataset does not already exist on your system, it will be created by running the corresponding simulator script. This ensures that all example scripts can be run without manually simulating data first. """ -if al.util.dataset.should_simulate(str(dataset_path)): - import subprocess - import sys - - subprocess.run( - [sys.executable, "scripts/simulator/no_lens_light__mass_sis.py"], - check=True, - ) +al.util.dataset.simulate_if_needed( + dataset_path, simulator="scripts/simulator/no_lens_light__mass_sis.py" +) dataset = al.Imaging.from_fits( data_path=dataset_path / "data.fits", diff --git a/scripts/chapter_2_lens_modeling/tutorial_7_results.py b/scripts/chapter_2_lens_modeling/tutorial_7_results.py index 450eeca..838dbfe 100644 --- a/scripts/chapter_2_lens_modeling/tutorial_7_results.py +++ b/scripts/chapter_2_lens_modeling/tutorial_7_results.py @@ -40,14 +40,9 @@ If the dataset does not already exist on your system, it will be created by running the corresponding simulator script. This ensures that all example scripts can be run without manually simulating data first. """ -if al.util.dataset.should_simulate(str(dataset_path)): - import subprocess - import sys - - subprocess.run( - [sys.executable, "scripts/simulator/no_lens_light__mass_sis.py"], - check=True, - ) +al.util.dataset.simulate_if_needed( + dataset_path, simulator="scripts/simulator/no_lens_light__mass_sis.py" +) dataset = al.Imaging.from_fits( data_path=dataset_path / "data.fits", diff --git a/scripts/chapter_2_lens_modeling/tutorial_9_search_chaining.py b/scripts/chapter_2_lens_modeling/tutorial_9_search_chaining.py index 27ebf2d..7b7187d 100644 --- a/scripts/chapter_2_lens_modeling/tutorial_9_search_chaining.py +++ b/scripts/chapter_2_lens_modeling/tutorial_9_search_chaining.py @@ -84,14 +84,9 @@ If the dataset does not already exist on your system, it will be created by running the corresponding simulator script. This ensures that all example scripts can be run without manually simulating data first. """ -if al.util.dataset.should_simulate(str(dataset_path)): - import subprocess - import sys - - subprocess.run( - [sys.executable, "scripts/simulator/lens_sersic.py"], - check=True, - ) +al.util.dataset.simulate_if_needed( + dataset_path, simulator="scripts/simulator/lens_sersic.py" +) dataset = al.Imaging.from_fits( data_path=dataset_path / "data.fits", diff --git a/scripts/chapter_3_pixelizations/tutorial_11_brightness_adaption.py b/scripts/chapter_3_pixelizations/tutorial_11_brightness_adaption.py index d0b6edf..bd8a029 100644 --- a/scripts/chapter_3_pixelizations/tutorial_11_brightness_adaption.py +++ b/scripts/chapter_3_pixelizations/tutorial_11_brightness_adaption.py @@ -63,14 +63,9 @@ If the dataset does not already exist on your system, it will be created by running the corresponding simulator script. This ensures that all example scripts can be run without manually simulating data first. """ -if al.util.dataset.should_simulate(str(dataset_path)): - import subprocess - import sys - - subprocess.run( - [sys.executable, "scripts/simulator/no_lens_light.py"], - check=True, - ) +al.util.dataset.simulate_if_needed( + dataset_path, simulator="scripts/simulator/no_lens_light.py" +) dataset = al.Imaging.from_fits( data_path=dataset_path / "data.fits", diff --git a/scripts/chapter_3_pixelizations/tutorial_12_adaptive_regularization.py b/scripts/chapter_3_pixelizations/tutorial_12_adaptive_regularization.py index 304ec95..78a391a 100644 --- a/scripts/chapter_3_pixelizations/tutorial_12_adaptive_regularization.py +++ b/scripts/chapter_3_pixelizations/tutorial_12_adaptive_regularization.py @@ -44,14 +44,9 @@ If the dataset does not already exist on your system, it will be created by running the corresponding simulator script. This ensures that all example scripts can be run without manually simulating data first. """ -if al.util.dataset.should_simulate(str(dataset_path)): - import subprocess - import sys - - subprocess.run( - [sys.executable, "scripts/simulator/no_lens_light.py"], - check=True, - ) +al.util.dataset.simulate_if_needed( + dataset_path, simulator="scripts/simulator/no_lens_light.py" +) dataset = al.Imaging.from_fits( data_path=dataset_path / "data.fits", diff --git a/scripts/chapter_3_pixelizations/tutorial_1_pixelizations.py b/scripts/chapter_3_pixelizations/tutorial_1_pixelizations.py index 22fa938..b69b039 100644 --- a/scripts/chapter_3_pixelizations/tutorial_1_pixelizations.py +++ b/scripts/chapter_3_pixelizations/tutorial_1_pixelizations.py @@ -63,11 +63,9 @@ dataset_path = Path("dataset") / "imaging" / "source_complex" -if al.util.dataset.should_simulate(str(dataset_path)): - subprocess.run( - [sys.executable, "scripts/simulator/source_complex.py"], - check=True, - ) +al.util.dataset.simulate_if_needed( + dataset_path, simulator="scripts/simulator/source_complex.py" +) dataset = al.Imaging.from_fits( data_path=dataset_path / "data.fits", diff --git a/scripts/chapter_3_pixelizations/tutorial_2_bayesian_regularization.py b/scripts/chapter_3_pixelizations/tutorial_2_bayesian_regularization.py index aec3022..3521268 100644 --- a/scripts/chapter_3_pixelizations/tutorial_2_bayesian_regularization.py +++ b/scripts/chapter_3_pixelizations/tutorial_2_bayesian_regularization.py @@ -47,11 +47,9 @@ dataset_path = Path("dataset") / "imaging" / "source_complex" -if al.util.dataset.should_simulate(str(dataset_path)): - subprocess.run( - [sys.executable, "scripts/simulator/source_complex.py"], - check=True, - ) +al.util.dataset.simulate_if_needed( + dataset_path, simulator="scripts/simulator/source_complex.py" +) dataset = al.Imaging.from_fits( data_path=dataset_path / "data.fits", diff --git a/scripts/chapter_3_pixelizations/tutorial_3_borders.py b/scripts/chapter_3_pixelizations/tutorial_3_borders.py index ef684c2..eafcc92 100644 --- a/scripts/chapter_3_pixelizations/tutorial_3_borders.py +++ b/scripts/chapter_3_pixelizations/tutorial_3_borders.py @@ -41,11 +41,9 @@ dataset_path = Path("dataset") / "imaging" / "simple__no_lens_light" -if al.util.dataset.should_simulate(str(dataset_path)): - subprocess.run( - [sys.executable, "scripts/simulator/no_lens_light.py"], - check=True, - ) +al.util.dataset.simulate_if_needed( + dataset_path, simulator="scripts/simulator/no_lens_light.py" +) dataset_unmasked = al.Imaging.from_fits( data_path=dataset_path / "data.fits", diff --git a/scripts/chapter_3_pixelizations/tutorial_4_lens_modeling.py b/scripts/chapter_3_pixelizations/tutorial_4_lens_modeling.py index ac675a1..7bd86d2 100644 --- a/scripts/chapter_3_pixelizations/tutorial_4_lens_modeling.py +++ b/scripts/chapter_3_pixelizations/tutorial_4_lens_modeling.py @@ -52,11 +52,9 @@ dataset_path = Path("dataset") / "imaging" / "simple__no_lens_light" -if al.util.dataset.should_simulate(str(dataset_path)): - subprocess.run( - [sys.executable, "scripts/simulator/no_lens_light.py"], - check=True, - ) +al.util.dataset.simulate_if_needed( + dataset_path, simulator="scripts/simulator/no_lens_light.py" +) dataset = al.Imaging.from_fits( data_path=dataset_path / "data.fits", @@ -603,11 +601,9 @@ def fit_at_einstein_radius(einstein_radius, coefficient=1.0): foreground_dataset_path = Path("dataset") / "imaging" / "lens_sersic" -if al.util.dataset.should_simulate(str(foreground_dataset_path)): - subprocess.run( - [sys.executable, "scripts/simulator/lens_sersic.py"], - check=True, - ) +al.util.dataset.simulate_if_needed( + foreground_dataset_path, simulator="scripts/simulator/lens_sersic.py" +) foreground_dataset = al.Imaging.from_fits( data_path=foreground_dataset_path / "data.fits", diff --git a/scripts/chapter_3_pixelizations/tutorial_8_adaptive_pixelization.py b/scripts/chapter_3_pixelizations/tutorial_8_adaptive_pixelization.py index 0c8a5dd..662d9bf 100644 --- a/scripts/chapter_3_pixelizations/tutorial_8_adaptive_pixelization.py +++ b/scripts/chapter_3_pixelizations/tutorial_8_adaptive_pixelization.py @@ -55,14 +55,9 @@ If the dataset does not already exist on your system, it will be created by running the corresponding simulator script. This ensures that all example scripts can be run without manually simulating data first. """ -if al.util.dataset.should_simulate(str(dataset_path)): - import subprocess - import sys - - subprocess.run( - [sys.executable, "scripts/simulator/no_lens_light.py"], - check=True, - ) +al.util.dataset.simulate_if_needed( + dataset_path, simulator="scripts/simulator/no_lens_light.py" +) dataset = al.Imaging.from_fits( data_path=dataset_path / "data.fits", diff --git a/scripts/chapter_4_scaling_up_lensing/tutorial_1_extra_galaxies.py b/scripts/chapter_4_scaling_up_lensing/tutorial_1_extra_galaxies.py index 976f04e..b79edd8 100644 --- a/scripts/chapter_4_scaling_up_lensing/tutorial_1_extra_galaxies.py +++ b/scripts/chapter_4_scaling_up_lensing/tutorial_1_extra_galaxies.py @@ -83,14 +83,9 @@ If the dataset does not already exist on your system, it will be created by running the corresponding simulator script. This ensures that all example scripts can be run without manually simulating data first. """ -if al.util.dataset.should_simulate(str(dataset_path)): - import subprocess - import sys - - subprocess.run( - [sys.executable, "scripts/simulator/lens_extra_galaxy.py"], - check=True, - ) +al.util.dataset.simulate_if_needed( + dataset_path, simulator="scripts/simulator/lens_extra_galaxy.py" +) dataset = al.Imaging.from_fits( data_path=dataset_path / "data.fits", diff --git a/scripts/chapter_4_scaling_up_lensing/tutorial_2_multi_galaxy.py b/scripts/chapter_4_scaling_up_lensing/tutorial_2_multi_galaxy.py index b8e3380..27a6852 100644 --- a/scripts/chapter_4_scaling_up_lensing/tutorial_2_multi_galaxy.py +++ b/scripts/chapter_4_scaling_up_lensing/tutorial_2_multi_galaxy.py @@ -71,14 +71,9 @@ dataset_name = "x2_lens_galaxies" dataset_path = Path("dataset") / "imaging" / dataset_name -if al.util.dataset.should_simulate(str(dataset_path)): - import subprocess - import sys - - subprocess.run( - [sys.executable, "scripts/simulator/lens_x2.py"], - check=True, - ) +al.util.dataset.simulate_if_needed( + dataset_path, simulator="scripts/simulator/lens_x2.py" +) dataset = al.Imaging.from_fits( data_path=dataset_path / "data.fits", @@ -388,14 +383,9 @@ dataset_name = "x3_lens_galaxies" dataset_path = Path("dataset") / "imaging" / dataset_name -if al.util.dataset.should_simulate(str(dataset_path)): - import subprocess - import sys - - subprocess.run( - [sys.executable, "scripts/simulator/lens_x3.py"], - check=True, - ) +al.util.dataset.simulate_if_needed( + dataset_path, simulator="scripts/simulator/lens_x3.py" +) dataset = al.Imaging.from_fits( data_path=dataset_path / "data.fits", diff --git a/scripts/chapter_4_scaling_up_lensing/tutorial_3_scaling_relation.py b/scripts/chapter_4_scaling_up_lensing/tutorial_3_scaling_relation.py index 981468e..e72d355 100644 --- a/scripts/chapter_4_scaling_up_lensing/tutorial_3_scaling_relation.py +++ b/scripts/chapter_4_scaling_up_lensing/tutorial_3_scaling_relation.py @@ -128,14 +128,9 @@ If the dataset does not already exist on your system, it will be created by running the corresponding simulator script. This ensures that all example scripts can be run without manually simulating data first. """ -if al.util.dataset.should_simulate(str(dataset_path)): - import subprocess - import sys - - subprocess.run( - [sys.executable, "scripts/simulator/lens_x2.py"], - check=True, - ) +al.util.dataset.simulate_if_needed( + dataset_path, simulator="scripts/simulator/lens_x2.py" +) dataset = al.Imaging.from_fits( data_path=dataset_path / "data.fits", diff --git a/scripts/chapter_4_scaling_up_lensing/tutorial_4_group_scale.py b/scripts/chapter_4_scaling_up_lensing/tutorial_4_group_scale.py index fb998b8..f746204 100644 --- a/scripts/chapter_4_scaling_up_lensing/tutorial_4_group_scale.py +++ b/scripts/chapter_4_scaling_up_lensing/tutorial_4_group_scale.py @@ -95,14 +95,7 @@ If the dataset does not already exist on your system, it will be created by running the corresponding simulator script. This ensures that all example scripts can be run without manually simulating data first. """ -if al.util.dataset.should_simulate(str(dataset_path)): - import subprocess - import sys - - subprocess.run( - [sys.executable, "scripts/simulator/group.py"], - check=True, - ) +al.util.dataset.simulate_if_needed(dataset_path, simulator="scripts/simulator/group.py") dataset = al.Imaging.from_fits( data_path=dataset_path / "data.fits", diff --git a/scripts/chapter_4_scaling_up_lensing/tutorial_5_cluster_scale.py b/scripts/chapter_4_scaling_up_lensing/tutorial_5_cluster_scale.py index 0e52a72..d63875a 100644 --- a/scripts/chapter_4_scaling_up_lensing/tutorial_5_cluster_scale.py +++ b/scripts/chapter_4_scaling_up_lensing/tutorial_5_cluster_scale.py @@ -125,14 +125,9 @@ If the dataset does not already exist on your system, it will be created by running the corresponding simulator script. This ensures that all example scripts can be run without manually simulating data first. """ -if al.util.dataset.should_simulate(str(dataset_path)): - import subprocess - import sys - - subprocess.run( - [sys.executable, "scripts/simulator/cluster.py"], - check=True, - ) +al.util.dataset.simulate_if_needed( + dataset_path, simulator="scripts/simulator/cluster.py" +) """ We first load and plot the cluster's CCD imaging. Note the pixel scale of 0.2" and the sheer size of the diff --git a/scripts/chapter_optional/tutorial_searches.py b/scripts/chapter_optional/tutorial_searches.py index dcab4c4..5cedfc6 100644 --- a/scripts/chapter_optional/tutorial_searches.py +++ b/scripts/chapter_optional/tutorial_searches.py @@ -41,14 +41,9 @@ If the dataset does not already exist on your system, it will be created by running the corresponding simulator script. This ensures that all example scripts can be run without manually simulating data first. """ -if al.util.dataset.should_simulate(str(dataset_path)): - import subprocess - import sys - - subprocess.run( - [sys.executable, "scripts/simulator/lens_sersic.py"], - check=True, - ) +al.util.dataset.simulate_if_needed( + dataset_path, simulator="scripts/simulator/lens_sersic.py" +) dataset = al.Imaging.from_fits( data_path=dataset_path / "data.fits",