/[escript]/trunk/downunder/py_src/domainbuilder.py
ViewVC logotype

Diff of /trunk/downunder/py_src/domainbuilder.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 4387 by jfenwick, Thu May 2 00:46:49 2013 UTC revision 4394 by caltinay, Tue May 7 04:56:59 2013 UTC
# Line 1  Line 1 
1    
 from __future__ import print_function  
2  ##############################################################################  ##############################################################################
3  #  #
4  # Copyright (c) 2003-2013 by University of Queensland  # Copyright (c) 2003-2013 by University of Queensland
# Line 61  class DomainBuilder(object): Line 60  class DomainBuilder(object):
60          self.logger = logging.getLogger('inv.%s'%self.__class__.__name__)          self.logger = logging.getLogger('inv.%s'%self.__class__.__name__)
61          if dim not in (2,3):          if dim not in (2,3):
62              raise ValueError("Number of dimensions must be 2 or 3")              raise ValueError("Number of dimensions must be 2 or 3")
63      if not reference_system:          if not reference_system:
64          self.__reference_system=CartesianReferenceSystem()              self.__reference_system=CartesianReferenceSystem()
65      else:          else:
66          self.__reference_system=reference_system              self.__reference_system=reference_system
67          self.__domain=None          self.__domain=None
68          self.__dim=dim          self.__dim=dim
69          self.__sources=[]          self.__sources=[]
# Line 101  class DomainBuilder(object): Line 100  class DomainBuilder(object):
100              raise RuntimeError("Invalid call to addSource(). Domain is already built.")              raise RuntimeError("Invalid call to addSource(). Domain is already built.")
101          if not isinstance(source, DataSource):          if not isinstance(source, DataSource):
102              raise TypeError("source is not a DataSource")              raise TypeError("source is not a DataSource")
103      if not source.getReferenceSystem() == self.getReferenceSystem():          if not source.getReferenceSystem() == self.getReferenceSystem():
104         raise ValueError("Source reference system does not match.")             raise ValueError("source reference system does not match.")
105    
106          DATA_DIM = len(source.getDataExtents()[0])          DATA_DIM = len(source.getDataExtents()[0])
107          if DATA_DIM != self.__dim-1:          if DATA_DIM != self.__dim-1:
# Line 133  class DomainBuilder(object): Line 132  class DomainBuilder(object):
132          :note: `pad_y` is ignored for 2-dimensional domains.          :note: `pad_y` is ignored for 2-dimensional domains.
133          """          """
134          if not pad_lat == None:          if not pad_lat == None:
135          if not pad_x == None:              if not pad_x == None:
136             raise ValueError("Either pad_lat or pad_x can be set.")                 raise ValueError("Either pad_lat or pad_x can be set.")
137          else:              else:
138            pad_x = pad_lat                pad_x = pad_lat
139          if not pad_lon == None:          if not pad_lon == None:
140          if not pad_y == None:              if not pad_y == None:
141            raise ValueError("Either pad_lon or pad_y can be set.")                raise ValueError("Either pad_lon or pad_y can be set.")
142          else:              else:
143            pad_y = pad_lan                        pad_y = pad_lan        
144          if self.__domain is not None:          if self.__domain is not None:
145              raise RuntimeError("Invalid call to setFractionalPadding(). Domain is already built.")              raise RuntimeError("Invalid call to setFractionalPadding(). Domain is already built.")
146          if pad_x is not None:          if pad_x is not None:
# Line 172  class DomainBuilder(object): Line 171  class DomainBuilder(object):
171          :note: this function can only be used if the reference system is Cartesian          :note: this function can only be used if the reference system is Cartesian
172          """          """
173          if not self.getReferenceSystem().isCartesian():          if not self.getReferenceSystem().isCartesian():
174          raise RuntimeError("setPadding can be called for the Cartesian reference system only.")              raise RuntimeError("setPadding can be called for the Cartesian reference system only.")
175          if self.__domain is not None:          if self.__domain is not None:
176              raise RuntimeError("Invalid call to setPadding(). Domain is already built.")              raise RuntimeError("Invalid call to setPadding(). Domain is already built.")
177          if pad_x is not None:          if pad_x is not None:
# Line 199  class DomainBuilder(object): Line 198  class DomainBuilder(object):
198          :note: this function can only be used if the reference system is not Cartesian          :note: this function can only be used if the reference system is not Cartesian
199          """          """
200          if self.getReferenceSystem().isCartesian():          if self.getReferenceSystem().isCartesian():
201          raise RuntimeError("setGeoPadding can be called for non-Cartesian reference systems only.")              raise RuntimeError("setGeoPadding can be called for non-Cartesian reference systems only.")
202          if self.__domain is not None:          if self.__domain is not None:
203              raise RuntimeError("Invalid call to setPadding(). Domain is already built.")              raise RuntimeError("Invalid call to setPadding(). Domain is already built.")
204          if pad_lat is not None:          if pad_lat is not None:
# Line 226  class DomainBuilder(object): Line 225  class DomainBuilder(object):
225          :note: `pad_y` is ignored for 2-dimensional datasets.          :note: `pad_y` is ignored for 2-dimensional datasets.
226          """          """
227          if not pad_lat == None:          if not pad_lat == None:
228          if not pad_x == None:              if not pad_x == None:
229            raise ValueError("Either pad_lat or pad_x can be set.")                raise ValueError("Either pad_lat or pad_x can be set.")
230          else:              else:
231            pad_x = pad_lat                pad_x = pad_lat
232          if not pad_lon == None:          if not pad_lon == None:
233          if not pad_y == None:              if not pad_y == None:
234            raise ValueError("Either pad_lon or pad_y can be set.")                raise ValueError("Either pad_lon or pad_y can be set.")
235          else:              else:
236            pad_y = pad_lan                pad_y = pad_lan
237                            
238          if self.__domain is not None:          if self.__domain is not None:
239              raise RuntimeError("Invalid call to setElementPadding(). Domain is already built.")              raise RuntimeError("Invalid call to setElementPadding(). Domain is already built.")
240          if pad_x is not None:          if pad_x is not None:
# Line 407  class DomainBuilder(object): Line 406  class DomainBuilder(object):
406          if len(self.__sources)==0:          if len(self.__sources)==0:
407              raise ValueError("No data")              raise ValueError("No data")
408          X0, NE, DX = self.__sources[0].getDataExtents()          X0, NE, DX = self.__sources[0].getDataExtents()
         print("X", X0, NE, DX)  
