Exemplo n.º 1
0
    def _spherical_to_cartesian(self, lon, lat, i, j):
        """Takes latitude, longitude arrays and returns cartesian unit vector.

        Latitude and longitude must be in degrees and must have already been 
        shifted .5 pixels as calculated from corners keyword of heliographic
        function. i and j represent the shift and thus corner.
        i, j
        0, 0: top-left
        1, 0: bottom-left
        1, 1: bottom-right
        0, 1: top-right
        """
        coslat = M.cos(lat)
        coslon = M.cos(lon)
        sinlat = M.sin(lat)
        sinlon = M.sin(lon)
        l = len(lat)
        Xar = coslat[i:l - 1 + i, j:l - 1 + j]*coslon[i:l - 1 + i, j:l - 1 + j]
        Yar = coslat[i:l - 1 + i, j:l - 1 + j]*sinlon[i:l - 1 + i, j:l - 1 + j]
        Zar = sinlat[i:l - 1 + i, j:l - 1 + j]
        r = np.ndarray(shape=(3,), dtype=np.object)
        r[0] = Xar
        r[1] = Yar
        r[2] = Zar
        return r
Exemplo n.º 2
0
def indices(m, pole, dlim=75.0):
    print ("Determining polar cap pixels.")
    if pole == 'north':
        p = np.where((m.lath > dlim) & (m.rg < m.rsun*np.sin(75.0*np.pi/180)))

        vp = np.where((m.rg < m.rsun) & (m.lath > dlim) 
                & M.isfinite(m.im_corr))

        posp = np.where((m.rg < m.rsun) & (m.lath > dlim)
                & (m.im_corr > 0.0))

        negp = np.where((m.rg < m.rsun) & (m.lath > dlim)
                & (m.im_corr < 0.0))
    else:
        p = np.where((m.lath < -dlim) & (m.rg < m.rsun*np.sin(75.0*np.pi/180)))

        vp = np.where((m.rg < m.rsun) & (m.lath < -dlim) 
                & M.isfinite(m.im_corr))

        posp = np.where((m.rg < m.rsun) & (m.lath < -dlim)
                & (m.im_corr > 0.0))

        negp = np.where((m.rg < m.rsun) & (m.lath < -dlim)
                & (m.im_corr < 0.0))

    return p, vp, posp, negp
Exemplo n.º 3
0
    def _grid(self, corners=False):
        """Create an xy grid of coordinates for heliographic array.

        Uses meshgrid. If corners is selected, this function will shift
        the array by half a pixel in both directions so that the corners
        of the normal array can be accessed easily.
        """
        # Retrieve integer dimensions and create arrays holding
        # x and y coordinates of each pixel
        xDim = np.int(np.floor(self.im_raw.dimensions[0].value))
        yDim = np.int(np.floor(self.im_raw.dimensions[1].value))
        
        if corners:
            xRow = (np.arange(0, xDim + 1) - self.X0 - 0.5)*self.xScale
            yRow = (np.arange(0, yDim + 1) - self.Y0 - 0.5)*self.yScale
            xg, yg = M.meshgrid(xRow, yRow)
            rg = M.sqrt(xg**2 + yg**2)
            self.Rg = rg
        else:
            xRow = (np.arange(0, xDim) - self.X0)*self.xScale
            yRow = (np.arange(0, yDim) - self.Y0)*self.yScale
            xg, yg = M.meshgrid(xRow, yRow)
            rg = M.sqrt(xg**2 + yg**2)
            self.xg = xg
            self.yg = yg
            self.rg = rg

        return xg, yg
Exemplo n.º 4
0
 def __init__(self, data=None, metadata=None, q=None, qx=None, qy=None, theta=None):
     self.data = Measurement(data, data)
     self.metadata = metadata
     self.q = q  # There are many places where q was not set, i think i fixed most, but there might be more; be wary
     self.qx = qx
     self.qy = qy
     self.theta = theta
Exemplo n.º 5
0
    def __init__(self,
                 data=None,
                 metadata=None,
                 q=None,
                 qx=None,
                 qy=None,
                 theta=None,
                 Tsam=None,
                 Temp=None):
        self.data = Measurement(data, data)
        self.metadata = metadata
        self.q = q  #There are many places where q was not set, i think i fixed most, but there might be more; be wary
        self.qx = qx
        self.qy = qy
        self.theta = theta

        self.Tsam = None  #Tsam and Temp are used to store the transmissions for later use
        self.Temp = None
