예제 #1
0
def test_resident():
    from memory import resident

    mem = resident()
    assert (isinstance(mem, float))
    assert (mem > -1e-6)

    mem = resident(children=True)
    assert (isinstance(mem, float))
    assert (mem > -1e-6)
예제 #2
0
 def __init__(self):
     self.tstart = process_time()
     self.tlast = self.tstart
     self.mstart = memory.resident(children=True)
     self.mlast = self.mstart
     self.verbosity = self.verbosity_levels.low
     self.indent = 0
예제 #3
0
def get_memory():
    result = {}
    f = open("/proc/meminfo")
    data = f.readlines()
    f.close()
    KB = 1024.0
    memtotal = int(data[0].split()[1]) / KB
    memfree = int(data[1].split()[1]) / KB
    result['total'] = memtotal
    result['free'] = memfree
    result['used'] = memtotal - memfree
    result['self-resident'] = memory.resident() / memory.MB
    result['self-memory'] = memory.memory() / memory.MB
    return result
예제 #4
0
def get_memory():
	result = {}
	f = open("/proc/meminfo")
	data = f.readlines()
	f.close()
	KB = 1024.0
	memtotal = int(data[0].split()[1]) / KB
	memfree = int(data[1].split()[1]) / KB
	result['total'] = memtotal
	result['free'] = memfree
	result['used'] = memtotal-memfree
	result['self-resident'] = memory.resident() / memory.MB
	result['self-memory'] = memory.memory() / memory.MB
	return result
예제 #5
0
 def run_project(self, status=False, status_only=False):
     self.log('\nProject starting', n=0)
     self.init_cascades()
     status_only = status_only or self.status_only
     status = status or status_only
     if status:
         self.write_simulation_status()
         if status_only:
             return
         #end if
     #end if
     self.log('\nstarting runs:\n' + 30 * '~', n=1)
     if self.dependent_modes <= self.stages_set:
         if self.monitor:
             ipoll = 0
             while len(self.progressing_cascades) > 0:
                 self.dlog('\n\n\n' + 70 * '=', n=1)
                 self.log('poll',
                          ipoll,
                          ' memory %3.2f MB' % (memory.resident() / 1e6),
                          n=1)
                 Pobj.wrote_something = False
                 self.dlog('cascades',
                           self.progressing_cascades.keys(),
                           n=2)
                 ipoll += 1
                 self.machine.query_queue()
                 self.progress_cascades()
                 self.machine.submit_jobs()
                 self.update_process_ids()
                 self.dlog('sleeping', self.sleep, n=2)
                 time.sleep(self.sleep)
                 self.dlog('awake', n=2)
                 if Pobj.wrote_something:
                     self.log()
                 #end if
             #end while
         elif len(self.progressing_cascades) > 0:
             self.machine.query_queue()
             self.progress_cascades()
             self.machine.submit_jobs()
             self.update_process_ids()
         #end if
     else:
         self.progress_cascades()
     #end if
     self.log('Project finished\n')
예제 #6
0
 def run_project(self, status=False, status_only=False):
     self.log('\nProject starting', n=0)
     self.init_cascades()
     status_only = status_only or nexus_core.status_only
     status = status or status_only or nexus_core.status != nexus_core.status_modes.none
     if status:
         self.write_simulation_status()
         if status_only:
             NexusCore.write_end_splash()
             return
         #end if
     #end if
     self.log('\nstarting runs:\n' + 30 * '~', n=1)
     if nexus_core.dependent_modes <= nexus_core.stages_set:
         if nexus_core.monitor:
             start_time = time.time()
             ipoll = 0
             while len(self.progressing_cascades) > 0:
                 elapsed_time = time.time() - start_time
                 self.log('elapsed time %.1f s' % elapsed_time,
                          ' memory %3.2f MB' %
                          (memory.resident(children=True) / 1e6),
                          n=1,
                          progress=True)
                 NexusCore.wrote_something = False
                 ipoll += 1
                 self.machine.query_queue()
                 self.progress_cascades()
                 self.machine.submit_jobs()
                 self.update_process_ids()
                 time.sleep(nexus_core.sleep)
                 if NexusCore.wrote_something:
                     self.log()
                 #end if
             #end while
         elif len(self.progressing_cascades) > 0:
             self.machine.query_queue()
             self.progress_cascades()
             self.machine.submit_jobs()
             self.update_process_ids()
         #end if
     else:
         self.progress_cascades()
     #end if
     self.log('Project finished\n')
     NexusCore.write_end_splash()
