Commit 63a12d48 authored by Paal Kvamme's avatar Paal Kvamme
Browse files

When passing create arguments from the Python wrapper to OpenZGY/C++, only...

When passing create arguments from the Python wrapper to OpenZGY/C++, only pass those explicitly specified. Needed for update, and also to make sure the defaults are hard coded just one place.
parent 728e6dc6
Pipeline #29127 passed with stages
in 5 minutes and 38 seconds
......@@ -1389,6 +1389,13 @@ IZgyWriter::reopen(const ZgyWriterArgs& args)
.compressor(args._compressor)
.lodcompressor(args._lodcompressor);
//std::cout << "Arguents passed to function:\n";
//args.dump(std::cout);
//std::cout << "Read frim the existing file:\n";
//oldargs.dump(std::cout);
//std::cout << "To be used to create new file:\n";
//newargs.dump(std::cout);
// Since the current implementation creates a completely new empty file
// I could in fact have allowed changing these supposedly immutable
// properties. But code using that feature would break after a proper
......
......@@ -497,26 +497,26 @@ public:
/**
* \brief Output in human readable form for debugging.
*/
void dump(std::ostream& out)
void dump(std::ostream& out) const
{
out << "ZgyWriterArgs\n"
<< " filename: \"" << _filename << "\"\n"
<< " iocontext: " << (_iocontext ? "*" : "(null)") << "\n"
<< " compressor: " << (_compressor ? "*" : "(null)") << "\n"
<< " lodcompress: " << (_lodcompressor ? "*" : "(null)") << "\n"
<< " size: (" << _size[0] << "," << _size[1] << "," << _size[2] << ")\n"
<< " bricksize: (" << _bricksize[0] << "," << _bricksize[1] << "," << _bricksize[2] << ")\n"
<< " datatype: " << int(_datatype) << "\n"
<< " datarange: " << _datarange[0] << " to " << _datarange[1] << "\n"
<< " zunit: " << int(_zunitdim) << " \"" << _zunitname << "\" " << _zunitfactor << "\n"
<< " hunit: " << int(_hunitdim) << " \"" << _hunitname << "\" " << _hunitfactor << "\n"
<< " ilstart/inc: " << _annotstart[0] << " / " << _annotinc[0] << "\n"
<< " xlstart/inc: " << _annotstart[1] << " / " << _annotinc[1] << "\n"
<< " zstart/inc: " << _zstart << " / " << _zinc << "\n"
<< " corner0: " << _corners[0][0] << ", " << _corners[0][1] << "\n"
<< " corner1: " << _corners[1][0] << ", " << _corners[1][1] << "\n"
<< " corner2: " << _corners[2][0] << ", " << _corners[2][1] << "\n"
<< " corner3: " << _corners[3][0] << ", " << _corners[3][1] << "\n";
<< " " << (_have_size?"*":"") << "size: (" << _size[0] << "," << _size[1] << "," << _size[2] << ")\n"
<< " " << (_have_bricksize?"*":"") << "bricksize: (" << _bricksize[0] << "," << _bricksize[1] << "," << _bricksize[2] << ")\n"
<< " " << (_have_datatype?"*":"") << "datatype: " << int(_datatype) << "\n"
<< " " << (_have_datarange?"*":"") << "datarange: " << _datarange[0] << " to " << _datarange[1] << "\n"
<< " " << (_have_zunit?"*":"") << "zunit: " << int(_zunitdim) << " \"" << _zunitname << "\" " << _zunitfactor << "\n"
<< " " << (_have_hunit?"*":"") << "hunit: " << int(_hunitdim) << " \"" << _hunitname << "\" " << _hunitfactor << "\n"
<< " " << (_have_ilstart||_have_ilinc?"*":"") << "ilstart/inc: " << _annotstart[0] << " / " << _annotinc[0] << "\n"
<< " " << (_have_xlstart||_have_xlinc?"*":"") << "xlstart/inc: " << _annotstart[1] << " / " << _annotinc[1] << "\n"
<< " " << (_have_zstart||_have_zinc?"*":"") << "zstart/inc: " << _zstart << " / " << _zinc << "\n"
<< " " << (_have_corners?"*":"") << "corner0: " << _corners[0][0] << ", " << _corners[0][1] << "\n"
<< " " << (_have_corners?"*":"") << "corner1: " << _corners[1][0] << ", " << _corners[1][1] << "\n"
<< " " << (_have_corners?"*":"") << "corner2: " << _corners[2][0] << ", " << _corners[2][1] << "\n"
<< " " << (_have_corners?"*":"") << "corner3: " << _corners[3][0] << ", " << _corners[3][1] << "\n";
}
/**
......
......@@ -1138,42 +1138,84 @@ ZgyWriter_create(ZgyClass* self, PyObject* args, PyObject* keywds)
std::shared_ptr<IOContext> iocontext =
ZgyCommon_getIOContext(self, filename, iocontext_obj);
ZgyWriterArgs writer_args = ZgyWriterArgs()
.filename(std::string(filename))
.iocontext(iocontext.get())
.size(size[0], size[1], size[2])
.bricksize(bricksize[0], bricksize[1], bricksize[2])
.datarange(datamin, datamax)
.zunit(UnitDimension::unknown, std::string(zunitname_str), zunitfactor)
.hunit(UnitDimension::unknown, std::string(hunitname_str), hunitfactor)
.ilstart(ilstart)
.ilinc(ilinc)
.xlstart(xlstart)
.xlinc(xlinc)
.zstart(zstart)
.zinc(zinc)
.corners(corners);
ZgyWriterArgs writer_args;
if (datatype_obj) {
long value = _decodeEnum(datatype_obj, _enum_SampleDataType);
if (value < 0)
return NULL;
writer_args.datatype(static_cast<SampleDataType>(value));
}
if (zunitdim_obj) {
if (filename != nullptr)
writer_args.filename(std::string(filename));
// filename and size are declared as mandatory, and can be passed
// either as positional or keyword arguments. With update=True
// it is valid to skip the size. Caller can fake a missing size
// by passing (0,0,0).
if (size[0] != 0 || size[1] != 0 || size[2] != 0)
writer_args.size(size[0], size[1], size[2]);
if (PyMapping_HasKeyString(keywds, "iocontext"))
writer_args.iocontext(iocontext.get());
if (PyMapping_HasKeyString(keywds, "bricksize"))
writer_args.bricksize(bricksize[0], bricksize[1], bricksize[2]);
if (PyMapping_HasKeyString(keywds, "datarange"))
writer_args.datarange(datamin, datamax);
if (PyMapping_HasKeyString(keywds, "zunitdim") &&
PyMapping_HasKeyString(keywds, "zunitname") &&
PyMapping_HasKeyString(keywds, "zunitfactor") &&
zunitdim_obj != nullptr)
{
long value = _decodeEnum(zunitdim_obj, _enum_UnitDimension);
if (value < 0)
return NULL;
writer_args.zunit(static_cast<UnitDimension>(value),
std::string(zunitname_str), zunitfactor);
}
if (hunitdim_obj) {
else if (PyMapping_HasKeyString(keywds, "zunitdim") ||
PyMapping_HasKeyString(keywds, "zunitname") ||
PyMapping_HasKeyString(keywds, "zunitfactor"))
{
return _raise_simple_error(_zgy_error_UserError, "zunitdim, zunitname, and zunitfactor must all be given if one of them are.");
}
if (PyMapping_HasKeyString(keywds, "hunitdim") &&
PyMapping_HasKeyString(keywds, "hunitname") &&
PyMapping_HasKeyString(keywds, "hunitfactor") &&
hunitdim_obj != nullptr)
{
long value = _decodeEnum(hunitdim_obj, _enum_UnitDimension);
if (value < 0)
return NULL;
writer_args.hunit(static_cast<UnitDimension>(value),
std::string(hunitname_str), hunitfactor);
}
else if (PyMapping_HasKeyString(keywds, "hunitdim") ||
PyMapping_HasKeyString(keywds, "hunitname") ||
PyMapping_HasKeyString(keywds, "hunitfactor"))
{
return _raise_simple_error(_zgy_error_UserError, "hunitdim, hunitname, and hunitfactor must all be given if one of them are.");
}
if (PyMapping_HasKeyString(keywds, "annotstart"))
writer_args.ilstart(ilstart).xlstart(xlstart);
if (PyMapping_HasKeyString(keywds, "annotinc"))
writer_args.ilinc(ilinc).xlinc(xlinc);
if (PyMapping_HasKeyString(keywds, "zstart"))
writer_args.zstart(zstart);
if (PyMapping_HasKeyString(keywds, "zinc"))
writer_args.zinc(zinc);
if (PyMapping_HasKeyString(keywds, "corners"))
writer_args.corners(corners);
if (datatype_obj) {
long value = _decodeEnum(datatype_obj, _enum_SampleDataType);
if (value < 0)
return NULL;
writer_args.datatype(static_cast<SampleDataType>(value));
}
// TODO-Low: Add zfp_[lod]compressor to the Python API so the same
// application- and test code can be used for Python and Wrapper.
......
......@@ -2384,15 +2384,7 @@ def testUpdateExisting(filename, zgyWriterFactory = newzgy.ZgyWriter, zgyReaderF
secondargs = {
"filename": filename,
"iocontext": SDCredentials(),
# Work in progress; should not need to re-specify these.
# But the wrapper has "size" as a mandatory argument.
# Also, the wrapper will touch every member of the
# ZgyWriterArgs instance even if we didn't specify them.
"size": (33, 28, 92),
"bricksize": (64, 64, 64),
"datatype": SampleDataType.int16,
"datarange": (-32768,+32767),
# End work in progress.
"size": (0, 0, 0), # Kudge; size is mandatory. This means "unset"
"annotstart": (1, 500),
"annotinc": (1, 2),
"zstart": 100,
......@@ -2418,9 +2410,8 @@ def testUpdateExisting(filename, zgyWriterFactory = newzgy.ZgyWriter, zgyReaderF
# Re-open again, re-specifying the basic info (no error unless it changes)
# and not re-specifying the mutable part (should then be retained).
# Work in progress. Fails because all ZgyWriterArgs members are touched.
#with zgyWriterFactory(update = True, **firstargs) as writer:
# pass
with zgyWriterFactory(update = True, **firstargs) as writer:
pass
with zgyReaderFactory(filename, iocontext = SDCredentials()) as reader:
assert reader.size == (33, 28, 92)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment