I am new to coding in python so please bear with me. I am attempting a 3D printer project that will require me to make use of data from several large data files. I will be using openscad script to produce stl files to 3D print a globe with a greatly exaggerated relief profile on the surface. I have extracted and combined relevant data from two large netcdf4 data files GEBCO_2023.nc and GEBCO_2023_TID.nc. I have produced ASCII txt files that contains the information that will be required by openscad. The file format that is required by openscad is a CSV array, with all data stored as string numbers, using [] to denote the dimensions in 2D arrays.
The global elevation/ocean depth data array. The data points represented in this file are a small fraction of the total held within the original netcdf files, but there are still hundreds of thousands of points within the file. Each geological location represented in the array have 5 variables (to use the term as I understand it in the original NETCDF format).
[[lat,long,elv,TI_Code,segment_code],
[[-85.00,-180.00,2331,0,20],[-85.00,-177.13,1034,0,20],[-85.00,-174.26,1966,0,20], ...,[84.75,172.06,-3224,41,0],[84.75,174.79,-2867,11,0],[84.75,177.52,-2561,41,0]]
I have taken several different approaches to attempt transform this file to a array format that can be used to "look up" location elevations within the array. I will need to find the location point within the array that is nearest to a given long/lat coordinate and copy the corresponding elevation value to a second array. From what I understand NETCDF format would be ideal as I believe that the included header information is intended to do this type of task. I have repeatedly failed to read the values of the string array into any other format let along a NETCDF file format. I believe that if I can read the values from the sting area into a NETCDF and build the required header information, or perhaps just read the file values into a 2D Numpy array I can likely work out how accomplish of the task from there.
The project has a second data array, with more than 6000 points of interest (cities) with are located around the globe. This second array is also stored in the same text file format as a 2d CVS [] array. In order to build a detailed STL file with openscad, I will need to loop through each location in the city file. The longitude and latitude coordinates listed in the city file will be used to determine the elevation of the nearest point included in the elevation data file. That corresponding elevation value will be copied to a new variable/column in the city array. The modified city array must be stored as a text file in the same format with the addition elevation value added for each city location.
Some, or most, of this may not be very clear. I am having a hard time describing what I am attempting in a concise way.
In the grand scheme of this project it will not mater if the processing time takes a second or an hour. I just require some method to include the elevations of each city location within the city array data.
I would be very gratefully for any advice, detailed information of how I might approach this.
If you have gotten this far. Thank you for your time.
My latest attempt was to read the file into a variable, then make a numpy array using the variable. I was hoping that numpy.array may recognize the CVS, [] format and load a 2D numpy array. It does not do that. it loads a 0 dimension array
import numpy as np
file1 = open("topo_glb2.txt", "r+")
print("Output of Read function is ")
print(file1.read())
lwarray= np.array(file1)
print(lwarray.ndim)
print(lwarray.shape)
print (lwarray.dtype)
print(lwarray)
produces this result on the console:
[84.75,161.15,-3490,41,0],[84.75,163.88,-3433,41,0],[84.75,166.61,-3370,41,0],[84.75,169.34,-3352,41,0],[84.75,172.06,-3224,41,0],[84.75,174.79,-2867,11,0],[84.75,177.52,-2561,41,0]]
0
()
object
<_io.TextIOWrapper name='topo_glb2.txt' mode='r+' encoding='cp1252'>