Skip to content

Issue when opening MTCollection and netcdf file in same script #92

@mmoorkamp

Description

@mmoorkamp

There seems to be an issue when working with a MTH5 file and a netcdf file in the same script. This minimal example

from mtpy import MTCollection
import numpy as np


mc = MTCollection()
mc.open_collection(r"/home/moorkamp/playground/MSH/eric/msh_edis/T1/tf_collection.h5")
mt =mc.to_mt_data()
mc.close_collection()

from netCDF4 import Dataset

nstat = 2
testdata = np.zeros(nstat)
data_fh = Dataset("test.nc", "w")
statdim = data_fh.createDimension("StationNumber", nstat)
vmeasx = data_fh.createVariable("MeasPosX","f8",("StationNumber"))
vmeasx.units = "m"
vmeasx[:] = testdata
data_fh.close()

gives the error

Traceback (most recent call last):
File "/home/moorkamp/playground/MSH/eric/msh_edis/T1/./minimal.py", line 26, in
vmeasx[:] = testdata
~~~~~~^^^
File "src/netCDF4/_netCDF4.pyx", line 5630, in netCDF4._netCDF4.Variable.setitem
File "src/netCDF4/_netCDF4.pyx", line 5917, in netCDF4._netCDF4.Variable._put
File "src/netCDF4/_netCDF4.pyx", line 2164, in netCDF4._netCDF4._ensure_nc_success
RuntimeError: NetCDF: HDF error

When the order of dealing with the files is swapped (first opening and writing the netcdf file then working with mth5) it works on my system.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions