Wednesday, August 9, 2023
HomeBig DataConstructing A Topographic Map of Nepal Utilizing Python

Constructing A Topographic Map of Nepal Utilizing Python


Introduction

Ever questioned how the topography of your nation influences financial and political improvement? Topographic maps – maps of the earth’s floor that use contour traces for visualization – may also help reply these questions! We are going to use Python to create a topographic map for Nepal, a rustic with an attention-grabbing topographic atmosphere. You’ll learn to learn geospatial knowledge that describes the topography of a rustic, find out how to interpret this knowledge, and find out how to visualize it. The ensuing map will be mixed with different knowledge of curiosity at very disaggregated subnational ranges to know how the topography of a rustic influences its financial and/or political improvement. This weblog submit will educate you find out how to generate a extremely attention-grabbing device that may inform insurance policies and personal sector improvement!

Studying Targets

  • Acquire proficiency in knowledge evaluation strategies for digital elevation knowledge.
  • Learn to use geospatial knowledge and associated evaluation instruments in Python.
  • Purchase information of mapping strategies.
  • Develop abilities in efficient knowledge visualization for communication.
  • Perceive the significance of elevation for inequality and poverty.

This text was printed as part of the Information Science Blogathon.

What are Topographic Maps?

Topographic maps are maps of the earth’s floor that use contour traces for visualization. Topographic maps are a helpful device for navigating unfamiliar terrain and function city planning and catastrophe administration inputs. They’re usually used to know the spatial context of insurance policies or non-public sector tasks round infrastructure improvement, to determine areas weak to pure disasters or with restricted entry to important providers, similar to training, healthcare, and infrastructure, or for pure useful resource administration. Finally, these maps can function enter for evidence-based decision-making. On this weblog submit, we are going to use Python to create a topographic map for Nepal, a rustic with a extremely attention-grabbing topographic atmosphere.

Information Description

To generate our map, we are going to depend on knowledge printed by the United States Geological Survey (USGS). USGS is a scientific company of america federal authorities that generates knowledge and analysis round pure assets, geology, geography, water assets, and pure hazards. To get to their knowledge web page, kind “USGS Information” in Google or click on the hyperlink that directs you to their Earth Explorer. The Earth Explorer is an internet device and knowledge portal that lets you search, entry, and obtain a variety of Earth science knowledge. You could arrange an account and log in to totally use the info.

Information Obtain

This weblog submit will use Nepal for example because of its distinctive topographic traits. Nepal has one of the vital difficult and attention-grabbing topographies on the planet. 8 out of the 14 mountains above 8,000 m are in Nepal (Trekking Path Nepal), and the nation is split into three very completely different topographic areas: the Mountains, Hills, and Terai (or plains) (DHS). Whereas these traits make the nation distinctive and attention-grabbing, some analysis exhibits that the topography of Nepal makes it difficult to attach the nation, ship important providers to its inhabitants, and impose dangers and obstacles to a sustainable improvement path.

To this finish, we are going to filter for Nepal within the Search Standards, as indicated within the image under. As soon as we chosen Nepal, we chosen our dataset of curiosity. To take action, click on the Information Units tab and select Digital Elevation. There are a number of choices for Digital Elevation Information, and when you might use a number of of those datasets, we are going to use the World Multi-resolution Terrain Elevation Information 2010 GMTED2010 knowledge. This knowledge gives international protection of the Earth’s terrain at a number of resolutions (starting from 7.5 arc-seconds (roughly 250 meters) to 30 arc-seconds (roughly 1 kilometer)). It’s generated from spaceborne and airborne distant sensing knowledge, together with satellite tv for pc altimetry, stereo-imagery, and topographic maps.

When you select the info, click on on the Outcomes tab. Now you can obtain the info by clicking the image with obtain choices. You too can show the info through the footprint icon. We obtain the info in its highest decision (7.5 arc seconds). Importantly, to cowl all of Nepal, we have to obtain two completely different mosaics (components) of the underlying knowledge and mix them later. You will notice that the ensuing knowledge set is in a tif format, which signifies raster knowledge.

Python gives a number of instruments for geospatial evaluation. On this weblog submit, we depend on the Rasterio library that makes it potential to learn and write geospatial raster knowledge (gridded knowledge). Let’s get began and skim the primary mosaic (half) of the info we beforehand downloaded into our Jupyter Pocket book:

