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)
def test_non_monotonic(self): with pytest.raises(ValueError): climapy.xr_area(data_dict['ds_strange'])
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
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')