Exemplo n.º 6
0
 def __truediv__(self, other):
     if isinstance(other, SansData):
         return SansData(
             Measurement(*err1d.div(self.data.x, self.data.variance,
                                    other.data.x, other.data.variance)).x,
             deepcopy(self.metadata),
             q=copy(self.q),
             qx=copy(self.qx),
             qy=copy(self.qy),
             theta=copy(self.theta))
     else:
         return SansData(data=Measurement(self.data.x / other,
                                          self.data.variance / other**2).x,
                         metadata=deepcopy(self.metadata),
                         q=copy(self.q),
                         qx=copy(self.qx),
                         qy=copy(self.qy),
                         theta=copy(self.theta))
Exemplo n.º 7
0
 def __init__(self,data=None,metadata=None,q=None,qx=None,qy=None,theta=None,Tsam=None,Temp=None):
     self.data=Measurement(data,data)
     self.metadata=metadata
     self.q=q #There are many places where q was not set, i think i fixed most, but there might be more; be wary
     self.qx=qx
     self.qy=qy
     self.theta=theta
     
     self.Tsam = None #Tsam and Temp are used to store the transmissions for later use
     self.Temp = None
Exemplo n.º 8
0
    def _hcc_hg(self, x, y, z):
        """Converts hcc coordinates to Stonyhurst heliographic. 

        x - x coordinate in meters
        y - y coordinate in meters 
        z - z coordinate in meters
        Calculations taken and shortened
        from sunpy.wcs.
        """
        cosb = M.cos(M.deg2rad(self.B0))
        sinb = M.sin(M.deg2rad(self.B0))

        hecr = M.sqrt(x**2 + y**2 + z**2)
        hgln = M.arctan2(x, z*cosb - y*sinb) \
                + M.deg2rad(self.L0)
        hglt = M.arcsin((y * cosb + z * sinb)/hecr)

        return hgln*180/np.pi, hglt*180/np.pi
Exemplo n.º 9
0
 def __mul__(self, other):
     if isinstance(other, SansData):
         return SansData(
             Measurement(*err1d.mul(self.data.x, self.data.variance,
                                    other.data.x, other.data.variance)).x,
             deepcopy(self.metadata),
             q=copy(self.q),
             qx=copy(self.qx),
             qy=copy(self.qy),
             theta=copy(self.theta))
     else:
         return SansData(data=self.data.__mul__(other).x,
                         metadata=deepcopy(self.metadata),
                         q=copy(self.q),
                         qx=copy(self.qx),
                         qy=copy(self.qy),
                         theta=copy(self.theta))
Exemplo n.º 10
0
    def _hpc_hcc(self, x, y):
        """Converts hpc coordinates to hcc coordinates. 

        x -- x coordinate in arcseconds
        y -- y coordinate in arcseconds
        Calculations taken and shortened from sunpy.wcs.
        """
        x *= np.deg2rad(1)/3600.0
        y *= np.deg2rad(1)/3600.0

        q = self.dsun * M.cos(y) * M.cos(x)
        distance = q**2 - self.dsun**2 + self.RSUN_METERS**2
        distance = q - M.sqrt(distance)
        
        rx = distance * M.cos(y) * M.sin(x)
        ry = distance * M.sin(y)
        rz = M.sqrt(self.RSUN_METERS**2 - rx**2 - ry**2)

        return rx, ry, rz
