예제 #1
0
    def __init__(self, filename, elements=slice(None), debug=False):
        # Class attributs
        self._debug = debug
        self._isMulti(filename)
        if not self._multi:
            self._load(filename, elements, debug=debug)
            self.Plots = PlotsStation(self.Variables, self.Grid, self._debug)
            self.Util2D = FunctionsStation(self.Variables, self.Grid, self.Plots, self.History, self._debug)
            if self.Variables._3D:
                self.Util3D = FunctionsStationThreeD(self.Variables, self.Grid, self.Plots, self.History, self._debug)
        else:
            print "---Finding matching files---"
            self._matches = findFiles(filename, "STATION")
            filename = self._matches.pop(0)
            self._load(filename, elements, debug=debug)
            self.Plots = PlotsStation(self.Variables, self.Grid, self._debug)
            self.Util2D = FunctionsStation(self.Variables, self.Grid, self.Plots, self.History, self._debug)
            if self.Variables._3D:
                self.Util3D = FunctionsStationThreeD(self.Variables, self.Grid, self.Plots, self.History, self._debug)
            for entry in self._matches:
                # Define new
                text = "Created from " + entry
                tmp = {}
                tmp["Data"] = self._load_nc(entry)
                tmp["History"] = [text]
                tmp["Grid"] = _load_grid(tmp["Data"], elements, [], debug=self._debug)
                tmp["Variables"] = _load_var(tmp["Data"], elements, tmp["Grid"], [], debug=self._debug)
                tmp = ObjectFromDict(tmp)
                self = self.__add__(tmp)

        ##Re-assignement of utility functions as methods
        self.dump_profile_data = self.Plots._dump_profile_data_as_csv

        return
예제 #2
0
    def __init__(self, filename, elements=slice(None), debug=False):
        #Class attributs
        self._debug = debug
        self._isMulti(filename)
        if not self._multi:
            self._load(filename, elements, debug=debug )
            self.Plots = PlotsStation(self.Variables,
                                      self.Grid,
                                      self._debug)
            self.Util2D = FunctionsStation(self.Variables,
                                           self.Grid,
                                           self.Plots,
                                           self.History,
                                           self._debug)
            if self.Variables._3D:
                self.Util3D = FunctionsStationThreeD(
                                       self.Variables,
                                       self.Grid,
                                       self.Plots,
                                       self.History,
                                       self._debug) 
        else:
            print "---Finding matching files---"
            self._matches = findFiles(filename, 'STATION')
            filename = self._matches.pop(0)
            self._load(filename, elements, debug=debug )
            self.Plots = PlotsStation(self.Variables,
                                      self.Grid,
                                      self._debug)
            self.Util2D = FunctionsStation(self.Variables,
                                           self.Grid,
                                           self.Plots,
                                           self.History,
                                           self._debug)
            if self.Variables._3D:
                self.Util3D = FunctionsStationThreeD(
                                       self.Variables,
                                       self.Grid,
                                       self.Plots,
                                       self.History,
                                       self._debug) 
            for entry in self._matches:
                #Define new 
                text = 'Created from ' + entry
                tmp = {}
                tmp['Data'] = self._load_nc(entry)
                tmp['History'] = [text]
                tmp['Grid'] = _load_grid(tmp['Data'], elements, [], debug=self._debug)
                tmp['Variables'] = _load_var(tmp['Data'], elements, tmp['Grid'], [],
                                             debug=self._debug)
                tmp = ObjectFromDict(tmp)
                self = self.__add__(tmp)

        ##Re-assignement of utility functions as methods
        self.dump_profile_data = self.Plots._dump_profile_data_as_csv

        return
예제 #3
0
    def _load(self, filename, elements, debug=False):
        """Loads data from *.nc, *.p and OpenDap url"""
        # Loading pickle file
        if filename.endswith(".p"):
            f = open(filename, "rb")
            data = pkl.load(f)
            self._origin_file = data["Origin"]
            self.History = data["History"]
            if debug:
                print "Turn keys into attributs"
            self.Grid = ObjectFromDict(data["Grid"])
            self.Variables = ObjectFromDict(data["Variables"])
            try:
                if self._origin_file.startswith("http"):
                    # Look for file through OpenDAP server
                    print "Retrieving data through OpenDap server..."
                    self.Data = open_url(data["Origin"])
                    # Create fake attribut to be consistent with the rest of the code
                    self.Data.variables = self.Data
                else:
                    self.Data = self._load_nc(data["Origin"])
            except:  # TR: need to precise the type of error here
                print "the original *.nc file has not been found"
                pass
        # Loading netcdf file
        elif filename.endswith(".nc"):
            if filename.startswith("http"):
                # Look for file through OpenDAP server
                print "Retrieving data through OpenDap server..."
                self.Data = open_url(filename)
                # Create fake attribut to be consistent with the rest of the code
                self.Data.variables = self.Data
            else:
                # Look for file locally
                print "Retrieving data from " + filename + " ..."
                self.Data = self._load_nc(filename)
            # Metadata
            text = "Created from " + filename
            self._origin_file = filename
            self.History = [text]
            # Calling sub-class
            print "Initialisation..."
            try:
                self.Grid = _load_grid(self.Data, elements, self.History, debug=self._debug)
                self.Variables = _load_var(self.Data, elements, self.Grid, self.History, debug=self._debug)

            except MemoryError:
                print "---Data too large for machine memory---"
                print "Tip: use ax or tx during class initialisation"
                print "---  to use partial data"
                raise

        elif filename.endswith(".mat"):
            raise PyseidonError("---Functionality not yet implemented---")
        else:
            raise PyseidonError("---Wrong file format---")
