def _convert_units(self, key, values): """ Convert SEGY units to plot units. """ _units = self._get_units(key) if _units is not None: scl = float(units.__getattribute__(_units[0])\ /units.__getattribute__(_units[1])) return [v * scl for v in values] else: return values
def interface2netcdf(vm, iref, filename, units="km", elevation=False): """ Write interface depths to a netcdf file. Parameters ---------- vm : :class:`rockfish.tomography.model.VM` VM model to extract an interface from. iref : int Index of interface to extract. filename: str Name of the netcdf file to write the interface to. units : 'str', optional Name of distance units in the output file. Must be a unit name understood by :class:`sympy.physics.units`. Distance units in the model are assumed to be 'km'. elevation : bool, optional If ``True``, flip the sign of interface depths. """ # Unit scaling scl = sunits.kilometers / sunits.__getattribute__(units) if elevation: zscl = scl * -1.0 else: zscl = scl # Open file f = netcdf(filename, "w") f.title = "Interface {:} from VM model.".format(iref) f.source = "Created by rockfish.tomography.vm2gmt.surface2netcdf" # x-dimension f.createDimension("x", vm.ny) x = f.createVariable("x", "f", ("x",)) x[:] = vm.y * scl x.units = units # y-dimension f.createDimension("y", vm.nx) y = f.createVariable("y", "f", ("y",)) y[:] = vm.x * scl y.units = units # depths (z) z = f.createVariable("z", "f", ("x", "y")) z[:, :] = vm.rf[iref].transpose() * zscl z.units = units z.scale_factor = 1.0 z.add_offset = 0.0 # depth range f.createDimension("side", 2) z_range = f.createVariable("z_range", "f", ("side",)) z_range[0] = np.min(vm.rf[0]) * zscl z_range[1] = np.min(vm.rf[1]) * zscl f.sync() f.close()