5050from arl .util .coordinate_support import xyz_at_latitude
5151from arl .visibility .base import create_blockvisibility
5252from arl .visibility .coalesce import convert_visibility_to_blockvisibility
53+ from arl .skycomponent .operations import insert_skycomponent
5354
5455log = logging .getLogger (__name__ )
5556
@@ -349,7 +350,8 @@ def create_low_test_image_composite(npixel=16384, polarisation_frame=Polarisatio
349350
350351def create_low_test_image_from_gleam (npixel = 512 , polarisation_frame = PolarisationFrame ("stokesI" ), cellsize = 0.000015 ,
351352 frequency = numpy .array ([1e8 ]), channel_bandwidth = numpy .array ([1e6 ]),
352- phasecentre = None , kind = 'cubic' , applybeam = False , flux_limit = 0.1 ) -> Image :
353+ phasecentre = None , kind = 'cubic' , applybeam = False , flux_limit = 0.1 ,
354+ radius = None , insert_method = 'Nearest' ) -> Image :
353355 """Create LOW test image from the GLEAM survey
354356
355357 Stokes I is estimated from a cubic spline fit to the measured fluxes. The polarised flux is always zero.
@@ -371,25 +373,21 @@ def create_low_test_image_from_gleam(npixel=512, polarisation_frame=Polarisation
371373 :return: Image
372374
373375 """
374-
375-
376- fitsfile = arl_path ("data/models/GLEAM_EGC.fits" )
377-
378- hdulist = fits .open (fitsfile , lazy_load_hdus = False )
379- recs = hdulist [1 ].data [0 ].array
380- ras = recs ['RAJ2000' ]
381- decs = recs ['DEJ2000' ]
382-
376+
383377 if phasecentre is None :
384378 phasecentre = SkyCoord (ra = + 15.0 * u .deg , dec = - 35.0 * u .deg , frame = 'icrs' , equinox = 'J2000' )
385-
379+
380+ if radius is None :
381+ radius = npixel * cellsize / numpy .sqrt (2.0 )
382+
383+ sc = create_low_test_skycomponents_from_gleam (flux_limit = flux_limit , polarisation_frame = polarisation_frame ,
384+ frequency = frequency , phasecentre = phasecentre ,
385+ kind = kind , radius = radius )
386386 if polarisation_frame is None :
387387 polarisation_frame = PolarisationFrame ("stokesI" )
388388
389389 npol = polarisation_frame .npol
390-
391390 nchan = len (frequency )
392-
393391 shape = [nchan , npol , npixel , npixel ]
394392 w = WCS (naxis = 4 )
395393 # The negation in the longitude is needed by definition of RA, DEC
@@ -398,59 +396,18 @@ def create_low_test_image_from_gleam(npixel=512, polarisation_frame=Polarisation
398396 w .wcs .ctype = ["RA---SIN" , "DEC--SIN" , 'STOKES' , 'FREQ' ]
399397 w .wcs .crval = [phasecentre .ra .deg , phasecentre .dec .deg , 1.0 , frequency [0 ]]
400398 w .naxis = 4
401-
402399 w .wcs .radesys = 'ICRS'
403400 w .wcs .equinox = 2000.0
404401
405402 model = create_image_from_array (numpy .zeros (shape ), w , polarisation_frame = polarisation_frame )
406403
407- p = w .sub (2 ).wcs_world2pix (numpy .array (ras ), numpy .array (decs ), 1 )
408-
409- p = numpy .array (p )
410- mask = numpy .isfinite (p [0 , :])
411- p = [p [0 , mask ], p [1 , mask ]]
412-
413- ip = numpy .round (p ).astype ('int' )
414- ok = numpy .where ((0 <= ip [0 , :]) & (npixel > ip [0 , :]) & (0 <= ip [1 , :]) & (npixel > ip [1 , :]))[0 ]
415- ps = ip [:, ok ]
416-
417- # For every source, we read all measured fluxes and interpolate to the
418- # required frequencies
419- fluxes = []
420- gleam_freqs = numpy .array ([76 , 84 , 92 , 99 , 107 , 115 , 122 , 130 , 143 , 151 , 158 , 166 , 174 , 181 , 189 , 197 , 204 ,
421- 212 , 220 , 227 ])
422- gleam_flux_freq = numpy .zeros ([len (ok ), len (gleam_freqs )])
423- for i , f in enumerate (gleam_freqs ):
424- gleam_flux_freq [:,i ] = recs ['int_flux_%03d' % (f )][:]
425-
404+ model = insert_skycomponent (model , sc , insert_method = insert_method )
426405 if applybeam :
427406 beam = create_low_test_beam (model )
407+ model .data [...] *= beam .data [...]
428408
429- for source in ok :
409+ log . info ( qa_image ( model , context = 'create_low_test_image_from_gleam' ))
430410
431- fint = interpolate .interp1d (gleam_freqs * 1.0e6 , gleam_flux_freq [source ,:], kind = kind )
432- factual = fint (frequency )
433- if applybeam :
434- factual *= beam .data [:, 0 , ip [1 , source ], ip [0 , source ]]
435-
436- fluxes .append (factual )
437-
438- fluxes = numpy .array (fluxes )
439- actual_flux = numpy .sum (fluxes )
440-
441- log .info ('create_low_test_image_from_gleam: %d sources inside the image' % (ps .shape [1 ]))
442-
443- log .info (
444- 'create_low_test_image_from_gleam: Average flux per channel in image = %.3f' % (actual_flux / float (nchan )))
445- for iflux , flux in enumerate (fluxes ):
446- if not numpy .isnan (flux ).any () and flux .any () > flux_limit :
447- model .data [:, 0 , ps [1 , iflux ], ps [0 , iflux ]] = flux [:]
448-
449- log .info (qa_image (model ), context = 'create_low_test_image_from_gleam' )
450- print (qa_image (model ), context = 'create_low_test_image_from_gleam' )
451-
452- hdulist .close ()
453-
454411 return model
455412
456413
@@ -470,6 +427,7 @@ def create_low_test_skycomponents_from_gleam(flux_limit=0.1, polarisation_frame=
470427 catalogue. Hurley-Walker N., et al., Mon. Not. R. Astron. Soc., 464, 1146-1167 (2017), 2017MNRAS.464.1146H
471428
472429
430+ :rtype: Union[None, List[arl.data.data_models.Skycomponent], List]
473431 :param flux_limit: Only write components brighter than this (Jy)
474432 :param polarisation_frame: Polarisation frame (default PolarisationFrame("stokesI"))
475433 :param frequency: Frequencies at which the flux will be estimated
@@ -481,27 +439,26 @@ def create_low_test_skycomponents_from_gleam(flux_limit=0.1, polarisation_frame=
481439
482440 fitsfile = arl_path ("data/models/GLEAM_EGC.fits" )
483441
484- decmin = phasecentre .dec .to ('rad' ).value - radius / 2.0
485- decmax = phasecentre .dec .to ('rad' ).value + radius / 2.0
442+ rad2deg = 180.0 / numpy .pi
443+ decmin = phasecentre .dec .to ('deg' ).value - rad2deg * radius / 2.0
444+ decmax = phasecentre .dec .to ('deg' ).value + rad2deg * radius / 2.0
486445
487446 hdulist = fits .open (fitsfile , lazy_load_hdus = False )
488447 recs = hdulist [1 ].data [0 ].array
489- print ("Before filter %s" % recs .shape )
448+
449+ # Do the simple forms of filtering in pyfits. Filtering on radious is done below.
490450 fluxes = recs ['peak_flux_wide' ]
491451
492452 mask = fluxes > flux_limit
493453 filtered_recs = recs [mask ]
494- print ("After flux filter %s" % filtered_recs .shape )
495454
496455 decs = filtered_recs ['DEJ2000' ]
497456 mask = decs > decmin
498457 filtered_recs = filtered_recs [mask ]
499- print ("After dec min filter %s" % filtered_recs .shape )
500458
501459 decs = filtered_recs ['DEJ2000' ]
502460 mask = decs < decmax
503461 filtered_recs = filtered_recs [mask ]
504- print ("After dec max filter %s" % filtered_recs .shape )
505462
506463 ras = filtered_recs ['RAJ2000' ]
507464 decs = filtered_recs ['DEJ2000' ]
@@ -579,7 +536,7 @@ def create_low_test_beam(model: Image) -> Image:
579536 beam2dwcs .wcs .ctype = model .wcs .sub (2 ).wcs .ctype
580537 model2dwcs .wcs .crpix = [model .shape [2 ] // 2 + 1 , model .shape [3 ] // 2 + 1 ]
581538
582- beam2d = create_image_from_array (beam .data [0 , 0 , :, :], beam2dwcs )
539+ beam2d = create_image_from_array (beam .data [0 , 0 , :, :], beam2dwcs , model . polarisation_frame )
583540 reprojected_beam2d , footprint = reproject_image (beam2d , model2dwcs , shape = model2dshape )
584541 assert numpy .max (footprint .data ) > 0.0 , "No overlap between beam and model"
585542
0 commit comments