Exemplo n.º 11
0
    def eoa(self, *args, array=True):
        """Takes in coordinates and returns the area of pixels on sun.

        Each pixel is projected onto the sun, and therefore pixels close to
        the limbs have vastly greater areas. This function uses a closed form
        solution to a spherical area integral to calulate the area based on
        the heliographic coordinate unit vectors of each corner of the pixel.
        We use these to calculate a solid angle of a pyramid with its apex
        at the center of the sun.
        """

        print ("Calculating element of area.")
        # Assume coordinate is in center of pixel.
        # Information on pixel standard is in this article.
        # http://www.aanda.org/component/article?access=bibcode&bibcode=&bibcode=2002A%2526A...395.1061GFUL
        if array:
            lon, lat = self.heliographic(corners=True)
            lon = lon*np.pi/180
            lat = lat*np.pi/180
            # Calculating unit vectors of pixel corners for solid angle.
            r1 = self._spherical_to_cartesian(lon, lat, 0, 0)
            r2 = self._spherical_to_cartesian(lon, lat, 1, 0)
            r3 = self._spherical_to_cartesian(lon, lat, 1, 1)
            r4 = self._spherical_to_cartesian(lon, lat, 0, 1)

        else:
            x = args[0]
            y = args[1]
            lonUL, latUL = self.heliographic(x - .5, y - .5)
            lonLL, latLL = self.heliographic(x + .5, y - .5)
            lonLR, latLR = self.heliographic(x + .5, y + .5)
            lonUR, latUR = self.heliographic(x - .5, y + .5)

            # Calculating unit vectors of pixel corners for solid angle.
            r1 = np.array([np.cos(np.deg2rad(latUL))*np.cos(np.deg2rad(lonUL)),
                            np.cos(np.deg2rad(latUL))*np.sin(np.deg2rad(lonUL)),
                            np.sin(np.deg2rad(latUL))])

            r2 = np.array([np.cos(np.deg2rad(latLL))*np.cos(np.deg2rad(lonLL)),
                            np.cos(np.deg2rad(latLL))*np.sin(np.deg2rad(lonLL)),
                            np.sin(np.deg2rad(latLL))])

            r3 = np.array([np.cos(np.deg2rad(latLR))*np.cos(np.deg2rad(lonLR)),
                            np.cos(np.deg2rad(latLR))*np.sin(np.deg2rad(lonLR)),
                            np.sin(np.deg2rad(latLR))])

            r4 = np.array([np.cos(np.deg2rad(latUR))*np.cos(np.deg2rad(lonUR)),
                            np.cos(np.deg2rad(latUR))*np.sin(np.deg2rad(lonUR)),
                            np.sin(np.deg2rad(latUR))])

        # Calculate solid angle of pixel based on a pyrimid shaped polygon.
        # See http://planetmath.org/solidangleofrectangularpyramid
        cross1 = M.cross(r1, r2, axis=0)
        cross2 = M.cross(r3, r4, axis=0)
        numerator1 = M.dot(cross1, r3)
        numerator2 = M.dot(cross2, r1)
        solid_angle1 = 2*M.arctan2(numerator1,
                (M.dot(r1, r2) + M.dot(r2, r3) + M.dot(r3, r1) + 1))
        solid_angle2 = 2*M.arctan2(numerator2, 
                (M.dot(r3, r4) + M.dot(r4, r1) + M.dot(r3, r1) + 1))
        solid_angle = solid_angle1 + solid_angle2

        r = self.RSUN_METERS*100 # Convert to centimeters
        if array:
            self.area = abs((r**2)*solid_angle)
            ind = np.where(self.Rg[1:len(self.Rg)-1, 1:len(self.Rg)-1] > self.rsun)
            del self.Rg
            self.area[ind] = np.nan
            return
        else:
            if self.rg > self.rsun:
                return np.nan
            else:    
                return np.abs((r**2)*solid_angle)
Exemplo n.º 12
0
    def los_corr(self, *args, array=True):
        """Takes in coordinates and returns corrected magnetic field.

        Applies the dot product between the observers unit vector and
        the heliographic radial vector to get the true magnitude of 
        the magnetic field vector. See geometric projection for
        calulations.
        """

        print("Correcting line of sight magnetic field.")
        if array:
            try:
                lonh, lath = M.deg2rad(self.lonh), M.deg2rad(self.lath)
            except AttributeError:
                self.heliographic()
                lonh, lath = M.deg2rad(self.lonh), M.deg2rad(self.lath)
        else:
            lonh, lath = M.deg2rad(self.heliographic(args[0], args[1]))

        B0 = M.deg2rad(self.B0)
        L0 = M.deg2rad(self.L0)

        Xobs = M.cos(B0)*M.cos(L0)
        Yobs = M.cos(B0)*M.sin(L0)
        Zobs = M.sin(B0)

        corr_factor = (M.cos(lath)*M.cos(lonh)*Xobs
                + M.cos(lath)*M.sin(lonh)*Yobs
                + M.sin(lath)*Zobs)

        if array:
            self.im_corr = self.im_raw_u/corr_factor
            bad_ind = np.where(self.rg > self.rsun*np.sin(75.0*np.pi/180))
            self.im_corr[bad_ind] = np.nan
            return
        else:
            return self.im_raw.data[args[0], args[1]]/corr_factor
