This tutorial teaches how to transform raw data and write it in Data Arrays.
Before doing this tutorial make sure you read and completed the following tutorial and have data in your wendelin instance:
Open your Wendelin dashboard.
In Modules click on Data Operations Module
Click on Add to add a new Data Operation.
Click Proceed to continue.
Fill the form to create Data Operation.
Title - we name it Convert Raw Environment Data to Array
Reference - data-operation-convert-raw-data-to-array
Script ID - DataAnalysisLine_convertEnvironmentDataStreamToArray : this script will do all the magic. It doesn't exist yet, we will create it later in this tutorial.
Item Types - Data Array : we choose Data Array as we will convert the raw data to Data Array
Click Save to save the changes.
Click on Validate on left side panel to validate Data Operation.
Click Proceed to confirm validation.
Next we need to create a new Data Product which will be the output Data Product of the Transformation.
Create a new Data Product as described in HowTo Create Data Product tutorial with following values
Title - Environment Raw Array
Reference - environment-raw-array
Item Types
After Data Product is created and validated, navigate to page called Portal Callables by clicking on Callables on the left side panel.
There we will create and store a python script that will transform raw data to arrays.
Click on Add button to add a new script.
Choose Python Script as Document Type and click on Create Document to create an empty python script.
Define ID, Title and Reference of your script.
We name it DataAnalysisLine_convertEnvironmentDataStreamToArray as we did in Data Operation.
And click Save to save the changes.
Next we define the parameters we will give to our script.
in_stream - the input Data Stream where raw data is stored
out_array - the output Data Array where data will be stored.
At the end click Save to save the changes.
import pandas as pd progress_indicator = in_stream["Progress Indicator"] in_data_stream = in_stream["Data Stream"] out_data_array = out_array["Data Array"] chunk_size = 20 * 10**6 start = progress_indicator.getIntOffsetIndex() end = min(start+chunk_size, in_data_stream.getSize()) unpacked, end = in_data_stream.readMsgpackChunkList(start, end) f = in_data_stream.extractDateTime df = pd.DataFrame((dict(**o[1]) for o in unpacked), dtype="float64", index=(f(o[0]) for o in unpacked)) if df.shape[0] == 0: return df.index.name="date" ndarray = df.to_records(convert_datetime64=False) zbigarray = out_data_array.getArray() if zbigarray is None: zbigarray = out_data_array.initArray(shape=(0,), dtype=ndarray.dtype.fields) zbigarray.append(ndarray) if end > start: progress_indicator.setIntOffsetIndex(end) # tell caller to create new activity after processing if we did not reach end of stream if end < in_data_stream.getSize(): return 1
This script will simply write raw data to Data Array. More sophisticated example like resampling data or data predictions are shown in following tutorials.
First we extract data from the Data stream and read a chunk of data at a time.
As data is in msgpack format we unpack it using iterUnpack method of wendelin Data Stream which is based on Unpacker of msgpack.
Next we create a data frame using pandas DataFrame.
After we convert it to ndarray and append it to zbigarray.
We use Progress Indicator to keep track of how much raw data we already processed.
After your transformation script is ready, it's time to create Data Transformation.
On Modules page click on Data Transformations.
Click on Add to add a new Data Transformation.
Click on Create Document to continue.
Chose descriptive title and reference. For example
Title : Convert Environment Raw Data
Reference : convert-environment-raw-data
For Initial Product we choose the Data Product we created in HowTo Create Data Product tutorial.
At the end click Save to save the changes.
Click on Add button to add a Data Transformation Line.
Choose Data Transformation Operation Line for Document Type and click on Create Document.
Fill the form.
For Data Operation put the name of the Data operation that we created at the beginning of this tutorial - Convert Raw Environment Data to Array.
At the end click on Save to save the changes.
Once needed fields are filled click Save to save the changes and go back to Data Transformations view by clicking on the upper panel.
Add another Data Transformation Line.
Now for Document Type choose Data Transformation Resource Line and click on Create Document.
Fill the form.
For Data Product put the name of the Data Product that we created in HowTo Create Data Product tutorial.
After filling in the Data Product name click Save to save the intermediate changes.
After saving a new field Item Types will appear.
Continue filling the form as shown on the screenshot
At the end don't forget to save the changes.
Head back to Data Transformation and add one more Transformation line.
Once again for Document Type choose Data Transformation Resource Line and click on Create Document.
Fill the form.
For Data Product put the name of the Data Product that we created earlier in this tutorial - Environment Raw Array.
Once filling in the Data Product name click Save to save the intermediate changes.
After saving a new field Item Types will appear.
Continue filling the form as shown on the screenshot
At the end don't forget to save the changes.
Head back to Data Transformation.
Now you can see that we have 3 Data Transformation Lines.
The first line defines what operation will be done.
The second line defines on what the operation will be done - the input.
And the third line defines the output.
Note the Quantity column of the Transformation Lines. Make sure the values are the same as shown on the screenshot.
The very last step is to validate the Data Transformation.
Click on Validate on the left side panel to validate the Data Transformation.
Click on Validate to confirm the Validation.
Go to Data Analyses module.
After few minutes in Data Analysis Module a new Data Analysis called Convert Environment Raw Data will appear.
Go to Data Array Module to see the data.
Here we can see the newly created Data Array called Convert Environment Raw Data.
Click on it to navigate to array.
Click on Preview to see the data.
Note it might take few minutes (<10) until data appears.
Data is here!
For more information, please contact Jean-Paul, CEO of Nexedi (+33 629 02 44 25).