Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
fail-fast: true
matrix:
os: [ 'ubuntu-latest', 'macos-latest', 'windows-latest']
python-version: ['3.8','3.9', '3.10', '3.11']
python-version: ['3.9', '3.10', '3.11', '3.12']

steps:
- name: Check out mdal-python
Expand Down Expand Up @@ -80,7 +80,7 @@ jobs:

- name: Publish package - test
uses: pypa/gh-action-pypi-publish@release/v1
if: github.event_name != 'release'
if: github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true
with:
user: __token__
password: ${{ secrets.PYPI_TEST_TOKEN }}
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@ mdal.egg-info/
mdal-python.code-workspace
mdal-pypi/LICENSE
mdal-pypi/README.rst
test/results_3di.nc

11 changes: 7 additions & 4 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
Changes
--------------------------------------------------------------------------------

2.0.0
1.0.2
-----

UNDER DEVELOPMENT
- fix memory leaks and inconsistencies around the Datagroup object (#11)

1.0.1
-----

- Add the PyPI package

- fix memory leaks and inconsistencies around the Datagroup object
- remove Open3D integration to separate package

1.0.0
-----
Expand Down
81 changes: 54 additions & 27 deletions mdal/DatasetGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,14 @@ PyArrayObject* Data::getDataAsDouble(int index)
MDAL_SetStatus(MDAL_LogLevel::Error, MDAL_Status::Err_FailToWriteToDisk, "Could not import numpy.core.multiarray.");
return (PyArrayObject*)defaultArray();
}

MDAL_DatasetH datasetH = MDAL_G_dataset(m_data, index);
if ( MDAL_LastStatus() != MDAL_Status::None)
{
return (PyArrayObject*)defaultArray();
}

npy_intp valueCount = (npy_intp)MDAL_D_valueCount( MDAL_G_dataset(m_data, index));
npy_intp valueCount = (npy_intp)MDAL_D_valueCount( datasetH);
int dims;
MDAL_DataType type;
if (MDAL_G_hasScalarData(m_data))
Expand Down Expand Up @@ -190,15 +196,16 @@ PyArrayObject* Data::getDataAsDouble(int index)
}

Py_XDECREF(dict);
Py_XDECREF(titles);
Py_XDECREF(formats);
Py_XDECREF(m_dataset);

// This is a valueCount array.
PyArrayObject* dataset = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, dtype,
m_dataset = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, dtype,
1, &valueCount, 0, nullptr, NPY_ARRAY_CARRAY, nullptr);

double* buffer = new double[dims * 1024];
size_t count = 0;
int bufs = std::ceil(valueCount/1024);
if (bufs == 0) bufs = 1;
int indexStart = 0;
int next = 1024;

Expand All @@ -207,7 +214,7 @@ PyArrayObject* Data::getDataAsDouble(int index)
int remain = valueCount - indexStart;
if (remain < 1024) next = remain;
if (remain <= 0 ) break;
count = MDAL_D_data(MDAL_G_dataset(m_data, index), indexStart, next , type, buffer);
count = MDAL_D_data(datasetH, indexStart, next , type, buffer);
if (count != next)
{
delete [] buffer;
Expand All @@ -216,7 +223,7 @@ PyArrayObject* Data::getDataAsDouble(int index)
int idx = 0;
for (int i = 0; i < count; i++)
{
char* p = (char *)PyArray_GETPTR1(dataset, indexStart + i);
char* p = (char *)PyArray_GETPTR1(m_dataset, indexStart + i);

for (int l =0; l < dims; l++)
{
Expand All @@ -230,7 +237,7 @@ PyArrayObject* Data::getDataAsDouble(int index)
}
delete [] buffer;

return dataset;
return m_dataset;
}

PyArrayObject* Data::getDataAsVolumeIndex(int index)
Expand All @@ -244,8 +251,13 @@ PyArrayObject* Data::getDataAsVolumeIndex(int index)
MDAL_SetStatus(MDAL_LogLevel::Error, MDAL_Status::Err_FailToWriteToDisk, "Could not import numpy.core.multiarray.");
return (PyArrayObject*)defaultArray();
}

if ( MDAL_LastStatus() != MDAL_Status::None)
{
return (PyArrayObject*)defaultArray();
}

npy_intp valueCount = (npy_intp)MDAL_M_faceCount( MDAL_G_mesh(m_data));
npy_intp valueCount = (npy_intp)MDAL_M_faceCount( MDAL_G_mesh(m_data) );

PyObject* dict = PyDict_New();
PyObject* formats = PyList_New(1);
Expand All @@ -265,15 +277,16 @@ PyArrayObject* Data::getDataAsVolumeIndex(int index)
}

Py_XDECREF(dict);
Py_XDECREF(titles);
Py_XDECREF(formats);
Py_XDECREF(m_dataset);

