Loading .gitignore +1 −0 Original line number Diff line number Diff line Loading @@ -7,6 +7,7 @@ *.h5 .*.swp .DS_Store *.code-workspace # work directory (for tmp development) work/* Loading drspine.code-workspacedeleted 100644 → 0 +0 −8 Original line number Diff line number Diff line { "folders": [ { "path": "." } ], "settings": {} } python/drspine/fits.py +55 −23 Original line number Diff line number Diff line Loading @@ -44,14 +44,15 @@ def read_data(fname): data = np.loadtxt(lines[iline:], delimiter=',').T return meta, data def save_fig(datadir, prefix="", suffix=""): def save_file(datadir, prefix="", suffix="", extension='.pdf'): "save fig" datadir = os.path.normpath(datadir) dirname = os.path.dirname(datadir) basename = os.path.basename(datadir) outfile = os.path.join(dirname, "%s%s%s.pdf" % (prefix, basename, suffix)) outfile = os.path.join(dirname, f"{prefix}{basename}{suffix}{extension}") print(" saving to %s" % outfile, end="") plt.savefig(outfile) return outfile #fig.savefig(outfile) Loading @@ -69,6 +70,7 @@ def plot_fit_pixel(itau, pix, axes=None, datadir='.', **kwargs): fcolor = kwargs.get('fitcolor' , 'red') flabel = kwargs.get('fitlabel', '') echo_only = kwargs.get('echo_only', False) only_good = kwargs.get('only_good', False) nud = kwargs.get('nud', -8) # n last points are "up/down" measurements label = '%s-%s' % (itau,pix) Loading Loading @@ -96,19 +98,27 @@ def plot_fit_pixel(itau, pix, axes=None, datadir='.', **kwargs): dn = mfit.get('dn', 0) bgcolor = axes.set_facecolor if only_good: if fit is None or np.isnan(amp): axes.set_xticklabels([]) axes.set_yticklabels([]) #axes.set_axis_off() return {} if mark_pixels: if fit is None: bgcolor('gray') elif np.isnan(amp) or amp<0: bgcolor('yellow') bgcolor(('gray', 0.3)) elif np.isnan(amp): bgcolor(('magenta', 0.3)) elif amp<0: bgcolor(('yellow', 0.3)) axes.errorbar(dat[0]/unit, dat[1], yerr=dat[2], fmt='.', markersize=3, lw=1, color=dcolor) if fit is not None: axes.axvline (sym/unit, color=fcolor, lw=1.5) axes.axhline (ave, color='green', lw=1.5) axes.axhline (up , color='green', lw=1.0, ls='--') axes.axhline (dn , color='green', lw=1.0, ls='--') axes.plot (fit[0]/unit, fit[1], ls='-', lw=1, color=fcolor, label=flabel) axes.axvline (sym/unit, color=fcolor, lw=1) axes.axhline (ave, color='green', lw=2) axes.axhline (up , color='green', lw=1, ls='--') axes.axhline (dn , color='green', lw=1, ls='--') if maxy: axes.set_ylim(ymin=miny, ymax=maxy) Loading Loading @@ -172,6 +182,7 @@ def plot_fit_map(itau, axes, datadir='.', what='sym', **kwargs): """ Plot maps """ cmap = kwargs.pop('cmap', 'viridis') npix = kwargs.pop('npix', 8) scale = kwargs.pop('scale', 1.0) Loading @@ -188,9 +199,23 @@ def plot_fit_map(itau, axes, datadir='.', what='sym', **kwargs): meta, _data = read_data(fname) if pix==center and meta and meta.get('title'): tit = meta.get('title') d[irow,icol] = meta.get(what, None) if what in ('fqt', 'updn'): amp = meta.get('amp', None) up = meta.get('up', None) dn = meta.get('dn', None) try: updn = up-dn if what=='fqt': res = 2*amp/updn if what=='updn': res = updn except (TypeError, ArithmeticError): res = None else: res = meta.get(what, None) d[irow,icol] = res img = axes.imshow(d/scale, extent=(0,npix, npix,0), interpolation='nearest') img = axes.imshow(d/scale, extent=(0,npix, npix,0), interpolation='nearest', cmap=cmap) return tit, img Loading @@ -209,28 +234,34 @@ def plot_fits(datadir, tau=1, npix=8, limy=(0.0,None), save=False, mark_pixels=T #nplot = rows*cols center = (npix+1)*npix//2 miny, maxy = limy _fig, axes = plt.subplots(npix,npix, figsize=(8,8)) plt.subplots_adjust(hspace=0.05, wspace=0.05) fig, axes = plt.subplots(npix,npix, figsize=(8,8)) fig.subplots_adjust(hspace=0.05, wspace=0.05) tit='' limits=[] for pix in range(npix**2): irow = pix % npix icol = pix // npix meta = plot_fit_pixel(tau, pix+1, axes[irow, icol] , miny=miny, maxy=maxy, datadir=datadir, xticks=False, yticks=False, mark_pixels=mark_pixels, **kwargs) if meta.get('limits'): limits.append(meta.get('limits')) if pix==center and meta and meta.get('title'): tit = meta.get('title') if pix%2: print(".", end="") sys.stdout.flush() tit = tit.split()[0] plt.suptitle("%s (%s echo[%s])" % (tit, datadir, tau), fontsize=12) basedir=os.path.normpath(datadir).split('/')[-1] fig.suptitle(f"{tit} ({basedir}/echo[{tau}])", fontsize=12) if save: save_fig(datadir, "", "-%02d" % tau) fig.savefig(save_file(datadir, "", "-%02d" % tau)) limits = np.asarray(limits) print(" done.") print(f"yrange=({np.min(limits):.4g},{np.max(limits):.4g})") def plot_maps(datadir, tau=1, npix=8, limz=(None,None), what='sym', scale=1.0, save=False): def plot_maps(datadir, tau=1, npix=8, limz=(None,None), what='sym', scale=1.0, save=False, cmap='viridis'): """ Plot maps """ Loading @@ -240,20 +271,21 @@ def plot_maps(datadir, tau=1, npix=8, limz=(None,None), what='sym', scale=1.0, s print("plotting maps tau=%-s" % tau, end="") minz, maxz = limz _fig, ax = plt.subplots() fig, ax = plt.subplots() t, img = plot_fit_map(tau, ax, datadir=datadir, what=what, scale=scale, npix=npix) t, img = plot_fit_map(tau, ax, datadir=datadir, what=what, scale=scale, npix=npix, cmap=cmap) tit = t.split()[0] img.set_clim(minz, maxz) plt.colorbar(img, ax=ax) plt.suptitle("%s (%s/%s[%s])" % (tit, datadir, what, tau), fontsize=12) #plt.colorbar(img, ax=ax) cbar = fig.colorbar(img, ax=ax) basedir=os.path.normpath(datadir).split('/')[-1] fig.suptitle(f"{tit} ({basedir}/{what}[{tau}])", fontsize=12) if save: save_fig(datadir, "maps_", "-%02d" % tau) fig.savefig(save_file(datadir, "maps_", "-%02d" % tau)) print(" done.") def find_minmax(datadir, tau=None): "find min and max" if tau: Loading Loading
.gitignore +1 −0 Original line number Diff line number Diff line Loading @@ -7,6 +7,7 @@ *.h5 .*.swp .DS_Store *.code-workspace # work directory (for tmp development) work/* Loading
drspine.code-workspacedeleted 100644 → 0 +0 −8 Original line number Diff line number Diff line { "folders": [ { "path": "." } ], "settings": {} }
python/drspine/fits.py +55 −23 Original line number Diff line number Diff line Loading @@ -44,14 +44,15 @@ def read_data(fname): data = np.loadtxt(lines[iline:], delimiter=',').T return meta, data def save_fig(datadir, prefix="", suffix=""): def save_file(datadir, prefix="", suffix="", extension='.pdf'): "save fig" datadir = os.path.normpath(datadir) dirname = os.path.dirname(datadir) basename = os.path.basename(datadir) outfile = os.path.join(dirname, "%s%s%s.pdf" % (prefix, basename, suffix)) outfile = os.path.join(dirname, f"{prefix}{basename}{suffix}{extension}") print(" saving to %s" % outfile, end="") plt.savefig(outfile) return outfile #fig.savefig(outfile) Loading @@ -69,6 +70,7 @@ def plot_fit_pixel(itau, pix, axes=None, datadir='.', **kwargs): fcolor = kwargs.get('fitcolor' , 'red') flabel = kwargs.get('fitlabel', '') echo_only = kwargs.get('echo_only', False) only_good = kwargs.get('only_good', False) nud = kwargs.get('nud', -8) # n last points are "up/down" measurements label = '%s-%s' % (itau,pix) Loading Loading @@ -96,19 +98,27 @@ def plot_fit_pixel(itau, pix, axes=None, datadir='.', **kwargs): dn = mfit.get('dn', 0) bgcolor = axes.set_facecolor if only_good: if fit is None or np.isnan(amp): axes.set_xticklabels([]) axes.set_yticklabels([]) #axes.set_axis_off() return {} if mark_pixels: if fit is None: bgcolor('gray') elif np.isnan(amp) or amp<0: bgcolor('yellow') bgcolor(('gray', 0.3)) elif np.isnan(amp): bgcolor(('magenta', 0.3)) elif amp<0: bgcolor(('yellow', 0.3)) axes.errorbar(dat[0]/unit, dat[1], yerr=dat[2], fmt='.', markersize=3, lw=1, color=dcolor) if fit is not None: axes.axvline (sym/unit, color=fcolor, lw=1.5) axes.axhline (ave, color='green', lw=1.5) axes.axhline (up , color='green', lw=1.0, ls='--') axes.axhline (dn , color='green', lw=1.0, ls='--') axes.plot (fit[0]/unit, fit[1], ls='-', lw=1, color=fcolor, label=flabel) axes.axvline (sym/unit, color=fcolor, lw=1) axes.axhline (ave, color='green', lw=2) axes.axhline (up , color='green', lw=1, ls='--') axes.axhline (dn , color='green', lw=1, ls='--') if maxy: axes.set_ylim(ymin=miny, ymax=maxy) Loading Loading @@ -172,6 +182,7 @@ def plot_fit_map(itau, axes, datadir='.', what='sym', **kwargs): """ Plot maps """ cmap = kwargs.pop('cmap', 'viridis') npix = kwargs.pop('npix', 8) scale = kwargs.pop('scale', 1.0) Loading @@ -188,9 +199,23 @@ def plot_fit_map(itau, axes, datadir='.', what='sym', **kwargs): meta, _data = read_data(fname) if pix==center and meta and meta.get('title'): tit = meta.get('title') d[irow,icol] = meta.get(what, None) if what in ('fqt', 'updn'): amp = meta.get('amp', None) up = meta.get('up', None) dn = meta.get('dn', None) try: updn = up-dn if what=='fqt': res = 2*amp/updn if what=='updn': res = updn except (TypeError, ArithmeticError): res = None else: res = meta.get(what, None) d[irow,icol] = res img = axes.imshow(d/scale, extent=(0,npix, npix,0), interpolation='nearest') img = axes.imshow(d/scale, extent=(0,npix, npix,0), interpolation='nearest', cmap=cmap) return tit, img Loading @@ -209,28 +234,34 @@ def plot_fits(datadir, tau=1, npix=8, limy=(0.0,None), save=False, mark_pixels=T #nplot = rows*cols center = (npix+1)*npix//2 miny, maxy = limy _fig, axes = plt.subplots(npix,npix, figsize=(8,8)) plt.subplots_adjust(hspace=0.05, wspace=0.05) fig, axes = plt.subplots(npix,npix, figsize=(8,8)) fig.subplots_adjust(hspace=0.05, wspace=0.05) tit='' limits=[] for pix in range(npix**2): irow = pix % npix icol = pix // npix meta = plot_fit_pixel(tau, pix+1, axes[irow, icol] , miny=miny, maxy=maxy, datadir=datadir, xticks=False, yticks=False, mark_pixels=mark_pixels, **kwargs) if meta.get('limits'): limits.append(meta.get('limits')) if pix==center and meta and meta.get('title'): tit = meta.get('title') if pix%2: print(".", end="") sys.stdout.flush() tit = tit.split()[0] plt.suptitle("%s (%s echo[%s])" % (tit, datadir, tau), fontsize=12) basedir=os.path.normpath(datadir).split('/')[-1] fig.suptitle(f"{tit} ({basedir}/echo[{tau}])", fontsize=12) if save: save_fig(datadir, "", "-%02d" % tau) fig.savefig(save_file(datadir, "", "-%02d" % tau)) limits = np.asarray(limits) print(" done.") print(f"yrange=({np.min(limits):.4g},{np.max(limits):.4g})") def plot_maps(datadir, tau=1, npix=8, limz=(None,None), what='sym', scale=1.0, save=False): def plot_maps(datadir, tau=1, npix=8, limz=(None,None), what='sym', scale=1.0, save=False, cmap='viridis'): """ Plot maps """ Loading @@ -240,20 +271,21 @@ def plot_maps(datadir, tau=1, npix=8, limz=(None,None), what='sym', scale=1.0, s print("plotting maps tau=%-s" % tau, end="") minz, maxz = limz _fig, ax = plt.subplots() fig, ax = plt.subplots() t, img = plot_fit_map(tau, ax, datadir=datadir, what=what, scale=scale, npix=npix) t, img = plot_fit_map(tau, ax, datadir=datadir, what=what, scale=scale, npix=npix, cmap=cmap) tit = t.split()[0] img.set_clim(minz, maxz) plt.colorbar(img, ax=ax) plt.suptitle("%s (%s/%s[%s])" % (tit, datadir, what, tau), fontsize=12) #plt.colorbar(img, ax=ax) cbar = fig.colorbar(img, ax=ax) basedir=os.path.normpath(datadir).split('/')[-1] fig.suptitle(f"{tit} ({basedir}/{what}[{tau}])", fontsize=12) if save: save_fig(datadir, "maps_", "-%02d" % tau) fig.savefig(save_file(datadir, "maps_", "-%02d" % tau)) print(" done.") def find_minmax(datadir, tau=None): "find min and max" if tau: Loading