[MDAL-Developer] Python-Bindings
Paul Harwood
runette at gmail.com
Thu Jun 10 17:18:58 PDT 2021
Just to close this off :
- The conda package is now up and running
- After using it in a real application I found a number of memory leaks and
null pointer errors. The package is now at 0.9.3 and I made the mesh object
a context manager, so the example usage snippet would now look like this :
from mdal import Datasource
ds = Datasource("data/ply/test_mesh.ply")
with ds.load(0) as mesh:
vertex = mesh.vertices
print(f"Vertex Array Shape : {vertex.shape}")
faces = mesh.faces
print(f"Face Array Shape : {faces.shape}")
edges = mesh.edges
print(f"Edges Array Shape : {edges.shape}")
group = mesh.group(0)
for i in range(0, group.dataset_count):
data = group.data_as_double(i)
time = group.dataset_time(i)
print(f"Dataset Shape for time {time} : {data.shape}")
meshio = mesh.meshio()
print(meshio)
On Mon, 31 May 2021 at 10:59, Paul Harwood <runette at gmail.com> wrote:
> Version 0.9.1 with a more pythonic API - it is better (thanks Martin).
> Apart from doc changes, I will probably leave it as is now for the time
> being - it does what I need and I have to complete my app.
>
> from mdal import Datasource, Info, last_status
>
> print(f"MDAL Version: {Info.version}")
> print(f"MDAL Driver Count :{Info.driver_count}")
> print(last_status())
>
> for driver in Info.drivers:
> print(driver)
>
>
> ds = Datasource("data/ply/test_mesh.ply")
> print(ds.meshes)
>
> mesh = ds.load(0)
> print(f"Driver : {mesh.driver_name}")
> print(f"Vertex Count : {mesh.vertex_count}")
> print(f"Face Count : {mesh.face_count}")
> print(f"Largest Face: {mesh.largest_face}")
> print(f"Edge Count : {mesh.edge_count}")
> print(f"CRS : {mesh.projection}")
> print(f"Mesh extent : {mesh.extent}")
> print(f"DatasetGroup Count : {mesh.group_count}")
> print("")
>
> vertex = mesh.vertices
> print(f"Vertex Array Shape : {vertex.shape}")
>
> faces = mesh.faces
> print(f"Face Array Shape : {faces.shape}")
>
> edges = mesh.edges
> print(f"Edges Array Shape : {edges.shape}")
>
> print("")
>
> group = mesh.group(0)
> print(f"DatasetGroup Name : {group.name}")
> print(f"DatasetGroup Location : {group.location}")
> print(f"Dataset Count : {group.dataset_count}")
> print(f"Group has scalar values : {group.has_scalar}")
> print(f"Group has temporal values : {group.is_temporal}")
> print(f"Reference Time : {group.reference_time}")
> print(f"Maximum Vertical Level Count : {group.level_count}")
> print(f"Minimum / Maximum ; {group.minmax}")
> print(f"Metadata : {group.metadata}")
>
> print("")
> for i in range(0, group.dataset_count):
> data = group.data_as_double(i)
> time = group.dataset_time(i)
> print(f"Dataset Shape for time {time} : {data.shape}")
>
> print("")
>
> meshio = mesh.meshio()
> print(meshio)
>
> On Mon, 31 May 2021 at 10:10, Paul Harwood <runette at gmail.com> wrote:
>
>> good feedback ...
>>
>> I may have been spending too much of my time in the C# universe recently
>> :(
>>
>> On Mon, 31 May 2021 at 09:41, Martin Dobias <wonder.sk at gmail.com> wrote:
>>
>>> Hi Paul
>>>
>>> Looking great!
>>>
>>> I understand this is still work in progress, may I just suggest to make
>>> the API look more pythonic, by using snake case (face_count) instead of
>>> camel case (faceCount)... Maybe also avoid using "get" prefix in getters?
>>>
>>> Regards
>>> Martin
>>>
>>>
>>> On Sat, May 29, 2021 at 2:46 PM Paul Harwood <runette at gmail.com> wrote:
>>>
>>>> As promised - I have been working on some Python Bindings. I now have a
>>>> 0.9.0b1 type release :
>>>>
>>>> See https://github.com/ViRGIS-Team/mdal-python
>>>>
>>>> There is a conda install for this in the process of being created.
>>>>
>>>> There is some documentation in the process of being created.
>>>>
>>>> Currently, this integration can:
>>>>
>>>> - read all MDAL compatible file formats,
>>>> - access the metadata for the source,
>>>> - access the vertex, face and edge data as NumPy arrays,
>>>> - access 'double' datasets (both scalar and vector) as NumPy arrays, and
>>>> - convert the MDAL source mesh into a meshio mesh object (with some
>>>> restrictions currently).
>>>> - This version does not currently allow the MDAL source mesh to be
>>>> written or amended.
>>>>
>>>> Note this very much beta and has not been comprehensively tested. The
>>>> following script has been run successfully on a number of different test
>>>> files and shows the usage.
>>>>
>>>> All comments and improvements welcome.
>>>>
>>>> """
>>>>
>>>> import mdalfrom mdal import Datasource
>>>> print(f"MDAL Version: {mdal.getVersionString()}")print(f"MDAL Driver Count :{mdal.getDriverCount()}")print(mdal.getLastStatus())
>>>> for driver in mdal.getDrivers():
>>>> print(driver.long_name)
>>>>
>>>> ds = Datasource("data/ply/test_mesh.ply")print(ds.meshes)
>>>> mesh = ds.load(0)print(f"Driver : {mesh.driverName}")print(f"Vertex Count : {mesh.vertexCount}")print(f"Face Count : {mesh.faceCount}")print(f"Largest Face: {mesh.largestFace}")print(f"Edge Count : {mesh.edgeCount}")print(f"CRS : {mesh.projection}")print(f"Mesh extent : {mesh.extent}")print(f"DatasetGroup Count : {mesh.groupCount}")print("")
>>>> mesh = ds.load(ds.meshes[0])print(f"Driver : {mesh.driverName}")print(f"Vertex Count : {mesh.vertexCount}")print(f"Face Count : {mesh.faceCount}")print(f"Largest Face: {mesh.largestFace}")print(f"Edge Count : {mesh.edgeCount}")print(f"CRS : {mesh.projection}")print(f"Mesh extent : {mesh.extent}")
>>>> vertex = mesh.getVertices()print(f"Vertex Array Shape : {vertex.shape}")
>>>> faces = mesh.getFaces()print(f"Face Array Shape : {faces.shape}")
>>>> edges = mesh.getEdges()print(f"Edges Array Shape : {edges.shape}")
>>>> print("")
>>>> group = mesh.getGroup(0)print(f"DatasetGroup Name : {group.name}")print(f"DatasetGroup Location : {group.location}")print(f"Dataset Count : {group.datasetCount}")print(f"Group has scalar values : {group.hasScalar}")print(f"Group has temporal values : {group.isTemporal}")print(f"Reference Time : {group.referenceTime}")print(f"Maximum Vertical Level Count : {group.levelCount}")print(f"Minimum / Maximum ; {group.minmax}")print(f"Metadata : {group.getMetadata()}")
>>>> print("")
>>>> data = group.getDataAsDouble(0)print(f"Dataset Shape : {data.shape}")
>>>>
>>>> """
>>>> (see next email to see results from this code)
>>>> _______________________________________________
>>>> MDAL-Developer mailing list
>>>> MDAL-Developer at lists.osgeo.org
>>>> https://lists.osgeo.org/mailman/listinfo/mdal-developer
>>>>
>>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/mdal-developer/attachments/20210611/81b1e821/attachment-0001.html>
More information about the MDAL-Developer
mailing list