krober10nd / SeismicMesh

2D/3D serial and parallel triangular mesh generation tool for finite element methods.
https://seismicmesh.readthedocs.io/
GNU General Public License v3.0
127 stars 33 forks source link

generalize WriteSegyToNetcdf.m #1

Closed HamishB closed 4 years ago

HamishB commented 4 years ago

Hi, for your consideration..

this patch against the 3dmeshing branch reads from a .segy as per script's filename, allows 2D arrays to be written, and follows given data's array size instead of hardcoding it.

Many nc*() functions don't return any output so don't need to end in ';', thus dropped those.

diff --git a/utilities/WriteSegyToNetcdf.m b/utilities/WriteSegyToNetcdf.m
index 98b86b6..1dd1847 100644
--- a/utilities/WriteSegyToNetcdf.m
+++ b/utilities/WriteSegyToNetcdf.m
@@ -1,7 +1,7 @@
 clearvars; close all; clc; 
 %%
 OFNAME = 'SeismicUnitCubeVp_V2.nc';
-data=ncread('SeismicUnitCubeVp.nc','vp'); 
+data = ReadSegy('SeismicUnitCubeVp.segy');
 dims = size(data);
 [nx,ny,nz]=size(data);

@@ -40,7 +40,7 @@ ncwriteatt(OFNAME, 'x0y0z0', 'long_name', 'position of bottom left front corner'
 ncwriteatt(OFNAME,'x0y0z0','units','cartesian coordinates'); 

-nccreate(OFNAME,'vp','Dimensions',{'x',50,'y',50,'z',50});
+nccreate(OFNAME,'vp','Dimensions',{'x',nx,'y',ny,'z',nz})
 ncwriteatt(OFNAME, 'vp', 'long_name', 'P-wave velocity');
 ncwriteatt(OFNAME,'vp','units','m/s')

@@ -50,14 +50,21 @@ ncwrite(OFNAME,'dim',length(dims));

 ncwrite(OFNAME,'gridspace',100);

-ncwrite(OFNAME,'x0y0z0',[0,0,0]);
+if(length(dims) > 2)
+   ncwrite(OFNAME, 'x0y0z0', [0,0,0])
+else
+   ncwrite(OFNAME, 'x0y0z0', [0,0])
+end

 ncwrite(OFNAME,'nx',dims(1));

 ncwrite(OFNAME,'ny',dims(2));

-ncwrite(OFNAME,'nz',dims(3));
-
+if(length(dims) > 2)
+   ncwrite(OFNAME,'nz',dims(3))
+else
+   ncwrite(OFNAME,'nz',1)
+end

 ncwrite(OFNAME,'vp',data);

thanks, Hamish

HamishB commented 4 years ago

mmph, not quite. ReadVelocityData() wants nz,ny not nx,ny,nz (where nz=1) so need to make a few more adjustments. I've got a patch if you need it but I maybe making a mess of it.

krober10nd commented 4 years ago

Thanks, Hamish. If you want to submit it feel free. I had written that as a reminder on how to format the file. In general, the file format for seismic modeling needs some serious work and catching up to nearly every other geophysical field...

krober10nd commented 4 years ago

A major rewrite is underway that will alleviate this issue. The entire codebase is being ported to python due to project requirements.