409          XN=[X0[i]+NE[i]*DX[i] for i in range(len(NE))]          XN=[X0[i]+NE[i]*DX[i] for i in range(len(NE))]
410    
411          for src in self.__sources[1:]:          for src in self.__sources[1:]:
# Line 437  class DomainBuilder(object): Line 435  class DomainBuilder(object):
435    
436          # origin of domain          # origin of domain
437          origin = X0 + [-self._v_depth]          origin = X0 + [-self._v_depth]
438          self._dom_origin = [np.floor(oi) for oi in origin]          if self.getReferenceSystem().isCartesian():
439                # rounding will give us about meter-accuracy with UTM coordinates
440                self._dom_origin = [np.floor(oi) for oi in origin]
441            else:
442                # this should give us about meter-accuracy with lat/lon coords
443                self._dom_origin = [1e-5*np.floor(oi*1e5) for oi in origin]
444    
445          # cell size / point spacing          # cell size / point spacing
446          spacing = DX + [np.floor((self._v_depth+self._v_air_layer)/self._v_num_cells)]          spacing = DX + [np.floor((self._v_depth+self._v_air_layer)/self._v_num_cells)]

Legend:
Removed from v.4387  
changed lines
  Added in v.4394

  ViewVC Help
Powered by ViewVC 1.1.26