當前位置: 首頁>>代碼示例>>Python>>正文


Python BaseMap.__subclasses__方法代碼示例

本文整理匯總了Python中sunpy.map.basemap.BaseMap.__subclasses__方法的典型用法代碼示例。如果您正苦於以下問題:Python BaseMap.__subclasses__方法的具體用法?Python BaseMap.__subclasses__怎麽用?Python BaseMap.__subclasses__使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在sunpy.map.basemap.BaseMap的用法示例。


在下文中一共展示了BaseMap.__subclasses__方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __new__

# 需要導入模塊: from sunpy.map.basemap import BaseMap [as 別名]
# 或者: from sunpy.map.basemap.BaseMap import __subclasses__ [as 別名]
    def __new__(cls, input_, sortby="date"):
        """Creates a new Map instance"""
        
        # Directory of files
        if isinstance(input_, basestring):
            filepaths = []
            fits_arr = []
            data = []
            headers = []

            # directory
            if os.path.isdir(input_):
                for filename in os.listdir(input_):
                    filepaths.append(os.path.join(input_, filename))

            # glob string
            else:
                from glob import glob
                filepaths = glob(input_)
                
            # read in files
            for filepath in filepaths:
                fits = pyfits.open(filepath)
                
                # append normalized header tags for use during sorting
                found_header_match = False
                
                for subcls in BaseMap.__subclasses__(): #pylint: disable=E1101
                    if subcls.is_datasource_for(fits[0].header):
                        found_header_match = True
                        fits.norm_header = subcls.get_properties(fits[0].header)
                if not found_header_match:
                    raise UnrecognizedDataSouceError

                fits_arr.append(fits)

            # sort data
            if sortby and hasattr(cls, '_sort_by_%s' % sortby):
                fits_arr.sort(key=getattr(cls, '_sort_by_%s' % sortby)())

            # create data cube
            for fits in fits_arr:
                data.append(fits[0].data)
                headers.append(fits[0].header)

            obj = np.asarray(data).view(cls)
            obj._headers = headers

        # List of data or filepaths
        elif isinstance(input_, list):
            obj = np.asarray(input_).view(cls)

        # ndarray
        elif isinstance(input_, np.ndarray):
            obj = input_

        return obj
開發者ID:calexyoung,項目名稱:sunpy,代碼行數:59,代碼來源:mapcube.py

示例2: __getitem__

# 需要導入模塊: from sunpy.map.basemap import BaseMap [as 別名]
# 或者: from sunpy.map.basemap.BaseMap import __subclasses__ [as 別名]
 def __getitem__(self, key):
     """Overiding indexing operation"""
     if self.ndim is 3 and isinstance(key, int):
         data = np.ndarray.__getitem__(self, key)
         header = self._headers[key]
         for cls in BaseMap.__subclasses__():
             if cls.is_datasource_for(header):
                 return cls(data, header)
         raise UnrecognizedDataSouceError
     else:
         return np.ndarray.__getitem__(self, key)
開發者ID:calexyoung,項目名稱:sunpy,代碼行數:13,代碼來源:mapcube.py

示例3: Map

# 需要導入模塊: from sunpy.map.basemap import BaseMap [as 別名]
# 或者: from sunpy.map.basemap.BaseMap import __subclasses__ [as 別名]
def Map(input_):
    """Map class factory
    
    Attempts to determine the type of data associated with input and returns
    an instance of either the generic BaseMap class or a subclass of BaseMap
    such as AIAMap, EUVIMap, etc.
    
    Parameters
    ----------
    input_ : filepath, data array
        The data source used to create the map object. This can be either a
        filepath to an image, a 2d list, or an ndarray.
        
    Returns
    -------
    out : BaseMap
        Returns a BaseMap or BaseMap subclass instance
        
    Notes
    -----
    PyFITS
        [1] Due to the way PyFITS works with images the header dictionary may
        differ depending on whether is accessed before or after the fits[0].data
        is requested. If the header is read before the data then the original
        header will be returned. If the header is read after the data has been
        accessed then the data will have been scaled and a modified header
        reflecting these changes will be returned: BITPIX may differ and
        BSCALE and B_ZERO may be dropped in the modified version.
        
        [2] The verify('fix') call attempts to handle violations of the FITS
        standard. For example, nan values will be converted to "nan" strings.
        Attempting to cast a pyfits header to a dictionary while it contains
        invalid header tags will result in an error so verifying it early on
        makes the header easier to work with later.
    References
    ----------
    | http://stackoverflow.com/questions/456672/class-factory-in-python
    | http://stsdas.stsci.edu/download/wikidocs/The_PyFITS_Handbook.pdf
    """
    if isinstance(input_, basestring):
        fits = pyfits.open(input_)
        fits.verify('silentfix')        
        data = fits[0].data
        header = fits[0].header

        for cls in BaseMap.__subclasses__():
            if cls.is_datasource_for(header):
                return cls(data, header)
        raise UnrecognizedDataSouceError

    else:
        return BaseMap(input_)
開發者ID:calexyoung,項目名稱:sunpy,代碼行數:54,代碼來源:__init__.py


注:本文中的sunpy.map.basemap.BaseMap.__subclasses__方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。