It can be called for communally; in fact the Mishna in Taanit describes public fasts because of famine, drought, war, natural disasters, and the like; everyone would gather and the communal leaders would first put ash on their own heads, then everyone would follow. (If the leader insists on others suffering while he's fully comfortable ... the message doesn't stick.) Contemporary Israeli rabbis have debated when exactly to invoke these today. (E.g. severe drought a few years ago, though thank God they're far less fatal due to modern technology and trade.)
For the individual on his/her own ... I'd tread very, very lightly. Talmud Yoma 86b says if a sin was private and was between the sinner and God, then it's best to not publicize it. (That does not, however, mean actively denying or covering it up.) Maimonides, Laws of Repentance 2:5 codifies this. If someone ate bacon on live television and now wants to repent, Raavad feels he should get back on TV and say "I ate bacon and now repented", whereas Kesef Mishnah reads Maimonides as saying there's nothing gained and much lost in rehashing that.
In the early 1800s, Rabbi Avraham Danzig in his code Chayei Adam on the laws of Yom Kippur notes that he sees people doing amazing acts of asceticism on Yom Kippur -- some never sat down the entire 24-hour period, apparently. He cautioned that the more dramatic the one-day display, very often the quicker such folks rushed right back into their old behaviors.
Medieval sources talked about self-affliction (e.g. sitting in snow or cold water) as a step to repentance, but most contemporary rabbis advise the typical person against it, other than maybe some occasional extra fasts. (Rabbi Asher Weiss, one of today's leading experts on medical halacha, was asked by someone who could have done better to prevent nursing-home residents from being exposed to SARS-CoV-2 and failed to do so, and one of them died of COVID-19. He says the whole medieval self-affliction thing is really not for most people today, and instead suggests the fellow redouble his efforts to help protect people's lives.)