def plotsummary(results, positions,deciX=1,deciY=1,title='',savefile=None): """ Plot results Inputs: 1. results, a pandas DataFrame 2. Positions, a list of depth positions 3. use every deciX sample along depth 4. use every deciY sample along time 5. title for the plots 6. save file name """ import pyradi.ryplot as ryplot from matplotlib import cm df = results.loc[positions,:] Z = results.T.values Z = Z[:-1:deciY,:-1:deciX] Xv = np.asarray(results.index[0:-1:deciX]) Yv = np.asarray(results.columns[0:-1:deciY]) maxtime = np.max(Yv) if maxtime > 50*24*60*60: timeStr = 'Time Years' Yv = Yv / (365.25*24*60*60) elif maxtime > 20*24*60*60: timeStr = 'Time Weeks' Yv = Yv / (7*24*60*60) elif maxtime > 3*24*60*60: timeStr = 'Time Days' Yv = Yv / (24*60*60) elif maxtime > 3*60*60: timeStr = 'Time Hours' Yv = Yv / (60*60) elif maxtime > 3*60: timeStr = 'Time Minutes' Yv = Yv / (60) else : timeStr = 'Time Seconds' X, Y = np.meshgrid(Xv, Yv) samples = df.values[:,0:-1:deciY] p = ryplot.Plotter(1,1,1,figsize=(10,16),doWarning=False) p.mesh3D(1,X,Y,Z,title,'Depth m',timeStr,'Temperature K',xInvert=True,yInvert=True,cmap=cm.seismic) if savefile is not None: fname = savefile.replace('.png','-3D.png') p.saveFig(f'{fname}') miny = np.min(samples) maxy = np.max(samples) q = ryplot.Plotter(2,1,1,figsize=(10,6),doWarning=False) for ix,(index, row) in enumerate(df.iterrows()): q.plot(1,Yv,samples[ix,:],title,timeStr,'Temperature K', pltaxis=[0,np.max(Yv),miny,maxy],label=[f'depth={positions[ix]:0.2f} m'],xAxisFmt='%.2f',maxNX=11) if savefile is not None: fname = savefile.replace('.png','-T.png') q.saveFig(f'{fname}')
def plotTau(alts, dirs): #first plot the different altitudes for each atmosphere for i, directory in enumerate(dirs): p = ryplot.Plotter(i, 1, 1, figsize=(12, 6)) for alt in alts: datadir = os.path.join('.', directory, '{}'.format(alt)) filename = '{}-{}m.1km'.format(directory, alt) data = np.loadtxt(os.path.join(datadir, filename), skiprows=1) p.plot(1, data[:, 0], data[:, 1], '{} {} 1 km transmittance, 135 deg zenith'.format( directory, directory), 'Wavelength $\mu$m', 'Transmittance', label=['{} m'.format(alt)], legendAlpha=0.5) p.saveFig(os.path.join('.', directory, '{}.png'.format(directory))) #now plot the different altitudes for each altitude for alt in alts: p = ryplot.Plotter(i, 1, 1, figsize=(12, 6)) for i, directory in enumerate(dirs): datadir = os.path.join('.', directory, '{}'.format(alt)) filename = '{}-{}m.1km'.format(directory, alt) data = np.loadtxt(os.path.join(datadir, filename), skiprows=1) p.plot( 1, data[:, 0], data[:, 1], '{} m altitude, 135 deg zenith 1 km transmittance'.format(alt), 'Wavelength $\mu$m', 'Transmittance', label=['{} {}'.format(directory, directory)], legendAlpha=0.5) p.saveFig(os.path.join('.', 'AllScen-{}m.png'.format(alt)))
print(rgb) print('xy values from sRGB RGB values:') print(xy) rgbn = CIExy2rgb(xy,system='sRGB') * np.max(rgb) print('RGB values (recomputed from xy):') print(rgbn.astype('int')) print(60*'*') if doAll: ## ----------------------load ciebar ----------------------------------- ciebarwl = loadCIEbar(wavelength, stype='wl') ciebarwn = loadCIEbar(wavenum, stype='wn') cietriplt = ryplot.Plotter(1, 2, 2, figsize=(12,6)) cietriplt.plot(1, ciebarwl[:,0], ciebarwl[:,1:4], "CIE tristimulus values, wl input", r'Wavelength $\mu$m', r'Response', plotCol = ['r','g','b'], label=['$\\bar{x}$', '$\\bar{y}$', '$\\bar{z}$'],legendAlpha=0.5); cietriplt.plot(2, 1e4/ciebarwl[:,0], ciebarwl[:,1:4], "CIE tristimulus values, wl input", r'Wavenumber cm$^{-1}$', r'Response', plotCol = ['r','g','b'], label=['$\\bar{x}$', '$\\bar{y}$', '$\\bar{z}$'],legendAlpha=0.5,maxNX=5); cietriplt.plot(3, 1e4/ciebarwn[:,0], ciebarwn[:,1:4], "CIE tristimulus values, wn input", r'Wavelength $\mu$m', r'Response', plotCol = ['r','g','b'], label=['$\\bar{x}$', '$\\bar{y}$', '$\\bar{z}$'],legendAlpha=0.5); cietriplt.plot(4, ciebarwn[:,0], ciebarwn[:,1:4], "CIE tristimulus values, wn input", r'Wavenumber cm$^{-1}$', r'Response', plotCol = ['r','g','b'], label=['$\\bar{x}$', '$\\bar{y}$', '$\\bar{z}$'],legendAlpha=0.5,maxNX=5); cietriplt.saveFig('cieBAR'+figtype)
"data/tape7-05", ['FREQ', 'TOT_TRANS', 'PTH_THRML', 'SURF_EMIS', 'TOTAL_RAD']) np.savetxt('tape7-05.txt', tape7, fmt=str('%.6e')) tape7 = loadtape7( "data/tape7-05b", ['FREQ', 'TOT_TRANS', 'PTH_THRML', 'SURF_EMIS', 'TOTAL_RAD']) np.savetxt('tape7-05b.txt', tape7, fmt=str('%.6e')) if doAll: colSelect = ['FREQ_CM-1', 'COMBIN_TRANS', 'H2O_TRANS', 'UMIX_TRANS', \ 'O3_TRANS', 'H2O_CONT', 'MOLEC_SCAT', 'AER+CLD_TRANS'] tape7 = loadtape7("data/tape7VISNIR5kmTrop23Vis", colSelect) wavelen = ryutils.convertSpectralDomain(tape7[:, 0], type='nl') mT = ryplot.Plotter(1, 1, 1,"Modtran Tropical, 23 km Visibility (Rural)"\ + ", 5 km Path Length",figsize=(12,6)) mT.plot(1, wavelen, tape7[:, 1:], "", "Wavelength [$\mu$m]", "Transmittance", label=colSelect[1:], legendAlpha=0.5, pltaxis=[0.4, 1, 0, 1], maxNX=10, maxNY=4, powerLimits=[-4, 4, -5, 5]) mT.saveFig('ModtranPlot.png') #mT.saveFig('ModtranPlot.eps')
def analyse_HDF5_image(imghd5,plotfile,gwidh=12,gheit=8): r"""Summarise the image properties and statistics Args: | imghd5 (handle to an open hdf5 file): file to be analysed | plotfile(string): filename for plot graphics | gwidh (float): graph width in inches | gheit (float): graph height in inches Returns: | nothing: as a side effect a set properties are written and graphs created Raises: | No exception is raised. Author: CJ Willers """ from scipy import stats import pyradi.ryplot #calculate and display values of these variables elements = ['image/imageFilename','image/imageName','image/filename','image/rad_dynrange', 'image/rad_min','image/irrad_dynrange','image/irrad_min','image/disk_diameter','image/blur', 'image/blur','image/steps','image/imtype','image/imageSizePixels','image/pixelPitch', 'image/imageSizeRows','image/imageSizeCols','image/imageSizeDiagonal', 'image/equivalentSignalType','image/equivalentSignalUnit','image/LinUnits','image/EinUnits', 'image/saveNoiseImage','image/saveEquivImage','image/joule_per_photon', 'image/conversion', ] for item in elements: if item in imghd5: print('{:30s} : {}'.format(item,imghd5[item].value)) # wavelength as scalar or vector print(imghd5) if isinstance( imghd5['image/wavelength'].value, float): print('{:30s} : {}'.format('wavelength',imghd5['image/wavelength'].value)) else: print('{:30s} : {}'.format('wavelength (mean)',np.mean(imghd5['image/wavelength'].value))) #calculate and display statistics of these variables elements = ['image/PhotonRateRadianceNoNoise','image/PhotonRateRadiance', 'image/PhotonRateIrradianceNoNoise','image/PhotonRateIrradiance','image/equivalentSignal' ] for item in elements: if item in imghd5: print('\nStatistics for {}:'.format(item)) print(stats.describe(imghd5[item].value,axis=None)) # plot the images p = ryplot.Plotter(1,3,1,plotfile, figsize=(gwidh,gheit)) for item in ['image/PhotonRateRadianceNoNoise','image/PhotonRateIrradianceNoNoise']: if item in imghd5: p.showImage(1,imghd5[item].value,item,cbarshow=True) for item in ['image/PhotonRateRadiance','image/PhotonRateIrradiance']: if item in imghd5: p.showImage(2,imghd5[item].value,item,cbarshow=True) if 'image/equivalentSignal' in imghd5: p.showImage(3,imghd5['image/equivalentSignal'].value,'image/equivalentSignal',cbarshow=True) p.saveFig('{}.png'.format(plotfile)) # plot interpolation function if 'image/interpolate_x' in imghd5: q = ryplot.Plotter(1,1,1,plotfile, figsize=(12,6)) q.plot(1,imghd5['image/interpolate_x'].value,imghd5['image/interpolate_y'].value) q.saveFig('{}-lookup.png'.format(plotfile)) print(50*'='+'\n\n')
################################################################################ if __name__ == '__init__': pass if __name__ == '__main__': pass """ In the model application, the user must define all the detector and semiconductor parameters. Each material type has its own paramenters, """ import pyradi.ryplot as ryplot #calculate the theoretical D* for a spectrally flat detector Tenvironment = np.linspace(1, 600, 100) Tdetector = [0, 77, 195, 290] dstarP = ryplot.Plotter(1, 1, 1, figsize=(5, 2)) for Tdetec in Tdetector: dStar = DstarSpectralFlatPhotonLim(Tdetec, Tenvironment, 1) dstarP.semilogY(1,Tenvironment,dStar,'',\ r'Environmental temperature [K]','D* [cm.\sqrt{Hz}/W]', pltaxis=[0, 600, 1e9, 1e13]) currentP = dstarP.getSubPlot(1) for xmaj in currentP.xaxis.get_majorticklocs(): currentP.axvline(x=xmaj, ls='-') for ymaj in currentP.yaxis.get_majorticklocs(): currentP.axhline(y=ymaj, ls='-') dstarP.saveFig('dstarFlat.eps') ###################################################################### # tempBack = np.asarray([1]) tempBack = np.asarray([1, 2, 4, 10, 25, 77, 195, 300, 500])
rows = 100 cols = 100 vartype = np.uint16 imagefile = 'data/sensornoise.raw' outfilename = 'sensornoise.txt' # load images framesToLoad = list(range(1, 21, 1)) frames, img = ryfiles.readRawFrames(imagefile, rows, cols, vartype, framesToLoad) if frames > 0: # show something P = ryplot.Plotter(1, 1, 1, 'Simulated noise', figsize=(12, 8)) P.showImage(1, img[0]) #P.getPlot().show() P.saveFig('rawframe0.png') outfile = open(outfilename, 'w') outfile.write('\n{0} Frames read from {1}\n'.format(frames, imagefile)) outfile.write('\nImage average S : {0:10.3f} \n'.format( getS(img))) outfile.write('Total system noise : {0:10.3f} \n\n'.format( getTotal(img))) outfile.write( 'Fixed/spatial noise | Temporal noise | Variation effect\n') outfile.write( '---------------------|---------------------|-----------------\n') outfile.write(
center=4.33, width=0.45, exponent=6, taupass=0.8, taustop=0.1) #construct the sensor filter from parameters sfilter = ryutils.sfilter(wavel, center=4.3, width=0.8, exponent=12, taupass=0.9, taustop=0.0001) #plot the data plot1 = ryplot.Plotter(1, 2, 2, 'Flame sensor', figsize=(24, 16)) plotdata = detR plotdata = numpy.hstack((plotdata, emis)) plotdata = numpy.hstack((plotdata, sfilter)) plotdata = numpy.hstack((plotdata, tauA)) label = ['Detector', 'Emissivity', 'Filter', 'Atmosphere transmittance'] plot1.plot(1, wavel, plotdata, "Spectral", "Wavelength [$\mu$m]", "Relative magnitude", label=label, maxNX=10, maxNY=10)
# see also reference images at http://sipi.usc.edu/database/ import numpy as np import Image import pyradi.ryplot as ryplot import pyradi.ryutils as ryutils if __name__ == '__main__': # im = Image.open('lena512color.png') im = Image.open('600px-Siemens_star-blurred.png').convert('RGB') # im = im.convert('RGB') data = np.array(im) """Plots an image reprojected into polar coordinages with the origin at "origin" (a tuple of (x0, y0), defaults to the center of the image)""" print(data.shape) origin = None #(300,350) pim = ryplot.ProcessImage() polar_grid, r, theta = pim.reproject_image_into_polar(data, origin, False) p = ryplot.Plotter(1, 1, 2) p.showImage(1, data, ptitle='Image') p.showImage(2, polar_grid, ptitle='Image in Polar Coordinates', xlabel='Angle', ylabel='Radial') p.saveFig('warpedStar.png') print('done')