def _append_array_types(self, array_types): ''' append to self.array_types the input array_types. :param array_types: set of array_types to be appended :type array_types: set() The set contains either a name as a string, say: 'rise_vel' In this case, get the ArrayType from gnome.array_types.rise_vel Set elements could also be tuples, say: ('rise_vel': ArrayType()) In this case the user name of the data_array and its array_type is specified by the tuple so append it. .. note:: If a tuple: ('name', ArrayType()), is given and an ArrayType with that name already exists in self._array_types, then it is overwritten. ''' for array in array_types: if isinstance(array, basestring): # allow user to override an array_type that might already exist # in self._array_types try: array = getattr(gat, array) except AttributeError: msg = ("Skipping {0} - not found in gnome.array_types;" " and ArrayType is not provided.").format(array) self.logger.error(msg) raise GnomeRuntimeError(msg) # must be an ArrayType of an object self._array_types[array.name] = array
def _set_init_relative_buoyancy(self, substance): ''' set the initial relative buoyancy of oil wrt water use temperature of water to get oil density if relative_buoyancy < 0 raises a GnomeRuntimeError - particles will sink. ''' rho_h2o = self.water.get('density') rho_oil = substance.density_at_temp(self.water.get('temperature')) # maybe weathering_data should catch error below? # todo: write and raise appropriate exception if np.any(rho_h2o < rho_oil): msg = ("Found particles with relative_buoyancy < 0. " "Oil is a sinker") raise GnomeRuntimeError(msg) self._init_relative_buoyancy = (rho_h2o - rho_oil) / rho_h2o