def _extrapolation(self):
        # Adding in custom parameters to the meta
        self.meta['extrapolator_routine'] = 'Ones Extrapolator'

        #arr_4d = np.ones([self.map_boundary_data.data.shape[0], self.map_boundary_data.data.shape[0], self.z, 3])
        arr_4d = np.ones(self.shape.tolist() + [3])
        return Map3D(arr_4d, self.meta)
Exemple #2
0
    def _extrapolation(self, **kwargs):
        """
        The method for running an extrapolation routine.
        This is the primary method to be edited in subclasses for specific
        extrapolation routine implementations.
        """
        # Add some type checking, we want a map object, check for .unit attribute.
        # Extrapolation code goes here.
        arr_4d = np.zeros([
            self.map_boundary_data.data.shape[0],
            self.map_boundary_data.data.shape[1], 1, 3
        ])

        # Calculate the ranges in each dimension in length units (meters)
        x_range = self._angle_to_length(self.xrange)
        y_range = self._angle_to_length(self.yrange)
        z_range = self.zrange

        # Turn the 4D array into a Map3D object.
        map_output = Map3D(arr_4d,
                           self.meta,
                           xrange=x_range,
                           yrange=y_range,
                           zrange=z_range,
                           xobsrange=self.xobsrange,
                           yobsrange=self.yobsrange)

        return map_output
Exemple #3
0
    def __init__(self, **kwargs):
        # Default grid shape and physical ranges for the volume the model covers.
        self.shape = kwargs.get('shape',
                                u.Quantity([5, 5, 5] * u.pixel))  # (x,y,z)
        self.xrange = kwargs.get('xrange', u.Quantity([-10, 10] * u.Mm))
        self.yrange = kwargs.get('yrange', u.Quantity([-10, 10] * u.Mm))
        self.yrange = kwargs.get('zrange', u.Quantity([0, 20] * u.Mm))

        # Metadata
        self.meta = {
            'ZNAXIS': 3,
            'ZNAXIS1': self.shape[0].value,
            'ZNAxXIS2': self.shape[0].value,
            'ZNAXIS3': self.shape[0].value
        }
        self.meta['analytical_model_notes'] = kwargs.get('notes', '')
        self.meta['BUNIT'] = kwargs.get('bunit', u.T)
        # CRVALn, CDELTn and NAXIS (alreadu in meta) used for storing range in 2D fits files.
        self.filepath = kwargs.get('filepath', None)
        self.routine = kwargs.get('analytical_model_routine', type(self))

        # Default 3D magnetic field
        #X,Y,Z = np.zeros(self.shape.value), np.zeros(self.shape.value), np.zeros(self.shape.value)
        npField = np.zeros([3] + self.shape.value)
        self.field = Map3D(npField, self.meta)

        # Default magnetic field on boundary
        magnetogram = np.zeros(self.shape[0:2].value)
        magnetogram_header = {
            'ZNAXIS': 2,
            'ZNAXIS1': self.shape[0].value,
            'ZNAXIS2': self.shape[1].value
        }
        self.magnetogram = sunpy.map.Map((magnetogram, magnetogram_header))
Exemple #4
0
        def _generate_field(self, **kwargs):
            # Adding in custom parameters to the metadata
            self.meta['analytical_model_routine'] = 'Ones Model'

            # Generate a trivial field and return (X,Y,Z,Vec)
            arr_4d = np.ones(self.shape.value.tolist() + [3])
            return Map3D(arr_4d, self.meta)
    def _extrapolation(self, enable_numba=True, **kwargs):
        """
        Override the primary execution method from the extrapolation class.
        The process is to extrapolate the potential (scalar) field (phi) and
        then use numerical differentiation (gradient) to find the vector field
        (Bxyz).
        """

        if enable_numba:
            # Test that numba and the numba'ed extrpolator can be imported
            try:
                import numba
                from potential_field_extrapolator_numba import phi_extrapolation_numba
            except ImportError:
                enable_numba = False

        phi = self._extrapolate_phi(enable_numba, **kwargs)

        if enable_numba:
            from numba.decorators import autojit
            determine_vec = autojit(self._determine_vec)
        else:
            determine_vec = self._determine_vec

        npmVecSpace = np.zeros(list(phi.shape) +
                               [3])  # in Order XYZC (C = component directions)
        Bxyz = determine_vec(phi, 1, npmVecSpace)

        return Map3D(Bxyz,
                     self.meta,
                     xrange=self.xrange,
                     yrange=self.yrange,
                     zrange=self.zrange)
Exemple #6
0
    def _generate_field(self, **kwargs):
        # Adding in custom parameters to the metadata
        self.meta['analytical_model_routine'] = 'Ones Model'

        # Generate a trivial field and return (X,Y,Z,Vec)
        arr_4d = np.ones(self.shape.value.tolist() + [3])
        self.field = arr_4d

        # Extract the LoS Magnetogram from this:
        self.magnetogram.data = arr_4d[:, :, 0, 2]

        # Now return the vector field.
        return Map3D(arr_4d, self.meta)
Exemple #7
0
    def _generate_field(self, **kwargs):
        """
        The method for running a model to generate the field.
        This is the primary method to be edited in subclasses for specific
        model implementations.
        """
        # Model code goes here.
        arr_4d = np.zeros([
            self.map_boundary_data.data.shape[0],
            self.map_boundary_data.data.shape[1], 1, 3
        ])

        # Turn the 4D array into a Map3D object.
        map_output = Map3D(arr_4d,
                           self.meta,
                           xrange=self.xrange,
                           yrange=self.yrange,
                           zrange=self.zrange,
                           xobsrange=self.xrange,
                           yobsrange=self.yrange)

        return map_output
def text_load_Map3d(text_save_Map3d):
    aMap3D = Map3D.load(text_save_Map3d)
    # Compare the returned data array
    assert (aMap3D.data == np.zeros((2,2,2,2))).all()
def test_create_vector_Map3d():
     aNumpyArray = np.zeros((2,2,2,2))
     aMetaDict = { 'file': 'test Map3D object'}
     aMap3D = Map3D(aNumpyArray, aMetaDict)
     assert not is_scalar
     return aMap3D
        def _extrapolation(self):
            # Adding in custom parameters to the meta
            self.meta['extrapolator_routine'] = 'Zeros Extrapolator'

            arr_4d = np.zeros([self.map_boundary_data.data.shape[0], self.map_boundary_data.data.shape[0], self.z, 3])
            return Map3D( arr_4d, self.meta )
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()
Exemple #12
0
################################################################################
# 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)

# Open the map and create a cropped version for the visualisation.
map_boundary = mp.Map(data_hmi[0])
map_boundary_cropped = map_boundary.submap(xrangeextended, yrangeextended)