예제 #7
0
 def run_project(self,status=False,status_only=False):
     self.log('\nProject starting',n=0)
     self.init_cascades()
     status_only = status_only or self.status_only
     status = status or status_only
     if status:
         self.write_simulation_status()
         if status_only:
             return
         #end if
     #end if
     self.log('\nstarting runs:\n'+30*'~',n=1)
     if self.dependent_modes <= self.stages_set:
         if self.monitor:
             ipoll = 0
             while len(self.progressing_cascades)>0:
                 self.dlog('\n\n\n'+70*'=',n=1)
                 self.log('poll',ipoll,' memory %3.2f MB'%(memory.resident()/1e6),n=1)
                 Pobj.wrote_something = False
                 self.dlog('cascades',self.progressing_cascades.keys(),n=2)
                 ipoll+=1
                 self.machine.query_queue()
                 self.progress_cascades()
                 self.machine.submit_jobs()
                 self.update_process_ids()
                 self.dlog('sleeping',self.sleep,n=2)
                 time.sleep(self.sleep)
                 self.dlog('awake',n=2)
                 if Pobj.wrote_something:
                     self.log()
                 #end if
             #end while
         elif len(self.progressing_cascades)>0:
             self.machine.query_queue()
             self.progress_cascades()
             self.machine.submit_jobs()
             self.update_process_ids()
         #end if
     else:
         self.progress_cascades()
     #end if
     self.log('Project finished\n')
예제 #8
0
 def run_project(self, status=False, status_only=False):
     self.log("\nProject starting", n=0)
     self.init_cascades()
     status_only = status_only or self.status_only
     status = status or status_only
     if status:
         self.write_simulation_status()
         if status_only:
             return
         # end if
     # end if
     self.log("\nstarting runs:\n" + 30 * "~", n=1)
     if self.dependent_modes <= self.stages_set:
         if self.monitor:
             ipoll = 0
             while len(self.progressing_cascades) > 0:
                 self.dlog("\n\n\n" + 70 * "=", n=1)
                 self.log("poll", ipoll, " memory %3.2f MB" % (memory.resident() / 1e6), n=1)
                 Pobj.wrote_something = False
                 self.dlog("cascades", self.progressing_cascades.keys(), n=2)
                 ipoll += 1
                 self.machine.query_queue()
                 self.progress_cascades()
                 self.machine.submit_jobs()
                 self.dlog("sleeping", self.sleep, n=2)
                 time.sleep(self.sleep)
                 self.dlog("awake", n=2)
                 if Pobj.wrote_something:
                     self.log()
                 # end if
             # end while
         elif len(self.progressing_cascades) > 0:
             self.machine.query_queue()
             self.progress_cascades()
             self.machine.submit_jobs()
         # end if
     else:
         self.progress_cascades()
     # end if
     self.log("Project finished\n")
예제 #9
0
 def __call__(self,msg,level='low',n=0,time=False,mem=False,width=75):
     if self.verbosity==self.verbosity_levels.none:
         return
     elif self.verbosity >= self.verbosity_levels[level]:
         if mem or time:
             npad = max(0,width-2*(n+self.indent)-len(msg)-36)
             if npad>0:
                 msg += npad*' '
             #end if
             if mem:
                 dm = 1e6 # MB
                 mnow = memory.resident(children=True)
                 msg += '  (mem add {:6.2f}, tot {:6.2f})'.format((mnow-self.mlast)/dm,(mnow-self.mstart)/dm)
                 self.mlast = mnow
             #end if
             if time:
                 tnow = process_time()
                 msg += '  (t elap {:7.3f}, tot {:7.3f})'.format(tnow-self.tlast,tnow-self.tstart)
                 self.tlast = tnow
             #end if
         #end if
         log(msg,n=n+self.indent)
예제 #10
0
 def mem_usage(self):
     return int(resident() / 1e6)
