Exemple #1
0
def find_times(obsid, pulsar, beg=None, end=None):
    """
    Find the total integration time of a pulsar in the primary beam of an obsid

    Parameters:
    ----------
    obsid: int
        The observation ID
    pulsar: string
        The J name of the pulsar
    beg: int
        OPTIONAL - The beginning of the observing time
    end: int
        OPTINAL - The end of the observing time

    Returns:
    -------
    beg: int
        The time when the pulsar enters the beam in gps
    end: int
        The time when the pulsar exits thebeam in gps
    t_int: int
        The total time that the pulsar is in the beam
    """
    t_int = None
    if beg is None or end is None:
        logger.info("Using duration for entire observation")
        beg, end = mwa_metadb_utils.obs_max_min(obsid)
        t_int = end - beg + 1
        enter_norm, exit_norm = pulsar_beam_coverage(obsid,
                                                     pulsar,
                                                     beg=beg,
                                                     end=end)
        beg = beg + enter_norm * t_int
        end = beg + exit_norm * t_int

    if t_int is None:
        enter_norm, exit_norm = pulsar_beam_coverage(obsid,
                                                     pulsar,
                                                     beg=beg,
                                                     end=end)
        if beg is not None and end is not None:
            if beg < obsid or end < obsid or beg > (obsid + 10000) or end > (
                    obsid + 10000):
                logger.warning(
                    "Beginning/end times supplied are outside the obsid")
                logger.warning("Have you entered the correct times and obsid?")
            dur = end - beg
        else:  #use entire obs duration
            beg, end = mwa_metadb_utils.obs_max_min(obsid)
            dur = end - beg + 1
        if enter_norm is None or exit_norm is None or dur is None:
            t_int = 0
        else:
            t_int = dur * (exit_norm - enter_norm)

    return beg, end, t_int
def multi_psr_snfe(pulsar_list, obsid,\
                   beg=None, end=None, obs_metadata=None, full_meta=None, plot_flux=False,\
                   query=None, min_z_power=0.3, trcvr=data_load.TRCVR_FILE):

    if obs_metadata is None or full_meta is None:
        logger.debug("Obtaining obs metadata")
        obs_metadata, full_meta = mwa_metadb_utils.get_common_obs_metadata(
            obsid, return_all=True)

    obs_beg, obs_end = mwa_metadb_utils.obs_max_min(obsid, meta=full_meta)
    if beg is None:
        beg = obs_beg
    if end is None:
        end = obs_end

    mega_query = psrqpy.QueryATNF(psrs=pulsar_list,
                                  loadfromdb=data_load.ATNF_LOC).pandas
    sn_dict = {}
    for i, pulsar in enumerate(mega_query["PSRJ"]):
        psr_query = {}
        for key in mega_query.keys():
            psr_query[key] = [mega_query[key][i]]

        sn, sn_e = est_pulsar_sn(pulsar, obsid,\
                                 beg=beg, end=end, obs_metadata=obs_metadata, full_meta=full_meta, plot_flux=plot_flux,\
                                 query=psr_query, min_z_power=min_z_power, trcvr=trcvr)

        sn_dict[pulsar] = [sn, sn_e]

    return sn_dict
        '%(asctime)s  %(filename)s  %(name)s  %(lineno)-4d  %(levelname)-9s :: %(message)s'
    )
    ch.setFormatter(formatter)
    logger.addHandler(ch)
    logger.propagate = False

    #option parsing
    if not args.obsid:
        print("Please input observation id by setting -o or --obsid. Exiting")
        quit()

    if args.begin and args.end:
        beg = args.begin
        end = args.end
    elif args.all:
        beg, end = obs_max_min(args.obsid)

    output_list = find_pulsars_in_fov(args.obsid, beg, end)
    with open('{}_fov_sources_temp.csv'.format(args.obsid), 'w',
              newline='') as csvfile:
        spamwriter = csv.writer(csvfile, delimiter=',')
        for ol in output_list:
            if len(ol) == 0:
                # Print a space to the line which prevents Nextflow formatting erorrs
                spamwriter.writerow([" "])
            else:
                spamwriter.writerow(ol)

    with open('{}_fov_sources_temp.csv'.format(args.obsid), 'r') as readfile:
        csv_read = readfile.readlines()
Exemple #4
0
            import version
            logger.info(version.__version__)
            sys.exit(0)
        except ImportError as ie:
            logger.error(
                "Couldn't import version.py - have you installed vcstools?")
            logger.error("ImportError: {0}".format(ie))
            sys.exit(0)

    if (args.mode is None) or (args.obsID is None):
        logger.error("You must specify BOTH a mode and observation ID")
        sys.exit(1)

    if args.all:
        from mwa_metadb_utils import obs_max_min
        args.begin, args.end = obs_max_min(args.obsID)
    if args.end:
        if not args.begin:
            logger.error(
                "If you supply and end time you also *have* to supply a begin time."
            )
            sys.exit(1)
        args.increment = args.end - args.begin + 1
        logger.info("Checking {0} seconds.".format(args.increment))
    if not args.all and not args.begin:
        logger.error(
            "You have to either set the -a flag to process the whole obs or povide a start and stop time with -b and -e"
        )
        sys.exit(1)
    if args.begin:
        if not args.end and not args.increment:
