示例#1
0
def get_filetypes_from_db(obsid, pulsar, filetype):
    """
    Searches the pulsar database and returns the given obsid/pulsar/filetype files

    Parameters:
    -----------
    obsid: int
        Observation ID
    pulsar: string
        The name of the puslar
    filetype: int
        The type of file to search for. Options are:
        1: Archive, 2: Timeseries, 3: Diagnostics, 4: Calibration Solution, 5: Bestprof

    Returns:
    --------
    myfiles: list
        A list of filenames fitting the given parameters
    """
    def find_obj(
            search_key, arrdict,
            search_for):  #for searching the various dictionaries in client
        for mydict in arrdict:
            if mydict[search_key] == search_for:
                return mydict

    #Check if any files of the filetype exist
    web_address, auth = get_db_auth_addr()
    obs_dets = client.detection_get(web_address, auth, observationid=obsid)
    if not obs_dets:
        logger.warn("No detections for this obs ID")
        return []

    detection = find_obj("pulsar", obs_dets, pulsar)
    if not detection:
        logger.warn("No detections for this pulsar")
        return []

    allfiles_list = detection["detection_files"]
    is_filetype = bool(find_obj("filetype", allfiles_list, filetype))
    if not is_filetype:
        logger.warn(
            "No files of the specified type available for this pulsar & obsid")
        return []

    #find the files with the filetype
    myfiles = []
    for detfile in allfiles_list:
        if detfile["filetype"] == filetype:
            myfiles.append(detfile["filename"])

    return myfiles
示例#2
0
            cal_db_id = None

        #uploads files to database if there's the no calc option
        #checks if the observation is on the database
        det_kwargs = {}
        det_kwargs["observationid"] = str(args.obsid)
        det_kwargs["pulsar"] = args.pulsar
        det_kwargs["calibrator"] = int(cal_db_id)
        det_kwargs["subband"] = int(subbands)
        det_kwargs["coherent"] = coh
        det_kwargs["startcchan"] = int(minfreq)
        det_kwargs["stopcchan"] = int(maxfreq)
        det_kwargs["observation_type"] = int(obstype)
        try:
            temp_dict = client.detection_get(web_address,
                                             auth,
                                             observationid=str(args.obsid))
        except:
            client.detection_create(web_address, auth, **det_kwargs)
            temp_dict = client.detection_get(web_address,
                                             auth,
                                             observationid=str(args.obsid))

        if not temp_dict:
            #no obsid so creats a blank one and assumes the subbands are continuous
            client.detection_create(web_address, auth, **det_kwargs)
            temp_dict = client.detection_get(web_address,
                                             auth,
                                             observationid=str(args.obsid))

        pulsar_dict_check = False