Пример #1
0
def bin_corrtag(corrtag_list, xtype='XCORR', ytype='YCORR', times=None):
    """Bin corrtag event lists into a 2D image.

    Filtering of unwanted events will be done before binning.  SDQFLAGS with
    the addition of PHA out of bounds (512), pixel outside active area (128),
    and bad times (2048) will be discarded.

    Parameters
    ----------
    corrtag_list : list
        list of datasets to combine into an image
    xtype : str, optional
        X-coordinate type
    ytype : str, optional
        Y-coordinate type

    Returns
    -------
    image : np.ndarray
        2D image of the corrtag

    """

    if not isinstance(corrtag_list, list):
        corrtag_list = [corrtag_list]

    final_image = np.zeros((1024, 16384)).astype(np.float32)

    for filename in corrtag_list:
        image = np.zeros((1024, 16384)).astype(np.float32)
        hdu = fits.open(filename)
        events = hdu['events'].data

        #-- No COS observation has data below ~923
        data_index = np.where((hdu[1].data['time'] >= times[0]) &
                              (hdu[1].data['time'] <= times[1]))[0]

        if not len(data_index):
            return image
        else:
            events = events[data_index]

        # Call for this is x_values, y_values, image to bin to, offset in x
        # ccos.binevents(x, y, array, x_offset, dq, sdqflags, epsilon)
        ccos.binevents(events[xtype].astype(np.float32),
                       events[ytype].astype(np.float32),
                       image,
                       0,
                       events['dq'],
                       0)

        final_image += image

    return final_image
Пример #2
0
def bin_corrtag(corrtag_list, xtype='XCORR', ytype='YCORR', times=None):
    """Bin corrtag event lists into a 2D image.

    Filtering of unwanted events will be done before binning.  SDQFLAGS with
    the addition of PHA out of bounds (512), pixel outside active area (128),
    and bad times (2048) will be discarded.

    Parameters
    ----------
    corrtag_list : list
        list of datasets to combine into an image
    xtype : str, optional
        X-coordinate type
    ytype : str, optional
        Y-coordinate type

    Returns
    -------
    image : np.ndarray
        2D image of the corrtag

    """

    if not isinstance(corrtag_list, list):
        corrtag_list = [corrtag_list]

    final_image = np.zeros((1024, 16384)).astype(np.float32)

    for filename in corrtag_list:
        image = np.zeros((1024, 16384)).astype(np.float32)
        hdu = fits.open(filename)
        events = hdu['events'].data

        #-- No COS observation has data below ~923
        data_index = np.where((hdu[1].data['time'] >= times[0])
                              & (hdu[1].data['time'] <= times[1]))[0]

        if not len(data_index):
            return image
        else:
            events = events[data_index]

        # Call for this is x_values, y_values, image to bin to, offset in x
        # ccos.binevents(x, y, array, x_offset, dq, sdqflags, epsilon)
        ccos.binevents(events[xtype].astype(np.float32),
                       events[ytype].astype(np.float32), image, 0,
                       events['dq'], 0)

        final_image += image

    return final_image
