Data Import and Export - Maple Programming Help

Online Help

All Products    Maple    MapleSim

Home : Support : Online Help : What's New and Release Notes : updates/Maple2020/DataImportExport

Data Import and Export

Maple 2020 includes these updates to data import and export.


Read Part of an Audio File


Import and Export of BSON and UBJSON Files

Read Part of an Audio File

The AudioTools:-Read command has a new samples option which enables reading part of an audio file.
Here the interval 103..60103 is specified, which indicates that only samples 1000 to 60000 will be read from the specified file.

audFile  FileTools:-JoinPathaudio, ViolinThreePosVibrato.wav,base=datadir:

violinNote_sub  AudioTools:-ReadaudFile, samples = 103..60103

violinNote_subSample Rate44100File FormatPCM File Bit Depth16Channels2Samples/Channel59001Duration1.33789s



The new FileTools:-Walk command generates an iterator to traverse subdirectories under a given directory.



iteratorFileTools:-Walk IteratorBase directory: C:\Program Files\Maple 2020\data\helpTraversal: top-down


forriniteratordoprintr:-dir,r:-subdirs,r:-filesend do

C:\Program Files\Maple 2020\data\help\XMLTools,,catalogue.xsd,item_invalid.xml,item_valid.xml,SimpleDocument.dtd,SimpleDocument.xml,SimpleDocument1.xml,SimpleDocument2.xml,SimpleDocument3.xml,SimpleDocument4.xml


Import and Export of BSON and UBJSON Files

The Import and Export commands now support and import and export of BSON and UBJSON files. These are both binary file formats modeled after the JSON format. They store structured expressions in a manner similar to JSON.
The BSON format can store additional types of data, including byte arrays and date/time objects.  The latter are translated to Maple Time objects upon import.UNDHR  Importexample/UNDHR.bson, base=datadir

UNDHRtableratification=<Time: 1970-01-01T00:00:00 - 664549200000 ms>&comma;event=United Nations Declaration of Human Rights&comma;location=tablecity=Paris&comma;country=France&comma;name=Palais de Chaillot&comma;address=1 Place du Trocadéro et du 11 Novembre






The ImportMatrix command has been updated with two new options: direct and fill.
The direct option enables parsing data from strings and ByteArrays (in addition to files and URLs):




The fill option specifies a default value for missing data when the input is ragged; a ragged input is an input in which some rows have fewer entries than others.

In the following example, the first row has four entries while the second and third are underspecified, in which case the fill value of 999 is used.

ImportMatrix1,4,7,10\n2,5,8\n3,6&comma; direct&comma; source&equals;csv&comma;fill&equals;999



Data conversions to and from Python

The convert command now allows explicit conversion of certain Maple expressions to their Python counterparts and vice-versa.

In the following example we convert three expressions to Python expressions:

pythonSet  convert 1&comma;5&comma;7&comma; python

pythonSet<Python object: {1, 5, 7}>


pythonDict  convert tableGold&equals;Au&comma;Iron&equals;Fe&comma;Sodium&equals;Na&comma;Tin&equals;Sb&comma;Tungsten&equals;W&comma; python

pythonDict<Python object: {'Tungsten': 'W', 'Sodium': 'Na', 'Iron': 'Fe', 'Gold': 'Au', 'Tin': 'Sb'}>


pythonMatrix  convert 9944−31299267&comma;python

pythonMatrix<Python object: [{99 44 -31} {29 92 67}]>


These inputs are suitable as input to Python:-EvalFunction, provided the underlying Python data types match:

result  Python:-EvalFunction numpy.invert&comma; pythonMatrix 

result<Python object: [{-100 -45 30} {-30 -93 -68}]>


We can also convert certain Python expressions into Maple expressions:convert pythonSet&comma; set