{ "cells": [ { "cell_type": "markdown", "id": "b0a16bcd-4ee4-435d-b045-cb2a9f62d966", "metadata": {}, "source": [ "# The Rock Cycle I: Introduction to Igneous Rocks" ] }, { "cell_type": "code", "execution_count": null, "id": "2b5627e5-a428-44fb-8dec-55e6744c7493", "metadata": { "tags": [ "remove-input" ] }, "outputs": [], "source": [ "import os,re, IPython\n", "import plotly.express as px\n", "from skimage import io,color\n", "import numpy as np\n", "\n", "# Specify folder containing Slides*.png\n", "folder = 'Lecture8_TheRockCycleI-Intro-IgneousRocks'\n", "\n", "# create list of png files\n", "files = []\n", "for (roots,dirs,file) in os.walk(folder):\n", " if roots==folder:\n", " for f in file: \n", " if f.endswith('.png') and f.startswith(folder): files.append(f)\n", "files.sort(key=lambda f: int(re.sub('\\D','',f))) # sort by number of slide\n", "\n", "num_slides = len(files)\n", "for slide, file in enumerate(files):\n", " image_file = folder+'/'+file\n", " img = io.imread(image_file)\n", " if len(img.shape) == 2: img = color.gray2rgb(img) # convert b/w to rgb\n", " \n", " #slide_deck.shape (Nimg, y, x) for monochrome. (Nimg, y, x, 3) for RGB color.\n", " if slide == 0: slide_deck = np.zeros([num_slides,img.shape[0],img.shape[1],img.shape[2]])\n", " slide_deck[slide] = img\n", " \n", "fig = px.imshow(slide_deck, animation_frame=0,binary_string=True, \n", " binary_format='png', binary_compression_level=3,\n", " width=img.shape[1], height=img.shape[0])\n", "fig.update_xaxes(showticklabels=False)\n", "fig.update_yaxes(showticklabels=False)\n", "fig.layout.updatemenus[0].buttons[0].args[1][\"frame\"][\"duration\"] = 2000\n", "fig.show() " ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.12" } }, "nbformat": 4, "nbformat_minor": 5 }