|
38 | 38 | "outputs": [], |
39 | 39 | "source": [ |
40 | 40 | "# Import necessary packages\n", |
| 41 | + "import matplotlib.pyplot as plt\n", |
41 | 42 | "import numpy as np\n", |
42 | | - "from tardis import constants as const\n", |
43 | 43 | "from astropy import units as u\n", |
| 44 | + "\n", |
| 45 | + "from tardis import run_tardis\n", |
| 46 | + "from tardis.io.atom_data import download_atom_data\n", |
44 | 47 | "from tardis.transport.montecarlo.packet_source import BlackBodySimpleSource\n", |
45 | | - "from tardis.transport.montecarlo.packet_collections import (\n", |
| 48 | + "from tardis.transport.montecarlo.packets.packet_collections import (\n", |
46 | 49 | " PacketCollection,\n", |
47 | | - ")\n", |
48 | | - "from tardis import run_tardis\n", |
49 | | - "import matplotlib.pyplot as plt\n", |
50 | | - "from tardis.io.atom_data import download_atom_data" |
| 50 | + ")" |
51 | 51 | ] |
52 | 52 | }, |
53 | 53 | { |
|
90 | 90 | " self.truncation_wavelength = truncation_wavelength\n", |
91 | 91 | " super().__init__(**kwargs)\n", |
92 | 92 | "\n", |
93 | | - " def create_packets(self, no_of_packets, drawing_sample_size=None, seed_offset=0, *args, **kwargs):\n", |
| 93 | + " def create_packets(\n", |
| 94 | + " self,\n", |
| 95 | + " no_of_packets,\n", |
| 96 | + " drawing_sample_size=None,\n", |
| 97 | + " seed_offset=0,\n", |
| 98 | + " *args,\n", |
| 99 | + " **kwargs,\n", |
| 100 | + " ):\n", |
94 | 101 | " \"\"\"\n", |
95 | 102 | " Packet source that generates a truncated Blackbody source.\n", |
96 | 103 | "\n", |
|
110 | 117 | " array\n", |
111 | 118 | " Packet energies\n", |
112 | 119 | " \"\"\"\n", |
113 | | - "\n", |
114 | 120 | " self._reseed(self.base_seed + seed_offset)\n", |
115 | 121 | " packet_seeds = self.rng.choice(\n", |
116 | 122 | " self.MAX_SEED_VAL, no_of_packets, replace=True\n", |
|
128 | 134 | " drawing_sample_size = 2 * no_of_packets\n", |
129 | 135 | "\n", |
130 | 136 | " # Blackbody will be truncated below truncation_wavelength / above truncation_frequency.\n", |
131 | | - " truncation_frequency = (\n", |
132 | | - " u.Quantity(self.truncation_wavelength, u.Angstrom)\n", |
133 | | - " .to(u.Hz, equivalencies=u.spectral())\n", |
134 | | - " )\n", |
| 137 | + " truncation_frequency = u.Quantity(\n", |
| 138 | + " self.truncation_wavelength, u.Angstrom\n", |
| 139 | + " ).to(u.Hz, equivalencies=u.spectral())\n", |
135 | 140 | "\n", |
136 | 141 | " # Draw nus from blackbody distribution and reject based on truncation_frequency.\n", |
137 | 142 | " # If more nus.shape[0] > no_of_packets use only the first no_of_packets.\n", |
|
141 | 146 | " # Only required if the truncation wavelength is too big compared to the maximum\n", |
142 | 147 | " # of the blackbody distribution. Keep sampling until nus.shape[0] > no_of_packets.\n", |
143 | 148 | " while nus.shape[0] < no_of_packets:\n", |
144 | | - " additional_nus = self.create_packet_nus(drawing_sample_size, *args, **kwargs)\n", |
| 149 | + " additional_nus = self.create_packet_nus(\n", |
| 150 | + " drawing_sample_size, *args, **kwargs\n", |
| 151 | + " )\n", |
145 | 152 | " mask = additional_nus < truncation_frequency\n", |
146 | 153 | " additional_nus = additional_nus[mask][:no_of_packets]\n", |
147 | 154 | " nus = np.hstack([nus, additional_nus])[:no_of_packets]\n", |
|
150 | 157 | " self.calculate_radfield_luminosity().to(u.erg / u.s).value\n", |
151 | 158 | " )\n", |
152 | 159 | "\n", |
153 | | - " return PacketCollection(radii, nus, mus, energies, packet_seeds, radiation_field_luminosity)" |
| 160 | + " return PacketCollection(\n", |
| 161 | + " radii, nus, mus, energies, packet_seeds, radiation_field_luminosity\n", |
| 162 | + " )" |
154 | 163 | ] |
155 | 164 | }, |
156 | 165 | { |
|
190 | 199 | "outputs": [], |
191 | 200 | "source": [ |
192 | 201 | "%matplotlib inline\n", |
193 | | - "plt.plot(mdl.spectrum_solver.spectrum_virtual_packets.wavelength,\n", |
194 | | - " mdl.spectrum_solver.spectrum_virtual_packets.luminosity_density_lambda,\n", |
195 | | - " color='red', label='truncated blackbody (custom packet source)')\n", |
196 | | - "plt.plot(mdl_norm.spectrum_solver.spectrum_virtual_packets.wavelength,\n", |
197 | | - " mdl_norm.spectrum_solver.spectrum_virtual_packets.luminosity_density_lambda,\n", |
198 | | - " color='blue', label='normal blackbody (default packet source)')\n", |
199 | | - "plt.xlabel(r'$\\lambda [\\AA]$')\n", |
200 | | - "plt.ylabel(r'$L_\\lambda$ [erg/s/$\\AA$]')\n", |
| 202 | + "plt.plot(\n", |
| 203 | + " mdl.spectrum_solver.spectrum_virtual_packets.wavelength,\n", |
| 204 | + " mdl.spectrum_solver.spectrum_virtual_packets.luminosity_density_lambda,\n", |
| 205 | + " color=\"red\",\n", |
| 206 | + " label=\"truncated blackbody (custom packet source)\",\n", |
| 207 | + ")\n", |
| 208 | + "plt.plot(\n", |
| 209 | + " mdl_norm.spectrum_solver.spectrum_virtual_packets.wavelength,\n", |
| 210 | + " mdl_norm.spectrum_solver.spectrum_virtual_packets.luminosity_density_lambda,\n", |
| 211 | + " color=\"blue\",\n", |
| 212 | + " label=\"normal blackbody (default packet source)\",\n", |
| 213 | + ")\n", |
| 214 | + "plt.xlabel(r\"$\\lambda [\\AA]$\")\n", |
| 215 | + "plt.ylabel(r\"$L_\\lambda$ [erg/s/$\\AA$]\")\n", |
201 | 216 | "plt.xlim(500, 10000)\n", |
202 | 217 | "plt.legend()" |
203 | 218 | ] |
|
0 commit comments