Skip to content

Commit

Permalink
Patch to address issue #570
Browse files Browse the repository at this point in the history
  • Loading branch information
pavlis committed Oct 24, 2024
1 parent 19c8568 commit 60d08aa
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions python/mspasspy/db/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -4375,9 +4375,12 @@ def _read_data_from_gridfs(self, mspass_object, gridfs_id):
fh = gfsh.get(file_id=gridfs_id)
if isinstance(mspass_object, (TimeSeries, Seismogram)):
if not mspass_object.is_defined("npts"):
raise KeyError(
"Database._read_data_from_gridfs: Required key npts is not defined"
)
message = "Required key npts is not defined in the document for this datum"
mspass_object.elog.log_error("Database._read_data_from_gridfs",
message,
ErrorSeverity.Invalid)
mspass_object.kill()
return
else:
if mspass_object.npts != mspass_object["npts"]:
message = "Database._read_data_from_gridfs: "
Expand All @@ -4396,19 +4399,22 @@ def _read_data_from_gridfs(self, mspass_object, gridfs_id):
np_arr = np.frombuffer(fh.read(npts * 8 * 3))
file_size = fh.tell()
if file_size != npts * 8 * 3:
# Note we can only detect the cases where given npts is larger than
# the number of points in the file
emess = (
"Database._read_data_from_gridfs: Size mismatch in sample data. Number of points in gridfs file = %d but expected %d"
% (file_size / 8, (3 * mspass_object["npts"]))
)
raise ValueError(emess)
message = "Size mismatch in sample data.\n"
message += "Number of points in gridfs file=%d but wf document expected %d".format(file_size/8, (3 * mspass_object["npts"]))
mspass_object.elog.log_error("Database._read_data_from_gridfs",
message,
ErrorSeverity.Invalid,
)
mspass_object.kill()
return
# v1 did a transpose on write that this reversed - unnecessary
# np_arr = np_arr.reshape(npts, 3).transpose()
np_arr = np_arr.reshape(3, npts)
mspass_object.data = dmatrix(np_arr)
else:
raise TypeError("only TimeSeries and Seismogram are supported")
message = "Database._read_data_from_gridfs: arg0 must be a TimeSeries or Seismogram\n"
message += "Actual type=" + str(type(mspass_object))
raise TypeError(message)
if mspass_object.npts > 0:
mspass_object.set_live()
else:
Expand Down

0 comments on commit 60d08aa

Please sign in to comment.