Exemplo n.º 13
0
class SansData(object):
    """SansData object used for storing values from a sample file (not div/mask).               
       Stores the array of data as a Measurement object (detailed in uncertainty.py)
       Stores all metadata
       q,qx,qy,theta all get updated with values throughout the reduction process
       Tsam and Temp are just used for storage across modules (in wireit)
    """
    def __init__(self,
                 data=None,
                 metadata=None,
                 q=None,
                 qx=None,
                 qy=None,
                 theta=None,
                 Tsam=None,
                 Temp=None):
        self.data = Measurement(data, data)
        self.metadata = metadata
        self.q = q  #There are many places where q was not set, i think i fixed most, but there might be more; be wary
        self.qx = qx
        self.qy = qy
        self.theta = theta

        self.Tsam = None  #Tsam and Temp are used to store the transmissions for later use
        self.Temp = None

    # Note that I have not defined an inplace subtraction
    def __sub__(self, other):
        if isinstance(other, SansData):
            return SansData(self.data - other.data,
                            deepcopy(self.metadata),
                            q=copy(self.q),
                            qx=copy(self.qx),
                            qy=copy(self.qy),
                            theta=copy(self.theta))
        else:
            return SansData(data=self.data - other,
                            metadata=deepcopy(self.metadata),
                            q=copy(self.q),
                            qx=copy(self.qx),
                            qy=copy(self.qy),
                            theta=copy(self.theta))

    #Actual subtraction
    def __sub1__(self, other):
        if isinstance(other, SansData):
            return SansData(self.data.x - other.data.x,
                            deepcopy(self.metadata),
                            q=copy(self.q),
                            qx=copy(self.qx),
                            qy=copy(self.qy),
                            theta=copy(self.theta))
        else:
            return SansData(data=self.data.x - other.data.x,
                            metadata=deepcopy(self.metadata),
                            q=copy(self.q),
                            qx=copy(self.qx),
                            qy=copy(self.qy),
                            theta=copy(self.theta))

    def __add__(self, other):
        if isinstance(other, SansData):
            return SansData(self.data.x + other.data.x,
                            deepcopy(self.metadata),
                            q=copy(self.q),
                            qx=copy(self.qx),
                            qy=copy(self.qy),
                            theta=copy(self.theta))
        else:
            return SansData(data=self.data.x + other.data.x,
                            metadata=deepcopy(self.metadata),
                            q=copy(self.q),
                            qx=copy(self.qx),
                            qy=copy(self.qy),
                            theta=copy(self.theta))

    def __rsub__(self, other):
        return SansData(data=other - self.data,
                        metadata=deepcopy(self.metadata),
                        q=copy(self.q),
                        qx=copy(self.qx),
                        qy=copy(self.qy),
                        theta=copy(self.theta))

    def __truediv__(self, other):
        if isinstance(other, SansData):
            return SansData(
                Measurement(*err1d.div(self.data.x, self.data.variance,
                                       other.data.x, other.data.variance)).x,
                deepcopy(self.metadata),
                q=copy(self.q),
                qx=copy(self.qx),
                qy=copy(self.qy),
                theta=copy(self.theta))
        else:
            return SansData(data=Measurement(self.data.x / other,
                                             self.data.variance / other**2).x,
                            metadata=deepcopy(self.metadata),
                            q=copy(self.q),
                            qx=copy(self.qx),
                            qy=copy(self.qy),
                            theta=copy(self.theta))

    def __mul__(self, other):
        if isinstance(other, SansData):
            return SansData(
                Measurement(*err1d.mul(self.data.x, self.data.variance,
                                       other.data.x, other.data.variance)).x,
                deepcopy(self.metadata),
                q=copy(self.q),
                qx=copy(self.qx),
                qy=copy(self.qy),
                theta=copy(self.theta))
        else:
            return SansData(data=self.data.__mul__(other).x,
                            metadata=deepcopy(self.metadata),
                            q=copy(self.q),
                            qx=copy(self.qx),
                            qy=copy(self.qy),
                            theta=copy(self.theta))

    #def __str__(self):
    #return self.data.x.__str__()
    #def __repr__(self):
    #return self.__str__()
    def get_plottable(self):
        data = self.data.x.tolist()
        if not (np.abs(self.data.x) > 1e-10).any():
            zmin = 0.0
            zmax = 1.0
        else:
            zmin = self.data.x[self.data.x > 1e-10].min()
            if IGNORE_CORNER_PIXELS == True:
                mask = np.ones(self.data.x.shape, dtype='bool')
                mask[0, 0] = mask[-1, 0] = mask[-1, -1] = mask[0, -1] = 0.0
                zmax = self.data.x[mask].max()
            else:
                zmax = self.data.x.max()
        plottable_data = {
            'type':
            '2d',
            'z': [data],
            'title':
            self.metadata['run.filename'] + ': ' +
            self.metadata['sample.labl'],
            'metadata':
            self.metadata,
            'options': {
                'fixedAspect': {
                    'fixAspect': True,
                    'aspectRatio': 1.0
                }
            },
            'dims': {
                'xmax': 128,
                'xmin': 0.0,
                'ymin': 0.0,
                'ymax': 128,
                'xdim': 128,
                'ydim': 128,
                'zmin': zmin,
                'zmax': zmax,
            },
            'xlabel':
            'X',
            'ylabel':
            'Y',
            'zlabel':
            'Intensity (I)',
        }
        out = simplejson.dumps(plottable_data, sort_keys=True)
        return out

    def dumps(self):
        return pickle.dumps(self)

    @classmethod
    def loads(cls, str):
        return pickle.loads(str)
