<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Thomas DeLillo on Medium]]></title>
        <description><![CDATA[Stories by Thomas DeLillo on Medium]]></description>
        <link>https://medium.com/@thomasdelillo?source=rss-c237024aed67------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*XIAccCUpmi96BIa5nHNHww.jpeg</url>
            <title>Stories by Thomas DeLillo on Medium</title>
            <link>https://medium.com/@thomasdelillo?source=rss-c237024aed67------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 05:44:48 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@thomasdelillo/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Creating Topographic Maps in Python: Convergence of Art and Data Science]]></title>
            <link>https://medium.com/better-programming/creating-topographic-maps-in-python-convergence-of-art-and-data-science-7492b8c9fa6e?source=rss-c237024aed67------2</link>
            <guid isPermaLink="false">https://medium.com/p/7492b8c9fa6e</guid>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[cartography]]></category>
            <category><![CDATA[iceland]]></category>
            <category><![CDATA[geospatial-data-science]]></category>
            <category><![CDATA[tutorial]]></category>
            <dc:creator><![CDATA[Thomas DeLillo]]></dc:creator>
            <pubDate>Sun, 26 Feb 2023 02:47:03 GMT</pubDate>
            <atom:updated>2023-04-24T07:50:23.409Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ijWH17SGJOpMtFynFwh3LA.png" /><figcaption>Image by author</figcaption></figure><p>Believe it or not, we do not need to use any GIS software such as ArcGIS Pro or QGIS to create this topographic map of Iceland below. Instead, we are going to create this using Python using a few geospatial packages (as well as Photoshop for some final finishing touches). I downloaded the TIFF files from the Copernicus Satellite website, which you can access <a href="https://ec.europa.eu/eurostat/web/gisco/geodata/reference-data/elevation/copernicus-dem/elevation">here</a>. You can also use SRTM data from the USGS’ Earth Explorer (<a href="https://earthexplorer.usgs.gov/">here</a>), but for larger areas such as Iceland, the Copernicus Satellite’s TIFFs are the way to go.</p><p>Since the country of Iceland covers two TIFF files, we will need to merge them to get the whole picture. First, I am going to load in the TIFF files using rasterio and print its dimensions.</p><pre>import rasterio<br><br>file = rasterio.open(&#39;10_DEM_y60x-20.tif&#39;)<br>file2 = rasterio.open(&#39;10_DEM_y60x-30.tif&#39;)<br>dataset = file.read()<br>dataset2 = file2.read()<br>print(dataset.shape)<br>print(dataset2.shape)</pre><pre>&gt;(1, 4801, 4801)<br>&gt;(1, 8401, 6001)</pre><p>The two TIFFs have different dimensions, but luckily for us, rasterio ‘s merge function automatically aligns the rasters based on their spatial reference systems and the pixel resolution, so the TIFFs’ input order and/or different dimensions do not require any further manipulation.</p><p>Next, we are going to merge the TIFFs by first setting their file paths, followed by extracting their pixel values, affining transformation matrices, and storing them in variables for the next step.</p><pre>import os<br><br>dem1_path = os.path.join(&quot;IcelandTopo/10_DEM_y60x-20.tif&quot;)<br>dem2_path = os.path.join(&quot;IcelandTopo/10_DEM_y60x-30.tif&quot;)</pre><pre>with rasterio.open(dem1_path) as src1:<br>    dem1 = src1.read(1, masked=True)<br>    transform1 = src1.transform<br>    crs1 = src1.crs<br><br>with rasterio.open(dem2_path) as src2:<br>    dem2 = src2.read(1, masked=True)<br>    transform2 = src2.transform<br>    crs2 = src2.crs</pre><p>The masked parameter takes invalid or missing data and replaces them with NaN values. transform aligns the pixel coordinates to real-life (x, y) coordinates. crs (coordinate reference system) specifies how the raster’s spatial coordinates relate to a specific geographic or projected coordinate system. With the appropriate scaling and image processing complete, we can merge the two TIFFs into one.</p><pre>from rasterio.merge import merge<br><br>mosaic, out_trans = merge([rasterio.open(dem1_path), rasterio.open(dem2_path)])</pre><p>Now that we have mosaic , which is a NumPy array for the merged files’ pixel values, we can see what we’re working with by plotting mosaic with one of rasterio ‘s default color maps, terrain. The color scale ranges from deep blue at lower altitudes, ascending to light blue, green, yellow, brown, and white for higher altitudes.</p><pre>from rasterio.plot import show<br><br>show(mosaic, cmap=&#39;terrain&#39;)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/674/1*LwdNysno5oQqapAazWrzvw.png" /><figcaption>Iceland and south eastern Greenland in rasterio’s terrain colormap. Image by author</figcaption></figure><p>We can see that we successfully merged the two TIFFs with the whole country of Iceland visible, as well as south eastern Greenland. However, this introduces a new problem — by looking at the plot with the terrain colormap in mind, it is evident that Greenland holds much higher altitudes with its brown color congregating around its mountain peaks. While moving forward to the next step without adjusting this would not introduce any computational errors, it would certainly dilute Iceland’s topographic features.</p><p>We want our map to emphasize Iceland’s distinctive landscape features, so we need to remove Greenland to rescale the colormap appropriately. We can do this with a simple bounding box, but we must save the TIFF file locally first.</p><pre>import tifffile as tiff<br><br>image_array = mosaic<br>tiff.imsave(&#39;output.tif&#39;, image_array)</pre><p>We can now crop ‘output.tif’ with bounding box dimensions from the x and y coordinate values from the image above.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/674/1*Y2Qte1WMspBvta3UOteWmA.png" /><figcaption>Bounding Box: xmin = 2500, ymin = 4000, xmax = 10000, ymax = 8000. Image by author</figcaption></figure><pre>from shapely.geometry import box<br>from rasterio.mask import mask<br><br>bbox = box(2500, 4000, 10000, 8000) #xmin, ymin, xmax, ymax<br><br>with rasterio.open(&#39;output.tif&#39;) as src:<br>    out_image, out_transform = mask(src, [bbox], crop=True)<br>    out_meta = src.meta.copy()<br><br>show(out_image, cmap=&#39;terrain&#39;)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/782/1*TjcCgP8eZe_75lDG1_g1Nw.png" /><figcaption>Iceland terrain colormap. Image by author</figcaption></figure><p>We can see that Iceland includes all of the colors in our colormap now! The pictures below highlight the contrast between Greenland’s inclusion vs exclusion in our map.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vClo_lquj-2nMlJjow-7Sg.png" /><figcaption>The inclusion vs exclusion of Greenland (not pictured) for our colormap of Iceland. Image by author</figcaption></figure><p>Again, we have to save the cropped file so we can move onto applying different colors and styles.</p><pre>cropped_tiff = out_image<br><br>tiff.imsave(&#39;cropped.tif&#39;, cropped_tiff)</pre><p>I am going to use Python’s min() and max() functions to see the lowest and highest altitudes in our image (in meters).</p><pre>print(&#39;Min = &#39; + str(cropped_tiff.min()) + &#39;     Max = &#39; + str(cropped_tiff.max()))</pre><pre>&gt;Min = -3.4729514 Max = 2080.751</pre><p>Our lowest altitude is ≈ -3.5 meters and our highest is just over 2080. While we would expect the lowest elevation to be 0 at sea level, the ocean is not always represented as 0 in a DEM/TIFF file. This is because the ocean is constantly in motion due to tides, waves, and currents, which can cause sea levels to vary.</p><p>It’s time to color our map! We are going to use matplotlib ‘s LinearSegmentedColormap to create our own color map, ditching rasterio ‘s terrain colormap. First we need to load in our cropped image.</p><pre>file3 = rasterio.open(&#39;cropped.tif&#39;)<br>dataset3 = file3.read()</pre><p>Now we can create our own colormap and scale it accordingly. I used 5 colors ranging from white to dark blue to produce the colormap below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KwDvCKPHTv7WcFHTHxboUA.png" /></figure><pre>import matplotlib.pyplot as plt<br>from matplotlib.colors import LinearSegmentedColormap<br>from matplotlib import colors<br><br>norm = colors.Normalize(vmin=-3.5, vmax=2081)<br><br>value_range = 256<br><br>#Enter the hex codes of your desired colors here!<br>iceland_colormap = LinearSegmentedColormap.from_list(&#39;iceland&#39;, [&#39;#ffffff&#39;,&#39;#CCDBE8&#39;, &#39;#6088AB&#39;, &#39;#305B80&#39;, &#39;#223F59&#39;], N=value_range)<br><br><br>fig = plt.figure(facecolor=&#39;#ffffff&#39;)<br>fig.set_size_inches(12, 12)<br>ax = plt.axes()<br>plt.imshow(dataset3[0], cmap=iceland_colormap)<br>ax.axis(&#39;off&#39;)<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C_3k9JYav6IaAWykI-U57w.png" /><figcaption>Iceland with custom colormap from Matlotib’s LinearSegmentedColormap. Image by author</figcaption></figure><p>value_range is the number of colors that will be displayed from your color map. Here, it maps the lowest data value (-3.5) to the white end of the colormap, and the highest data value (2081) to the darker blue end of the colormap. Intermediate data values are allocated to colors that lie between these whites and blues. I have value_range set to 256 colors, but if we reduce it to 10, it would mean that every ≈ 209 meters gets its own one color, giving us a spotty map with only 10 colors from our colormap as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H13S_2Ei65hTraicKHncEQ.png" /><figcaption>Iceland with colormap value_range = 10. Image by author</figcaption></figure><p>To get our final image, we will be placing two images on top of each other — our map of Iceland with its custom colormap and a grey hillshade map of Iceland. First, we are going to create a hillshade map of Iceland using Python’s EarthPy package.</p><pre>import earthpy.spatial as es<br>import earthpy.plot as ep<br><br>hillshade = es.hillshade(dataset3[0], azimuth=315, altitude=0)<br><br>ep.plot_bands(hillshade, cmap=&#39;gray&#39;)<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iMMRZ3wM47V5Ov5-YZC4jQ.png" /><figcaption>Map of Iceland with grey hillshade. Image by author</figcaption></figure><p>We can control our hillshade with the azimuth and altitude parameters. These are used to show where the light source is coming from. I always use an altitude of 0 so that the features are more highlighted as higher altitudes tend to wash landscape features out. I encourage you to play around with both to see what you like!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cCRoBh4N19a89LYhk56OuA.jpeg" /><figcaption>Upper hemisphere of celestial sphere with azimuth and altitude features. Image by TheSolarLabs.com</figcaption></figure><p>Finally, we can overlay our hillshade with our custom colormap of Iceland to get a topographic map of Iceland in the colors of our choice!</p><pre>fig, ax = plt.subplots()<br>fig.set_size_inches(12, 12)<br>bgcolor = &quot;#ffffff&quot;<br>i = plt.imshow(dataset3[0], cmap=iceland_colormap, norm=norm)<br>ax.imshow(hillshade, cmap=&quot;gray&quot;, alpha=0.15)<br>ax.axis(&#39;off&#39;)<br>plt.savefig(&#39;iceland_topo.png&#39;, dpi = 300, transparent = True)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RvB2zr7Vlv47EtwSLh6QoQ.png" /><figcaption>Custom colormap and hillshade map of Iceland. Image by author</figcaption></figure><p>Here we have it! The alpha value can lie between 0 and 1 with lower values adding subtle hillshade and vice versa. I found that a value of 0.15 worked best for this map but I encourage you to try out different ones to get your map looking exactly how you’d like! You can change the resolution and dimension (in inches) so you can save in the configuration you’d like.</p><p>The last step I did was making color adjustments in Adobe Photoshop:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ijWH17SGJOpMtFynFwh3LA.png" /><figcaption>Image by author</figcaption></figure><p>Behold! Our final masterpiece, a topographic map of Iceland crafted through a fusion of data analysis, data visualization, terrain analysis, and art. I humbly invite any feedback you may have to enhance the aesthetic appeal or explore alternate approaches in achieving this feat of cartography.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7492b8c9fa6e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/creating-topographic-maps-in-python-convergence-of-art-and-data-science-7492b8c9fa6e">Creating Topographic Maps in Python: Convergence of Art and Data Science</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>