def test_chain_all(): # Test that running the simulation functions in chain works table = make_base_catalog_galactic(n_sources=10, random_state=0) table = add_snr_parameters(table) table = add_pulsar_parameters(table, random_state=0) table = add_pwn_parameters(table) table = add_observed_parameters(table) d = table[0] # Note: the individual functions are tested above. # Here we just run them in a chain and do very basic asserts # on the output so that we make sure we notice changes. assert len(table) == 10 assert len(table.colnames) == 34 assert table["r_out_PWN"].unit == "pc" assert_allclose(d["r_out_PWN"], 1.378224, atol=1e-4) assert table["RA"].unit == "deg" assert_allclose(d["RA"], 244.347149, atol=1e-5)
def test_add_observed_parameters(): table = make_base_catalog_galactic(n_sources=10, random_state=0) table = add_observed_parameters(table) d = table[0] assert len(table) == 10 assert len(table.colnames) == 20 assert table["distance"].unit == "pc" assert_allclose(d["distance"], 13016.572756, atol=1e-5) assert table["GLON"].unit == "deg" assert_allclose(d["GLON"], -27.156565, atol=1e-5) assert table["GLAT"].unit == "deg" assert_allclose(d["GLAT"], 0.101948, atol=1e-5) assert table["VGLON"].unit == "deg / Myr" assert_allclose(d["VGLON"], 0.368166, atol=1e-5) assert table["VGLAT"].unit == "deg / Myr" assert_allclose(d["VGLAT"], -0.209514, atol=1e-5) assert table["RA"].unit == "deg" assert_allclose(d["RA"], 244.347149, atol=1e-5) assert table["DEC"].unit == "deg" assert_allclose(d["DEC"], -50.410142, atol=1e-5)
luminosity_min = 4e34 # Maximum source luminosity (ph s^-1) luminosity_max = 4e37 # Luminosity function differential power-law index luminosity_index = 1.5 # Assigns luminosities to sources luminosity = sample_powerlaw(luminosity_min, luminosity_max, luminosity_index, n_sources, random_state=0) table['luminosity'] = luminosity # Adds parameters to table: distance, glon, glat, flux, angular_extension table = population.add_observed_parameters(table) table.meta['Energy Bins'] = np.array([10, 500]) * u.GeV # Create image image = catalog_image(reference, psf, catalog='simulation', source_type='point', total_flux=True, sim_table=table) # Plot fig = FITSFigure(image.to_fits()[0], figsize=(15, 5)) fig.show_colorscale(interpolation='bicubic', cmap='afmhot', stretch='log', vmin=1E30,
spiralarms=spiralarms, random_state=0) # Minimum source luminosity (ph s^-1) luminosity_min = 4e34 # Maximum source luminosity (ph s^-1) luminosity_max = 4e37 # Luminosity function differential power-law index luminosity_index = 1.5 # Assigns luminosities to sources luminosity = sample_powerlaw(luminosity_min, luminosity_max, luminosity_index, n_sources, random_state=0) table['luminosity'] = luminosity # Adds parameters to table: distance, glon, glat, flux, angular_extension table = population.add_observed_parameters(table) table.meta['Energy Bins'] = np.array([10, 500]) * u.GeV # Create image image = catalog_image(reference, psf, catalog='simulation', source_type='point', total_flux=True, sim_table=table) # Plot fig = FITSFigure(image.to_fits()[0], figsize=(15, 5)) fig.show_colorscale(interpolation='bicubic', cmap='afmhot', stretch='log', vmin=1E30, vmax=1E35) fig.tick_labels.set_xformat('ddd') fig.tick_labels.set_yformat('dd') ticks = np.logspace(30, 35, 6) fig.add_colorbar(ticks=ticks, axis_label_text='Flux (ph s^-1)') fig.colorbar._colorbar_axes.set_yticklabels(['{:.0e}'.format(_) for _ in ticks]) plt.tight_layout() plt.show()