#import related libraries (after putting in them)
import rasterio
import matplotlib.pyplot as plt
import numpy as np

#Learn the info and present the form of the dataset
file = rasterio.open(r'path10n060e_20101117_gmted_mea075.tif')
dataset = file.learn()
print(dataset.form)

Let’s additionally add the second mosaic and mix them by merging them. To this finish, we observe normal raster knowledge studying and manipulation strategies in Python as follows:

#Add second dataset and present the form of the dataset
file2 = rasterio.open(r'path30n060e_20101117_gmted_mea075.tif')
dataset2 = file2.learn()
print(dataset2.form)


#Mix each datasets
from rasterio.merge import merge
from rasterio.plot import present

#Create empty listing
src_files_to_mosaic = []

#Append the listing with each information
src_files_to_mosaic.append(file)
src_files_to_mosaic.append(file2)
src_files_to_mosaic

#Merge each information
mosaic, out_trans = merge(src_files_to_mosaic)

# Copy Metadata
output_meta = file.meta.copy()

#Replace Metadata
output_meta.replace(
    {"driver": "GTiff",
        "top": mosaic.form[1],
        "width": mosaic.form[2],
        "remodel": out_trans,
    }
)

#Write to vacation spot
# Write the mosaic raster to disk
out_fp = r"pathNepal_Mosaic.tif"

with rasterio.open(out_fp, "w", **output_meta) as dest:
        dest.write(mosaic)

#Open the mixed raster knowledge
file_mosaic = rasterio.open(out_fp)

#Learn the info
dataset_mosaic = file_mosaic.learn()
print(file_mosaic.form)

#Present the info
plt.imshow(dataset_mosaic[0], cmap='Spectral')
plt.present()
Topographic Map | Python

World Multi-resolution Terrain Elevation Information

We now have a mixed World Multi-resolution Terrain Elevation Information 2010 GMTED2010 knowledge for all of Nepal, however the file additionally covers massive components of the encircling space that aren’t a part of Nepal. Let’s limit the world to Nepal through the use of a shapefile of Nepal. We are going to use a shapefile with nation borders for the world. You possibly can obtain this dataset right here. Let’s then clip the raster knowledge and shapefile utilizing the masks perform. We are going to solely use the primary row of the shapefile and the geometry column. The results of this operation is saved in clipped_array, which is the clipped raster knowledge, and clipped_transform, which represents the transformation info of the clipped raster.

import geopandas as gpd
from shapely.geometry import mapping
from rasterio import masks as msk#import csv

#Add shapefile with nation boarders of the world
df = gpd.read_file(r'path/world-administrative-boundaries.shp')

#Prohibit to Nepal
nepal = df.loc[df.name=="Nepal"]
nepal.head()

#Clip knowledge
clipped_array, clipped_transform = msk.masks(file_mosaic, [mapping(nepal.iloc[0].geometry)], crop=True)

#

There’s one remaining downside. The no knowledge values in raster knowledge are extremely damaging. Due to this fact, would distort the visualization of our map, as these kind a part of the worth vary.

Perceive the Drawback

Let’s deal with this downside as follows, as described in this weblog submit:

  • Let’s construct a perform that takes care of no knowledge values. We assemble a no-data parameter to specify the worth thought-about “no knowledge” within the clipped array. On this case, it’s set to (np.amax(clipped_array[0]) + 1), which signifies that it is the same as the utmost worth within the clipped array plus one. This worth shall be thought-about because the “no knowledge” worth.
  • Regulate the clipped array by including absolutely the worth of the minimal worth within the clipped array to the primary band (index 0) of the clipped array. This step ensures that each one values within the clipped array grow to be non-negative.
  • We additionally calculate the worth vary of the clipped array. It provides the utmost and absolute worth of the minimal worth within the clipped array. The value_range variable will maintain the calculated worth vary.
  • Use a manually constructed color-value dictionary based mostly on an current one (the seismic one) and outline our background coloration for the “no knowledge” values.
  • Within the final step, we plot the map with the brand new coloration vary referred to as new_seismic.
#Let's examine no knowledge values

nodata_value = file_mosaic.nodata 
print("Nodata worth:", nodata_value)
#Nodata worth: -32768.0