예제 #11
0
 def mem_usage(self):
     return int(resident()/1e6)
예제 #12
0
def main():
    parser = optparse.OptionParser(prog="sp_pipeline..py", \
                        version=" Chitrang Patel (May. 12, 2015)", \
                        usage="%prog INFILE(PsrFits FILE, SINGLEPULSE FILES)", \
                        description="Create single pulse plots to show the " \
                                    "frequency sweeps of a single pulse,  " \
                    "DM vs time, and SNR vs DM,"\
                                    "in psrFits data.")
    parser.add_option('--infile', dest='infile', type='string', \
                        help="Give a .inf file to read the appropriate header information.")
    parser.add_option('--groupsfile', dest='txtfile', type='string', \
                        help="Give the groups.txt file to read in the groups information.") 
    parser.add_option('--mask', dest='maskfile', type='string', \
                        help="Mask file produced by rfifind. (Default: No Mask).", \
                        default=None)
    options, args = parser.parse_args()
    if not hasattr(options, 'infile'):
        raise ValueError("A .inf file must be given on the command line! ") 
    if not hasattr(options, 'txtfile'):
        raise ValueError("The groups.txt file must be given on the command line! ") 
    
    files = get_textfile(options.txtfile)
    print_debug("Begining waterfaller... "+strftime("%Y-%m-%d %H:%M:%S"))
    Detrendlen = 50
    if not args[0].endswith("fits"):
        raise ValueError("The first file must be a psrFits file! ") 
    basename = args[0][:-5]
    filetype = "psrfits"
    inffile = options.infile
    topo, bary = bary_and_topo.bary_to_topo(inffile)
    time_shift = bary-topo
    inf = infodata.infodata(inffile)
    RA = inf.RA
    dec = inf.DEC
    MJD = inf.epoch
    mjd = Popen(["mjd2cal", "%f"%MJD], stdout=PIPE, stderr=PIPE)
    date, err = mjd.communicate()
    date = date.split()[2:5]
    telescope = inf.telescope
    N = inf.N
    Total_observed_time = inf.dt *N
    print_debug('getting file..')
    rawdatafile = psrfits.PsrfitsFile(args[0])
    print "rawdatafile",memory.resident()/(1024.0**3)
    bin_shift = np.round(time_shift/rawdatafile.tsamp).astype('int')
    for group in [6,5,4,3,2]:
        rank = group+1
        if files[group] != "Number of rank %i groups: 0 "%rank:
            print_debug(files[group])
            values = split_parameters(rank, options.txtfile)
            lis = np.where(files == '\tRank:             %i.000000'%rank)[0]
            for ii in range(len(values)):
                #### Array for Plotting DM vs SNR
                print "DM, S/N",memory.resident()/(1024.0**3)
                print_debug("Making arrays for DM vs Signal to Noise...")
                temp_list = files[lis[ii]-6].split()
                npulses = int(temp_list[2])
                temp_lines = files[(lis[ii]+3):(lis[ii]+npulses+1)]
                arr = np.split(temp_lines, len(temp_lines))
                dm_list = []
                time_list = []
                for i in range(len(arr)):
                    dm_val= float(arr[i][0].split()[0])
                    time_val = float(arr[i][0].split()[2])
                    dm_list.append(dm_val)
                    time_list.append(time_val)
                arr_2 = np.array([arr[i][0].split() for i in range(len(arr))], dtype = np.float32)
                dm_arr = np.array([arr_2[i][0] for i in range(len(arr))], dtype = np.float32)
                sigma_arr = np.array([arr_2[i][1] for i in range(len(arr))], dtype = np.float32)
                print "After DM, S/N",memory.resident()/(1024.0**3)


                #### Array for Plotting DM vs Time is in show_spplots.plot(...)

                
                #### Setting variables up for the waterfall arrays.
                j = ii+1
                subdm = dm = sweep_dm= values[ii][0]
                integrate_dm = None
                sigma = values[ii][1]
                sweep_posn = 0.0
                topo_start_time = values[ii][2] - topo_timeshift(values[ii][2], time_shift, topo)[0]
                sample_number = values[ii][3]
                width_bins = values[ii][4]
                binratio = 50
                scaleindep = False
                zerodm = None
                downsamp = np.round((values[ii][2]/sample_number/6.54761904761905e-05)).astype('int')
                duration = binratio * width_bins * rawdatafile.tsamp * downsamp
                start = topo_start_time - (0.25 * duration)
                if (start<0.0):
                    start = 0.0
                pulse_width = width_bins*downsamp*6.54761904761905e-05
                if sigma <= 10:
                    nsub = 32
                elif sigma >= 10 and sigma < 15:
                    nsub = 64
                else:
                    nsub = 96
                nbins = np.round(duration/rawdatafile.tsamp).astype('int')
                start_bin = np.round(start/rawdatafile.tsamp).astype('int')
                dmfac = 4.15e3 * np.abs(1./rawdatafile.frequencies[0]**2 - 1./rawdatafile.frequencies[-1]**2)
                nbinsextra = np.round((duration + dmfac * dm)/rawdatafile.tsamp).astype('int')
                if (start_bin+nbinsextra) > N-1:
                    nbinsextra = N-1-start_bin
                data = rawdatafile.get_spectra(start_bin, nbinsextra)
                print "After rawdata",memory.resident()/(1024.0**3)
                data = maskdata(data, start_bin, nbinsextra, options.maskfile)
                #make an array to store header information for the .npz files
                temp_filename = basename+"_DM%.1f_%.1fs_rank_%i"%(subdm, topo_start_time, rank)
                # Array for Plotting Dedispersed waterfall plot - zerodm - OFF
                print_debug("Running waterfaller with Zero-DM OFF...")
                data, Data_dedisp_nozerodm = waterfall_array(start_bin, dmfac, duration, nbins, zerodm, nsub, subdm, dm, integrate_dm, downsamp, scaleindep, width_bins, rawdatafile, binratio, data)
                print "waterfall",memory.resident()/(1024.0**3)
                # Add additional information to the header information array
                text_array = np.array([args[0], 'Arecibo', RA, dec, MJD, rank, nsub, nbins, subdm, sigma, sample_number, duration, width_bins, pulse_width, rawdatafile.tsamp, Total_observed_time, topo_start_time, data.starttime, data.dt, data.numspectra, data.freqs.min(), data.freqs.max()])

                #### Array for plotting Dedispersed waterfall plot zerodm - ON
                print_debug("Running Waterfaller with Zero-DM ON...")
                data = rawdatafile.get_spectra(start_bin, nbinsextra)
                data = maskdata(data, start_bin, nbinsextra, options.maskfile)
                zerodm = True
                data, Data_dedisp_zerodm = waterfall_array(start_bin, dmfac, duration, nbins, zerodm, nsub, subdm, dm, integrate_dm, downsamp, scaleindep, width_bins, rawdatafile, binratio, data)
                print "waterfall",memory.resident()/(1024.0**3)
                ####Sweeped without zerodm
                print_debug("Running waterfaller for sweeped arrays.")
                start = start + (0.25*duration)
                start_bin = np.round(start/rawdatafile.tsamp).astype('int')
                sweep_duration = 4.15e3 * np.abs(1./rawdatafile.frequencies[0]**2-1./rawdatafile.frequencies[-1]**2)*sweep_dm
                nbins = np.round(sweep_duration/(rawdatafile.tsamp)).astype('int')
                if ((nbins+start_bin)> (N-1)):
                    nbins = N-1-start_bin
                data = rawdatafile.get_spectra(start_bin, nbins)
                data = maskdata(data, start_bin, nbins, options.maskfile)
                zerodm = None
                dm = None
                data, Data_nozerodm = waterfall_array(start_bin, dmfac, duration, nbins, zerodm, nsub, subdm, dm, integrate_dm, downsamp, scaleindep, width_bins, rawdatafile, binratio, data)
                print "waterfall",memory.resident()/(1024.0**3)
                text_array = np.append(text_array, sweep_duration)
                text_array = np.append(text_array, data.starttime)
                # Array to Construct the sweep
                if sweep_dm is not None:
                    ddm = sweep_dm-data.dm
                    delays = psr_utils.delay_from_DM(ddm, data.freqs)
                    delays -= delays.min()
                    delays_nozerodm = delays
                    freqs_nozerodm = data.freqs
                # Sweeped with zerodm-on 
                zerodm = True
                downsamp_temp = 1
                data, Data_zerodm = waterfall_array(start_bin, dmfac, duration, nbins, zerodm, nsub, subdm, dm, integrate_dm, downsamp_temp, scaleindep, width_bins, rawdatafile, binratio, data)
                print "waterfall",memory.resident()/(1024.0**3)
                # Saving the arrays into the .spd file.
                with open(temp_filename+".spd", 'wb') as f:
                    np.savez_compressed(f, Data_dedisp_nozerodm = Data_dedisp_nozerodm.astype(np.float16), Data_dedisp_zerodm = Data_dedisp_zerodm.astype(np.float16), Data_nozerodm = Data_nozerodm.astype(np.float16), delays_nozerodm = delays_nozerodm, freqs_nozerodm = freqs_nozerodm, Data_zerodm = Data_zerodm.astype(np.float16), dm_arr= map(np.float16, dm_arr), sigma_arr = map(np.float16, sigma_arr), dm_list= map(np.float16, dm_list), time_list = map(np.float16, time_list), text_array = text_array)
                print_debug("Now plotting...")
                print "Before plot..",memory.resident()/(1024.0**3)
                show_spplots.plot(temp_filename+".spd", args[1:], xwin=False, outfile = basename, tar = None)
                print "After plot..",memory.resident()/(1024.0**3)
                print_debug("Finished plot %i " %j+strftime("%Y-%m-%d %H:%M:%S"))
        print_debug("Finished group %i... "%rank+strftime("%Y-%m-%d %H:%M:%S"))
    print_debug("Finished running waterfaller... "+strftime("%Y-%m-%d %H:%M:%S"))
