Data Import and Export - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Mozilla Firefox.

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : System : Information : Updates : Maple 2020 : Data Import and Export

Data Import and Export

Maple 2020 includes these updates to data import and export.

 

Read Part of an Audio File

FileTools:-Walk

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..60⋅103 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..60⋅103

violinNote_sub≔Sample Rate44100File FormatPCM File Bit Depth16Channels2Samples/Channel59001Duration1.33789⁢s

(1.1)

FileTools:-Walk

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

withFileTools:

iterator≔WalkJoinPathhelp,base=datadir

iterator≔FileTools:-Walk IteratorBase directory: C:\Program Files\Maple 2020\data\helpTraversal: top-down

(2.1)

forriniteratordoprint⁡r:-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

(2.2)

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

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

(3.1)

DateUNDHRratification

<Date: 1948-12-10T11:00:00 GMT>

(3.2)

ImportMatrix

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):

ImportMatrix1,3.2,7.5\n2,6.7,7.8&comma;direct&comma;source&equals;csv

1.3.200000000000007.500000000000002.6.700000000000007.80000000000000

(3.3)

 

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

1471025899936999999

(3.4)

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}>

(3.5)

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'}>

(3.6)

pythonMatrix ≔ convert 9944−31299267&comma;python

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

(3.7)

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]]>

(3.8)

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

1&comma;5&comma;7

(3.9)

convertpythonDict&comma;table

table⁡Tungsten=W&comma;Sodium=Na&comma;Iron=Fe&comma;Gold=Au&comma;Tin=Sb

(3.10)

convertresult&comma;Matrix

−100−4530−30−93−68

(3.11)