#Change worth of nodata to at least one greater than the utmost elevation
 def clip_raster(gdf, img):
     clipped_array, clipped_transform = msk.masks(img, [mapping(gdf.iloc[0].geometry)], crop=True)
     clipped_array, clipped_transform = msk.masks(img, [mapping(gdf.iloc[0].geometry)],
                                                           crop=True, nodata=(np.amax(clipped_array[0]) + 1))
     clipped_array[0] = clipped_array[0] + abs(np.amin(clipped_array))
     value_range = np.amax(clipped_array) + abs(np.amin(clipped_array))
     return clipped_array, value_range

nepal_topography, value_range = clip_raster(nepal, file_mosaic)


#Test that this labored
print(value_range)


#Let's give the nodata worth a brand new background coloration
from matplotlib import cm
from matplotlib.colours import ListedColormap,LinearSegmentedColormap

#Sesmic
new_seismic = cm.get_cmap('seismic', 8828)

#Outline background coloration
background_color = np.array([0.9882352941176471, 0.9647058823529412, 0.9607843137254902, 1.0])

#Use coloration map
newcolors = new_seismic(np.linspace(0, 1, 8828))

# Add the background coloration because the final row to the newcolors array.
newcolors = np.vstack((newcolors, background_color))

#Use new Italy Shade Map
new_seismic = ListedColormap(newcolors)

#Create last map and save
plt.determine(figsize=(10,10))
c = plt.imshow(nepal_topography[0], cmap = new_seismic)
clb = plt.colorbar(c, shrink=0.4)
clb.ax.set_title('Elevation (meters)',fontsize=10)

plt.savefig(r'pathTopographic_Map_Nepal.png', bbox_inches="tight")
plt.present()
Topographic Map | Python

Voilá! We’ve got a topographic map of Nepal that clearly signifies the completely different elevations within the nation and the three topographic zones.

Conclusion

You discovered to generate a topographic map in Python utilizing geospatial knowledge from the United States Geological Survey (USGS). You additionally discovered the significance of caring for lacking values within the last dataset for visualization.

Policymakers or practitioners can now use this map for additional evaluation, similar to combining it with different maps, similar to maps of poverty, or pure disasters, to research if there may be some connection. We’ve got generated a helpful device that may inform evidence-based decision-making in politics!

Key Takeaways

  • Topographic Maps are helpful instruments for evidence-based decision-making.
  • Topography and elevation play a vital position in city planning, service supply, and inequality.
  • Python has helpful instruments for analyzing geospatial knowledge.
  • Taking good care of no knowledge values in this sort of knowledge is essential for visualization.
  • Visualizing geospatial knowledge can generate helpful info at disaggregated ranges.

Hope you discovered this text informative. Be happy to succeed in out to me on LinkedIn. Let’s join and work in direction of leveraging knowledge for optimistic change.

Regularly Requested Questions

Q1. What’s on a topographic map?

A. Topographic maps comprehensively signify a particular geographical area, offering exact details about pure and human components. They depict the terrain’s traits, together with mountains, valleys, and plains, utilizing contour traces, which point out factors of equal elevation above sea stage. Topographic maps supply an in depth report of the land’s options, enabling customers to know its form and elevation precisely.

Q2. What’s a topographic map used for?

A. Topography goals to exactly find varied options and factors on the Earth’s floor utilizing a horizontal coordinate system like latitude, longitude, and altitude. It includes figuring out positions, naming recognized options, and figuring out frequent patterns of landforms. Topography seeks to know and signify the spatial association and traits of the Earth’s floor options.

Q3. What’s geospatial evaluation in Python?

A. Geospatial evaluation in Python includes utilizing Python programming language and specialised libraries to work with and analyze geospatial knowledge. Geospatial knowledge encompasses details about the Earth’s options and occasions, together with geographical positions, spatial connections, and traits related to these areas.

This autumn. What’s the GMTED2010 Dataset?

A. The GMTED2010 dataset advantages from the provision of higher-quality elevation knowledge obtained from varied sources, such because the Shuttle Radar Topography Mission (SRTM), Canadian elevation knowledge, Spot 5 Reference3D knowledge, and the Ice, Cloud, and land Elevation Satellite tv for pc (ICESat). These new sources contribute to enhanced accuracy and protection of worldwide topographic knowledge. GMTED2010 represents a big development in international topographic knowledge, facilitating varied geospatial analyses and supporting many essential functions.

The media proven on this article shouldn’t be owned by Analytics Vidhya and is used on the Writer’s discretion.



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments