SkillTable
SkillTable(data)Visualize skill metrics.
SkillTable object for visualization and analysis returned by the comparer’s skill method. The object wraps the pd.DataFrame class which can be accessed from the attribute data.
The columns are assumed to be metrics and data for a single metric can be accessed by e.g. s.rmse or s["rmse"]. The resulting object can be used for plotting.
Examples
>>> sk = cc.skill()
>>> sk.mod_names
['SW_1', 'SW_2']
>>> sk.style()
>>> sk.sel(model='SW_1').style()
>>> sk.rmse.plot.bar()Attributes
| Name | Description |
|---|---|
| metrics | List of metrics (columns) in the SkillTable |
| mod_names | List of model names (in index) |
| obs_names | List of observation names (in index) |
| quantity_names | List of quantity names (in index) |
Methods
| Name | Description |
|---|---|
| query | Select a subset of the SkillTable by a query string |
| round | Round all values in SkillTable |
| sel | Filter (select) specific models or observations. |
| sort_index | Sort by index (level) e.g. sorting by observation |
| sort_values | Sort by values e.g. sorting by rmse values |
| style | Style SkillTable with colors using pandas style |
| swaplevel | Swap the levels of the MultiIndex e.g. swapping ‘model’ and ‘observation’ |
| to_dataframe | Convert SkillTable to pd.DataFrame |
| to_geodataframe | Convert SkillTable to geopandas.GeoDataFrame |
query
SkillTable.query(query)Select a subset of the SkillTable by a query string
wrapping pd.DataFrame.query()
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| query | str | string supported by pd.DataFrame.query() | required |
Returns
| Name | Type | Description |
|---|---|---|
| SkillTable | A subset of the original SkillTable |
Examples
>>> sk = cc.skill()
>>> sk_above_0p3 = sk.query("rmse>0.3")round
SkillTable.round(decimals=3)Round all values in SkillTable
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| decimals | int | Number of decimal places to round to (default: 3). If decimals is negative, it specifies the number of positions to the left of the decimal point. | 3 |
Returns
| Name | Type | Description |
|---|---|---|
| SkillTable | A new SkillTable with rounded values |
sel
SkillTable.sel(query=None, reduce_index=True, **kwargs)Filter (select) specific models or observations.
Select a subset of the SkillTable by a query, (part of) the index, or specific columns
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| reduce_index | bool | Should unnecessary levels of the index be removed after subsetting? Removed levels will stay as columns. By default True | True |
| **kwargs | Any | Concrete keys depend on the index names of the SkillTable (from the “by” argument in cc.skill() method) “model”=… to select specific models, “observation”=… to select specific observations | {} |
Returns
| Name | Type | Description |
|---|---|---|
| SkillTable | A subset of the original SkillTable |
Examples
>>> sk = cc.skill()
>>> sk_SW1 = sk.sel(model = "SW_1")
>>> sk2 = sk.sel(observation = ["EPL", "HKNA"])sort_index
SkillTable.sort_index(*args, **kwargs)Sort by index (level) e.g. sorting by observation
Wrapping pd.DataFrame.sort_index()
Returns
| Name | Type | Description |
|---|---|---|
| SkillTable | A new SkillTable with sorted index |
Examples
>>> sk = cc.skill()
>>> sk.sort_index()
>>> sk.sort_index(level="observation")sort_values
SkillTable.sort_values(*args, **kwargs)Sort by values e.g. sorting by rmse values
Wrapping pd.DataFrame.sort_values()
Returns
| Name | Type | Description |
|---|---|---|
| SkillTable | A new SkillTable with sorted values |
Examples
>>> sk = cc.skill()
>>> sk.sort_values("rmse")
>>> sk.sort_values("rmse", ascending=False)
>>> sk.sort_values(["n", "rmse"])style
SkillTable.style(
decimals=3,
metrics=None,
cmap='OrRd',
show_best=True,
**kwargs,
)Style SkillTable with colors using pandas style
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| decimals | int | Number of decimal places to round to (default: 3). | 3 |
| metrics | str or List[str] | apply background gradient color to these columns, by default all; if columns is [] then no background gradient will be applied. | None |
| cmap | str | colormap of background gradient, by default “OrRd”, except “bias” column which will always be “coolwarm” | 'OrRd' |
| show_best | bool | indicate best of each column by underline, by default True | True |
Returns
| Name | Type | Description |
|---|---|---|
| pd.Styler | Returns a pandas Styler object. |
Examples
>>> sk = cc.skill()
>>> sk.style()
>>> sk.style(precision=1, metrics="rmse")
>>> sk.style(cmap="Blues", show_best=False)swaplevel
SkillTable.swaplevel(*args, **kwargs)Swap the levels of the MultiIndex e.g. swapping ‘model’ and ‘observation’
Wrapping pd.DataFrame.swaplevel()
Returns
| Name | Type | Description |
|---|---|---|
| SkillTable | A new SkillTable with swapped levels |
Examples
>>> sk = cc.skill()
>>> sk.swaplevel().sort_index(level="observation")
>>> sk.swaplevel("model", "observation")
>>> sk.swaplevel(0, 1)to_dataframe
SkillTable.to_dataframe(drop_xy=True)Convert SkillTable to pd.DataFrame
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| drop_xy | bool | Drop the x, y coordinates?, by default True | True |
Returns
| Name | Type | Description |
|---|---|---|
| pd.DataFrame | Skill data as pd.DataFrame |
to_geodataframe
SkillTable.to_geodataframe(crs='EPSG:4326')Convert SkillTable to geopandas.GeoDataFrame
Note: requires geopandas to be installed
Note: requires x and y columns to be present
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| crs | str | Coordinate reference system identifier passed to the GeoDataFrame constructor, by default “EPSG:4326” | 'EPSG:4326' |
Returns
| Name | Type | Description |
|---|---|---|
| gpd.GeoDataFrame | Skill data as GeoDataFrame |