You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add the ability to filter each HourlyContinuousCollection with an AnalysisPeriod to the utci_comfort_band_comparison plot.
Here is a rough version of something that works. It needs additional verification, e.g. to ensure that the length of the analysis_periods is the same as the length of the utci_collections, it is handled if this is not the case, and comments need updating. Add any additional necessary imports too. Further comments welcome.
defutci_comfort_band_comparison(
utci_collections: tuple[HourlyContinuousCollection],
ax: plt.Axes=None,
identifiers: tuple[str] =None,
utci_categories: CategoricalComfort=UTCI_DEFAULT_CATEGORIES,
density: bool=True,
analysis_periods= [],
**kwargs,
) ->plt.Axes:
"""Create a proportional bar chart showing how different UTCI collections compare in terms of time within each comfort band. Args: utci_collections (list[HourlyContinuousCollection]): A list of UTCI collections. ax (plt.Axes, optional): The matplotlib Axes to plot on. Defaults to None which uses the current Axes. identifiers (list[str], optional): A list of names to give each collection. Defaults to None. utci_categories (Categories, optional): The UTCI categories to use. Defaults to UTCI_DEFAULT_CATEGORIES. density (bool, optional): If True, then show percentage, otherwise show count. Defaults to True. **kwargs: Additional keyword arguments to pass to the function. Returns: plt.Axes: A matplotlib Axes object. """forn, colinenumerate(utci_collections):
ifnotisinstance(col.header.data_type, LB_UniversalThermalClimateIndex):
raiseValueError(
f"Collection {n} data type is not UTCI and cannot be used in this plot."
)
ifany(len(i) !=len(utci_collections[0]) foriinutci_collections):
raiseValueError("All collections must be the same length.")
ifaxisNone:
ax=plt.gca()
# set the titleax.set_title(kwargs.pop("title", None))
ifidentifiersisNone:
identifiers= [f"{n}"forninrange(len(utci_collections))]
iflen(identifiers) !=len(utci_collections):
raiseValueError(
"The number of identifiers given does not match the number of UTCI collections given!"
)
#new stuff starts hereiflen(analysis_periods) >0andlen(analysis_periods) ==len(utci_collections):
series_zips=zip(utci_collections, analysis_periods)
serieses= [collection_to_series(utci_collection.filter_by_analysis_period(analysis_period)) forutci_collection, analysis_periodinseries_zips]
counts=pd.concat(
[utci_categories.value_counts(i, density=density) foriinserieses],
axis=1,
keys=identifiers,
)
counts.T.plot(
ax=ax,
kind="bar",
stacked=True,
color=utci_categories.colors,
width=0.8,
legend=False,
)
# rest of file.....
The text was updated successfully, but these errors were encountered:
After seeing this, we talked in person - I suggested that this functionality isn't really necessary as the HourlyContinuousCollection has a method to filter data by an analysis period (among other filter methods) - so a user can provide an already filtered collection to this method.
The only problem is that the method enforces that the lengths of both collections must be the same. Therefore to get the functionality that is needed, we should change the error to a warning that warns that the collections given were not the same size, but continue code execution anyway.
forn, colinenumerate(utci_collections):
ifnotisinstance(col.header.data_type, LB_UniversalThermalClimateIndex):
raiseValueError(
f"Collection {n} data type is not UTCI and cannot be used in this plot."
)
ifany(len(i) !=len(utci_collections[0]) foriinutci_collections):
CONSOLE_LOGGER.warn("The collections given have different lengths.")
And to make it clearer to users that the input collection doesn't actually have to be continuous, we should update the type hint to List[BaseCollection] instead.
Add the ability to filter each HourlyContinuousCollection with an AnalysisPeriod to the utci_comfort_band_comparison plot.
Here is a rough version of something that works. It needs additional verification, e.g. to ensure that the length of the analysis_periods is the same as the length of the utci_collections, it is handled if this is not the case, and comments need updating. Add any additional necessary imports too. Further comments welcome.
The text was updated successfully, but these errors were encountered: