Example #1
0
def test_mapsequence_solar_derotate(aia171_test_mapsequence, aia171_test_submap):
    # Test that a mapsequence is returned when the clipping is False.
    tmc = mapsequence_solar_derotate(aia171_test_mapsequence, clip=False)
    assert(isinstance(tmc, sunpy.map.MapSequence))

    # Test that all entries have the same shape when clipping is False
    for m in tmc:
        assert(m.data.shape == aia171_test_submap.data.shape)

    # Test that a mapsequence is returned on default clipping (clipping is True)
    tmc = mapsequence_solar_derotate(aia171_test_mapsequence)
    assert(isinstance(tmc, sunpy.map.MapSequence))

    # Test that the shape of data is correct when clipped
    clipped_shape = (25, 18)
    for m in tmc:
        assert(m.data.shape == clipped_shape)

    # Test that the returned reference pixels are correctly displaced.
    layer_index = 0
    derotated = mapsequence_solar_derotate(aia171_test_mapsequence, clip=True, layer_index=layer_index)
    tshift = calculate_solar_rotate_shift(aia171_test_mapsequence, layer_index=layer_index)
    derotated_reference_pixel_at_layer_index = derotated[layer_index].reference_pixel
    for i, m_derotated in enumerate(derotated):
        for i_s, s in enumerate(['x', 'y']):
            diff_in_rotated_reference_pixel = derotated[i].reference_pixel[i_s] - derotated_reference_pixel_at_layer_index[i_s]
            diff_arcsec = tshift[s][i] - tshift[s][layer_index]
            diff_pixel = diff_arcsec / m.scale[0]
            assert_quantity_allclose(diff_in_rotated_reference_pixel, diff_pixel, rtol=5e-2)
Example #2
0
def test_mapsequence_solar_derotate(aia171_test_mapsequence, aia171_test_submap):
    # Test that a mapsequence is returned when the clipping is False.
    tmc = mapsequence_solar_derotate(aia171_test_mapsequence, clip=False)
    assert(isinstance(tmc, sunpy.map.MapSequence))

    # Test that all entries have the same shape when clipping is False
    for m in tmc:
        assert(m.data.shape == aia171_test_submap.data.shape)

    # Test that a mapsequence is returned on default clipping (clipping is True)
    tmc = mapsequence_solar_derotate(aia171_test_mapsequence)
    assert(isinstance(tmc, sunpy.map.MapSequence))

    # Test that the shape of data is correct when clipped
    clipped_shape = (24, 19)
    for m in tmc:
        assert(m.data.shape == clipped_shape)

    # Test that the returned reference pixels are correctly displaced.
    layer_index = 0
    derotated = mapsequence_solar_derotate(aia171_test_mapsequence, clip=True, layer_index=layer_index)
    tshift = calculate_solar_rotate_shift(aia171_test_mapsequence, layer_index=layer_index)
    derotated_reference_pixel_at_layer_index = derotated[layer_index].reference_pixel
    for i, m_derotated in enumerate(derotated):
        for i_s, s in enumerate(['x', 'y']):
            diff_in_rotated_reference_pixel = derotated[i].reference_pixel[i_s] - derotated_reference_pixel_at_layer_index[i_s]
            diff_arcsec = tshift[s][i] - tshift[s][layer_index]
            diff_pixel = diff_arcsec / m.scale[0]
            assert_quantity_allclose(diff_in_rotated_reference_pixel, diff_pixel, rtol=5e-2)
Example #3
0
 def modifyData(self, data_model: CompositeMapModel) -> DataModel:
     mc = Map(data_model.getMaps(), cube=True)
     derotated = mapsequence_solar_derotate(mc)
     data_model.updateMaps(derotated.maps)
     return data_model
def Flarefinder(start_datetime, end_datetime):
    instrument = a.Instrument('AIA')
    wave = a.Wavelength(13 * u.nm, 14 * u.nm)

    start_datetime_d = start_datetime + timedelta(seconds=15)
    end_datetime_d = end_datetime + timedelta(seconds=15)
    result = Fido.search(
        a.Time(start_datetime, start_datetime_d)
        | a.Time(end_datetime, end_datetime_d), instrument, wave)
    downloaded_files = Fido.fetch(
        result, path="C:/Users/Nils/Documents/MaTa/flaskandst/sunpymaps")
    maps = smap.Map(downloaded_files, sequence=True)
    maps = mapsequence_solar_derotate(maps)
    amount = len(maps)

    #%%######################################################################-Superpixel-######################################################################
    pixamt = 128
    newdim1 = u.Quantity(maps[0].dimensions) / pixamt
    newdim2 = u.Quantity(maps[amount - 1].dimensions) / pixamt
    spmap1 = maps[0].superpixel(newdim1)
    spmap2 = maps[amount - 1].superpixel(newdim2)

    #%%######################################################################-Difference Map-######################################################################

    diff = spmap1.data - spmap2.data
    metadiff = spmap2.meta
    diffmap = smap.Map(diff, metadiff)
    #vdef = diffmap.max()*0.6
    #fig = plt.figure()
    #ax_diffmap= plt.subplot(projection = diffmap)
    #dplot = diffmap.plot(cmap='Greys_r', norm=colors.Normalize(vmin=-vdef, vmax=vdef))
    #st.write(fig)

    #%%#####################################################################-Flare Detection Procedure-########################################################################

    bar = diffmap.max() * 0.99

    pixelpos = np.argwhere(abs(diffmap.data) >= bar) * u.pixel
    if len(pixelpos) == 0:
        print('no flares found')

    else:
        print('Possible flare locations:')
        print(pixelpos)
        print('Keep in mind here in pixel format it is y,x and not x,y')

    pixelcord = diffmap.pixel_to_world(pixelpos[:, 1], pixelpos[:, 0])
    print(pixelcord)

    #%%#####################################################################-Submap-########################################################################

    pixoperator = (540, 960) * u.pixel
    pixelpos4k = pixelpos * (4096 / pixamt)
    PPLEN = len(pixelpos)

    x = 0
    while x < PPLEN:
        now = datetime.utcnow()
        nowstr = now.strftime("%Y%b%athe%d%H%M%S")
        startstr = start_datetime.strftime("%Y%b%athe%d%H%M%S")
        endstr = end_datetime.strftime("%Y%b%athe%d%H%M%S")
        pixbot = pixelpos4k[x] - pixoperator
        cordbot = maps[amount - 1].pixel_to_world(pixbot[1], pixbot[0])
        submap = maps[amount - 1].submap(cordbot,
                                         width=1153.43016 * u.arcsec,
                                         height=648.75384 * u.arcsec)
        fig = plt.figure()
        ax_submap = plt.subplot(projection=submap)
        submap.plot(cmap='sdoaia131')
        urlstr = "static/Submaps/" + nowstr + "_" + startstr + "_" + endstr + ".jpeg"
        plt.savefig(urlstr)

        newflare = [startstr, endstr, urlstr]
        conn.execute(
            '''insert into flares(stime, etime, urlfor) values (?,?,?) ''',
            newflare)
        conn.commit()
        st.write(fig)
        x += 1