Пример #3
0
def locate_stims(fits_file, start=0, increment=None):
    print(fits_file)
    DAYS_PER_SECOND = 1. / 60. / 60. / 24.

    file_path, file_name = os.path.split(fits_file)

    with fits.open(fits_file) as hdu:
        exptime = hdu[1].header['exptime']
        expstart = hdu[1].header['expstart']
        segment = hdu[0].header['segment']

        stim_info = {'rootname': hdu[0].header['rootname']}

        try:
            hdu[1].data
        except:
            yield stim_info

        if not len(hdu[1].data):
            yield stim_info

        # If increment is not supplied, use the rates supplied by the detector
        if not increment:
            if exptime < 10:
                increment = .03
            elif exptime < 100:
                increment = 1
            else:
                increment = 30

            increment *= 4

        stop = start + increment

        # Iterate from start to stop, excluding final bin if smaller than increment
        for sub_start in np.arange(start, exptime-increment, increment):
            events = hdu['events'].data

            #-- No COS observation has data below ~923
            data_index = np.where((hdu[1].data['time'] >= sub_start) &
                                  (hdu[1].data['time'] <= sub_start+increment))[0]

            events = events[data_index]

            # Call for this is x_values, y_values, image to bin to, offset in x
            # ccos.binevents(x, y, array, x_offset, dq, sdqflags, epsilon)
            im = np.zeros((1024, 16384)).astype(np.float32)
            ccos.binevents(events['RAWX'].astype(np.float32),
                           events['RAWY'].astype(np.float32),
                           im,
                           0,
                           events['dq'],
                           0)

            ABS_TIME = expstart + sub_start * DAYS_PER_SECOND

            found_ul_x, found_ul_y = find_stims(im, segment, 'ul', brf_file)
            found_lr_x, found_lr_y = find_stims(im, segment, 'lr', brf_file)

            stim_info['time'] = round(sub_start, 5)
            stim_info['abs_time'] = round(ABS_TIME, 5)
            stim_info['stim1_x'] = round(found_ul_x, 3)
            stim_info['stim1_y'] = round(found_ul_y, 3)
            stim_info['stim2_x'] = round(found_lr_x, 3)
            stim_info['stim2_y'] = round(found_lr_y, 3)
            stim_info['counts'] = round(im.sum(), 7)

            yield stim_info
Пример #4
0
def locate_stims(fits_file, start=0, increment=None, brf_file=None):

    ### change this to pull brf file from the header if not specified
    if not brf_file:
        brf_file = os.path.join(os.environ['lref'], 's7g1700el_brf.fits')

    DAYS_PER_SECOND = 1. / 60. / 60. / 24.

    file_path, file_name = os.path.split(fits_file)

    with fits.open(fits_file) as hdu:
        exptime = hdu[1].header['exptime']
        expstart = hdu[1].header['expstart']
        segment = hdu[0].header['segment']

        stim_info = {'rootname': hdu[0].header['rootname'], 'segment': segment}

        try:
            hdu[1].data
        except:
            yield stim_info
            raise StopIteration

        if not len(hdu[1].data):
            yield stim_info
            raise StopIteration

        # If increment is not supplied, use the rates supplied by the detector
        if not increment:
            if exptime < 10:
                increment = .03
            elif exptime < 100:
                increment = 1
            else:
                increment = 30

            increment *= 4

        stop = start + increment

        # Iterate from start to stop, excluding final bin if smaller than increment
        start_times = np.arange(start, exptime - increment, increment)
        if not len(start_times):
            yield stim_info

        for sub_start in start_times:
            events = hdu['events'].data

            #-- No COS observation has data below ~923
            data_index = np.where((hdu[1].data['time'] >= sub_start) & (
                hdu[1].data['time'] <= sub_start + increment))[0]

            events = events[data_index]

            # Call for this is x_values, y_values, image to bin to, offset in x
            # ccos.binevents(x, y, array, x_offset, dq, sdqflags, epsilon)
            im = np.zeros((1024, 16384)).astype(np.float32)
            ccos.binevents(events['RAWX'].astype(np.float32),
                           events['RAWY'].astype(np.float32), im, 0,
                           events['dq'], 0)

            ABS_TIME = expstart + sub_start * DAYS_PER_SECOND

            found_ul_x, found_ul_y = find_stims(im, segment, 'ul', brf_file)
            found_lr_x, found_lr_y = find_stims(im, segment, 'lr', brf_file)

            stim_info['time'] = round(sub_start, 5)
            stim_info['abs_time'] = round(ABS_TIME, 5)
            stim_info['stim1_x'] = round(found_ul_x, 3)
            stim_info['stim1_y'] = round(found_ul_y, 3)
            stim_info['stim2_x'] = round(found_lr_x, 3)
            stim_info['stim2_y'] = round(found_lr_y, 3)
            stim_info['counts'] = round(im.sum(), 7)

            yield stim_info