def plotparams(datapath,indch): # read in the files geofile = os.path.join(datapath,'Fitted','fitteddataGEOD.h5') acffile = os.path.join(datapath,'ACF','00lags.h5') geod = GeoData.read_h5(geofile) acfIono = IonoContainer.readh5(acffile) picklefile = os.path.join(datapath,'config.ini') (sensdict,simparams) = readconfigfile(picklefile) #determine the ind dataloc = geod.dataloc rngloc = 210 ind = sp.argmin(sp.absolute(dataloc[:,0]-rngloc)) # Ne = geod.data['Ne'][ind] Ti = geod.data['Ti'][ind] Te = geod.data['Te'][ind] #make a spectrum npts = 128 datablock = sp.array([[Ne[indch],Ti[indch]],[Ne[indch],Te[indch]]]) specobj = ISRSpectrum(centerFrequency =sensdict['fc'],nspec = npts,sampfreq=sensdict['fs']) (omeg,specexample,rcs) = specobj.getspecsep(datablock,simparams['species'],rcsflag=True) specexample = rcs*npts*specexample/sp.absolute(specexample).sum() acf = acfIono.Param_List[ind,indch] origspec = scfft.fftshift(scfft.fft(acf,n=npts)).real (figmplf, [[ax1,ax2],[ax3,ax4]]) = plt.subplots(2, 2,figsize=(16, 12), facecolor='w') ax1.plot(sp.arange(len(Ne)),Ne) ax1.set_title('$N_e$') ax2.plot(sp.arange(len(Ti)),Ti) ax2.set_title('$T_i$') ax3.plot(sp.arange(len(Te)),Te) ax3.set_title('$T_e$'); spec1 = ax4.plot(omeg*1e-3,origspec,label='Measured') spec2 = ax4.plot(omeg*1e-3,specexample,label='Fitted') ax4.set_title('Measured and Fitted Spectrums') ax4.set_xlabel('Frequency KHz') ax4.legend(loc = 1) # Nevals = sp.linspace(5e10,5e11,10) # Tivals = sp.linspace(1e3,2e5,10) # Tevals = sp.linspace(1e3,2e5,10) # xlist = [[1],Tivals,Nevals,Tevals,[0]] # outsurf = makefitsurf(xlist,acf,sensdict,simparams) return(figmplf)
def main(allskydir,ionofdir,plotdir,latlim2,lonlim2,wl,tint,reinterp=False,timelim=[-sp.infty,sp.infty]): """ This is the main function for plot data. This function will determine what is to be plotted and call all of the spatial and time regestration programs from GeoData. Inputs allskydir - The directory that holds the FITS files for the allsky data. If a None is passed then a the allsky is not plotted. ionofdir - The directory that holds all of the ionofiles. If a None is passed then a the allsky is not plotted. plotdir - The directory where the plots are stored. wl - The wavelength of the allsky light tint - The number of minutes the GPS data is plotted over. Default is 5. reinterp - A bool that determines if the GeoData files for the optical data should be remade. timelim - A list that shows the time boundaries in posix.""" wl = str(int(wl)) #%% Make map fig,ax,m=setupmap(latlim2,lonlim2) isallsky=False isgps = False TECtime = None if ionofdir is not None: isgps=True TEClist = [] TECfiles = glob.glob(os.path.join(ionofdir,'*.iono')) if not TECfiles: raise IOError('found no TEC files in {}'.format(ionofdir)) print('found {} .iono files in {}'.format(len(TECfiles),ionofdir)) for i,ifile in enumerate(TECfiles): print('processing {}/{} {} '.format(i+1,len(TECfiles),ifile)) TECGD = GeoData(readIonofiles,(ifile,)) if timelim is not None: TECGD.timereduce(timelim) if len(TECGD.times)==0: continue TEClist.append(TECGD) if TECtime is not None: TECtime[0] = min(TECGD.times[:,0].min(), TECtime[0]) TECtime[1] = max(TECGD.times[:,0].max(), TECtime[1]) else: TECtime = [TECGD.times[:,0].min(), TECGD.times[:,0].max()] if allskydir is not None: isallsky=True wlstr ='*_0'+wl+'_*.FITS' interpsavedfile = os.path.join(allskydir,'interp'+wl+'.h5') if reinterp or (not os.path.isfile(interpsavedfile)): flist558 = glob.glob(os.path.join(allskydir,wlstr)) if not flist558: raise IOError('no allsky files found in {}'.format(allskydir)) print(('{} allsky files found in {}'.format(len(flist558),allskydir))) allsky_data = GeoData(readAllskyFITS, (flist558, ('PKR_20111006_AZ_10deg.FITS','PKR_20111006_EL_10deg.FITS'), 150.)) if timelim is not None: allsky_data.timereduce(timelim) # reduce the size of the allskydata allskytime = allsky_data.times[:,0] allsky_data=allsky_data.timeslice(sp.where((allskytime>=TECtime[0]) & (allskytime<TECtime[1]))[0]) allskytime=allsky_data.times[:,0] xcoords = allsky_data.__changecoords__('WGS84') latlim=[xcoords[:,0].min(),xcoords[:,0].max()] lonlim=[xcoords[:,1].min(),xcoords[:,1].max()] nlat = 256 nlon = 256 latvec = sp.linspace(latlim[0],latlim[1],nlat) lonvec = sp.linspace(lonlim[0],lonlim[1],nlon) [LATM,LONM] = sp.meshgrid(latvec,lonvec) newcoords = sp.column_stack((LATM.ravel(),LONM.ravel(),150.*sp.ones(LONM.size))) allsky_data.interpolate(newcoords,'WGS84',method='linear',twodinterp=True) print('writing {}'.format(interpsavedfile)) allsky_data.write_h5(interpsavedfile) else: allsky_data = GeoData.read_h5(interpsavedfile) if timelim is not None: allsky_data.timereduce(timelim) allskytime=allsky_data.times[:,0] #%% make lists for plotting tectime = sp.arange(TECtime[0],TECtime[1],60.*tint) nptimes= tectime.size if isallsky and isgps: allskylist = [] gpslist = [] tlistkeep = sp.zeros(nptimes-1,dtype=bool) for itasn in range(nptimes-1): techlist = [] tlistemp=True itback=tectime[itasn] itfor = tectime[itasn+1] itas = sp.where((allskytime>=itback) & (allskytime<itfor))[0] if len(itas)==0: itas = sp.where(allskytime<=itback)[0] if len(itas)==0: continue itas = [itas[-1]] for k in range(len(TEClist)): Geoone=TEClist[k]; timevec = Geoone.times[:,0]; itgps = sp.where((timevec>=itback) & (timevec<itfor))[0] if len(itgps)>0: tlistemp=False techlist.append(itgps) if tlistemp: continue allskylist.append(itas) gpslist.append(techlist) tlistkeep[itasn]=True plotgpswoptics(allsky_data,TEClist,allskylist,gpslist,plotdir,m,ax,fig,latlim2,lonlim2) elif isgps: gpslist = [] tlistkeep = sp.zeros(nptimes-1,dtype=bool) for itasn in range(nptimes-1): techlist = [] tlistemp=True itback=tectime[itasn] itfor = tectime[itasn+1] for k in range(len(TEClist)): Geoone=TEClist[k]; timevec = Geoone.times[:,0]; itgps = sp.where((timevec>=itback)& (timevec<itfor))[0] if len(itgps)>0: tlistemp=False techlist.append(itgps) if tlistemp: continue gpslist.append(techlist) tlistkeep[itasn]=True plotgpsonly(TEClist,gpslist,plotdir,m,ax,fig,latlim2,lonlim2) elif isallsky: plotopticsonly(allsky_data,plotdir,m,ax,fig,latlim2,lonlim2) plt.close(fig)
def ISRRead(self,ISRloc): """ This function will read in the ISR data from SRI files or structured h5 files for GeoData. It will assign the class variable GDISR to the resultant GeoData object. Input ISRloc - This can be either a file from SRI or an h5 file thats been pre interpolated. """ if ISRloc is None: return ISRloc = Path(ISRloc).expanduser() if not ISRloc.is_file(): print('ISR Data is not a file') return self.numGD+=1 print('Reading in ISR Data') pnheights= self.params['paramheight'] paramstr = list(set([i[0] for i in pnheights])) try: SRIh5 = GeoData(readSRI_h5,(ISRloc,paramstr)) except Exception: try: SRIh5 = GeoData.read_h5(ISRloc) except Exception: return dt1ts,dt2ts = self.params['timebounds'] timelist = sp.where((SRIh5.times[:,1]>=dt1ts)&(SRIh5.times[:,0]<=dt2ts))[0] if len(timelist)==0: return SRIh5 = SRIh5.timeslice(timelist) hset = sp.array([i[1] for i in pnheights]) uh,uhs =sp.unique(hset,return_inverse=True) uh=uh*1e3 newcoordname = 'WGS84' if not (SRIh5.coordnames.lower() == newcoordname.lower()): changed_coords = SRIh5.__changecoords__(newcoordname) latmin,latmax = [changed_coords[:,0].min(),changed_coords[:,0].max()] lonmin,lonmax = [changed_coords[:,1].min(),changed_coords[:,1].max()] latvec = sp.linspace(latmin,latmax,self.params['ISRLatnum']) lonvec = sp.linspace(lonmin,lonmax,self.params['ISRLonnum']) LON,LAT = sp.meshgrid(lonvec,latvec) xycoords = sp.column_stack([LAT.flatten(),LON.flatten()]) # interpolation ncoords = xycoords.shape[0] uhall = sp.repeat(uh,ncoords) coords = sp.tile(xycoords,(len(uh),1)) coords = sp.column_stack((coords,uhall)) SRIh5.interpolate(coords,newcoordname,method='linear') self.GDISR = SRIh5 print('Finished Reading in ISR Data')
def ASRead(self,ASloc): """ This function will read in the All sky data from FITS files or structured h5 files for GeoData. Input ASloc - This can be either a directory holding the FITS files or a h5 file thats been pre interpolated. It will assign the class variable GDAS to the resultant GeoData object.""" if ASloc is None: return ASloc = Path(ASloc).expanduser() if not ASloc.is_dir() and not ASloc.is_file(): print('All Sky Data cannot be read') return self.numGD+=1 print('Reading in All sky data') wl = str(int(self.params['wl'])) wlstr ='*_0'+wl+'_*.FITS' interpsavedfile = ASloc/('interp'+wl+'.h5') reinterp=self.params['reinterp'] timelim=self.params['timebounds'] if self.nointerp: flist558 = sorted(ASloc.glob(wlstr)) self.GDAS = GeoData(readAllskyFITS,(flist558, ('PKR_DASC_20110112_AZ_10deg.FITS', 'PKR_DASC_20110112_EL_10deg.FITS'), 150.,timelim)) return if reinterp or not ASloc.is_file(): # pfalla = sp.array([65.136667,-147.447222,689.]) flist558 = sorted(ASloc.glob(wlstr)) if not flist558: return allsky_data = GeoData(readAllskyFITS,(flist558,('PKR_DASC_20110112_AZ_10deg.FITS','PKR_DASC_20110112_EL_10deg.FITS'),150.,timelim)) if timelim is not None: allsky_data.timereduce(timelim) xcoords = allsky_data.__changecoords__('WGS84') latlim=[xcoords[:,0].min(),xcoords[:,0].max()] lonlim=[xcoords[:,1].min(),xcoords[:,1].max()] nlat = 256 nlon = 256 latvec = sp.linspace(latlim[0],latlim[1],nlat) lonvec = sp.linspace(lonlim[0],lonlim[1],nlon) [LATM,LONM] = sp.meshgrid(latvec,lonvec) newcoords = sp.column_stack((LATM.flatten(),LONM.flatten(),150.*sp.ones(LONM.size))) allsky_data.interpolate(newcoords,'WGS84',method='linear',twodinterp=True) allsky_data.write_h5(interpsavedfile) else: allsky_data = GeoData.read_h5(ASloc) if timelim is not None: allsky_data.timereduce(timelim) self.GDAS = allsky_data print('Finished Reading in Allsky Data')