Code Monkey home page Code Monkey logo

Comments (1)

tmontaigu avatar tmontaigu commented on July 19, 2024 1

The SubFieldView class was introduced to fix an inconsistency between 'subfields' (fields that are bit fields and are stored on less than a byte, such as return_number) and other regular fields (eg: gps_time, user_data, point_source_id)

In pylas < 0.5 when accessing a sub field las.return_number a copy would be returned, meaning that modifications whould not
propagate.

import pylas
las = pylas.read("pylastests/simple.las")
import numpy as np

print(las.return_number)
# array([1, 1, 1, ..., 1, 1, 1], dtype=uint8)

ascending_order = np.argsort(las.return_number)[::-1]
print(las.return_number[ascending_order])
# array([4, 4, 4, ..., 1, 1, 1], dtype=uint8)
las.return_number[:] = las.return_number[ascending_order]
print(las.return_number)
# array([1, 1, 1, ..., 1, 1, 1], dtype=uint8) # bif oof

# To actually update you have to do
rn = las.return_number[ascending_order]
las.return_number = rn
print(las.return_number)
# array([4, 4, 4, ..., 1, 1, 1], dtype=uint8)

Whereas with pylas >= 0.5 the same script would have a more consistent behaviour.

The SubFieldView tries to behave has much as possible as a np.ndarray, however there may be things that cannot be possible to
immitate.

As for errors you mentionned:

>>> np.concatenate([cloud.return_number, cloud.return_number])
...
ValueError: zero-dimensional arrays cannot be concatenated

^ Should be fixable

>>> cloud.return_number[0] + 1
...
TypeError: unsupported operand type(s) for +: 'SubFieldView' and 'int'

^ should be fixable

>>> ordered = np.argsort(cloud.gps_time)
>>> cloud.return_number[:] = cloud.return_number[ordered]
...
TypeError: unsupported operand type(s) for <<: 'SubFieldView' and 'int'

^ Is already fixed on master

>>> field = np.zeros(len(cloud.points), dtype=np.uint8)
>>> field[:] = cloud.return_number[:]
...
TypeError: __array__() takes 1 positional argument but 2 were given

^ I don't think it is fixable.
however you can copy the SubFieldView into a proper numpy array

field = np.array(cloud.return_number)
print(field)
# [4 4 4 ... 1 1 1]
# if field is modified:
las.return_number[:] = field[:]

from pylas.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.