columncolab / EMC2

Earth Model Column Collabratory
BSD 3-Clause "New" or "Revised" License
10 stars 7 forks source link

Add unit tests for the COSP emulator; fix some minor unit test issues #85

Closed isilber closed 2 years ago

isilber commented 2 years ago

@rcjackson please double-check the COSP unit test I added. If OK, we can close issue #36

rcjackson commented 2 years ago

Your COSP emulator test is ok, but it looks like changing the units to kelvin in TestConvection broke the test for that:

def test_set_convective_profile(): my_model = emc2.core.model.TestConvection() column_ds = emc2.simulator.subcolumn.set_convective_sub_col_frac(my_model, 'cl', N_columns=8) where_gt_1km = np.where(np.logical_and(column_ds.ds['height'] > 1000., column_ds.ds['t'] > 273.15))[0] where_lt_1km = np.where(np.logical_and(column_ds.ds['height'] < 1000., column_ds.ds['t'] > 273.15))[0] assert np.all(column_ds.ds['conv_frac_subcolumns_cl'].values[:, where_gt_1km, 0])

  assert np.all(~column_ds.ds['conv_frac_subcolumns_cl'].values[:, where_lt_1km, 0])

E IndexError: index 1 is out of bounds for axis 1 with size 1

rcjackson commented 2 years ago

This may simply be a matter of using Celsius in that test versus Kelvin.

isilber commented 2 years ago

It appears that there was an inconsistency in T units in that test script, though I'm not sure this will resolve the issue. Note that in the tests below the T threshold was 274.15, which I have changed to 273.15. Not sure whether that 1 C threshold instead of 0 C was delibirate.

rcjackson commented 2 years ago

You might need to change to >= 273.15 to be consistent with the test model in these lines:

where_gt_1km = np.where(np.logical_and(column_ds.ds['height'] > 1000., column_ds.ds['t'] > 273.15))[0] where_lt_1km = np.where(np.logical_and(column_ds.ds['height'] < 1000., column_ds.ds['t'] > 273.15))[0]

rcjackson commented 2 years ago

There was an issue with comparing a 1000 x 1 vs 1 x 1000 array that was screwing up the test. I've fixed this issue.