Example #1
0
 def test_global_sum(self):
     cdo_sum = cdo_dict['gridarea']['cell_area'].values.sum()
     for key, data in data_dict.items():
         if key != 'ds_strange':
             if key == 'ds_renamed':
                 area_sum = climapy.xr_area(data_dict[key], lon_name='longitude',
                                            lat_name='latitude').values.sum()
             else:
                 area_sum = climapy.xr_area(data_dict[key]).values.sum()
             rel_diff = (area_sum - cdo_sum) / cdo_sum  # relative difference
             if key in ['ds_irr_lon', 'ds_irr_lat',
                        'ds_irr_both']:  # more leeway allowed for irregular coords
                 assert abs(rel_diff) < 1e-3, AssertionError(key)
             else:
                 assert abs(rel_diff) < 1e-6, AssertionError(key)
Example #2
0
 def test_non_monotonic(self):
     with pytest.raises(ValueError):
         climapy.xr_area(data_dict['ds_strange'])
Example #3
0
 def test_area_values(self):
     cdo_values = cdo_dict['gridarea']['cell_area'].values
     area_values = climapy.xr_area(data_dict['data01']).values
     rel_diff = (area_values - cdo_values) / cdo_values  # relative difference
     assert np.abs(rel_diff).max() < 1e-3  # check that diffs are small
Example #4
0
 def test_incorrect_lat_name(self):
     with pytest.raises(KeyError):
         climapy.xr_area(data_dict['ds_renamed'])
     with pytest.raises(KeyError):
         climapy.xr_area(data_dict['data01'], lat_name='latitude')