From 8bf7cdb2fcac5295755e6c6ad7c7cdd99fd9855a Mon Sep 17 00:00:00 2001 From: Mark Piper Date: Fri, 9 Aug 2024 14:11:46 -0600 Subject: [PATCH] Make pretty --- lessons/python/yet_another_oop.ipynb | 51 ++++++++++++++-------------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/lessons/python/yet_another_oop.ipynb b/lessons/python/yet_another_oop.ipynb index 2a8d720..6ed6db2 100644 --- a/lessons/python/yet_another_oop.ipynb +++ b/lessons/python/yet_another_oop.ipynb @@ -540,7 +540,7 @@ " # Note: I didn't realize this when I originally wrote the class, but we won't actually need dz\n", " # Want to know why? Check out the documentation for np.gradient -> https://numpy.org/doc/stable/reference/generated/numpy.gradient.html\n", " # (What does the second argument to np.gradient do?)\n", - " \n", + "\n", " # We'll need attributes for rho, c, and k\n", " # You could also store info about boundary conditions at this point, if you want\n", " self.rho = 917\n", @@ -548,9 +548,9 @@ " self.k = 2.1\n", "\n", " # Let's store boundary conditions too\n", - " \n", + "\n", " # Maybe we should go ahead and calculate diffusivity right away?\n", - " \n", + "\n", " # Let's keep track of the elapsed time\n", "\n", " def calc_diffusivity(self) -> float:\n", @@ -559,7 +559,7 @@ "\n", " def calc_heat_flux(self) -> np.ndarray:\n", " \"\"\"The heat flux is -kappa * dT / dz.\"\"\"\n", - " \n", + "\n", " # How should we calculate the difference in temperature with depth? (hint: see dz, above)\n", "\n", " # Are dT and dz the same size? Are they the same size as z?\n", @@ -634,16 +634,16 @@ "\n", "dt = 60 * 60 * 24 * 20\n", "\n", - "for i in range(30000): \n", + "for i in range(30000):\n", " model.run_one_step(dt)\n", "\n", " if i % 1000 == 0:\n", - " print(f'{model.time_elapsed / 31556926} years.')\n", + " print(f\"{model.time_elapsed / 31556926} years.\")\n", "\n", "plt.plot(model.temperature, model.z)\n", - "plt.xlabel('Temperature ($^\\circ$ C)')\n", - "plt.ylabel('Depth (m)')\n", - "plt.gca().invert_yaxis() # This forces matplotlib to invert the y-axis\n", + "plt.xlabel(r\"Temperature ($^\\circ$ C)\")\n", + "plt.ylabel(\"Depth (m)\")\n", + "plt.gca().invert_yaxis() # This forces matplotlib to invert the y-axis\n", "plt.show()" ] }, @@ -662,8 +662,7 @@ "metadata": {}, "outputs": [], "source": [ - "# Initialize your model with a new bottom boundary condition\n", - "\n" + "# Initialize your model with a new bottom boundary condition" ] }, { @@ -675,16 +674,16 @@ "source": [ "dt = 60 * 60 * 24 * 20\n", "\n", - "for i in range(30000): \n", + "for i in range(30000):\n", " model.run_one_step(dt)\n", "\n", " if i % 1000 == 0:\n", - " print(f'{model.time_elapsed / 31556926} years.')\n", + " print(f\"{model.time_elapsed / 31556926} years.\")\n", "\n", "plt.plot(model.temperature, model.z)\n", - "plt.xlabel('Temperature ($^\\circ$ C)')\n", - "plt.ylabel('Depth (m)')\n", - "plt.gca().invert_yaxis() # This forces matplotlib to invert the y-axis\n", + "plt.xlabel(r\"Temperature ($^\\circ$ C)\")\n", + "plt.ylabel(\"Depth (m)\")\n", + "plt.gca().invert_yaxis() # This forces matplotlib to invert the y-axis\n", "plt.show()" ] }, @@ -717,8 +716,8 @@ "source": [ "class SimpleGlacier:\n", " \"\"\"Models the temperature profile with a glacier.\n", - " \n", - " This model is based off of: \n", + "\n", + " This model is based off of:\n", " The Physics of Glaciers (Cuffey and Paterson, 2010).\n", " Lecture notes from Andy Aschwanden (McCarthy school, summer 2012).\n", "\n", @@ -736,7 +735,7 @@ " self.dz = np.gradient(self.z)\n", " # Note: I didn't realize this when I originally wrote the class, but we won't need dz\n", " # Want to know why? Check out the documentation for np.gradient -> https://numpy.org/doc/stable/reference/generated/numpy.gradient.html\n", - " \n", + "\n", " # We'll need attributes for rho, c, and k\n", " # You could also store info about boundary conditions at this point, if you want\n", " self.rho = 917\n", @@ -746,10 +745,10 @@ " # Let's store boundary conditions too\n", " self.surface_temperature = -10.0\n", " self.basal_heat_flux = 0.0\n", - " \n", + "\n", " # Maybe we should go ahead and calculate diffusivity right away?\n", " self.kappa = self.calc_diffusivity()\n", - " \n", + "\n", " # Let's keep track of the elapsed time\n", " self.time_elapsed = 0.0\n", "\n", @@ -759,7 +758,7 @@ "\n", " def calc_heat_flux(self) -> np.ndarray:\n", " \"\"\"The heat flux is -kappa * dT / dz.\"\"\"\n", - " \n", + "\n", " # How should we calculate the difference in temperature with depth? (hint: see dz, above)\n", " temperature_gradient = np.gradient(self.temperature, self.z)\n", "\n", @@ -770,15 +769,15 @@ " temperature_gradient[-1] = self.basal_heat_flux\n", "\n", " return -self.kappa * temperature_gradient\n", - " \n", + "\n", " def calc_divergence(self) -> np.ndarray:\n", " \"\"\"In 1D, divergence is just the derivative. yay!\"\"\"\n", " heat_flux = self.calc_heat_flux()\n", - " \n", + "\n", " flux_divergence = np.gradient(heat_flux, self.z)\n", - " \n", + "\n", " return flux_divergence\n", - " \n", + "\n", " def run_one_step(self, dt: float):\n", " \"\"\"Advance the model by one step of size dt.\"\"\"\n", " flux_divergence = self.calc_divergence()\n",