Skip to content

Commit

Permalink
Representation and small plot updates. (#138)
Browse files Browse the repository at this point in the history
* Representation update: Glacier and GlacierCollection

- Adds the glacier type to the HTML representation of the glacier and the
  collection.
- Max ice thickness is included in the representation, both for one
  glacier and a collection.
- Box containing information about the glaciers in the collection plots now include the
  glacier type.

* Glacier plot update.

Indicate the ELA location in the top down view when there is no ice.
Previously we only plotted the ELA when there was ice.
  • Loading branch information
Holmgren825 committed Feb 23, 2022
1 parent d1239aa commit f8c63f1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
19 changes: 18 additions & 1 deletion oggm_edu/glacier.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,20 @@ def _repr_html_(self):
attrs = self._to_json()
df = pd.DataFrame.from_dict(attrs, orient="index")
df.columns = [""]
df.index.name = type(self).__name__
df.index.name = "Attribute"

return df._repr_html_()

def _to_json(self):
"""Json represenation"""
state = self.state()
json = {
"Type": type(self).__name__,
"Age": int(self.age),
"Length [m]": state.length_m,
"Area [km2]": state.area_km2,
"Volume [km3]": state.volume_km3,
"Max ice thickness [m]": state.thick.max(),
"Response time [yrs]": self.response_time,
}
return json
Expand Down Expand Up @@ -536,6 +538,19 @@ def plot(self):
ls="--",
lw=1,
)
# If we don't have a state yet, plot the ELA on the bed.
else:
# Where is the ela in regards to the bed height?
idx = (np.abs(self.bed.bed_h - self.ela)).argmin()
# Add vertical line.
ax2.vlines(
self.bed.distance_along_glacier[idx],
ymin=-self.bed.widths[idx] / 2 * self.bed.map_dx,
ymax=self.bed.widths[idx] / 2 * self.bed.map_dx,
color="k",
ls="--",
lw=1,
)

# Limits etc
plt.xlim((0, self.bed.distance_along_glacier[-1] + 2))
Expand Down Expand Up @@ -768,10 +783,12 @@ def _to_json(self):
"""Json represenation"""
state = self.state()
json = {
"Type": type(self).__name__,
"Age": int(self.age),
"Length [m]": state.length_m,
"Area [km2]": state.area_km2,
"Volume [km3]": state.volume_km3,
"Max ice thickness [m]": state.thick.max(),
"Surging periodicity (off/on)": [[self.normal_years, self.surging_years]],
"Surging now?": not self._normal_period,
}
Expand Down
16 changes: 10 additions & 6 deletions oggm_edu/glacier_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ def plot(self):
for glacier in self._glaciers:
# Create the label
label = (
f"Type: {type(glacier).__name__}\n"
f"ELA: {glacier.ela} \n"
f"MB grad: {glacier.mb_gradient} \n"
f"Age: {glacier.age} \n"
Expand Down Expand Up @@ -380,12 +381,15 @@ def plot_history(self):
# Plot the area
glacier.history.area_m2.plot(
ax=ax3,
label=f"Glacier {i}\n"
+ f"ELA: {glacier.ela}\n"
+ f"MB grad: {glacier.mb_gradient}\n"
+ f"Age: {glacier.age}\n"
+ f"Creep: {glacier.creep:.2e}\n"
+ f"Sliding: {glacier.basal_sliding}",
label=(
f"Glacier {i}\n"
f"Type: {type(glacier).__name__}\n"
f"ELA: {glacier.ela}\n"
f"MB grad: {glacier.mb_gradient}\n"
f"Age: {glacier.age}\n"
f"Creep: {glacier.creep:.2e}\n"
f"Sliding: {glacier.basal_sliding}"
),
)
else:
print("Glacier history missing")
Expand Down

0 comments on commit f8c63f1

Please sign in to comment.