Exemple #1
0
from chmap.utilities.idl_connect import idl_helper
import time
import os.path
from chmap.settings.app import App

# file locations
fits_compressed = os.path.join(App.APP_HOME, 'reference_data',
                               'sta_euvi_20140413T190530_195.fits')
fits_uncompressed = os.path.join(App.TMP_HOME, 'tmp_euvi_uncompressed.fits')
fits_prepped = os.path.join(App.TMP_HOME, 'tmp_euvi_prepped.fits')

print(fits_compressed)
print(fits_uncompressed)

# uncompress the image to a temporary location
io_helpers.uncompress_compressed_fits_image(fits_compressed,
                                            fits_uncompressed,
                                            int=True)

# begin the IDL session (opens a subprocess)
idl_session = idl_helper.Session()

# call secchi_prep (time it)
t1 = time.perf_counter()
idl_session.secchi_prep(fits_uncompressed, fits_prepped)
t2 = time.perf_counter()
print(t2 - t1)

# end the IDL session (closes a subprocess)
idl_session.end()
Exemple #2
0
def prep_euvi_image(map_raw, deconvolve=True, idl_session=None):
    """
    Prepare an EUVI image for processing by the CHD database.
    The basic steps include:
    - Calling SSW/IDL to run secchi_prep to get a calibrated lvl 1 image (no rotation)
    - PSF deconvolution.
    - Rebinning (optional).
    - Image rotation.
    - Exposure normalization.
    - Assembling/updating metadata.

    The subroutine routines an LosImage object, which is specific to this project.

    A running IDL session object can be passed to the subroutine.
      to allow one session to take care of multiple prep steps
    """
    # Begin secchi_prep with SSW/IDL
    t0 = timer()
    print("  Calling secchi_prep with SSW/IDL... ", end='', flush=True)

    # first save the data as a temporary, uncompressed uint16 fits file
    fits_raw = os.path.join(App.TMP_HOME, 'tmp_euvi_raw.fits')
    io_helpers.write_sunpy_map_as_fits(fits_raw, map_raw, dtype=np.uint16)

    # call secchi prep (open a new subprocess if one does not exist)
    new_session = False
    if idl_session is None:
        idl_session = idl_helper.Session()
        new_session = True

    # run the SSW/IDL prep command
    fits_prepped = os.path.join(App.TMP_HOME, 'tmp_euvi_prepped.fits')
    idl_session.secchi_prep(fits_raw, fits_prepped, quiet=True)

    # end the idl session if necessary (closes a subprocess)
    if new_session:
        idl_session.end()

    # read in the result as a sunpy map object
    map_prepped = sunpy.map.Map(fits_prepped)

    # get image data in double precision for processing
    image = np.float64(map_prepped.data)

    # end the secchi_prep SSW timer
    time_idl = timer() - t0
    print('done ({0:.2f}s)'.format(time_idl), flush=True)

    # deconvolve the image
    if deconvolve:
        # build the deconvolution string (making sure its in angstroms)
        wave_string = str(np.int(map_prepped.wavelength.to(u.angstrom).to_value()))

        if map_prepped.nickname == 'EUVI-A':
            inst_string = 'STA'
        if map_prepped.nickname == 'EUVI-B':
            inst_string = 'STB'

        psf_name = inst_string + '_' + wave_string + '_2048'
        if euvi_psf_version == 2:
            psf_name = psf_name + '_SHEARER'

        # Call the deconvolution script
        print("  Calling Remote PSF Deconvolution (" + psf_name + ")... ", end='', flush=True)
        t0 = timer()
        image = deconv.deconv_decurlog_gpu(image, psf_name)
        time_deconv = timer() - t0
        print('done ({0:.2f}s)'.format(time_deconv), flush=True)

    # now do the various prep steps
    print("  Prepping Image... ", end='', flush=True)
    t0 = timer()

    # remake the map with the floating point image
    map = sunpy.map.Map(image, map_prepped.meta)

    # bin the image to the desired resolution (this updates some metadata, manually update rsun)
    if euvi_bin_factor != 1:
        new_dimensions = u.Quantity([euvi_bin_factor, euvi_bin_factor]*u.pix)
        map = map.superpixel(new_dimensions, func=np.mean)

    # now rotate the image so solar north is up (this updates metadata)
    map = rotate_map_nopad(map)

    # label this new map as level 2 processing and add a history to the metadata
    level = 2.0
    map.meta['lvl_num'] = level
    map.meta['history'] = map.meta['history'] + \
                          ' Processed to lvl {0:.1f} by prep_euvi_image (CHD v{1})'.format(
                              level, chmap.settings.info.version)

    # replace the exposure time flag since it was normalized by secchi_prep
    map.meta['exptime'] = 1.0

    # get the chd specific metadata (delete the datetime object)
    chd_meta = get_metadata(map)
    if 'datetime' in chd_meta:
        chd_meta.pop('datetime')

    # get the x and y 1D scales for the image
    x, y = get_scales_from_map(map)

    # get the image data as the desired data type
    data = hdf_dtype(map.data)
    map.meta['bitpix'] = hdf_bitpix

    # Convert the final image to an LosImage object
    los = datatypes.LosImage(data, x, y, chd_meta, map.meta)

    # stop the prep time
    time_prep = timer() - t0
    print('done ({0:.2f}s)'.format(time_prep), flush=True)

    # return the LosImage
    return los