create a netcdf file readable by ASAGI (but not by paraview)
(sname, x, y, aName, aData)
| 24 | |
| 25 | |
| 26 | def writeNetcdf4SeisSol(sname, x, y, aName, aData): |
| 27 | "create a netcdf file readable by ASAGI (but not by paraview)" |
| 28 | ########## creating the file for SeisSol |
| 29 | fname = sname + "_ASAGI.nc" |
| 30 | print("writing " + fname) |
| 31 | ####Creating the netcdf file |
| 32 | nx = x.shape[0] |
| 33 | ny = y.shape[0] |
| 34 | |
| 35 | rootgrp = Dataset(fname, "w", format="NETCDF4") |
| 36 | |
| 37 | rootgrp.createDimension("u", nx) |
| 38 | rootgrp.createDimension("v", ny) |
| 39 | |
| 40 | vx = rootgrp.createVariable("u", "f4", ("u",)) |
| 41 | vx[:] = x |
| 42 | vy = rootgrp.createVariable("v", "f4", ("v",)) |
| 43 | vy[:] = y |
| 44 | ldata4 = [(name, "f4") for name in aName] |
| 45 | ldata8 = [(name, "f8") for name in aName] |
| 46 | mattype4 = np.dtype(ldata4) |
| 47 | mattype8 = np.dtype(ldata8) |
| 48 | mat_t = rootgrp.createCompoundType(mattype4, "material") |
| 49 | |
| 50 | # this transform the 4 D array into an array of tuples |
| 51 | arr = np.stack([aData[i] for i in range(len(aName))], axis=2) |
| 52 | newarr = arr.view(dtype=mattype8) |
| 53 | newarr = newarr.reshape(newarr.shape[:-1]) |
| 54 | mat = rootgrp.createVariable("data", mat_t, ("v", "u")) |
| 55 | mat[:] = newarr |
| 56 | rootgrp.close() |
| 57 | |
| 58 | |
| 59 | dx = 200.0 |
no test coverage detected