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
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
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
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
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>,event=United Nations Declaration of Human Rights,location=table⁡city=Paris,country=France,name=Palais de Chaillot,address=1 Place du Trocadéro et du 11 Novembre
DateUNDHRratification
<Date: 1948-12-10T11:00:00 GMT>
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,direct,source=csv
1.3.200000000000007.500000000000002.6.700000000000007.80000000000000
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, direct, source=csv,fill=999
1471025899936999999
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,5,7, python
pythonSet≔<Python object: {1, 5, 7}>
pythonDict ≔ convert tableGold=Au,Iron=Fe,Sodium=Na,Tin=Sb,Tungsten=W, python
pythonDict≔<Python object: {'Tungsten': 'W', 'Sodium': 'Na', 'Iron': 'Fe', 'Gold': 'Au', 'Tin': 'Sb'}>
pythonMatrix ≔ convert 9944−31299267,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, pythonMatrix
result≔<Python object: [[-100 -45 30] [ -30 -93 -68]]>
We can also convert certain Python expressions into Maple expressions:convert pythonSet, set
1,5,7
convertpythonDict,table
table⁡Tungsten=W,Sodium=Na,Iron=Fe,Gold=Au,Tin=Sb
convertresult,Matrix
−100−4530−30−93−68
Download Help Document