예제 #1
0
파일: rhessi.py 프로젝트: ndchorley/sunpy
def backprojection(calibrated_event_list, pixel_size=(1.0, 1.0), image_dim=(64, 64)):
    """Given a stacked calibrated event list fits file create a back projection image."""
    import sunpy.sun.constants as sun
    from sunpy.sun.sun import angular_size
    from sunpy.sun.sun import sunearth_distance
    from sunpy.time.util import TimeRange

    calibrated_event_list = sunpy.RHESSI_EVENT_LIST
    fits = pyfits.open(calibrated_event_list)
    info_parameters = fits[2]
    xyoffset = info_parameters.data.field("USED_XYOFFSET")[0]
    time_range = TimeRange(info_parameters.data.field("ABSOLUTE_TIME_RANGE")[0])

    image = np.zeros(image_dim)

    # find out what detectors were used
    det_index_mask = fits[1].data.field("det_index_mask")[0]
    detector_list = (np.arange(9) + 1) * np.array(det_index_mask)
    for detector in detector_list:
        if detector > 0:
            image = image + _backproject(
                calibrated_event_list, detector=detector, pixel_size=pixel_size, image_dim=image_dim
            )

    dict_header = {
        "DATE-OBS": time_range.center().strftime("%Y-%m-%d %H:%M:%S"),
        "CDELT1": pixel_size[0],
        "NAXIS1": image_dim[0],
        "CRVAL1": xyoffset[0],
        "CRPIX1": image_dim[0] / 2 + 0.5,
        "CUNIT1": "arcsec",
        "CTYPE1": "HPLN-TAN",
        "CDELT2": pixel_size[1],
        "NAXIS2": image_dim[1],
        "CRVAL2": xyoffset[1],
        "CRPIX2": image_dim[0] / 2 + 0.5,
        "CUNIT2": "arcsec",
        "CTYPE2": "HPLT-TAN",
        "HGLT_OBS": 0,
        "HGLN_OBS": 0,
        "RSUN_OBS": angular_size(time_range.center()),
        "RSUN_REF": sun.radius,
        "DSUN_OBS": sunearth_distance(time_range.center()) * sunpy.sun.constants.au,
    }

    header = sunpy.map.MapHeader(dict_header)
    result_map = sunpy.map.BaseMap(image, header)

    return result_map
예제 #2
0
파일: rhessi.py 프로젝트: dbseaton/sunpy
def backprojection(calibrated_event_list, pixel_size=(1.,1.), image_dim=(64,64)):
    """Given a stacked calibrated event list fits file create a back 
    projection image.
    
    .. warning:: The image is not in the right orientation!

    Parameters
    ----------
    calibrated_event_list : string
        filename of a RHESSI calibrated event list
    
    detector : int
        the detector number
        
    pixel_size : 2-tuple
        the size of the pixels in arcseconds. Default is (1,1).
        
    image_dim : 2-tuple
        the size of the output image in number of pixels
        
    Returns
    -------
    map : RHESSImap
        Return a backprojection map.

    See Also
    --------

    Examples
    --------
    >>> import sunpy.instr.rhessi as rhessi
    >>> map = rhessi.backprojection(sunpy.RHESSI_EVENT_LIST)
    >>> map.show()
    
    Reference
    ---------
    | 

    """
    import sunpy.sun.constants as sun
    from sunpy.sun.sun import angular_size
    from sunpy.sun.sun import sunearth_distance
    from sunpy.time.util import TimeRange
    
    calibrated_event_list = sunpy.RHESSI_EVENT_LIST
    fits = pyfits.open(calibrated_event_list)
    info_parameters = fits[2]
    xyoffset = info_parameters.data.field('USED_XYOFFSET')[0]
    time_range = TimeRange(info_parameters.data.field('ABSOLUTE_TIME_RANGE')[0])
    
    image = np.zeros(image_dim)
    
    #find out what detectors were used
    det_index_mask = fits[1].data.field('det_index_mask')[0]    
    detector_list = (np.arange(9)+1) * np.array(det_index_mask)
    for detector in detector_list:
        if detector > 0:
            image = image + _backproject(calibrated_event_list, detector=detector, pixel_size=pixel_size, image_dim=image_dim)
    
    dict_header = {
        "DATE-OBS": time_range.center().strftime("%Y-%m-%d %H:%M:%S"), 
        "CDELT1": pixel_size[0],
        "NAXIS1": image_dim[0],
        "CRVAL1": xyoffset[0],
        "CRPIX1": image_dim[0]/2 + 0.5, 
        "CUNIT1": "arcsec",
        "CTYPE1": "HPLN-TAN",
        "CDELT2": pixel_size[1],
        "NAXIS2": image_dim[1],
        "CRVAL2": xyoffset[1],
        "CRPIX2": image_dim[0]/2 + 0.5,
        "CUNIT2": "arcsec",
        "CTYPE2": "HPLT-TAN",
        "HGLT_OBS": 0,
        "HGLN_OBS": 0,
        "RSUN_OBS": angular_size(time_range.center()),
        "RSUN_REF": sun.radius,
        "DSUN_OBS": sunearth_distance(time_range.center()) * sunpy.sun.constants.au
    }
    
    header = sunpy.map.MapHeader(dict_header)
    result_map = sunpy.map.BaseMap(image, header)
            
    return result_map