Example #1
0
 def SaveAsOSSMWind(self, filename, name=None, units='mps'):
     print("writing:", filename)
     SpeedUnits = self.Units["WindSpeed"]
     spd_idx = self.Fields["WindSpeed"]
     dir_idx = self.Fields["WindDirection"]
     data = self.DataArray[:, (spd_idx, dir_idx)]
     # write the file:
     outfile = open(filename, 'w', encoding='utf-8')
     outfile.write("%s\n"%self.Name)
     if self.LatLong[0] is not None and self.LatLong[1] is not None:
         print("writting lat-lon:", self.LatLong)
         outfile.write("%f, %f\n"%tuple(self.LatLong)) ## this needs to be fixed!
     else:
         outfile.write("\n")
     outfile.write("%s\n"%units)
     outfile.write("%s\n"%self.TimeZone)
     outfile.write("0,0,0,0,0,0,0,0\n")
     for t, (speed, dir) in zip(self.Times, data):
         if np.isnan(speed):
             continue
         if np.isnan(dir):
             if speed == 0.0: # we can still use it if speed is zero
                 dir = 0 # arbitrary
             else:
                 continue
         outfile.write("%i, %i, %i, %i, %i, "%(t.day, t.month, t.year, t.hour, t.minute) )
         # convert speed
         speed = UC.Convert("Velocity", SpeedUnits, units, speed)
         outfile.write("%.2f, %i\n"%(speed, dir))
def check_known_value(test):
#        print "testing:", test
        Type = test[0]
        From = test[1]
        To = test[2]
        Value = test[3]
        True = test[4]
        Calculated = unit_conversion.Convert(*test[:4])
        print "Calculated: %f, True: %f"%((Calculated, True))
        assert(Close(Calculated, True))
Example #3
0
    def prepare_for_model_step(self, sc, time_step, model_time):
        '''
        1. set 'active' flag based on active_start, and model_time
        2. Mark LEs to be burned - do them in order right now. Assume all LEs
           that are released together will be burned together since they would
           be closer to each other in position.
           Assumes: there is more mass in water than amount of mass to be
           burned. The LEs marked for Burning are marked only once -
           during the very first step that the object becomes active
        '''
        super(Burn, self).prepare_for_model_step(sc, time_step, model_time)
        if not self.active:
            return

        # if initial oilwater_thickness is < _min_thickness, then stop
        # don't want to deal with active_start being equal to active_stop, need
        # this incase user sets a bad initial value
        if self._oilwater_thickness <= self._min_thickness:
            self._active = False
            return

        # only when it is active, update the status codes
        if (sc['fate_status'] == bt_fate.burn).sum() == 0:
            substance = self._get_substance(sc)

            _si_area = uc.Convert('Area', self.area_units, 'm^2', self.area)
            _si_thickness = uc.Convert('Length', self.thickness_units, 'm',
                                       self.thickness)

            mass_to_remove = (
                self.efficiency *
                self._get_mass(substance, _si_area * _si_thickness, 'm^3'))

            self._update_LE_status_codes(sc, bt_fate.burn, substance,
                                         mass_to_remove)

            self._set_burn_params(sc, substance)

            # set timestep after active stop is set
            self._set__timestep(time_step, model_time)
Example #4
0
 def _log_thickness_warning(self):
     '''
     when thickness or thickness_units are updated, check to see that the
     value in SI units is > _min_thickness. If it is not, then log a
     warning
     '''
     if (uc.Convert('Length', self.thickness_units, 'm', self.thickness) <=
             self._min_thickness):
         msg = ("thickness of {0} {1}, is less than min required {2} m."
                " Burn will not occur".format(self.thickness,
                                              self.thickness_units,
                                              self._min_thickness))
         self.logger.warning(msg)
Example #5
0
    def Recalculate(self, event):
        try:
            from_string = self.InputBox.GetValue()
            from_val = float(from_string)

            from_unit = self.FromUnits.GetStringSelection()
            to_unit = self.ToUnits.GetStringSelection()

            to_val = UC.Convert(self.UnitType, from_unit, to_unit, from_val)

            format_string = "%%.%ig" % SignificantFigures(from_string)
            self.OutBox.SetValue(format_string % (to_val, ))
        except ValueError:
            self.OutBox.SetValue("")
Example #6
0
    def _init_rate_duration(self, avg_frac_oil=1):
        '''
        burn duration based on avg_frac_oil content for LEs marked for burn
        __init__ invokes this to initialize all parameters assuming
        frac_water = 0.0
        '''
        # burn rate constant is defined as a thickness rate in m/sec
        _si_area = uc.Convert('Area', self.area_units, 'm^2', self.area)

        # rate if efficiency is 100 %
        self._oilwater_thick_burnrate = self._burn_constant * avg_frac_oil
        self._oil_vol_burnrate = (self._burn_constant * avg_frac_oil**2 *
                                  _si_area)

        # burn duration is known once rate is known
        # reset current thickness to initial thickness whenever model is rerun
        self._oilwater_thickness = uc.Convert('Length', self.thickness_units,
                                              'm', self.thickness)

        burn_duration = ((self._oilwater_thickness - self._min_thickness) /
                         self._oilwater_thick_burnrate)

        self.active_stop = (self.active_start +
                            timedelta(seconds=burn_duration))
Example #7
0
    def SaveAsOSSMWave(self, filename, name=None, units='mps'):
        print("writing:", filename)
        SpeedUnits = self.Units["WindSpeed"]
        spd_idx = self.Fields["WaveHeight"]
        data = self.DataArray[:, (spd_idx, )]
        # write the file:
        outfile = open(filename, 'w', encoding='utf-8')
        outfile.write("%s\n" % self.Name)
        outfile.write("%f, %f\n" % self.LatLong)  # this needs to be fixed!

        outfile.write("%s\n" % units)
        outfile.write("%s\n" % self.TimeZone)
        outfile.write("0,0,0,0,0,0,0,0\n")
        for t, (speed) in zip(self.Times, data):
            if np.isnan(speed):
                continue
            outfile.write("%i, %i, %i, %i, %i, "%(t.day, t.month, t.year, t.hour, t.minute) )
            # convert speed
            speed = UC.Convert("Velocity", SpeedUnits, units, speed)
            outfile.write("%.2f\n"%(speed,))
Example #8
0
def check_known_value(test):
    true = test[4]
    Calculated = unit_conversion.Convert(*test[:4])
    print("Calculated: %f, True: %f" % ((Calculated, true)))
    assert (isclose(Calculated, true))