Пример #1
0
    def setup(self):
        """Get a list of existing processed files."""

        # Find processed transit files
        self.proc_transits = []
        for processed_dir in self.processed_dir:
            self.log.debug(
                "Looking for processed transits in {}...".format(processed_dir)
            )
            # Expand path
            processed_dir = path.expanduser(processed_dir)
            processed_dir = path.expandvars(processed_dir)

            try:
                processed_files = listdir(processed_dir)
            except FileNotFoundError:
                processed_files = []
            for fname in processed_files:
                if not path.splitext(fname)[1] == ".h5":
                    continue
                with ContainerBase.from_file(
                    fname, ondisk=True, distributed=False, mode="r"
                ) as fh:
                    obs_id = fh.attrs.get("observation_id", None)
                    if obs_id is not None:
                        self.proc_transits.append(obs_id)
        self.log.debug("Found {:d} processed transits.".format(len(self.proc_transits)))

        # Query database for observations of this source
        hol_obs = None
        if mpiutil.rank0:
            hol_obs = list(get_holography_obs(self.source))
        self.hol_obs = mpiutil.bcast(hol_obs, root=0)
        mpiutil.barrier()
Пример #2
0
def mpi_tmp_path(tmp_path_factory):

    dirname = None
    if mpiutil.rank0:
        dirname = str(tmp_path_factory.mktemp("mpi"))
    dirname = mpiutil.bcast(dirname, root=0)

    return pathlib.Path(dirname)
Пример #3
0
    def mpi(self):
        rank = mpiutil.rank
        size = mpiutil.size

        if rank == 0:

            #g = free_free(v = self.v, nside = self.nside)
            #delt_m, params = g.delta_m()
            delt_m = np.ones(np.int(12 * self.nside**2))
            params = [1, 2, 3, 4, 5, 6, 7]

        else:
            delt_m = None
        #local_delt_m = mpiutil.mpilist(delt_m, method = 'con',comm = MPI.COMM_WORLD)
        local_range = mpiutil.mpirange(0, hp.nside2npix(self.nside))

        delt_m = mpiutil.bcast(delt_m, root=0)
        params = mpiutil.bcast(params, root=0)
        result = []
        for pix_number in local_range:
            a = time.time()
            l, b = hp.pix2ang(self.nside, pix_number, nest=False, lonlat=True)
            #pix_value = delt_m[pix_number] + 100.
            pix_value = self.integrate_by_hand(self._new,
                                               0.01,
                                               dist,
                                               args=(l, b, delt_m[pix_number],
                                                     params))
            b = time.time()

            print 'pix_number', pix_number, 'delta_time', b - a
            result.append([pix_number, pix_value])
        result = mpiutil.gather_list(result, root=None)
        if rank == 0:
            with h5py.File('text_0to1.hdf5', 'w') as f:
                f.create_dataset('result', data=result)
                print 'end'
Пример #4
0
    def setup(self, observer=None):
        """Set the local observers position if not using CHIME.

        Parameters
        ----------
        observer : caput.time.Observer, optional
            Details of the observer, if not set default to CHIME.

        Raises
        ------
        `caput.config.CaputConfigError`
            If config value ``source`` doesn't match any in `ch_util.ephemeris`.
        """
        self.observer = ephem.chime if observer is None else observer
        try:
            self.src = ephem.source_dictionary[self.source]
        except KeyError:
            msg = (
                "Could not find source {} in catalogue. "
                "Must use same spelling as in `ch_util.ephemeris`.".format(self.source)
            )
            self.log.error(msg)
            raise config.CaputConfigError(msg)
        self.cur_transit = None
        self.tstreams = []
        self.last_time = 0

        # Get list of holography observations
        # Only allowed to query database from rank0
        db_runs = None
        if mpiutil.rank0:
            connect_database()
            db_runs = list(get_holography_obs(self.db_source))
            db_runs = [(int(r.id), (r.start_time, r.finish_time)) for r in db_runs]
        self.db_runs = mpiutil.bcast(db_runs, root=0)
        mpiutil.barrier()
