def test_approx_cli(args): settings = make_test_approx_parser().parse_args(args=args) from . import geometry, particles from pwkit import cgs from pwkit.astutil import D2R from pwkit.ndshow_gtk3 import cycle, view particles = particles.ParticleDistribution.load(settings.particles_path) distrib = geometry.GriddedDistribution(particles, cgs.rjup) soln = distrib.test_approx( settings.mlat * D2R, settings.mlon * D2R, settings.L, ) def patchlog(a): pos = (a > 0) mn = a[pos].min() a[~pos] = 0.01 * mn return np.log10(a) cycle( [patchlog(soln.data), patchlog(soln.mdata)], descs = ['Data', 'Model'], ) view(soln.resids, title='Residuals')
def view_specmovie_cli(args): from pwkit.ndshow_gtk3 import cycle settings = make_view_specmovie_parser().parse_args(args=args) ii = IntegratedImages(settings.path) arrays = ii.specmovie(settings.icml, settings.stokes, yflip=True) descs = [ '%s freq=%s stokes=%s CML=%.0f' % (settings.path, fn, settings.stokes, ii.cmls[settings.icml]) for fn in ii.freq_names ] cycle(arrays, descs, yflip=True)
def view_rot_cli(args): from pwkit.ndshow_gtk3 import cycle settings = make_view_rot_parser().parse_args(args=args) ii = IntegratedImages(settings.path) arrays = ii.rotmovie(settings.ifreq, settings.stokes, yflip=True) descs = [ '%s freq=%s stokes=%s CML=%.0f' % (settings.path, ii.freq_names[settings.ifreq], settings.stokes, cn) for cn in ii.cmls ] cycle(arrays, descs, yflip=True)
def report (self, cfg): import omega as om import omega.gtk3 from pwkit import ndshow_gtk3 self.all_aps = np.sort (list (self.all_aps)) self.all_bps = sorted (self.all_bps) self.all_times = np.sort (list (self.all_times)) # Antpols by DDID, time: data = [] descs = [] for ddid, stats in self.ap_time_stats_by_ddid.iteritems (): mean, scat = postproc (stats.finish (self.all_times, self.all_aps)) data.append (mean / scat) descs.append ('DDID %d' % ddid) print ('Viewing X axis: antpol; Y axis: time; iteration: DDID (~= spwid) ...') ndshow_gtk3.cycle (data, descs, run_main=True) # Antpols by DDID, freq: data = [] descs = [] for ddid, stats in self.ap_spec_stats_by_ddid.iteritems (): mean, scat = postproc (stats.finish (self.all_aps)) data.append (mean / scat) descs.append ('DDID %d' % ddid) print ('Viewing X axis: frequency; Y axis: antpol; iteration: DDID ...') ndshow_gtk3.cycle (data, descs, run_main=True) # Antpols by DDID p = om.RectPlot () for ddid, stats in self.ap_stats_by_ddid.iteritems (): ok, mean, scat = postproc_mask (stats.finish (self.all_aps)) p.addXYErr (np.arange (len (self.all_aps))[ok], mean, scat, 'DDID %d' % ddid) p.setBounds (-0.5, len (self.all_aps) - 0.5) p.setLabels ('Antpol number', 'Mean closure phase (rad)') p.addHLine (0, keyText=None, zheight=-1) print ('Viewing everything grouped by antpol ...') p.show () # Basepols by DDID data = [] descs = [] tostatuses = [] def bpgrid_status (pol1, pol2, ants, yx): i, j = [int (_) for _ in np.floor (yx + 0.5)] if i < 0 or j < 0 or i >= ants.size or j >= ants.size: return '' ni = self._getname (ants[i]) nj = self._getname (ants[j]) if i <= j: return '%s-%s %s' % (ni, nj, util.pol_names[pol1]) return '%s-%s %s' % (nj, ni, util.pol_names[pol2]) for ddid, stats in self.bp_stats_by_ddid.iteritems (): mean, scat = postproc (stats.finish (self.all_bps)) nmean = mean / scat from itertools import izip pol1, pol2, ants, grid = grid_bp_data (self.all_bps, izip (self.all_bps, nmean)) data.append (grid) descs.append ('DDID %d' % ddid) tostatuses.append (lambda yx: bpgrid_status (pol1, pol2, ants, yx)) print ('Viewing X axis: antpol1; Y axis: antpol2; iteration: DDID ...') ndshow_gtk3.cycle (data, descs, tostatuses=tostatuses, run_main=True) # Everything by time ok, mean, scat = postproc_mask (self.global_stats_by_time.finish (self.all_times)) stimes = self.all_times[ok] / 86400 st0 = int (np.floor (stimes.min ())) stimes -= st0 p = om.quickXYErr (stimes, mean, scat) p.addHLine (0, keyText=None, zheight=-1) p.setLabels ('MJD - %d' % st0, 'Mean closure phase (rad)') print ('Viewing everything grouped by time ...') p.show ()
def report(self, cfg): import omega as om import omega.gtk3 from pwkit import ndshow_gtk3 self.all_aps = np.sort(list(self.all_aps)) self.all_bps = sorted(self.all_bps) self.all_times = np.sort(list(self.all_times)) # Antpols by DDID, time: data = [] descs = [] for ddid, stats in self.ap_time_stats_by_ddid.items(): mean, scat = postproc(stats.finish(self.all_times, self.all_aps)) data.append(mean / scat) descs.append('DDID %d' % ddid) print( 'Viewing X axis: antpol; Y axis: time; iteration: DDID (~= spwid) ...' ) ndshow_gtk3.cycle(data, descs, run_main=True) # Antpols by DDID, freq: data = [] descs = [] for ddid, stats in self.ap_spec_stats_by_ddid.items(): mean, scat = postproc(stats.finish(self.all_aps)) data.append(mean / scat) descs.append('DDID %d' % ddid) print('Viewing X axis: frequency; Y axis: antpol; iteration: DDID ...') ndshow_gtk3.cycle(data, descs, run_main=True) # Antpols by DDID p = om.RectPlot() for ddid, stats in self.ap_stats_by_ddid.items(): ok, mean, scat = postproc_mask(stats.finish(self.all_aps)) p.addXYErr( np.arange(len(self.all_aps))[ok], mean, scat, 'DDID %d' % ddid) p.setBounds(-0.5, len(self.all_aps) - 0.5) p.setLabels('Antpol number', 'Mean closure phase (rad)') p.addHLine(0, keyText=None, zheight=-1) print('Viewing everything grouped by antpol ...') p.show() # Basepols by DDID data = [] descs = [] tostatuses = [] def bpgrid_status(pol1, pol2, ants, yx): i, j = [int(_) for _ in np.floor(yx + 0.5)] if i < 0 or j < 0 or i >= ants.size or j >= ants.size: return '' ni = self._getname(ants[i]) nj = self._getname(ants[j]) if i <= j: return '%s-%s %s' % (ni, nj, util.pol_names[pol1]) return '%s-%s %s' % (nj, ni, util.pol_names[pol2]) for ddid, stats in self.bp_stats_by_ddid.items(): mean, scat = postproc(stats.finish(self.all_bps)) nmean = mean / scat pol1, pol2, ants, grid = grid_bp_data(self.all_bps, zip(self.all_bps, nmean)) data.append(grid) descs.append('DDID %d' % ddid) tostatuses.append(lambda yx: bpgrid_status(pol1, pol2, ants, yx)) print('Viewing X axis: antpol1; Y axis: antpol2; iteration: DDID ...') ndshow_gtk3.cycle(data, descs, tostatuses=tostatuses, run_main=True) # Everything by time ok, mean, scat = postproc_mask( self.global_stats_by_time.finish(self.all_times)) stimes = self.all_times[ok] / 86400 st0 = int(np.floor(stimes.min())) stimes -= st0 p = om.quickXYErr(stimes, mean, scat) p.addHLine(0, keyText=None, zheight=-1) p.setLabels('MJD - %d' % st0, 'Mean closure phase (rad)') print('Viewing everything grouped by time ...') p.show()
def view_hdf5_cli(args): """XXX: huge code redundancy with "view cube". Whatever.""" import h5py ap = argparse.ArgumentParser(prog='vernon view hdf5', ) ap.add_argument('-s', dest='stretch', type=str, nargs=1, default=['default'], choices='default sqrt neg'.split(), help='What kind of stretch to use on the data.') ap.add_argument( '-p', dest='outer_plane_number', metavar='P', type=int, help='Isolate the outermost P\'th plane of the cube before viewing.') ap.add_argument('-T', dest='transpose', action='store_true', help='Transpose the array before viewing.') ap.add_argument( '-f', dest='y_flip', action='store_true', help='Render the cube so that the first row is at the bottom.') ap.add_argument('FILE', metavar='HDF5-PATH', help='The HDF5 file to load') ap.add_argument('ITEMS', nargs='+', metavar='ITEM-NAMES', help='The name of the item within the file to view') settings = ap.parse_args(args=args) stretch_spec = settings.stretch[0] if stretch_spec == 'default': stretch = lambda data: data elif stretch_spec == 'sqrt': def stretch(data): neg = (data < 0) data[neg] *= -1 data = np.sqrt(data) data[neg] *= -1 return data elif stretch_spec == 'neg': stretch = lambda data: (data < 0).astype(np.int) else: cli.die('unknown stretch specification %r', stretch_spec) if settings.y_flip: y_slice = slice(None, None, -1) else: y_slice = slice(None, None) def describe(a): print('Final shape:', repr(a.shape)) print('Min/max/med: %.16e %.16e %.16e' % (np.nanmin(a), np.nanmax(a), np.nanmedian(a))) print('# positive / # negative / # nonfinite: %d %d %d' % ((a > 0).sum(), (a < 0).sum(), (~np.isfinite(a)).sum())) return a # convenience arrays = [] with h5py.File(settings.FILE, 'r') as ds: for item in settings.ITEMS: a = ds[item][...] if settings.outer_plane_number is not None: a = a[settings.outer_plane_number] arrays.append(a) if len(arrays) > 2: a = np.stack(arrays) else: a = arrays[0] if settings.transpose: a = a.T if a.ndim == 2: stretched = stretch(describe(a)) view(stretched[y_slice], yflip=settings.y_flip) elif a.ndim == 3: stretched = stretch(describe(a)) cycle(stretched[:, y_slice], yflip=settings.y_flip) elif a.ndim == 4: print('Shape:', a.shape) for i in range(a.shape[0]): stretched = stretch(describe(a[i])) cycle(stretched[:, y_slice], yflip=settings.y_flip) else: cli.die('cannot handle %d-dimensional arrays', a.ndim)