Exemplo n.º 14
0
class SansData(object):
    """SansData object used for storing values from a sample file (not div/mask).               
       Stores the array of data as a Measurement object (detailed in uncertainty.py)
       Stores all metadata
       q,qx,qy,theta all get updated with values throughout the reduction process
       Tsam and Temp are just used for storage across modules (in wireit)
    """
    def __init__(self,data=None,metadata=None,q=None,qx=None,qy=None,theta=None,Tsam=None,Temp=None):
        self.data=Measurement(data,data)
        self.metadata=metadata
        self.q=q #There are many places where q was not set, i think i fixed most, but there might be more; be wary
        self.qx=qx
        self.qy=qy
        self.theta=theta
        
        self.Tsam = None #Tsam and Temp are used to store the transmissions for later use
        self.Temp = None
    # Note that I have not defined an inplace subtraction
    def __sub__(self,other):
        if isinstance(other,SansData):
            return SansData(self.data-other.data,deepcopy(self.metadata),q=copy(self.q),qx=copy(self.qx),qy=copy(self.qy),theta=copy(self.theta))
        else:
            return SansData(data=self.data-other,metadata=deepcopy(self.metadata),q=copy(self.q),qx=copy(self.qx),qy=copy(self.qy),theta=copy(self.theta))
    #Actual subtraction
    def __sub1__(self,other):
        if isinstance(other,SansData):
            return SansData(self.data.x-other.data.x,deepcopy(self.metadata),q=copy(self.q),qx=copy(self.qx),qy=copy(self.qy),theta=copy(self.theta))
        else:
            return SansData(data=self.data.x-other.data.x,metadata=deepcopy(self.metadata),q=copy(self.q),qx=copy(self.qx),qy=copy(self.qy),theta=copy(self.theta))
    def __add__(self,other):
        if isinstance(other,SansData):
            return SansData(self.data.x+other.data.x,deepcopy(self.metadata),q=copy(self.q),qx=copy(self.qx),qy=copy(self.qy),theta=copy(self.theta))
        else:
            return SansData(data=self.data.x+other.data.x,metadata=deepcopy(self.metadata),q=copy(self.q),qx=copy(self.qx),qy=copy(self.qy),theta=copy(self.theta))
    def __rsub__(self, other):
        return SansData(data=other-self.data, metadata=deepcopy(self.metadata),q=copy(self.q),qx=copy(self.qx),qy=copy(self.qy),theta=copy(self.theta))
    def __truediv__(self,other):
        if isinstance(other,SansData):
            return SansData(Measurement(*err1d.div(self.data.x,self.data.variance,other.data.x,other.data.variance)).x,deepcopy(self.metadata),q=copy(self.q),qx=copy(self.qx),qy=copy(self.qy),theta=copy(self.theta))
        else:
            return SansData(data=Measurement(self.data.x/other, self.data.variance/other**2).x,metadata=deepcopy(self.metadata),q=copy(self.q),qx=copy(self.qx),qy=copy(self.qy),theta=copy(self.theta))
    def __mul__(self,other):
        if isinstance(other,SansData):
            return SansData(Measurement(*err1d.mul(self.data.x,self.data.variance,other.data.x,other.data.variance)).x,deepcopy(self.metadata),q=copy(self.q),qx=copy(self.qx),qy=copy(self.qy),theta=copy(self.theta))
        else:
            return SansData(data = self.data.__mul__(other).x,metadata=deepcopy(self.metadata),q=copy(self.q),qx=copy(self.qx),qy=copy(self.qy),theta=copy(self.theta))
        
    #def __str__(self):
        #return self.data.x.__str__()
    #def __repr__(self):
        #return self.__str__()
    def get_plottable(self): 
        data = self.data.x.astype("float")
        xdim = data.shape[0]
        ydim = data.shape[1]
        if not (np.abs(data) > 1e-10).any():
            zmin = 0.0
            zmax = 1.0
        else: 
            zmin = data[data > 1e-10].min()
            if IGNORE_CORNER_PIXELS == True:
                mask = np.ones(data.shape, dtype='bool')
                mask[0,0] = mask[-1,0] = mask[-1,-1] = mask[0,-1] = 0.0
                zmax = data[mask].max()
            else:
                zmax = data.max()
        if self.qx is None or self.qy is None:
            xmin = 0
            xmax = 128
            ymin = 0
            ymax = 128
            xlabel = "X"
            ylabel = "Y"
        else:
            xmin = self.qx.min()
            xmax = self.qx.max()
            ymin = self.qy.min()
            ymax = self.qy.max()
            xlabel = "Qx (inv. Angstroms)"
            ylabel = "Qy (inv. Angstroms)"
        plottable_data = {
            'type': '2d',
            'z':  [data.T.tolist()],
            'title': self.metadata['run.filename']+': ' + self.metadata['sample.labl'],
            #'metadata': self.metadata,
            'options': {
                'fixedAspect': {
                    'fixAspect': True,
                    'aspectRatio': 1.0
                }
            },
            'dims': {
                'xmax': xmax,
                'xmin': xmin, 
                'ymin': ymin, 
                'ymax': ymax,
                'xdim': xdim,
                'ydim': ydim,
                'zmin': zmin,
                'zmax': zmax,
                },
            'xlabel': xlabel,
            'ylabel': ylabel,
            'zlabel': 'Intensity (I)',
            };
        return plottable_data
    
    def get_metadata(self):
        metadata = {}
        metadata.update(self.metadata)
        metadata['plottable'] = self.get_plottable()
        return metadata
    
    def dumps(self):
        return pickle.dumps(self)
    @classmethod
    def loads(cls, str): 
        return pickle.loads(str)