// This is a dsCount x valueCount array.
PyArrayObject* dataset = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, dtype,
m_dataset = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, dtype,
1, &valueCount, 0, nullptr, NPY_ARRAY_CARRAY, nullptr);

int* buffer = new int[1024];
size_t count = 0;
int bufs = std::ceil(valueCount/1024);
if (bufs == 0) bufs = 1;
int indexStart = 0;
int next = 1024;

Expand All @@ -282,7 +295,7 @@ PyArrayObject* Data::getDataAsVolumeIndex(int index)
int remain = valueCount - indexStart;
if (remain < 1024) next = remain;
if (remain <= 0 ) break;
count = MDAL_D_data(MDAL_G_dataset(m_data, index), indexStart, next , MDAL_DataType::FACE_INDEX_TO_VOLUME_INDEX_INTEGER, buffer);
count = MDAL_D_data( MDAL_G_dataset(m_data, index), indexStart, next , MDAL_DataType::FACE_INDEX_TO_VOLUME_INDEX_INTEGER, buffer);
if (count != next)
{
delete [] buffer;
Expand All @@ -291,7 +304,7 @@ PyArrayObject* Data::getDataAsVolumeIndex(int index)
int idx = 0;
for (int i = 0; i < count; i++)
{
char* p = (char *)PyArray_GETPTR1(dataset, indexStart + i);
char* p = (char *)PyArray_GETPTR1(m_dataset, indexStart + i);
uint32_t val = (uint32_t)buffer[idx];
idx++;
std::memcpy(p, &val, 4);
Expand All @@ -300,12 +313,12 @@ PyArrayObject* Data::getDataAsVolumeIndex(int index)
}
delete [] buffer;

return dataset;
return m_dataset;
}

PyArrayObject* Data::getDataAsLevelCount(int index)
{
if (! m_data)
if (! m_data)
return (PyArrayObject*)defaultArray();

MDAL_ResetStatus();
Expand All @@ -314,6 +327,12 @@ PyArrayObject* Data::getDataAsLevelCount(int index)
MDAL_SetStatus(MDAL_LogLevel::Error, MDAL_Status::Err_FailToWriteToDisk, "Could not import numpy.core.multiarray.");
return (PyArrayObject*)defaultArray();
}

MDAL_DatasetH datasetH = MDAL_G_dataset(m_data, index);
if ( MDAL_LastStatus() != MDAL_Status::None)
{
return (PyArrayObject*)defaultArray();
}

npy_intp valueCount = (npy_intp)MDAL_M_faceCount( MDAL_G_mesh(m_data));

Expand All @@ -335,15 +354,16 @@ PyArrayObject* Data::getDataAsLevelCount(int index)
}

Py_XDECREF(dict);
Py_XDECREF(titles);
Py_XDECREF(formats);
Py_XDECREF(m_dataset);

// This is a dsCount x valueCount array.
PyArrayObject* dataset = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, dtype,
m_dataset = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, dtype,
1, &valueCount, 0, nullptr, NPY_ARRAY_CARRAY, nullptr);

int* buffer = new int[1024];
size_t count = 0;
int bufs = std::ceil(valueCount/1024);
if (bufs == 0) bufs = 1;
int indexStart = 0;
int next = 1024;

Expand All @@ -352,7 +372,7 @@ PyArrayObject* Data::getDataAsLevelCount(int index)
int remain = valueCount - indexStart;
if (remain < 1024) next = remain;
if (remain <= 0 ) break;
count = MDAL_D_data(MDAL_G_dataset(m_data, index), indexStart, next , MDAL_DataType::VERTICAL_LEVEL_COUNT_INTEGER, buffer);
count = MDAL_D_data( datasetH, indexStart, next , MDAL_DataType::VERTICAL_LEVEL_COUNT_INTEGER, buffer);

if (count != next)
{
Expand All @@ -362,7 +382,7 @@ PyArrayObject* Data::getDataAsLevelCount(int index)
int idx = 0;
for (int i = 0; i < count; i++)
{
char* p = (char *)PyArray_GETPTR1(dataset, indexStart + i);
char* p = (char *)PyArray_GETPTR1(m_dataset, indexStart + i);
uint32_t val = (uint32_t)buffer[idx];
idx++;
std::memcpy(p, &val, 4);
Expand All @@ -371,7 +391,7 @@ PyArrayObject* Data::getDataAsLevelCount(int index)
}
delete [] buffer;

return dataset;
return m_dataset;
}

PyArrayObject* Data::getDataAsLevelValue(int index)
Expand All @@ -385,6 +405,12 @@ PyArrayObject* Data::getDataAsLevelValue(int index)
MDAL_SetStatus(MDAL_LogLevel::Error, MDAL_Status::Err_FailToWriteToDisk, "Could not import numpy.core.multiarray.");
return (PyArrayObject*)defaultArray();
}