예제 #4
0
 def __init__(self, filename, elements=slice(None), debug=False):
     #Class attributs
     self._debug = debug
     self._isMulti(filename)
     if not self._multi:
         self._load(filename, elements)
         self.Plots = PlotsStation(self.Variables,
                                   self.Grid,
                                   self._debug)
         self.Util2D = FunctionsStation(self.Variables,
                                        self.Grid,
                                        self.Plots,
                                        self.History,
                                        self._debug)
         if self.Variables._3D:
             self.Util3D = FunctionsStationThreeD(
                                    self.Variables,
                                    self.Grid,
                                    self.Plots,
                                    self.History,
                                    self._debug) 
     else:
         print "---Finding matching files---"
         self._matches = findFiles(filename, 'STATION')
         filename = self._matches.pop(0)
         self._load(filename, elements, debug=debug )
         self.Plots = PlotsStation(self.Variables,
                                   self.Grid,
                                   self._debug)
         self.Util2D = FunctionsStation(self.Variables,
                                        self.Grid,
                                        self.Plots,
                                        self.History,
                                        self._debug)
         if self.Variables._3D:
             self.Util3D = FunctionsStationThreeD(
                                    self.Variables,
                                    self.Grid,
                                    self.Plots,
                                    self.History,
                                    self._debug) 
         for entry in self._matches:
             #Define new 
             text = 'Created from ' + entry
             tmp = {}
             tmp['Data'] = _load_nc(entry)
             tmp['History'] = [text]
             tmp['Grid'] = _load_grid(tmp['Data'], elements, [], debug=self._debug)
             tmp['Variables'] = _load_var(tmp['Data'], elements, tmp['Grid'], [],
                                          debug=self._debug)
             tmp = ObjectFromDict(tmp)
             self = self.__add__(tmp)
예제 #5
0
    def _load(self, filename, elements, debug=False):
        """Loads data from *.nc, *.p and OpenDap url"""
        #Loading pickle file
        if filename.endswith('.p'):
            f = open(filename, "rb")
            data = pkl.load(f)
            self._origin_file = data['Origin']
            self.History = data['History']
            if debug: print "Turn keys into attributs"
            self.Grid = ObjectFromDict(data['Grid'])
            self.Variables = ObjectFromDict(data['Variables'])
            try:
                if self._origin_file.startswith('http'):
                    #Look for file through OpenDAP server
                    print "Retrieving data through OpenDap server..."
                    self.Data = open_url(data['Origin'])
                    #Create fake attribut to be consistent with the rest of the code
                    self.Data.variables = self.Data
                else:
                    #WB_Alternative: self.Data = sio.netcdf.netcdf_file(filename, 'r')
                    #WB_comments: scipy has causes some errors, and even though can be
                    #             faster, can be unreliable
                    #self.Data = nc.Dataset(data['Origin'], 'r')
                    self.Data = netcdf.netcdf_file(data['Origin'], 'r',mmap=True)
            except: #TR: need to precise the type of error here
                print "the original *.nc file has not been found"
                pass

        #Loading netcdf file         
        elif filename.endswith('.nc'):
            if filename.startswith('http'):
                #Look for file through OpenDAP server
                print "Retrieving data through OpenDap server..."
                self.Data = open_url(filename)
                #Create fake attribut to be consistent with the rest of the code
                self.Data.variables = self.Data
            else:
                #Look for file locally
                print "Retrieving data from " + filename + " ..."
                #WB_Alternative: self.Data = sio.netcdf.netcdf_file(filename, 'r')
                #WB_comments: scipy has causes some errors, and even though can be
                #             faster, can be unreliable
                #self.Data = nc.Dataset(filename, 'r')
                self.Data = netcdf.netcdf_file(filename, 'r',mmap=True)
            #Metadata
            text = 'Created from ' + filename
            self._origin_file = filename
            self.History = [text]
            # Calling sub-class
            print "Initialisation..."
            try:
                self.Grid = _load_grid(self.Data,
                                       elements,
                                       self.History,
                                       debug=self._debug)
                self.Variables = _load_var(self.Data,
                                           elements,
                                           self.Grid,
                                           self.History,
                                           debug=self._debug)

            except MemoryError:
                print '---Data too large for machine memory---'
                print 'Tip: use ax or tx during class initialisation'
                print '---  to use partial data'
                raise

        elif filename.endswith('.mat'):
            print "---Functionality not yet implemented---"
            sys.exit()
        else:
            print "---Wrong file format---"
            sys.exit()