Exemplo n.º 15
0
class SansData(object):
    def __init__(self, data=None, metadata=None, q=None, qx=None, qy=None, theta=None):
        self.data = Measurement(data, data)
        self.metadata = metadata
        self.q = q  # There are many places where q was not set, i think i fixed most, but there might be more; be wary
        self.qx = qx
        self.qy = qy
        self.theta = theta

    # Note that I have not defined an inplace subtraction
    def __sub__(self, other):
        if isinstance(other, SansData):
            return SansData(
                self.data - other.data,
                deepcopy(self.metadata),
                q=copy(self.qx),
                qx=copy(self.qx),
                qy=copy(self.qy),
                theta=copy(self.theta),
            )
        else:
            return SansData(
                data=self.data - other,
                metadata=deepcopy(self.metadata),
                q=copy(self.qx),
                qx=copy(self.qx),
                qy=copy(self.qy),
                theta=copy(self.theta),
            )

    # Actual subtraction
    def __sub1__(self, other):
        if isinstance(other, SansData):
            return SansData(
                self.data.x - other.data.x,
                deepcopy(self.metadata),
                q=copy(self.qx),
                qx=copy(self.qx),
                qy=copy(self.qy),
                theta=copy(self.theta),
            )
        else:
            return SansData(
                data=self.data.x - other.data.x,
                metadata=deepcopy(self.metadata),
                q=copy(self.qx),
                qx=copy(self.qx),
                qy=copy(self.qy),
                theta=copy(self.theta),
            )

    def __add__(self, other):
        if isinstance(other, SansData):
            return SansData(
                self.data.x + other.data.x,
                deepcopy(self.metadata),
                q=copy(self.qx),
                qx=copy(self.qx),
                qy=copy(self.qy),
                theta=copy(self.theta),
            )
        else:
            return SansData(
                data=self.data.x + other.data.x,
                metadata=deepcopy(self.metadata),
                q=copy(self.qx),
                qx=copy(self.qx),
                qy=copy(self.qy),
                theta=copy(self.theta),
            )

    def __rsub__(self, other):
        return SansData(
            data=other - self.data,
            metadata=deepcopy(self.metadata),
            q=copy(self.qx),
            qx=copy(self.qx),
            qy=copy(self.qy),
            theta=copy(self.theta),
        )

    def __truediv__(self, other):
        if isinstance(other, SansData):
            return SansData(
                Measurement(*err1d.div(self.data.x, self.data.variance, other.data.x, other.data.variance)).x,
                deepcopy(self.metadata),
                q=copy(self.qx),
                qx=copy(self.qx),
                qy=copy(self.qy),
                theta=copy(self.theta),
            )
        else:
            return SansData(
                data=Measurement(self.data.x / other, self.data.variance / other ** 2).x,
                metadata=deepcopy(self.metadata),
                q=copy(self.qx),
                qx=copy(self.qx),
                qy=copy(self.qy),
                theta=copy(self.theta),
            )

    def __mul__(self, other):
        if isinstance(other, SansData):
            return SansData(
                Measurement(*err1d.mul(self.data.x, self.data.variance, other.data.x, other.data.variance)).x,
                deepcopy(self.metadata),
                q=copy(self.qx),
                qx=copy(self.qx),
                qy=copy(self.qy),
                theta=copy(self.theta),
            )
        else:
            return SansData(
                data=self.data.__mul__(other).x,
                metadata=deepcopy(self.metadata),
                q=copy(self.qx),
                qx=copy(self.qx),
                qy=copy(self.qy),
                theta=copy(self.theta),
            )

    def __str__(self):
        return self.data.x.__str__()

    def __repr__(self):
        return self.__str__()
