def Map(filepath): """Creates a map from specified file. .. deprecated:: 0.1 Use `make_map` instead. Parameters ---------- filepath : string Filepath to a FITs or JPEG 2000 file Returns ------- out : Map Creates a map instance using the specific file and return it """ import warnings warnings.warn("sunpy.Map is deprecated: use sunpy.make_map instead.", DeprecationWarning) if isinstance(filepath, basestring): return BaseMap.read(filepath) else: raise InvalidMapInput("Invalid input for make_map. Please specify " "one or more filepaths, Maps, directories, " "or wildcard expressions.")
def __new__(cls, *args, **kwargs): """Creates a new Map instance""" maps = [] data = [] headers = [] # convert input to maps for item in args: if isinstance(item, BaseMap): maps.append(item) else: maps.append(BaseMap.read(item)) # sort data sortby = kwargs.get("sortby", "date") if hasattr(cls, '_sort_by_%s' % sortby): maps.sort(key=getattr(cls, '_sort_by_%s' % sortby)()) # create data cube for map_ in maps: data.append(np.array(map_)) headers.append(map_.header) obj = np.asarray(data).view(cls) obj._headers = headers return obj
def add_map(self, input_, zorder=None, alpha=1): """Adds a map to the CompositeMap Parameters ---------- input_ : {sunpy.map, string} Map instance or filepath to map to be added zorder : int The index to use when determining where the map should lie along the z-axis; maps with higher z-orders appear above maps with lower z-orders. alpha : float Opacity at which the map should be displayed. An alpha value of 0 results in a fully transparent image while an alpha value of 1 results in a fully opaque image. Values between result in semi- transparent images. """ if zorder is None: zorder = max([m.zorder for m in self._maps]) + 10 m = BaseMap.read(input_) m.zorder = zorder m.alpha = alpha self._maps.append(m)
def __init__(self, *args): self._maps = [] # Default alpha and zorder values alphas = [1] * len(args) zorders = range(0, 10 * len(args), 10) # Parse input Maps/filepaths for i, item in enumerate(args): # Parse map if isinstance(item, BaseMap): m = item else: m = BaseMap.read(item) # Set z-order and alpha values for the map m.zorder = zorders[i] m.alpha = alphas[i] # Add map self._maps.append(m)
def make_map(*args, **kwargs): """Processes one or more inputs and returns a Map, MapCube, or CompositeMap instance. Parameters ---------- args : filepath(s), 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. type : {'composite' | 'cube'} Type of multimap to construct when passed more than one input. The default choice is a CompositeMap which is more lenient with respect to how similar the input data is. Returns ------- out : Map, MapCube, CompositeMap Returns a subclass instance Examples -------- >>> import sunpy >>> sunpy.make_map("file.fts") >>> sunpy.make_map("file1.fts", "file2.fts",..) >>> sunpy.make_map(["file1.fts", "file2.fts",..]) >>> sunpy.make_map("path/to/files/*.fts") >>> sunpy.make_map(Map) >>> sunpy.make_map(Map1, Map2,..) """ # Single Map or wildcard string if len(args) == 1: # String if isinstance(args[0], basestring): # Wildcard string if args[0].find("*") != -1: import glob maps = glob.glob(args[0]) # Directory (use all files) elif os.path.isdir(args[0]): maps = os.listdir(args[0]) # Filepath else: return BaseMap.read(args[0]) # Map/MapCube/CompositeMap elif (isinstance(args[0], BaseMap) or isinstance(args[0], CompositeMap) or isinstance(args[0], MapCube)): return args[0] # List of filepaths or Maps elif isinstance(args[0], list): maps = args[0] # Unrecognized input else: raise InvalidMapInput("Invalid input for make_map. Please specify " "one or more filepaths, Maps, directories, " "or wildcard expressions.") else: maps = args # Make sure we found some data if len(maps) is 0: raise NoMapsFound("Specified path contains no valid files.") mtype = kwargs.get("type", "composite") # MapCube if mtype == "cube": return MapCube(*maps) # CompositeMap (default) elif mtype == "composite": return CompositeMap(*maps) else: raise InvalidMapType("Invalid multi-map type specified. Please choose " "between 'composite' or 'cube'.")
def make_map(*args, **kwargs): """Processes one or more inputs and returns a Map, MapCube, or CompositeMap instance. Parameters ---------- args : filepath(s), 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. type : {'composite' | 'cube'} Type of multimap to construct when passed more than one input. The default choice is a CompositeMap which is more lenient with respect to how similar the input data is. Returns ------- out : Map, MapCube, CompositeMap Returns a subclass instance Examples -------- >>> import sunpy >>> sunpy.make_map("file.fts") >>> sunpy.make_map("file1.fts", "file2.fts",..) >>> sunpy.make_map(["file1.fts", "file2.fts",..]) >>> sunpy.make_map("path/to/files/*.fts") >>> sunpy.make_map(Map) >>> sunpy.make_map(Map1, Map2,..) >>> sunpy.make_map([[0, 1],[2, 3]], {'telescop': 'sunpy',..}) """ if len(args) is 0: raise TypeError("Invalid input.") # First check to see if data/header were passed in if isinstance(args[0], list) or isinstance(args[0], np.ndarray): data = None # n-dimensional list if isinstance(args[0][0], list) or isinstance(args[0], np.ndarray): data = args[0] else: try: float(args[0][0]) except (ValueError, TypeError): pass else: # 1-dimensional data data = args[0] # if either of the above cases hold, then create a new BaseMap if data is not None: if len(args) > 1: return BaseMap(args[0], args[1]) else: return BaseMap(args[0], {}) # If not, check for one or more maps or filepaths if len(args) == 1: # String if isinstance(args[0], basestring): filepath = os.path.expanduser(args[0]) # Wildcard string if filepath.find("*") != -1: import glob maps = glob.glob(filepath) # Directory (use all files) elif os.path.isdir(filepath): maps = [os.path.join(filepath, x) for x in os.listdir(filepath)] # Filepath else: return BaseMap.read(filepath) # Map/MapCube/CompositeMap elif (isinstance(args[0], BaseMap) or isinstance(args[0], CompositeMap) or isinstance(args[0], MapCube)): return args[0] # List of filepaths, Maps elif isinstance(args[0], list): # list of maps or filepaths maps = args[0] # Unrecognized input else: raise InvalidMapInput("Invalid input for make_map. Please specify " "one or more filepaths, Maps, directories, " "or wildcard expressions.") else: maps = args # Make sure we found some data if len(maps) is 0: raise NoMapsFound("Specified path contains no valid files.") mtype = kwargs.get("type", "composite") # MapCube if mtype == "cube": return MapCube(*maps) # CompositeMap (default) elif mtype == "composite": return CompositeMap(*maps) else: raise InvalidMapType("Invalid multi-map type specified. Please choose " "between 'composite' or 'cube'.")