def GPSRead(self,GPSloc): """ This function will read in the GPS data from ionofiles. It will assign the class variable GDGPS to the resultant GeoData object. Input GPSloc - The directory that holds all of the iono/h5 GeoData files. Can also be the filename of a mahali gps file """ self.numGD+=1 if GPSloc is None: return GPSloc = Path(GPSloc).expanduser() timelim=self.params['timebounds'] TEClist = [] ish5file = GPSloc.is_file() and GPSloc.suffix=='.h5' if ish5file: print('Reading in GPS Data') f = h5py.File(GPSloc, "r", libver='latest') siteinfo = f['sites'].value GPSNames = [i[0] for i in siteinfo] for isite in GPSNames: try: TECGD = GeoData(readMahalih5,(GPSloc,isite)) except Exception: TECGD = read_h5(os.path.join(GPSloc,isite)) if timelim is not None: TECGD.timereduce(timelim) if len(TECGD.times)==0: continue TEClist.append(TECGD) self.GPSNames = GPSNames self.GDGPS = TEClist print('Finished Reading in GPS Data') elif GPSloc.is_dir(): print('Reading in GPS Data') # Read in either iono files or h5 files TECfiles = GPSloc.glob('*.iono') funcname = readIonofiles if len(TECfiles) == 0: TECfiles = GPSloc.glob('*.h5') funcname = read_h5_main for ifile in TECfiles: TECGD = GeoData(funcname, str(ifile)) if timelim is not None: TECGD.timereduce(timelim) if len(TECGD.times)==0: continue TEClist.append(TECGD) # Determine the receiver names self.GPSNames = [os.path.splitext(os.path.split(i)[-1])[0].split('-')[0] for i in TECfiles] self.GDGPS = TEClist print('Finished Reading in GPS Data') else: print('GPS path is not a directory') return
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 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')