Exemplo n.º 16
0
def calc_parameters(mgnt, p, vp, posp, negp):
    """Calculates certain parameters based on passed pixel groups.

    p:      pixels defined by the polar crown
    vp:     finite pixels in the polar crown
    posp:   positive flux pixels in the polar crown
    negp:   negative flux pixels in the polar crown
    """
    swt = 0
    meanf = M.nanmean(mgnt.im_raw_u[vp])
    meanfc = M.nanmean(mgnt.im_corr[vp])
    sumf = M.nansum(mgnt.im_raw_u[vp])
    sumfc = M.nansum(mgnt.im_corr[vp])
    unsflux = M.nansum(abs(mgnt.mflux_raw[vp]))
    unsfluxc = M.nansum(abs(mgnt.mflux_corr[vp]))
    sflux = M.nansum(mgnt.mflux_raw[vp])
    sfluxc = M.nansum(mgnt.mflux_corr[vp])
    posfluxc = M.nansum(mgnt.mflux_corr[posp])
    negfluxc = M.nansum(mgnt.mflux_corr[negp])
    visarea = M.nansum(mgnt.area[vp])
    max_pxflux = M.nanmax(abs(mgnt.mflux_corr[vp]))
    max_pxf = M.nanmax(mgnt.im_raw.data[vp])
    max_pxfc =  M.nanmax(mgnt.im_corr[vp])

    # Corrected field might be zero. Replace entries with NaNs.
    if unsfluxc == 0.0:
        unsfluxc = M(np.nan, np.nan)
        sfluxc = M(np.nan, np.nan)
        posfluxc = M(np.nan, np.nan)
        negfluxc = M(np.nan, np.nan)
        max_pxflux = np.nan
        swt = 4

    var = {'meanf': meanf, 'meanfc': meanfc, 'sumf': sumf, 'sumfc': sumfc,
                'unsflux': unsflux, 'unsfluxc': unsfluxc, 'sflux': sflux,
                'sfluxc': sfluxc, 'posfluxc': posfluxc, 'negfluxc': negfluxc,
                'nvp_px': np.size(vp), 'p_ratio': np.size(vp)/np.size(p),
                'visarea': visarea, 'max_pxflux': max_pxflux, 'max_pxf': max_pxf,
                'max_pxfc': max_pxfc, 'swt': swt}
    return var