pyoints.examples.file_examples package

Submodules

pyoints.examples.file_examples.csv_example module

Learn how to save and load .csv-files.

>>> import os
>>> from pyoints import storage

Create output path.

>>> outpath = os.path.join(
...             os.path.dirname(os.path.abspath(__file__)), '..', 'output')

Create GeoRecords from scratch.

>>> geoRecords = storage.misc.create_random_GeoRecords(
...                     center=[332592.88, 5513244.80, 120], epsg=25832)
>>> print(geoRecords.shape)
(1000,)
>>> print(sorted(geoRecords.dtype.names))
['classification', 'coords', 'intensity', 'keypoint', 'synthetic', 'values', 'withheld']

Save as a .csv-file.

>>> outfile = os.path.join(outpath, 'test.csv')
>>> storage.writeCsv(geoRecords, outfile)

Load the .csv-file again and check the characteristics.

>>> geoRecords = storage.loadCsv(outfile, header=True)
>>> print(geoRecords.shape)
(1000,)
>>> print(sorted(geoRecords.dtype.names))
['classification', 'coords', 'index', 'intensity', 'keypoint', 'synthetic', 'values', 'withheld']

pyoints.examples.file_examples.dump_example module

Learn how to save and load DUMP-files.

>>> import os
>>> import numpy as np
>>> from pyoints import storage

Create an output path.

>>> outpath = os.path.join(
...             os.path.dirname(os.path.abspath(__file__)), '..', 'output')

Create GeoRecords from scratch.

>>> geoRecords = storage.misc.create_random_GeoRecords(
...                     center=[332592.88, 5513244.80, 120], epsg=25832)
>>> print(geoRecords.shape)
(1000,)
>>> print(sorted(geoRecords.dtype.names))
['classification', 'coords', 'intensity', 'keypoint', 'synthetic', 'values', 'withheld']
>>> print(hasattr(geoRecords, 'proj'))
True

Save as a DUMP-file.

>>> outfile = os.path.join(outpath, 'test.pydump')
>>> storage.writeDump(geoRecords, outfile)

Load the DUMP-file again and check the characteristics.

>>> dumpReader = storage.DumpReader(outfile)
>>> geoRecords = dumpReader.load()
>>> print(geoRecords.shape)
(1000,)
>>> print(sorted(geoRecords.dtype.names))
['classification', 'coords', 'intensity', 'keypoint', 'synthetic', 'values', 'withheld']
>>> print(hasattr(geoRecords, 'proj'))
True

Working with DUMP-strings.

>>> dumpstr = storage.dumpstring_from_object(geoRecords)
>>> print(isinstance(dumpstr, str))
True
>>> geoRecords = storage.dumpstring_to_object(dumpstr)
>>> print(hasattr(geoRecords, 'proj'))
True

pyoints.examples.file_examples.las_example module

Learn how to save and load LAS-files.

>>> import os
>>> import numpy as np
>>> from datetime import datetime
>>> from pyoints import storage

Create an output path.

>>> outpath = os.path.join(
...             os.path.dirname(os.path.abspath(__file__)), '..', 'output')

Create GeoRecords from scratch.

>>> geoRecords = storage.misc.create_random_GeoRecords(
...                     center=[332592.88, 5513244.80, 120], epsg=25832)
>>> print(geoRecords.shape)
(1000,)
>>> print(sorted(geoRecords.dtype.names))
['classification', 'coords', 'intensity', 'keypoint', 'synthetic', 'values', 'withheld']

Set the capturing date.

>>> print(geoRecords.date)
None
>>> geoRecords.date = datetime(year=2019, month=3, day=4)
>>> print(geoRecords.date.year)
2019

Save as LAS-file.

>>> outfile = os.path.join(outpath, 'test.las')
>>> storage.writeLas(geoRecords, outfile)

Load LAS-file again and check the characteristics.

>>> lasReader = storage.LasReader(outfile)
>>> print(len(lasReader))
1000
>>> print(lasReader.date.month)
3
>>> las = lasReader.load()
>>> print(las.shape)
(1000,)
>>> print(sorted(las.dtype.descr))
[('classification', '|u1'), ('coords', '<f8', (3,)), ('intensity', '|u1'), ('keypoint', '|b1'), ('synthetic', '|b1'), ('values', '<f8'), ('withheld', '|b1')]

Check values.

>>> np.all(geoRecords.classification == las.classification)
True
>>> np.all(geoRecords.synthetic == las.synthetic)
True
>>> np.all(geoRecords.keypoint == las.keypoint)
True
>>> np.all(geoRecords.withheld == las.withheld)
True
>>> np.all(geoRecords.intensity == las.intensity)
True
>>> print(geoRecords.date.day)
4

