def test_componentlist(self): srclist = [ (SkyCoord(10 * u.deg, 5 * u.deg), 1.5 * u.mJy, 3 * u.GHz), (SkyCoord(10 * u.deg, 5.1 * u.deg), 15 * u.mJy, 2.5 * u.GHz), ] out_path = os.path.join(self.output_dir, "foo.cl") script = [] sim.make_componentlist(script, srclist, out_path) # Need to insert these prior to `cl.close()` script.insert(-1, "print cl.length()") script.insert(-1, "print cl.getcomponent(0)") self.casa.run_script(script) out, err = self.casa.run_script([]) self.assertTrue(os.path.isdir(out_path))
def test_componentlist(self): srclist = [ (SkyCoord(10 * u.deg, 5 * u.deg), 1.5 * u.mJy, 3 * u.GHz,), (SkyCoord(10 * u.deg, 5.1 * u.deg), 15 * u.mJy, 2.5 * u.GHz,), ] out_path = os.path.join(self.output_dir, "foo.cl") script = [] sim.make_componentlist(script, srclist, out_path) # Need to insert these prior to `cl.close()` script.insert(-1, 'print cl.length()') script.insert(-1, 'print cl.getcomponent(0)') self.casa.run_script(script) out, err = self.casa.run_script([]) self.assertTrue(os.path.isdir(out_path))
def simulate_vis_with_casa(pointing_centre, source_list, output_dir): """ Use casapy to simulate a visibility measurementset with noise. (This also produces an initial set of UVW data) Args: pointing_centre (:class:`astropy.coordinates.SkyCoord`) source_list: list of :class:`fastimgproto.skymodel.helpers.SkySource` output_dir (str): Output directory which will contain `vis.ms` Returns (str): Full path to `vis.ms`. """ ensure_dir(output_dir) commands_logfile = os.path.join( output_dir, "./casa-visibilities_for_point_source-commands.log") component_list_path = os.path.join(output_dir, './sources.cl') output_visibility = os.path.abspath(os.path.join(output_dir, './vis.ms')) if os.path.isfile(commands_logfile): os.unlink(commands_logfile) casa = drivecasa.Casapy(commands_logfile=commands_logfile) script = [] # For VLA reference numbers, see: # https://science.nrao.edu/facilities/vla/docs/manuals/oss/performance/fov # https://science.nrao.edu/facilities/vla/docs/manuals/oss/performance/resolution # Define some observation parameters: obs_central_frequency = 3. * u.GHz obs_frequency_bandwidth = 0.125 * u.GHz primary_beam_fwhm = (45. * u.GHz / obs_central_frequency) * u.arcmin # Convert the sources to a CASA 'componentlist' component_list_path = sim.make_componentlist( script, source_list=[(s.position, s.flux, s.frequency) for s in source_list], out_path=component_list_path) # Open the visibility file sim.open_sim(script, output_visibility) # Configure the virtual telescope # sim.setpb(script, # telescope_name='VLA', # primary_beam_hwhm=primary_beam_fwhm * 0.5, # frequency=obs_central_frequency) sim.setconfig(script, telescope_name='VLA', antennalist_path=vla_c_antennalist_path) sim.setspwindow( script, freq_start=obs_central_frequency - 0.5 * obs_frequency_bandwidth, freq_resolution=obs_frequency_bandwidth, freq_delta=obs_frequency_bandwidth, n_channels=1, ) sim.setfeed(script, ) sim.setfield(script, pointing_centre) sim.setlimits(script) sim.setauto(script) ref_time = Time('2014-05-01T19:55:45', format='isot', scale='tai') sim.settimes(script, integration_time=10 * u.s, reference_time=ref_time) # Generate the visibilities sim.observe(script, stop_delay=10 * u.s) sim.predict(script, component_list_path) sim.set_simplenoise(script, noise_std_dev=1 * u.mJy) sim.corrupt(script) sim.close_sim(script) casa.run_script(script) return output_visibility
obs_frequency_bandwidth = 0.125 * u.GHz primary_beam_fwhm = (45. * u.GHz / obs_central_frequency) * u.arcmin # Define the field centre and sources: centre_ra = 180 * u.deg centre_dec = 34 * u.deg # Sources are represented by tuples of (posn, flux, freq) pointing_centre = SkyCoord(centre_ra, centre_dec) srclist = [ (SkyCoord(centre_ra, centre_dec), 1. * u.mJy, obs_central_frequency), (SkyCoord(centre_ra, centre_dec + primary_beam_fwhm * 0.5), 1. * u.mJy, obs_central_frequency), ] # Convert the sources to a CASA 'componentlist' component_list_path = sim.make_componentlist(script, srclist, component_list_path) # Open the visibility file sim.open_sim(script, output_visibility) # Configure the virtual telescope sim.setpb(script, telescope_name='VLA', primary_beam_hwhm=primary_beam_fwhm * 0.5, frequency=obs_central_frequency) sim.setconfig(script, telescope_name='VLA', antennalist_path='./vla.c.cfg') sim.setspwindow( script, freq_start=obs_central_frequency - 0.5 * obs_frequency_bandwidth, freq_resolution=obs_frequency_bandwidth, freq_delta=obs_frequency_bandwidth,
obs_frequency_bandwidth = 0.125 * u.GHz primary_beam_fwhm = (45. * u.GHz / obs_central_frequency) * u.arcmin # Define the field centre and sources: centre_ra = 180 * u.deg centre_dec = 34 * u.deg # Sources are represented by tuples of (posn, flux, freq) pointing_centre = SkyCoord(centre_ra, centre_dec) srclist = [ (SkyCoord(centre_ra, centre_dec), 1. * u.mJy, obs_central_frequency), (SkyCoord(centre_ra, centre_dec + primary_beam_fwhm * 0.5), 1. * u.mJy, obs_central_frequency), ] # Convert the sources to a CASA 'componentlist' component_list_path = sim.make_componentlist(script, srclist, component_list_path) # Open the visibility file sim.open_sim(script, output_visibility) # Configure the virtual telescope sim.setpb(script, telescope_name='VLA', primary_beam_hwhm=primary_beam_fwhm * 0.5, frequency=obs_central_frequency) sim.setconfig(script, telescope_name='VLA', antennalist_path='./vla.c.cfg') sim.setspwindow(script, freq_start=obs_central_frequency - 0.5 * obs_frequency_bandwidth, freq_resolution=obs_frequency_bandwidth,
def simulate_vis_with_casa(pointing_centre, source_list, noise_std_dev, vis_path, overwrite=True, echo=False): """ Use casapy to simulate a visibility measurementset with noise. (This also produces an initial set of UVW data) Args: pointing_centre (:class:`astropy.coordinates.SkyCoord`) source_list: list of :class:`fastimgproto.skymodel.helpers.SkySource` noise_std_dev (astropy.units.Quantity): Standard deviation of the noise (units of Jy). vis_path (str): Path to visibilities generated. echo (bool): Echo the CASA output to terminal during processing. Returns (str): Full path to `vis.ms`. """ vis_abspath = os.path.abspath(vis_path) commands_logfile = vis_abspath + "_casa_commands.log" casa_logfile = vis_abspath + "_casa_log.log" component_list_path = vis_abspath + "_sources.cl" for outdir in vis_abspath, component_list_path: if os.path.isdir(outdir): if overwrite: shutil.rmtree(outdir) else: raise IOError( "{} already present and overwrite==False.".format(outdir)) if os.path.isfile(commands_logfile): os.remove(commands_logfile) ensure_dir(os.path.dirname(vis_abspath)) casa = drivecasa.Casapy(commands_logfile=commands_logfile, casa_logfile=casa_logfile, echo_to_stdout=echo) script = [] # Add subroutine definition, for manual reproduction with CASA: script.append( drivecasa.drivecasa.commands.subroutines.def_load_antennalist) # Define some observation parameters... # For VLA reference numbers, see: # https://science.nrao.edu/facilities/vla/docs/manuals/oss/performance/fov # https://science.nrao.edu/facilities/vla/docs/manuals/oss/performance/resolution obs_central_frequency = 3. * u.GHz obs_frequency_bandwidth = 0.125 * u.GHz primary_beam_fwhm = (45. * u.GHz / obs_central_frequency) * u.arcmin # Convert the sources to a CASA 'componentlist' component_list_path = sim.make_componentlist( script, source_list=[(s.position, s.flux, s.frequency) for s in source_list], out_path=component_list_path) # Open the visibility file sim.open_sim(script, vis_abspath) # Configure the virtual telescope # sim.setpb(script, # telescope_name='VLA', # primary_beam_hwhm=primary_beam_fwhm * 0.5, # frequency=obs_central_frequency) sim.setconfig(script, telescope_name='VLA', antennalist_path=vla_c_antennalist_path) sim.setspwindow( script, freq_start=obs_central_frequency - 0.5 * obs_frequency_bandwidth, freq_resolution=obs_frequency_bandwidth, freq_delta=obs_frequency_bandwidth, n_channels=1, ) sim.setfeed(script, ) sim.setfield(script, pointing_centre) sim.setlimits(script) sim.setauto(script) ref_time = Time('2014-05-01T19:55:45', format='isot', scale='tai') sim.settimes(script, integration_time=10 * u.s, reference_time=ref_time) # Generate the visibilities sim.observe(script, stop_delay=10 * u.s) sim.predict(script, component_list_path) sim.set_simplenoise(script, noise_std_dev=noise_std_dev) sim.corrupt(script) sim.close_sim(script) casa_output = casa.run_script(script) return casa_output
def simulate_vis_with_casa(pointing_centre, source_list, noise_std_dev, vis_path, overwrite=True, echo=False): """ Use casapy to simulate a visibility measurementset with noise. (This also produces an initial set of UVW data) Args: pointing_centre (:class:`astropy.coordinates.SkyCoord`) source_list: list of :class:`fastimgproto.skymodel.helpers.SkySource` noise_std_dev (astropy.units.Quantity): Standard deviation of the noise (units of Jy). vis_path (str): Path to visibilities generated. echo (bool): Echo the CASA output to terminal during processing. Returns (str): Full path to `vis.ms`. """ vis_abspath = os.path.abspath(vis_path) commands_logfile = vis_abspath + "_casa_commands.log" casa_logfile = vis_abspath + "_casa_log.log" component_list_path = vis_abspath + "_sources.cl" for outdir in vis_abspath, component_list_path: if os.path.isdir(outdir): if overwrite: shutil.rmtree(outdir) else: raise IOError("{} already present and overwrite==False.".format( outdir )) if os.path.isfile(commands_logfile): os.remove(commands_logfile) ensure_dir(os.path.dirname(vis_abspath)) casa = drivecasa.Casapy(commands_logfile=commands_logfile, casa_logfile=casa_logfile, echo_to_stdout=echo) script = [] # Add subroutine definition, for manual reproduction with CASA: script.append(drivecasa.drivecasa.commands.subroutines.def_load_antennalist) # Define some observation parameters... # For VLA reference numbers, see: # https://science.nrao.edu/facilities/vla/docs/manuals/oss/performance/fov # https://science.nrao.edu/facilities/vla/docs/manuals/oss/performance/resolution obs_central_frequency = 3. * u.GHz obs_frequency_bandwidth = 0.125 * u.GHz primary_beam_fwhm = (45. * u.GHz / obs_central_frequency) * u.arcmin # Convert the sources to a CASA 'componentlist' component_list_path = sim.make_componentlist( script, source_list=[(s.position, s.flux, s.frequency) for s in source_list], out_path=component_list_path) # Open the visibility file sim.open_sim(script, vis_abspath) # Configure the virtual telescope # sim.setpb(script, # telescope_name='VLA', # primary_beam_hwhm=primary_beam_fwhm * 0.5, # frequency=obs_central_frequency) sim.setconfig(script, telescope_name='VLA', antennalist_path=vla_c_antennalist_path) sim.setspwindow(script, freq_start=obs_central_frequency - 0.5 * obs_frequency_bandwidth, freq_resolution=obs_frequency_bandwidth, freq_delta=obs_frequency_bandwidth, n_channels=1, ) sim.setfeed(script, ) sim.setfield(script, pointing_centre) sim.setlimits(script) sim.setauto(script) ref_time = Time('2014-05-01T19:55:45', format='isot', scale='tai') sim.settimes(script, integration_time=10 * u.s, reference_time=ref_time) # Generate the visibilities sim.observe(script, stop_delay=10 * u.s) sim.predict(script, component_list_path) sim.set_simplenoise(script, noise_std_dev=noise_std_dev) sim.corrupt(script) sim.close_sim(script) casa_output = casa.run_script(script) return casa_output