Пример #5
0
# mpirange
separator(sec, 'mpirange')
local_ary = mpiutil.mpirange(1, 7)
print "rank %d has %s with method = 'con'" % (rank, local_ary)
local_ary = mpiutil.mpirange(1, 7, method='alt')
print "rank %d has %s with method = 'alt'" % (rank, local_ary)
local_ary = mpiutil.mpirange(1, 7, method='rand')
print "rank %d has %s with method = 'rand'" % (rank, local_ary)

# bcast
separator(sec, 'bcast')
if rank == 0:
    sendobj = 'obj'
else:
    sendobj = None
sendobj = mpiutil.bcast(sendobj, root=0)
print 'rank %d has sendobj = %s after bcast' % (rank, sendobj)

# gather_list
separator(sec, 'gather_list')
if rank == 0:
    lst = [0.5, 2]
elif rank == 1:
    lst = ['a', False, 'xy']
elif rank == 2:
    lst = [{'x': 1}]
else:
    lst = []
lst = mpiutil.gather_list(lst, root=None)
print 'rank %d has %s after gather_list' % (rank, lst)
    def mpi(self):
        rank = mpiutil.rank
        size = mpiutil.size

        if rank == 0:
             
            g = free_free(v = self.v, nside = self.nside,index_type = self.index_type,dist = self.dist,emi_form = self.emi_form,I_E_form = self.I_E_form,R0_R1_equal = self.R0_R1_equal,using_raw_diffuse = self.using_raw_diffuse,only_fit_Anu = self.only_fit_Anu)
            delt_m, params = g.delta_m()
            
        else:
            delt_m = None
            params = None
        #local_delt_m = mpiutil.mpilist(delt_m, method = 'con',comm = MPI.COMM_WORLD)
        local_range = mpiutil.mpirange(0,hp.nside2npix(self.nside))

        delt_m = mpiutil.bcast(delt_m, root = 0)
        params = mpiutil.bcast(params, root = 0)
        result_absorb = []
        for pix_number in local_range:
            a = time.time()
            l, b = hp.pix2ang(self.nside, pix_number, nest = False, lonlat = True)
            if self.test == True:
                pix_value =self.integrate_by_hand(self._new, 0.1, dist, args=(l, b, delt_m[pix_number], params)) 
            else:

                pix_value =self.integrate_by_hand(self._new, 0.01, dist, args=(l, b, delt_m[pix_number], params)) 
                distance = self.critical_distance(l,b,delt_m[pix_number],params)
                l, b = hp.pix2ang(self.nside, pix_number, nest = False, lonlat = True)
            b = time.time()
            
            if self.test == True:

                result_absorb.append([pix_number, pix_value])
            else:
                result_absorb.append([pix_number, pix_value, distance])
        if self.test == True:

            result_absorb = mpiutil.gather_list(result_absorb, root = None)
        else:
            result_absorb = mpiutil.gather_list(result_absorb, root = None)
        if rank == 0:
            if self.test == True:
                with h5py.File('./' + str(self.emi_form)+str(self.v) + 'F2py_absorb.hdf5', 'w') as f:
                    f.create_dataset('F2py_absorb', data = result_absorb)
            else:
                with h5py.File('./' + 'exp'+str(self.v)+'Mhz_delt_m_and_unabsorb_and_delt_m_percentage.hdf5','r') as f:
                    #print f.keys()
                    unabsorb = f['integrated_temperature_total_m'][:]
                    diffuse_raw = f['diffuse_raw'][:]
                result_absorb = np.array(result_absorb)
                absorb = result_absorb[:,1]
                I_E = self.I_E(self.v)
                result = []
                print ('in the beginning')
                for pix_number in range(unabsorb.size):
                    print ('left number of pixel',unabsorb.size - pix_number) 
                    X = unabsorb[pix_number] - self.I_E(self.v)
                    l, b = hp.pix2ang(self.nside, pix_number, nest = False, lonlat = True)
                    tao = self.Fortran2Py_optical_deepth(l, b)
                    Y = absorb[pix_number] - I_E * np.exp(-tao[-1])
                    mean_exptao = Y / X
                    pix_value = diffuse_raw[pix_number] * mean_exptao + I_E*np.exp(-tao[-1])
                    result.append([pix_number,pix_value])
                    #print 'pixel_number',pix_number
                with h5py.File('./' + str(self.emi_form)+str(self.v)+'MHz_global_spectrum_with_perterbation.hdf5','w') as h:
                    h.create_dataset('result',data = result)
                    #h.create_dataset('smooth_result',data = result_absorb)
                    print ('end, good job!, you are the best')

        return result