pyoints.examples.file_examples.ply_example module

Learn how to save and load .ply-files.

>>> import os
>>> from pyoints import storage

Create an output path.

>>> outpath = os.path.join(
...             os.path.dirname(os.path.abspath(__file__)), '..', 'output')

Create GeoRecords from scratch.

>>> geoRecords = storage.misc.create_random_GeoRecords(
...                     center=[332592.88, 5513244.80, 120], epsg=25832)
>>> print(geoRecords.shape)
(1000,)
>>> print(sorted(geoRecords.dtype.names))
['classification', 'coords', 'intensity', 'keypoint', 'synthetic', 'values', 'withheld']

Save as .ply-file.

>>> outfile = os.path.join(outpath, 'test.ply')
>>> storage.writePly(geoRecords, outfile)

Load .ply-file again and check the characteristics.

>>> geoRecords = storage.loadPly(outfile)
>>> print(geoRecords.shape)
(1000,)
>>> print(sorted(geoRecords.dtype.names))
['classification', 'coords', 'intensity', 'keypoint', 'synthetic', 'values', 'withheld']

pyoints.examples.file_examples.raster_example module

Learn how to save and load image files.

>>> import os
>>> from pyoints import (
...     storage,
...     transformation,
...     projection,
... )
>>> from pyoints.misc import print_rounded

Create input and output path.

>>> inpath = os.path.join(
...     os.path.dirname(os.path.abspath(__file__)), '..', 'data')
>>> outpath = os.path.join(
...     os.path.dirname(os.path.abspath(__file__)), '..', 'output')

Load an image file.

>>> infile = os.path.join(inpath, 'logo_pyoints.jpg')
>>> proj = projection.Proj.from_epsg(32632)
>>> rasterHandler = storage.RasterReader(infile, proj=proj)
>>> raster = rasterHandler.load()
>>> print_rounded(raster.shape)
(96, 250)
>>> print(sorted(raster.dtype.names))
['bands', 'coords']

Apply a transformation to the matrix to get a propper spatial reference.

>>> T = transformation.matrix(
...         t=[332575, 5513229], s=[0.5, -0.5], r=0.1, order='srt')
>>> raster = raster.transform(T)

Save the image as a tif-file. You might like to check the spatial reference of the output image using a Geographic Information System (GIS).

>>> outfile = os.path.join(outpath, 'test.tif')
>>> storage.writeRaster(raster, outfile)

Load image again and check characteristics.

>>> rasterHandler = storage.RasterReader(outfile, proj=projection.Proj())
>>> print_rounded(rasterHandler.t.origin)
[  332575.  5513229.]
>>> raster = rasterHandler.load()
>>> print_rounded(raster.t.origin)
[  332575.  5513229.]
>>> print_rounded(raster.shape)
(96, 250)
>>> print(sorted(raster.dtype.names))
['bands', 'coords']

pyoints.examples.file_examples.structured_example module

Learn how to save and load structured files.

>>> import os
>>> import numpy as np
>>> from pyoints import storage

Create output path.

>>> outpath = os.path.join(
...             os.path.dirname(os.path.abspath(__file__)), '..', 'output')

Create structured data from scratch.

>>> data = {
...     'my_text': 'Some text',
...     'my_integer': 4,
...     'my_list': [0, 1, 2, 2],
...     'my_bool': False,
...     'my_ndarray': np.array([1, 4, 5]),
...     'nested': {
...         'my_text': 'Nested text.',
...         'my_float': 3.5
...     },
...     'my_recarray': np.array(
...         [(1, 'text 1'), (6, 'text 2'), (2, 'text 3')],
...         dtype=[('A', int), ('B', object)]
...      ).view(np.recarray)
... }
>>> print(data['my_text'])
Some text
>>> print(data['nested']['my_text'])
Nested text.
>>> print(type(data['my_ndarray']))
<class 'numpy.ndarray'>
>>> print(type(data['my_recarray']))
<class 'numpy.recarray'>

Save as a .json-file.

>>> outfile = os.path.join(outpath, 'test.json')
>>> storage.writeJson(data, outfile)

Load the a .json-file again. Be carefull, since some data types might have been changed.

>>> data = storage.loadJson(outfile)
>>> print(data['my_text'])
Some text
>>> print(data['nested']['my_float'])
3.5
>>> print(type(data['my_ndarray']))
<class 'list'>
>>> print(type(data['my_recarray']))
<class 'dict'>

Module contents

Examples to explain how files can be saved and loaded.