Exemplo n.º 1
0
def test_read_header():
    """
    Tests the reading of the JP2 header.
    """
    from sunpy.io.jp2 import get_header
    header = get_header(AIA_193_JP2)[0]
    assert isinstance(header, FileHeader)
 def bbox_viz(img, X, Y):
     """
     This function takes image and solar event coordinate and then reutns the image object with a bounding-box
     :param img: image url of a fits file
     :param X: x coordinate arcsec
     :param Y: y coordinate arcsec
     :return: image object
     """
     h = jp2.get_header(img)
     header = h[0]
     image_w = header['NAXIS1']
     image_h = header['NAXIS2']
     center_x = header['CRPIX1']
     center_y = header['CRPIX2']
     scale_x = header['CDELT1']
     scale_y = header['CDELT2']
     PixX = (center_x + (X / scale_x))
     PixY = (center_y - (Y / scale_y))
     im = Image.open(img)
     offset = 100
     left = PixX - offset
     top = PixY - offset
     right = PixX + offset
     bottom = PixY + offset
     source_img = Image.open(img).convert("RGBA")
     draw = ImageDraw.Draw(source_img)
     draw.rectangle(((left, top), (right, bottom)), outline="yellow", width=4)
     return source_img
Exemplo n.º 3
0
def test_read_header():
    """
    Tests the reading of the JP2 header.
    """
    from sunpy.io.jp2 import get_header
    header = get_header(AIA_193_JP2)[0]
    assert isinstance(header, FileHeader)
Exemplo n.º 4
0
def header(file_path):
    """
    This function takes the JP2 file path as input and returns the spatial header info of that file.
    :param file_path: full path of the .jp2 file
    :return: spatial header info
    """
    h = jp2.get_header(file_path)
    header = h[0]
    image_w = header['NAXIS1']
    image_h = header['NAXIS2']
    center_x = header['CRPIX1']
    center_y = header['CRPIX2']
    scale_x = header['CDELT1']
    scale_y = header['CDELT2']
    header_spatial_info = [
        image_w, image_h, center_x, center_y, scale_x, scale_y
    ]
    return header_spatial_info
Exemplo n.º 5
0
def read_header_only_but_still_use_sunpy_map(filepath):
    """
    Reads the header for a JPEG200 file and returns some dummy data.
    Why does this function exist?  SunPy map objects perform some important
    homogenization steps that we would like to take advantage of in
    Helioviewer.  The homogenization steps occur on the creation of the sunpy
    map object.  All SunPy maps have the same properties, some of which are
    useful for Helioviewer to use in order to ingest JPEG2000 data.  The SunPy
    map properties are based on the header information in the JPEG2000 file,
    which is a copy of the source FITS header (with some modifications in
    some cases - see JP2Gen).  So by using SunPy's maps, Helioviewer does not
    have to implement these homogenization steps.

    So what's the problem?  Why not use SunPy's JPEG2000 file reading
    capability?  Well let's explain. SunPy's JPEG2000 file reading reads
    both the file header and the image data.  The image data is then decoded
    ultimately creating a numpy array.  The decoding step is computationally
    expensive for the 4k by 4k images provided by AIA and HMI.  It takes long
    enough that the ingestion of AIA and HMI data would be severely impacted,
    possibly to the point that we would never catch up if we fell behind in
    ingesting the latest data.

    The solution is to not decode the image data, but to pass along only the
    minimal amount of information required to create the SunPy map.  This
    function implements this solution tactic, admittedly in an unsatisfying
    manner.  The actual image data is replaced by a 1 by 1 numpy array.  This
    is sufficient to create a SunPy map with the properties required by the
    Helioviewer Project.

    Parameters
    ----------
    filepath : `str`
        The file to be read.

    Returns
    -------
    pairs : `list`
        A (data, header) tuple
    """
    header = get_header(filepath)

    return [(np.zeros([1, 1]), header[0])]
Exemplo n.º 6
0
def test_read_header():
    """Tests the reading of the JP2 header"""
    header = get_header(AIA_193_JP2)[0]
    assert isinstance(header, FileHeader)
Exemplo n.º 7
0
def test_read_header():
    header = get_header(AIA_193_JP2)[0]
    assert isinstance(header, FileHeader)