Пример #7
0
    def read_input(self):
        """Method for (maybe iteratively) reading data from input data files."""

        days = self.params['days']
        extra_inttime = self.params['extra_inttime']
        drop_days = self.params['drop_days']
        mode = self.params['mode']
        dist_axis = self.params['dist_axis']

        ngrp = len(self.input_grps)

        if self.next_grp and ngrp > 1:
            if mpiutil.rank0:
                print 'Start file group %d of %d...' % (self.grp_cnt, ngrp)
            self.restart_iteration()  # re-start iteration for each group
            self.next_grp = False
            self.abs_start = None
            self.abs_stop = None

        input_files = self.input_grps[self.grp_cnt]
        start = self.start[self.grp_cnt]
        stop = self.stop[self.grp_cnt]

        if self.int_time is None:
            # NOTE: here assume all files have the same int_time
            with h5py.File(self.input_files[0], 'r') as f:
                self.int_time = f.attrs['inttime']

        if self.abs_start is None or self.abs_stop is None:
            tmp_tod = self._Tod_class(input_files, mode, start, stop,
                                      dist_axis)
            self.abs_start = tmp_tod.main_data_start
            self.abs_stop = tmp_tod.main_data_stop
            del tmp_tod

        iteration = self.iteration if self.iterable else 0
        this_start = self.abs_start + np.int(
            np.around(iteration * days * const.sday / self.int_time))
        this_stop = min(
            self.abs_stop, self.abs_start + np.int(
                np.around(
                    (iteration + 1) * days * const.sday / self.int_time)) +
            2 * extra_inttime)
        if this_stop >= self.abs_stop:
            self.next_grp = True
            self.grp_cnt += 1
        if this_start >= this_stop:
            self.next_grp = True
            self.grp_cnt += 1
            return None

        this_span = self.int_time * (this_stop - this_start)  # in unit second
        if this_span < drop_days * const.sday:
            if mpiutil.rank0:
                print 'Not enough span time, drop it...'
            return None
        elif (this_stop - this_start) <= extra_inttime:  # use int comparision
            if mpiutil.rank0:
                print 'Not enough span time (less than `extra_inttime`), drop it...'
            return None

        tod = self._Tod_class(input_files, mode, this_start, this_stop,
                              dist_axis)

        tod, _ = self.data_select(tod)

        tod.load_all()  # load in all data

        if self.start_ra is None:  # the first iteration
            if 'time' == tod.main_data_axes[tod.main_data_dist_axis]:
                # ra_dec is distributed among processes
                # find the point of ra_dec[extra_inttime, 0] of the global array
                local_offset = tod['ra_dec'].local_offset[0]
                local_shape = tod['ra_dec'].local_shape[0]
                if local_offset <= extra_inttime and extra_inttime < local_offset + local_shape:
                    in_this = 1
                    start_ra = tod['ra_dec'].local_data[extra_inttime -
                                                        local_offset, 0]
                else:
                    in_this = 0
                    start_ra = None

                # get the rank
                max_val, in_rank = mpiutil.allreduce((in_this, tod.rank),
                                                     op=mpiutil.MAXLOC,
                                                     comm=tod.comm)
                # bcast from this rank
                start_ra = mpiutil.bcast(start_ra, root=in_rank, comm=tod.comm)
                self.start_ra = start_ra
            else:
                self.start_ra = ra_dec[extra_inttime, 0]

        tod.vis.attrs['start_ra'] = self.start_ra  # used for re_order

        return tod