<p>So I hope I finally understood what your problem really was and this gives you the height information at your specific lat lon values from your csv data.</p>
<pre><code>import numpy as np
from netCDF4 import Dataset
import matplotlib.pyplot as plt

csv_data = np.loadtxt('1994_12_O18grid.csv',skiprows=1,delimiter=',')

num_el = csv_data[:,0]
lat = csv_data[:,1]
lon = csv_data[:,2]
value = csv_data[:,3]

data = Dataset(&quot;ETOPO1_Bed_g_gdal.grd&quot;,'r')
lon_range = data.variables['x_range'][:]
lat_range = data.variables['y_range'][:]
topo_range = data.variables['z_range'][:]
spacing = data.variables['spacing'][:]
dimension = data.variables['dimension'][:]
z = data.variables['z'][:]
lon_num =  dimension[0]
lat_num =  dimension[1]

etopo_lon = np.linspace(lon_range[0],lon_range[1],dimension[0])
etopo_lat = np.linspace(lat_range[0],lat_range[1],dimension[1])
topo = np.reshape(z, (lat_num, lon_num))

height = np.empty_like(num_el)
for i in range(len(num_el)):  #in this loop we search for the height values for the specific lat and lon values from your csv
    desired_lat_idx = np.abs(etopo_lat - lat[i]).argmin()
    desired_lon_idx = np.abs(etopo_lon - lon[i]).argmin()
    height[i] = topo[desired_lat_idx,desired_lon_idx]

plt.figure()
height[height&lt;0]=0 # if you want to disregard values below 0
plt.imshow(np.reshape(height,(180,360))) # if the resolution of your csv data changes from 1 degree to something different you need to chance the values in the reshape. For simplicity I hardcoded the numbers.
</code></pre>
<p>The searching for the height levels is not that efficient but I didnt have the time to do a proper numpy style solution.</p>

CC BY-SA 4.0
2022-06-22T12:08:52.360Z
I will have a detailed look at it! but it looks very promising! Thank you very much for your time and for answering me so patiently!
Weiss
CC BY-SA 4.0
2022-06-22T12:13:35.667Z
You are welcome, maybe as an advice in the future try to better formulate your issues and questions. Then people can help you more quickly :)
smichel
CC BY-SA 4.0
2022-06-22T12:14:52.533Z
OK I will do that! You may notice that I am new to coding and still need some help :-)
Weiss
CC BY-SA 4.0
2022-06-22T12:25:05.977Z
Yeah, no worries. Everyone started at one point.
smichel
CC BY-SA 4.0
2022-06-23T10:08:44.570Z
Hi @smichel I'm afraid I don't quite understand the probgram and I still want to ask how I can extract the data from this figure that I have a table that looks like this: Long/lat/Value(CSV)/Altitude? If something is unclear, I will try to ask the question again in more detail in a new question.
Weiss
CC BY-SA 4.0
2022-06-23T15:59:02.803Z
I now managed to save the data as I want, however the data are upside down, how can I change it?
Weiss
CC BY-SA 4.0
2022-06-22T12:00:20.933Z
2022-06-22T12:00:20.933Z
smichel
<p>Hi I need For each Lat and Long value also the Alt value! However, I am having problems extracting these values from a Geotiff and wonder if this data is publicly available in Excel or CSV file format? Unfortunately I have not found anything myself!</p>
<p>my data: <a href="https://wetransfer.com/downloads/8e5ba7aa4cd8c406068a60543b353b0420220622084939/d3c744" rel="nofollow noreferrer">https://wetransfer.com/downloads/8e5ba7aa4cd8c406068a60543b353b0420220622084939/d3c744</a>
For people who know Python:</p>
<pre><code>import numpy as np
import matplotlib.pyplot as plt
from netCDF4 import Dataset
import pandas as pd

data = Dataset(&quot;C:/Users/Oliver Weisser/Desktop/Bachelor/Programm/Daten/Daten/ETOPO1_Bed_g_gdal.grd&quot;,'r')
print(data.variables.keys())

lon_range = data.variables['x_range'][:]
lat_range = data.variables['y_range'][:]
topo_range = data.variables['z_range'][:]
spacing = data.variables['spacing'][:]
dimension = data.variables['dimension'][:]
z = data.variables['z'][:]
lon_num =  dimension[0]
lat_num =  dimension[1]

lon = np.linspace(lon_range[0],lon_range[1],dimension[0])
lat = np.linspace(lat_range[0],lat_range[1],dimension[1])

topo = np.reshape(z, (lat_num, lon_num))


dfl = pd.DataFrame({
        'Latitude': lat.reshape(-1),
        'Longitude': lon.reshape(-1),
        'Altitude': topo.reshape(-1)
        })
print(dfl)

</code></pre>
<p>Source: <a href="https://earthscience.stackexchange.com/questions/23904/etopo1-region-selection-in-python/23924#23924">ETOPO1 region selection (in python)</a></p>
<p>This is the code I have written so far, maybe someone will find a bug there</p>