MDAL_DatasetH datasetH = MDAL_G_dataset(m_data, index);
if ( MDAL_LastStatus() != MDAL_Status::None)
{
return (PyArrayObject*)defaultArray();
}

npy_intp valueCount = (npy_intp)MDAL_M_faceCount( MDAL_G_mesh(m_data)) + (npy_intp)MDAL_D_valueCount( MDAL_G_dataset(m_data, index));

Expand All @@ -406,15 +432,16 @@ PyArrayObject* Data::getDataAsLevelValue(int index)
}

Py_XDECREF(dict);
Py_XDECREF(titles);
Py_XDECREF(formats);
Py_XDECREF(m_dataset);

// This is a dsCount x valueCount array.
PyArrayObject* dataset = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, dtype,
m_dataset = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, dtype,
1, &valueCount, 0, nullptr, NPY_ARRAY_CARRAY, nullptr);

double* buffer = new double[1024];
size_t count = 0;
int bufs = std::ceil(valueCount/1024);
if (bufs == 0) bufs = 1;
int indexStart = 0;
int next = 1024;

Expand All @@ -423,7 +450,7 @@ PyArrayObject* Data::getDataAsLevelValue(int index)
int remain = valueCount - indexStart;
if (remain < 1024) next = remain;
if (remain <= 0 ) break;
count = MDAL_D_data(MDAL_G_dataset(m_data, index), indexStart, next , MDAL_DataType::VERTICAL_LEVEL_DOUBLE, buffer);
count = MDAL_D_data( datasetH, indexStart, next , MDAL_DataType::VERTICAL_LEVEL_DOUBLE, buffer);

if (count != next)
{
Expand All @@ -433,15 +460,15 @@ PyArrayObject* Data::getDataAsLevelValue(int index)
int idx = 0;
for (int i = 0; i < count; i++)
{
char* p = (char *)PyArray_GETPTR1(dataset, indexStart + i);
char* p = (char *)PyArray_GETPTR1(m_dataset, indexStart + i);
double val = buffer[idx];
idx++;
std::memcpy(p, &val, 8);
}
indexStart += count;
}
delete [] buffer;
return dataset;
return m_dataset;
}

MDAL_Status Data::setDataAsDouble(PyArrayObject* data, double time)
Expand Down
11 changes: 8 additions & 3 deletions mdal/PyMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,9 @@ PyArrayObject *Mesh::getFaces()
if (PyArray_DescrConverter(dict, &dtype) == NPY_FAIL)
{}
// throw pdal_error("Unable to build numpy dtype");
Py_XDECREF(dict);
Py_XDECREF(dict);
Py_XDECREF(titles);
Py_XDECREF(formats);

npy_intp size = (npy_intp)faceCount();

Expand Down Expand Up @@ -292,7 +294,9 @@ PyArrayObject *Mesh::getEdges()
if (PyArray_DescrConverter(dict, &dtype) == NPY_FAIL)
{}
// throw pdal_error("Unable to build numpy dtype");
Py_XDECREF(dict);
Py_XDECREF(dict);
Py_XDECREF(titles);
Py_XDECREF(formats);

npy_intp size = (npy_intp)edgeCount();

Expand Down Expand Up @@ -450,8 +454,9 @@ bool Mesh::addFaces(PyArrayObject* faces, long int count){
PyObject *names_dict = dtype->fields;
PyObject *names = PyDict_Keys(names_dict);
PyObject *values = PyDict_Values(names_dict);
if (!names || !values) {}
if (!names || !values) {
//throw pdal_error("Bad field specification in numpy array.");
}

if (numFields< 3) {}
//throw pdal_error("Faces"
Expand Down
2 changes: 1 addition & 1 deletion mdal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from mdal.transform import MDAL_transform

__version__ = '1.0.1'
__version__ = '1.0.2'


class Info(object):
Expand Down
9 changes: 5 additions & 4 deletions mdal/libmdalpython.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -228,20 +228,21 @@ cdef class Datasource:

def __cinit__(self, uri: Path, driver_name : str = None):
self.uri = str(uri)
if type(uri) != Path:
path = Path(uri)
if type(uri) == str:
uri = Path(uri)
print(uri)
if driver_name:
self.driver_name = driver_name
return
if path.is_file():
if uri.is_file():
try:
meshes = self.meshes
if len(meshes) > 0:
self.driver_name = meshes[0].split(":")[0]
return
except Exception:
pass
ex = path.suffix
ex = uri.suffix
for driver in drivers():
if ex in driver.filters:
self.driver_name = driver.name
Expand Down
Loading