NOAA-ORR-ERD / PyGnome

The General NOAA Operational Modeling Environment
https://gnome.orr.noaa.gov/doc/pygnome/index.html
Other
58 stars 44 forks source link

3 failed tests #26

Open rsignell-usgs opened 7 years ago

rsignell-usgs commented 7 years ago

I'm following the instructions for conda install at https://github.com/NOAA-ORR-ERD/PyGnome/blob/master/InstallingWithAnaconda.rst and running this:

> cd PyGnome/py_gnome/tests/unit_tests
> py.test

produces 3 failed tests.

These all seem minor but reporting them here:

============================================ FAILURES ============================================
_____________________________ test_Water_get[temperature-C-0-273.16] _____________________________

attr = 'temperature', unit = 'C', val = 0, si_val = 273.16

    @pytest.mark.parametrize(("attr", "unit", "val", "si_val"),
                             [('temperature', 'C', 0, 273.16),
                              ('sediment', 'mg/l', 5, 0.005),
                              ('sediment', 'percent', 0.005, 0.05),
                              ('wave_height', 'cm', 100.0, 1.0),
                              ('fetch', 'km', 1.0, 1000.0)])
    def test_Water_get(attr, unit, val, si_val):
        w = Water()
        setattr(w, attr, val)
        w.units[attr] = unit

>       assert w.get(attr) == si_val
E       AssertionError: assert 273.15 == 273.16
E        +  where 273.15 = <bound method Water.get of gnome.environment.environment.Water(temperature=0, salinity=35.0)>('temperature')
E        +    where <bound method Water.get of gnome.environment.environment.Water(temperature=0, salinity=35.0)> = gnome.environment.environment.Water(temperature=0, salinity=35.0).get

test_environment/test_environment.py:56: AssertionError
_________________________ test_properties_in_si[temperature-C-0-273.16] __________________________

attr = 'temperature', unit = 'C', val = 0, exp_si = 273.16

    @pytest.mark.parametrize(("attr", "unit", "val", "exp_si"),
                             [('temperature', 'C', 0, 273.16),
                              ('sediment', 'mg/l', 5, 0.005),
                              ('wave_height', 'km', .001, 1),
                              ('fetch', 'km', .01, 10),
                              ('fetch', 'm', 0.323, 0.323)])
    def test_properties_in_si(attr, unit, val, exp_si):
        '''
        set properties in non SI units and check default get() returns it in SI
        '''
        kw = {attr: val, 'units': {attr: unit}}
        w = Water(**kw)
        assert getattr(w, attr) == val
        assert w.units[attr] == unit

>       assert w.get(attr) == exp_si
E       AssertionError: assert 273.15 == 273.16
E        +  where 273.15 = <bound method Water.get of gnome.environment.environment.Water(temperature=0, salinity=35.0)>('temperature')
E        +    where <bound method Water.get of gnome.environment.environment.Water(temperature=0, salinity=35.0)> = gnome.environment.environment.Water(temperature=0, salinity=35.0).get

test_environment/test_environment.py:115: AssertionError
_____________ test_dissolution_mass_balance[oil_bahia-288.15-15.0-3-0.0036288-True] ______________