Exemple #5
0
def pulsar_beam_coverage(obsid, pulsar, beg=None, end=None, ondisk=False):
    """
    Finds the normalised time that a pulsar is in the beam for a given obsid
    If pulsar is not in beam, returns None, None

    Parameters:
    -----------
    obsid: int
        The observation ID
    pulsar: string
        The pulsar's J name
    beg: int
        OPTIONAL - The beginning of the observing time in gps time
    end: int
        OPTIONAL - The end of the observing time in gps time
    ondisk: boolean
        Whether to use files that are on-disk for beginning and end times. Default=False

    Returns:
    --------
    enter_files: float
        A float between 0 and 1 that describes the normalised time that the pulsar enters the beam
    exit_files: float
         a float between 0 and 1 that describes the normalised time that the pulsar exits the beam
    """
    #Find the beginning and end of obs
    obs_beg, obs_end = files_beg, files_end = mwa_metadb_utils.obs_max_min(
        obsid)
    obs_dur = obs_end - obs_beg + 1

    #Logic loop:
    if ondisk == True:
        #find the beginning and end time of the observation FILES you have on disk
        files_beg, files_end = process_vcs.find_combined_beg_end(obsid)
        files_duration = files_end - files_beg + 1
    elif beg is None and end is None:
        logger.warning(
            "ondisk==False so beg and end can not be None. Returning Nones")
        return None, None
    else:
        #uses manually input beginning and end times to find beam coverage
        files_beg = beg
        files_end = end
        files_duration = files_end - files_beg + 1

    #find the enter and exit times of pulsar normalized with the observing time
    names_ra_dec = fpio.grab_source_alog(pulsar_list=[pulsar])
    beam_source_data, _ = fpio.find_sources_in_obs([obsid], names_ra_dec)
    enter_obs_norm = beam_source_data[obsid][0][1]
    exit_obs_norm = beam_source_data[obsid][0][2]

    #times the source enters and exits beam
    time_enter = obs_beg + obs_dur * enter_obs_norm
    time_exit = obs_beg + obs_dur * exit_obs_norm

    #normalised time the source enters/exits the beam in the files
    enter_files = (time_enter - files_beg) / files_duration
    exit_files = (time_exit - files_beg) / files_duration

    if enter_files < 0.:
        enter_files = 0.
    if exit_files > 1.:
        exit_files = 1.
    if enter_files > 1. or exit_files < 0.:
        logger.warning(
            "source {0} is not in the beam for the files on disk".format(
                pulsar))
        enter_files = None
        exit_files = None

    return enter_files, exit_files
def find_times(obsid,
               pulsar,
               beg=None,
               end=None,
               metadata=None,
               full_meta=None,
               min_z_power=0.3,
               query=None):
    """
    Find the total integration time of a pulsar in the primary beam of an obsid

    Parameters:
    ----------
    obsid: int
        The observation ID
    pulsar: string
        The J name of the pulsar
    beg: int
        OPTIONAL - The beginning of the processed observing time
    end: int
        OPTIONAL - The end of the processed observing time

    Returns:
    -------
    enter_time: int
        The time when the pulsar enters the beam in gps
    exit_time: int
        The time when the pulsar exits the beam in gps
    t_int: int
        The total time that the pulsar is in the beam in seconds
    """
    #type assurances
    obsid = int(obsid)

    if not metadata or not full_meta:
        metadata, full_meta = mwa_metadb_utils.get_common_obs_metadata(
            obsid, return_all=True)
    obs_beg, obs_end = mwa_metadb_utils.obs_max_min(obsid, meta=full_meta)

    t_int = None
    if beg is None or end is None:
        logger.info("Using duration for entire observation")
        beg = obs_beg
        end = obs_end
        dur = end - beg + 1
        enter_norm, exit_norm = pulsar_beam_coverage(obsid,
                                                     pulsar,
                                                     beg=beg,
                                                     end=end,
                                                     metadata=metadata,
                                                     full_meta=full_meta,
                                                     min_z_power=min_z_power,
                                                     query=query)
        enter_time = beg + enter_norm * dur
        exit_time = beg + exit_norm * dur
        t_int = (exit_norm - enter_norm) * dur

    if t_int is None:
        enter_norm, exit_norm = pulsar_beam_coverage(obsid,
                                                     pulsar,
                                                     beg=beg,
                                                     end=end,
                                                     metadata=metadata,
                                                     full_meta=full_meta,
                                                     min_z_power=min_z_power,
                                                     query=query)
        if beg is not None and end is not None:
            dur = end - beg
        else:  #use entire obs duration
            beg = obs_beg
            end = obs_end
            dur = end - beg + 1
        if enter_norm is not None and exit_norm is not None:
            enter_time = beg + enter_norm * dur
            exit_time = beg + exit_norm * dur
            t_int = dur * (exit_norm - enter_norm)
        else:
            logger.warn("Integration time calculation failed")
            enter_time = 0
            exit_time = 0
            t_int = 0

    return enter_time, exit_time, t_int
Exemple #7
0
    #remove pointings outside of ra or dec range
    if args.dec_range != [-90, 90] or args.ra_range != [0, 360]:
        print("Removing pointings outside of ra dec ranges")
        radls = []
        decdls = []
        for i in range(len(rads)):
            if  (args.dec_range[0] < float(decds[i]) < args.dec_range[1] ) and \
                (args.ra_range[0]  < float(rads[i]) < args.ra_range[1]):
                radls.append(rads[i])
                decdls.append(decds[i])
        rads = radls
        decds = decdls

    if args.all_pointings:
        #calculate powers
        obeg, oend = meta.obs_max_min(obs)
        if args.begin:
            start_time = obeg - args.begin
        else:
            start_time = 0
        if args.end and args.begin:
            duration = args.end - args.begin
        elif args.end:
            duration = args.end - obeg
        obs_metadata = [obs, ra, dec, duration, xdelays, centrefreq, channels]
        names_ra_dec = []
        for ni in range(len(rads)):
            if float(decds[ni]) < -90.:
                continue
            names_ra_dec.append(["name", rads[ni], decds[ni]])
        names_ra_dec = np.array(names_ra_dec)