CC BY-SA 4.0
2022-06-24T08:04:15.040Z
Comments are not for extended discussion; this conversation has been [moved to chat](https://chat.stackexchange.com/rooms/137302/discussion-on-question-by-weiss-world-elevation-data-as-csv).
gerrit
<models>
World Elevation Data as CSV
Weiss
# World Elevation Data as CSV

(Asked by: username_0 on 2022-06-22)

Hi I need For each Lat and Long value also the Alt value! However, I am having problems extracting these values from a Geotiff and wonder if this data is publicly available in Excel or CSV file format? Unfortunately I have not found anything myself!
my data: https://wetransfer.com/downloads/8e5ba7aa4cd8c406068a60543b353b0420220622084939/d3c744
For people who know Python:
import numpy as np
import matplotlib.pyplot as plt
from netCDF4 import Dataset
import pandas as pd

data = Dataset("C:/Users/Oliver username_0er/Desktop/Bachelor/Programm/Daten/Daten/ETOPO1_Bed_g_gdal.grd",'r')
print(data.variables.keys())

lon_range = data.variables['x_range'][:]
lat_range = data.variables['y_range'][:]
topo_range = data.variables['z_range'][:]
spacing = data.variables['spacing'][:]
dimension = data.variables['dimension'][:]
z = data.variables['z'][:]
lon_num =  dimension[0]
lat_num =  dimension[1]

lon = np.linspace(lon_range[0],lon_range[1],dimension[0])
lat = np.linspace(lat_range[0],lat_range[1],dimension[1])

topo = np.reshape(z, (lat_num, lon_num))


dfl = pd.DataFrame({
        'Latitude': lat.reshape(-1),
        'Longitude': lon.reshape(-1),
        'Altitude': topo.reshape(-1)
        })
print(dfl)


Source: ETOPO1 region selection (in python)
This is the code I have written so far, maybe someone will find a bug there

**Tags:** models

> **Comments:**
> **username_1**: Comments are not for extended discussion; this conversation has been [moved to chat](https://chat.stackexchange.com/rooms/137302/discussion-on-question-by-weiss-world-elevation-data-as-csv).  

---

## 1 answers

### Answer by username_2 on 2022-06-22. Score: 4 | Accepted answer

So I hope I finally understood what your problem really was and this gives you the height information at your specific lat lon values from your csv data.
import numpy as np
from netCDF4 import Dataset
import matplotlib.pyplot as plt

csv_data = np.loadtxt('1994_12_O18grid.csv',skiprows=1,delimiter=',')

num_el = csv_data[:,0]
lat = csv_data[:,1]
lon = csv_data[:,2]
value = csv_data[:,3]

data = Dataset("ETOPO1_Bed_g_gdal.grd",'r')
lon_range = data.variables['x_range'][:]
lat_range = data.variables['y_range'][:]
topo_range = data.variables['z_range'][:]
spacing = data.variables['spacing'][:]
dimension = data.variables['dimension'][:]
z = data.variables['z'][:]
lon_num =  dimension[0]
lat_num =  dimension[1]

etopo_lon = np.linspace(lon_range[0],lon_range[1],dimension[0])
etopo_lat = np.linspace(lat_range[0],lat_range[1],dimension[1])
topo = np.reshape(z, (lat_num, lon_num))

height = np.empty_like(num_el)
for i in range(len(num_el)):  #in this loop we search for the height values for the specific lat and lon values from your csv
    desired_lat_idx = np.abs(etopo_lat - lat[i]).argmin()
    desired_lon_idx = np.abs(etopo_lon - lon[i]).argmin()
    height[i] = topo[desired_lat_idx,desired_lon_idx]

plt.figure()
height[height<0]=0 # if you want to disregard values below 0
plt.imshow(np.reshape(height,(180,360))) # if the resolution of your csv data changes from 1 degree to something different you need to chance the values in the reshape. For simplicity I hardcoded the numbers.

The searching for the height levels is not that efficient but I didnt have the time to do a proper numpy style solution.

> **Comments:**
> **username_0**: I will have a detailed look at it! but it looks very promising! Thank you very much for your time and for answering me so patiently!  
> **username_2**: You are welcome, maybe as an advice in the future try to better formulate your issues and questions. Then people can help you more quickly :)  
> **username_0**: OK I will do that! You may notice that I am new to coding and still need some help :-)  
> **username_2**: Yeah, no worries. Everyone started at one point.  
> **username_0**: Hi @username_2 I'm afraid I don't quite understand the probgram and I still want to ask how I can extract the data from this figure that I have a table that looks like this: Long/lat/Value(CSV)/Altitude? If something is unclear, I will try to ask the question again in more detail in a new question.  
> **username_0**: I now managed to save the data as I want, however the data are upside down, how can I change it?  

---