oil = 'oil_bahia', temp = 288.15, wind_speed = 15.0, num_elems = 3, expected_mb = 0.0036288
on = True

    @pytest.mark.parametrize(mb_param_names, mb_params)
    def test_dissolution_mass_balance(oil, temp, wind_speed,
                                      num_elems, expected_mb, on):
        '''
        Test a single dissolution step.
        - for this, we need a dispersion weatherer to give us a droplet size
          distribution.
        Fuel Oil #6 does not exist...
        '''
        et = floating(substance=oil)

        waves = build_waves_obj(wind_speed, 'knots', 270, temp)
        water = waves.water

        disp = NaturalDispersion(waves, water)
        diss = Dissolution(waves)

        all_array_types = diss.array_types.union(disp.array_types)

        (sc, time_step) = weathering_data_arrays(all_array_types,
                                                 water,
                                                 element_type=et,
                                                 num_elements=num_elems,
                                                 units='kg',
                                                 amount_per_element=1.0
                                                 )[:2]

        print 'time_step: {}'.format(time_step)
        print 'num spills:', len(sc.spills)
        print 'spill[0] amount: {} {}'.format(sc.spills[0].amount,
                                              sc.spills[0].units)
        print 'temperature = ', temp
        print 'wind = ',
        print '\n'.join(['\t{} {}'.format(ts[1][0], waves.wind.units)
                         for ts in waves.wind.timeseries])
        print

        # we don't want to query the oil database, but get the sample oil
        assert sc.spills[0].element_type.substance.record.id is None

        initial_amount = sc.spills[0].amount
        model_time = (sc.spills[0].release_time +
                      timedelta(seconds=time_step))

        disp.on = on
        disp.prepare_for_model_run(sc)
        disp.initialize_data(sc, sc.num_released)

        diss.on = on
        diss.prepare_for_model_run(sc)
        diss.initialize_data(sc, sc.num_released)

        disp.prepare_for_model_step(sc, time_step, model_time)
        diss.prepare_for_model_step(sc, time_step, model_time)

        disp.weather_elements(sc, time_step, model_time)
        diss.weather_elements(sc, time_step, model_time)

        if on:
            print ('fraction dissolved: {}'
                   .format(sc.mass_balance['dissolution'] / initial_amount)
                   )
            print ('fraction dissolved: {:.2%}'
                   .format(sc.mass_balance['dissolution'] / initial_amount)
                   )
            print sc.mass_balance['dissolution'], expected_mb
>           assert np.isclose(sc.mass_balance['dissolution'], expected_mb)
E           assert False
E            +  where False = <function isclose at 0x7f8bd09cea28>(0.003628851565623533, 0.0036288)
E            +    where <function isclose at 0x7f8bd09cea28> = np.isclose

test_weatherers/test_dissolution.py:266: AssertionError
-------------------------------------- Captured stdout call --------------------------------------
time_step: 900.0
num spills: 1
spill[0] amount: 3.0 kg
temperature =  288.15
wind =          15.0 knots

fraction dissolved: 0.00120961718854
fraction dissolved: 0.12%
0.00362885156562 0.0036288
=========== 3 failed, 1389 passed, 64 skipped, 5 xfailed, 1 xpassed in 168.56 seconds =======
ChrisBarker-NOAA commented 7 years ago

Thanks!

These look familiar, and I think are fixed in our internal repo -- we need to push an update to gitHub -- and will soon,

-CHB

On Mar 31, 2017, at 2:55 PM, Rich Signell notifications@github.com wrote:

I'm following the instructions for conda install at https://github.com/NOAA-ORR-ERD/PyGnome/blob/master/InstallingWithAnaconda.rst and running this:

cd PyGnome/py_gnome/tests/unit_tests py.test produces 3 failed tests. These all seem minor:

============================================ FAILURES

_____ test_Water_get[temperature-C-0-273.16]


attr = 'temperature', unit = 'C', val = 0, si_val = 273.16

@pytest.mark.parametrize(("attr", "unit", "val", "si_val"),
                         [('temperature', 'C', 0, 273.16),
                          ('sediment', 'mg/l', 5, 0.005),
                          ('sediment', 'percent', 0.005, 0.05),
                          ('wave_height', 'cm', 100.0, 1.0),
                          ('fetch', 'km', 1.0, 1000.0)])
def test_Water_get(attr, unit, val, si_val):
    w = Water()
    setattr(w, attr, val)
    w.units[attr] = unit
  assert w.get(attr) == si_val

E AssertionError: assert 273.15 == 273.16 E + where 273.15 = <bound method Water.get of gnome.environment.environment.Water(temperature=0, salinity=35.0)>('temperature') E + where <bound method Water.get of gnome.environment.environment.Water(temperature=0, salinity=35.0)> = gnome.environment.environment.Water(temperature=0, salinity=35.0).get

test_environment/test_environment.py:56: AssertionError


test_properties_in_si[temperature-C-0-273.16]


attr = 'temperature', unit = 'C', val = 0, exp_si = 273.16

@pytest.mark.parametrize(("attr", "unit", "val", "exp_si"),
                         [('temperature', 'C', 0, 273.16),
                          ('sediment', 'mg/l', 5, 0.005),
                          ('wave_height', 'km', .001, 1),
                          ('fetch', 'km', .01, 10),
                          ('fetch', 'm', 0.323, 0.323)])
