MATLAB to Python

Validation of moisture recycling in China

More Info


In this thesis, focus lays on converting a MATLAB model to Python. Models are used a lot by students and researchers at universities and they provide an unique way of calculating and reviewing data and results. However, at the Delft University of Technology, a lot of these models are written in MATLAB. MATLAB is a programming language which requires a expensive license. Many researchers in- and outside universities can’t afford this licensewhich means that models are not available for everyone although lots of people would like to work hands on with these type of models. By making the first step in solving this problem, the WAM2-model originally created by R.J. van der Ent, is converted from MATLAB to Python. This conversion is done due to the fact that Python is open-source software which makes the model free to use for everyone. Also, MATLAB and Python syntax is generally the same which makes conversion even easier. Ultimately, theWAM2-model is converted to Python and ready to use by everyone. There are two versions in Python available, namely 1.0 and 2.0. 1.0 is the version with the same structure as the model in MATLAB. However, itwas found that the overall running time for version 1.0was much larger than the original model in MATLAB. This is due to Python executing notebooks inside of one masterscript notebook, which is not very fast with Python’s data structure. To solve this problem, Python WAM2-model 2.0 is created. Version 2.0 makes more effective use of Python’s data structure and this has led to running times almost twice as fast as the original model in MATLAB. Another benefit of conversion is that both model versions in Python are more user-friendly. Headers are possible in Python and by defining the data paths in the beginning of every masterscript, users don’t have to go through every script to change directories. In the tracking of moisture, sometimes the first day requires data which is not available. To make the calculation possible, empty arrays are needed which are now automatically created in Python whereas inMATLAB, the user has to do this at his own expense. Ultimately, the plots created in Python are the same as inMATLAB.However, one additional plot is added, called the contourplot. With agreeing statements from the supervisors, these contourplots are more pleasing to the human eye and therefore they are included in the Python model. Next to converting the model, a readme has been made which can be found in Appendix B. This readme is a step by step guide, helping users by explaining lots of the Python syntax. This guide is therefore also included with the Python model. The WAM2-model in Python is used to create an evaporation shed for Eurasia and an precipitation shed for China to find a correlation between the two areas. In previous research done by Cömert et al. (2016), the correlation between precipitation in China and evaporation in Eurasia was studied. By making the aforementioned precipitation and evaporation sheds, this study by Cömert et al. can be validated and maybe improved for future purposes. It is important to research moisture recycling in China. Currently, there are lots of droughts happening in China and precipitation is decreasing. The origin of this precipitation needs to be known and moisturerecycling provides an answer for this. Cömert et al. (2016) already made an attempt and they proved that there is a high correlation between source region Eurasia and sink region China. They quantified this with the Pearson correlation coefficient and for their used dataset, they found a correlation coefficient of 0.84. To validate these results, precipitation and evaporation sheds for respectively Eurasia and China can be made. The precipitation shed is defined for the region equal to that of Cömert et al. The same holds for the evaporation shed. The results are quite interesting in comparison to that of Cömert et al. The correlation coefficient found with the WAM2-model is 0.87, which is higher than the one found by Cömert et al. This is explainable since theWAM2-model removes the sea mask whereas Cömert et al. took the sea into account. The sheds resulting from theWAM2-model show that the defined regions by Cömert et al. are quite good estimations. However, a more precise source and sink region can be defined and further research should look at increasing the correlation coefficient as high as possible by redefining these regions. The model is available at