def test_potential_extrapolator_subclass():
    # Parameters for the extrapolator
    xrange = u.Quantity([50,    300] * u.arcsec)
    yrange = u.Quantity([-350, -100] * u.arcsec)
    zrange = u.Quantity([0,     250] * u.arcsec)
    shape = u.Quantity([5, 5, 5] * u.pixel)

    # Load HMI map (from fits file) then submap and resample.
    hmi_filename = pkg_resources.resource_filename('solarbextrapolation',
                                                   'data/sdo-hmi_2011-02-14_20-34-12.fits')
    map_boundary = sunpy.map.Map(hmi_filename)
    map_boundary = map_boundary.submap(xrange, yrange).resample(shape[0:2], method='linear')
    
    # Extrapolate using python native code
    aPotExt = PotentialExtrapolator(map_boundary, zshape=shape[2].value, zrange=zrange)
    aMap3D = aPotExt.extrapolate(enable_numba=False)
    
    # Extrapolate using numba
    aMap3D = aPotExt.extrapolate()
# Generate the data and make into a map
arr_data = generate_example_data(arr_grid_shape[0:2], xrange, yrange, arrA0, arrA1)
map_boundary = dummyDataToMap(arr_data, xrange, yrange)

##############################################################################
# You can check the resulting generated data by using peek().
map_boundary.peek()

##############################################################################
# You now simply want to extrapolate using this boundary data, this is achieved
# by first creating a potential extrapolator object and then by running the
# extrapolate on this to return a Map3D object with the resulting vector field.

# Use potential extrapolator to generate field
aPotExt = PotentialExtrapolator(map_boundary, zshape=arr_grid_shape[2], zrange=zrange)
aMap3D  = aPotExt.extrapolate(enable_numba=True)

# The Extrapolations run time is stored in the meta
floSeconds = np.round(aMap3D.meta['extrapolator_duration'],3)
print('\nextrapolation duration: ' + str(floSeconds) + ' s\n')

##############################################################################
# Note that you used enable_numba=True to speed up the computation on systems
# with Anaconda numba installed.

##############################################################################
# You can now get a quick and easy visualisation using the
# solarbextrapolation.example_data_generator.visualise tools:

# Visualise the 3D vector field
Beispiel #3
0
arr_data = generate_example_data(arr_grid_shape[0:2], xrange, yrange, arrA0,
                                 arrA1)
map_boundary = dummyDataToMap(arr_data, xrange, yrange)

##############################################################################
# You can check the resulting generated data by using peek().
map_boundary.peek()

##############################################################################
# You now simply want to extrapolate using this boundary data, this is achieved
# by first creating a potential extrapolator object and then by running the
# extrapolate on this to return a Map3D object with the resulting vector field.

# Use potential extrapolator to generate field
aPotExt = PotentialExtrapolator(map_boundary,
                                zshape=arr_grid_shape[2],
                                zrange=zrange)
aMap3D = aPotExt.extrapolate(enable_numba=True)

# The Extrapolations run time is stored in the meta
floSeconds = np.round(aMap3D.meta['extrapolator_duration'], 3)
print('\nextrapolation duration: ' + str(floSeconds) + ' s\n')

##############################################################################
# Note that you used enable_numba=True to speed up the computation on systems
# with Anaconda numba installed.

##############################################################################
# You can now get a quick and easy visualisation using the
# solarbextrapolation.example_data_generator.visualise tools:
dimensions = u.Quantity([100, 100] * u.pixel)
map_hmi_cropped_resampled = map_hmi_cropped.resample(dimensions,
                                                     method='linear')

# Open the map and create a cropped version for the visualisation.
#map_boundary = mp.Map('C:\\git\\solarbextrapolation\\examples\\2011-02-14__20-35-25__02_aia.fits') # For AIA
map_boundary = mp.Map(
    'C:\\git\\solarbextrapolation\\examples\\2011-02-14__20-35-25__01_hmi.fits'
)  # For HMI

map_boundary_cropped = map_boundary.submap(xrangeextended, yrangeextended)

# Only extrapolate if we don't have a saved version
if not os.path.isfile(str_vol_filepath):
    aPotExt = PotentialExtrapolator(map_hmi_cropped_resampled,
                                    filepath=str_vol_filepath,
                                    zshape=dimensions[0].value,
                                    zrange=zrange)
    aMap3D = aPotExt.extrapolate()
aMap3D = Map3D.load(str_vol_filepath)
print('\nextrapolation duration: ' + str(np.round(aMap3D.meta['extrapolator_duration'], 3)) + ' s\n')

# Visualise this
visualise(aMap3D,
          boundary=map_boundary_cropped,
          scale=1.0 * u.Mm,
          boundary_unit=1.0 * u.arcsec,
          show_boundary_axes=False,
          show_volume_axes=True,
          debug=False)
mlab.show()
Beispiel #5
0
################################################################################
# You can check the resulting generated data by using peek().
map_hmi_cropped_resampled.peek()

################################################################################
# To speed up repeat usage of this script it will save the extrapolation output,
# you can use os.path.isfile() to check if the file already exists, assuming it
# doesn't you will extrapolate and create it, otherwise you load it.

# Only extrapolate if we don't have a saved version
str_vol_filepath = data_hmi[0][0:-5] + '_Bxyz.npy'
if not os.path.isfile(str_vol_filepath):
    # Create the potential extrapolator and run the extrapolate method.
    aPotExt = PotentialExtrapolator(map_hmi_cropped_resampled,
                                    filepath=str_vol_filepath,
                                    zshape=20,
                                    zrange=zrange)
    aMap3D = aPotExt.extrapolate()
# Load the results.
aMap3D = Map3D.load(str_vol_filepath)
#print '\nextrapolation duration: ' + str(np.round(aMap3D.meta['extrapolator_duration'],3)) + ' s\n'

################################################################################
# For the perposes of visualisation we will want an extended boundary data, not
# just that of the extrapolated region, and at the instruments full resolution,
# not resampled.

xrangeextended = u.Quantity([xrange.value[0] - 50, xrange.value[1] + 50] *
                            xrange.unit)
yrangeextended = u.Quantity([yrange.value[0] - 50, yrange.value[1] + 50] *
                            yrange.unit)
Beispiel #6
0
            generate_example_data(shape[0:2], xrange, yrange, arrA0, arrA1,
                                  arrA2, arrA3), xrange, yrange)
    ])

##############################################################################
# You may wish to run each test more than once, so you can use a parameter to
# autimate this.
int_trials = 1  # The times to repeat each extrapolation.

##############################################################################
# You iterate through the extrapolations on each dataset, adding teh runtime to
# the table.
for extrapolation in lis_datasets:
    # Setup the extrapolator and table
    aPotExt = PotentialExtrapolator(extrapolation[3],
                                    zshape=extrapolation[1],
                                    zrange=extrapolation[2])

    # List to store the trial
    lis_times = []

    # Run the extrapolation without numba for each dataset (map and ranges).
    for i in range(0, int_trials):
        aMap3D = aPotExt.extrapolate(enable_numba=False)
        lis_times.append(aMap3D.meta['extrapolator_duration'])
    t.add_row([
        extrapolation[0],
        np.round(np.min(lis_times), 2),
        np.round(np.average(lis_times), 2),
        np.round(np.std(lis_times), 2)
    ])