def test_properties_in_si(attr, unit, val, exp_si):
    '''
    set properties in non SI units and check default get() returns it in SI
    '''
    kw = {attr: val, 'units': {attr: unit}}
    w = Water(**kw)
    assert getattr(w, attr) == val
    assert w.units[attr] == unit
  assert w.get(attr) == exp_si

E AssertionError: assert 273.15 == 273.16 E + where 273.15 = <bound method Water.get of gnome.environment.environment.Water(temperature=0, salinity=35.0)>('temperature') E + where <bound method Water.get of gnome.environment.environment.Water(temperature=0, salinity=35.0)> = gnome.environment.environment.Water(temperature=0, salinity=35.0).get

test_environment/testenvironment.py:115: AssertionError ____ test_dissolution_mass_balance[oil_bahia-288.15-15.0-3-0.0036288-True]


oil = 'oil_bahia', temp = 288.15, wind_speed = 15.0, num_elems = 3, expected_mb = 0.0036288 on = True

@pytest.mark.parametrize(mb_param_names, mb_params)
def test_dissolution_mass_balance(oil, temp, wind_speed,
                                  num_elems, expected_mb, on):
    '''
    Test a single dissolution step.
    - for this, we need a dispersion weatherer to give us a droplet size
      distribution.
    Fuel Oil #6 does not exist...
    '''
    et = floating(substance=oil)

    waves = build_waves_obj(wind_speed, 'knots', 270, temp)
    water = waves.water

    disp = NaturalDispersion(waves, water)
    diss = Dissolution(waves)

    all_array_types = diss.array_types.union(disp.array_types)

    (sc, time_step) = weathering_data_arrays(all_array_types,
                                             water,
                                             element_type=et,
                                             num_elements=num_elems,
                                             units='kg',
                                             amount_per_element=1.0
                                             )[:2]

    print 'time_step: {}'.format(time_step)
    print 'num spills:', len(sc.spills)
    print 'spill[0] amount: {} {}'.format(sc.spills[0].amount,
                                          sc.spills[0].units)
    print 'temperature = ', temp
    print 'wind = ',
    print '\n'.join(['\t{} {}'.format(ts[1][0], waves.wind.units)
                     for ts in waves.wind.timeseries])
    print

    # we don't want to query the oil database, but get the sample oil
    assert sc.spills[0].element_type.substance.record.id is None

    initial_amount = sc.spills[0].amount
    model_time = (sc.spills[0].release_time +
                  timedelta(seconds=time_step))

    disp.on = on
    disp.prepare_for_model_run(sc)
    disp.initialize_data(sc, sc.num_released)

    diss.on = on
    diss.prepare_for_model_run(sc)
    diss.initialize_data(sc, sc.num_released)

    disp.prepare_for_model_step(sc, time_step, model_time)
    diss.prepare_for_model_step(sc, time_step, model_time)

    disp.weather_elements(sc, time_step, model_time)
    diss.weather_elements(sc, time_step, model_time)

    if on:
        print ('fraction dissolved: {}'
               .format(sc.mass_balance['dissolution'] / initial_amount)
               )
        print ('fraction dissolved: {:.2%}'
               .format(sc.mass_balance['dissolution'] / initial_amount)
               )
        print sc.mass_balance['dissolution'], expected_mb
      assert np.isclose(sc.mass_balance['dissolution'], expected_mb)

E assert False E + where False = <function isclose at 0x7f8bd09cea28>(0.003628851565623533, 0.0036288) E + where <function isclose at 0x7f8bd09cea28> = np.isclose

test_weatherers/test_dissolution.py:266: AssertionError -------------------------------------- Captured stdout call

time_step: 900.0 num spills: 1 spill[0] amount: 3.0 kg temperature = 288.15 wind = 15.0 knots

fraction dissolved: 0.00120961718854 fraction dissolved: 0.12% 0.00362885156562 0.0036288 =========== 3 failed, 1389 passed, 64 skipped, 5 xfailed, 1 xpassed in 168.56 seconds =======

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/NOAA-ORR-ERD/PyGnome/issues/26, or mute the thread https://github.com/notifications/unsubscribe-auth/AA38YATtNewXEoihY3moOlJaWVV8BpDZks5rrUw5gaJpZM4MwCB1 .