def main():
    parser = optparse.OptionParser(prog="sp_pipeline..py", \
                        version=" Chitrang Patel (May. 12, 2015)", \
                        usage="%prog INFILE(PsrFits FILE, SINGLEPULSE FILES)", \
                        description="Create single pulse plots to show the " \
                                    "frequency sweeps of a single pulse,  " \
                    "DM vs time, and SNR vs DM,"\
                                    "in psrFits data.")
    parser.add_option('--infile', dest='infile', type='string', \
                        help="Give a .inf file to read the appropriate header information.")
    parser.add_option('--groupsfile', dest='txtfile', type='string', \
                        help="Give the groups.txt file to read in the groups information.")
    parser.add_option('--mask', dest='maskfile', type='string', \
                        help="Mask file produced by rfifind. (Default: No Mask).", \
                        default=None)
    options, args = parser.parse_args()
    if not hasattr(options, 'infile'):
        raise ValueError("A .inf file must be given on the command line! ")
    if not hasattr(options, 'txtfile'):
        raise ValueError(
            "The groups.txt file must be given on the command line! ")

    files = get_textfile(options.txtfile)
    print_debug("Begining waterfaller... " + strftime("%Y-%m-%d %H:%M:%S"))
    Detrendlen = 50
    if not args[0].endswith("fits"):
        raise ValueError("The first file must be a psrFits file! ")
    basename = args[0][:-5]
    filetype = "psrfits"
    inffile = options.infile
    topo, bary = bary_and_topo.bary_to_topo(inffile)
    time_shift = bary - topo
    inf = infodata.infodata(inffile)
    RA = inf.RA
    dec = inf.DEC
    MJD = inf.epoch
    mjd = Popen(["mjd2cal", "%f" % MJD], stdout=PIPE, stderr=PIPE)
    date, err = mjd.communicate()
    date = date.split()[2:5]
    telescope = inf.telescope
    N = inf.N
    Total_observed_time = inf.dt * N
    print_debug('getting file..')
    rawdatafile = psrfits.PsrfitsFile(args[0])
    print "rawdatafile", memory.resident() / (1024.0**3)
    bin_shift = np.round(time_shift / rawdatafile.tsamp).astype('int')
    for group in [6, 5, 4, 3, 2]:
        rank = group + 1
        if files[group] != "Number of rank %i groups: 0 " % rank:
            print_debug(files[group])
            values = split_parameters(rank, options.txtfile)
            lis = np.where(files == '\tRank:             %i.000000' % rank)[0]
            for ii in range(len(values)):
                #### Array for Plotting DM vs SNR
                print "DM, S/N", memory.resident() / (1024.0**3)
                print_debug("Making arrays for DM vs Signal to Noise...")
                temp_list = files[lis[ii] - 6].split()
                npulses = int(temp_list[2])
                temp_lines = files[(lis[ii] + 3):(lis[ii] + npulses + 1)]
                arr = np.split(temp_lines, len(temp_lines))
                dm_list = []
                time_list = []
                for i in range(len(arr)):
                    dm_val = float(arr[i][0].split()[0])
                    time_val = float(arr[i][0].split()[2])
                    dm_list.append(dm_val)
                    time_list.append(time_val)
                arr_2 = np.array([arr[i][0].split() for i in range(len(arr))],
                                 dtype=np.float32)
                dm_arr = np.array([arr_2[i][0] for i in range(len(arr))],
                                  dtype=np.float32)
                sigma_arr = np.array([arr_2[i][1] for i in range(len(arr))],
                                     dtype=np.float32)
                print "After DM, S/N", memory.resident() / (1024.0**3)

                #### Array for Plotting DM vs Time is in show_spplots.plot(...)

                #### Setting variables up for the waterfall arrays.
                j = ii + 1
                subdm = dm = sweep_dm = values[ii][0]
                integrate_dm = None
                sigma = values[ii][1]
                sweep_posn = 0.0
                topo_start_time = values[ii][2] - topo_timeshift(
                    values[ii][2], time_shift, topo)[0]
                sample_number = values[ii][3]
                width_bins = values[ii][4]
                binratio = 50
                scaleindep = False
                zerodm = None
                downsamp = np.round((values[ii][2] / sample_number /
                                     6.54761904761905e-05)).astype('int')
                duration = binratio * width_bins * rawdatafile.tsamp * downsamp
                start = topo_start_time - (0.25 * duration)
                if (start < 0.0):
                    start = 0.0
                pulse_width = width_bins * downsamp * 6.54761904761905e-05
                if sigma <= 10:
                    nsub = 32
                elif sigma >= 10 and sigma < 15:
                    nsub = 64
                else:
                    nsub = 96
                nbins = np.round(duration / rawdatafile.tsamp).astype('int')
                start_bin = np.round(start / rawdatafile.tsamp).astype('int')
                dmfac = 4.15e3 * np.abs(1. / rawdatafile.frequencies[0]**2 -
                                        1. / rawdatafile.frequencies[-1]**2)
                nbinsextra = np.round(
                    (duration + dmfac * dm) / rawdatafile.tsamp).astype('int')
                if (start_bin + nbinsextra) > N - 1:
                    nbinsextra = N - 1 - start_bin
                data = rawdatafile.get_spectra(start_bin, nbinsextra)
                print "After rawdata", memory.resident() / (1024.0**3)
                data = maskdata(data, start_bin, nbinsextra, options.maskfile)
                #make an array to store header information for the .npz files
                temp_filename = basename + "_DM%.1f_%.1fs_rank_%i" % (
                    subdm, topo_start_time, rank)
                # Array for Plotting Dedispersed waterfall plot - zerodm - OFF
                print_debug("Running waterfaller with Zero-DM OFF...")
                data, Data_dedisp_nozerodm = waterfall_array(
                    start_bin, dmfac, duration, nbins, zerodm, nsub, subdm, dm,
                    integrate_dm, downsamp, scaleindep, width_bins,
                    rawdatafile, binratio, data)
                print "waterfall", memory.resident() / (1024.0**3)
                # Add additional information to the header information array
                text_array = np.array([
                    args[0], 'Arecibo', RA, dec, MJD, rank, nsub, nbins, subdm,
                    sigma, sample_number, duration, width_bins, pulse_width,
                    rawdatafile.tsamp, Total_observed_time, topo_start_time,
                    data.starttime, data.dt, data.numspectra,
                    data.freqs.min(),
                    data.freqs.max()
                ])

                #### Array for plotting Dedispersed waterfall plot zerodm - ON
                print_debug("Running Waterfaller with Zero-DM ON...")
                data = rawdatafile.get_spectra(start_bin, nbinsextra)
                data = maskdata(data, start_bin, nbinsextra, options.maskfile)
                zerodm = True
                data, Data_dedisp_zerodm = waterfall_array(
                    start_bin, dmfac, duration, nbins, zerodm, nsub, subdm, dm,
                    integrate_dm, downsamp, scaleindep, width_bins,
                    rawdatafile, binratio, data)
                print "waterfall", memory.resident() / (1024.0**3)
                ####Sweeped without zerodm
                print_debug("Running waterfaller for sweeped arrays.")
                start = start + (0.25 * duration)
                start_bin = np.round(start / rawdatafile.tsamp).astype('int')
                sweep_duration = 4.15e3 * np.abs(
                    1. / rawdatafile.frequencies[0]**2 -
                    1. / rawdatafile.frequencies[-1]**2) * sweep_dm
                nbins = np.round(sweep_duration /
                                 (rawdatafile.tsamp)).astype('int')
                if ((nbins + start_bin) > (N - 1)):
                    nbins = N - 1 - start_bin
                data = rawdatafile.get_spectra(start_bin, nbins)
                data = maskdata(data, start_bin, nbins, options.maskfile)
                zerodm = None
                dm = None
                data, Data_nozerodm = waterfall_array(
                    start_bin, dmfac, duration, nbins, zerodm, nsub, subdm, dm,
                    integrate_dm, downsamp, scaleindep, width_bins,
                    rawdatafile, binratio, data)
                print "waterfall", memory.resident() / (1024.0**3)
                text_array = np.append(text_array, sweep_duration)
                text_array = np.append(text_array, data.starttime)
                # Array to Construct the sweep
                if sweep_dm is not None:
                    ddm = sweep_dm - data.dm
                    delays = psr_utils.delay_from_DM(ddm, data.freqs)
                    delays -= delays.min()
                    delays_nozerodm = delays
                    freqs_nozerodm = data.freqs
                # Sweeped with zerodm-on
                zerodm = True
                downsamp_temp = 1
                data, Data_zerodm = waterfall_array(start_bin, dmfac, duration,
                                                    nbins, zerodm, nsub, subdm,
                                                    dm, integrate_dm,
                                                    downsamp_temp, scaleindep,
                                                    width_bins, rawdatafile,
                                                    binratio, data)
                print "waterfall", memory.resident() / (1024.0**3)
                # Saving the arrays into the .spd file.
                with open(temp_filename + ".spd", 'wb') as f:
                    np.savez_compressed(
                        f,
                        Data_dedisp_nozerodm=Data_dedisp_nozerodm.astype(
                            np.float16),
                        Data_dedisp_zerodm=Data_dedisp_zerodm.astype(
                            np.float16),
                        Data_nozerodm=Data_nozerodm.astype(np.float16),
                        delays_nozerodm=delays_nozerodm,
                        freqs_nozerodm=freqs_nozerodm,
                        Data_zerodm=Data_zerodm.astype(np.float16),
                        dm_arr=map(np.float16, dm_arr),
                        sigma_arr=map(np.float16, sigma_arr),
                        dm_list=map(np.float16, dm_list),
                        time_list=map(np.float16, time_list),
                        text_array=text_array)
                print_debug("Now plotting...")
                print "Before plot..", memory.resident() / (1024.0**3)
                show_spplots.plot(temp_filename + ".spd",
                                  args[1:],
                                  xwin=False,
                                  outfile=basename,
                                  tar=None)
                print "After plot..", memory.resident() / (1024.0**3)
                print_debug("Finished plot %i " % j +
                            strftime("%Y-%m-%d %H:%M:%S"))
        print_debug("Finished group %i... " % rank +
                    strftime("%Y-%m-%d %H:%M:%S"))
    print_debug("Finished running waterfaller... " +
                strftime("%Y-%m-%d %H:%M:%S"))
예제 #14
0
def show_mem():
    print "memory usage:"
    import memory
    print memory.memory()/(1024*1024)
    print memory.resident()/(1024*1024)
예제 #15
0
def show_mem():
    print "memory usage:"
    import memory
    print memory.memory() / (1024 * 1024)
    print memory.resident() / (1024 * 1024)