Note
The Macro to Python converter is available from Metview version 5.22.0
There are two different ways to perform the conversion.
In the user interface <mv_desktop_overview>
if we right-click on any Macro icon we can use the Convert to Python action.
It will generate a Python script in the same folder where the Macro is located. The name of the Python script is formed by adding the ".py" suffix to the file name or if the Macro name contains the ".mv" suffix it is replaced by ".py". Subsequent calls will always generate a new Python script with an increment added to the file name.
The conversion also works for multiple selected Macros:
It the conversion fails for a given Macro its name turns red and the error message will be avialable in the icon Log (you can launch it from the icon context menu):
In the Macro editor we can use the Convert to Python action from the File menu in the menubar:
It will generate a Python script in the same folder where the Macro is located. The name of the Python script is generated by adding the ".py" suffix to the file name or if the Macro name contains the ".mv" suffix it is replaced by ".py". Subsequent calls will always generate a new Python script with an increment added to the file name.
On success a popup dialog appears showing the path to the generated Python script. If an error happens the popup will contain the error message as to why the conversion failed.
For simple Macros you should expect to get a correctly formatted and fully functional Python script. However, the converter cannot handle certain code structures and data types and it does not have any run-time information, so the generated code most probably will require further adjustments. If this happens a set of warnings will be added to the top of the Python script and in certain cases next to the affected code lines. Please check these warnings and modify your script accordingly. The following list gives you detailed advice on how to do it:
convert/convert_concat convert/convert_date convert/convert_plot convert/convert_newpage convert/convert_vector_index4 convert/convert_for
Some features are unsupported in Metview Python and it is not possible to generate a working Python code out of them:
Feature | Comment |
---|---|
Inline C/Fortran | Macro supports embedded C and Fortran code via the inline keyword. In Metview Python this is unsupported. The converter simply puts the C or Fortran code inside a triple quoted string resulting in a correctly formatted but non-functional Python script. |
matrix |
This method does not exists in Metview Python. You need to use 2D numpy arrays to convert your code. |
Once the adjustments are done try to run the Python script and see if it generates the same output as your Macro. If it does then congratulations you can start using your nice new Python script. However, if the results differ or the script fails please let the developers know about it by reporting it via the ECMWF Support Portal.