Salome HOME
Copyright update 2020
[modules/med.git] / doc / tut / medcoupling / testmed_lena.py
index 15558f5878873cf19ba0eb3802568650134aea54..4d4162a3a0d1345736bbc1174949617c038736ee 100755 (executable)
@@ -1,6 +1,5 @@
-#!/usr/bin/env python
-#  -*- coding: iso-8859-1 -*-
-# Copyright (C) 2011-2016  CEA/DEN, EDF R&D
+#!/usr/bin/env python3
+# Copyright (C) 2011-2020  CEA/DEN, EDF R&D
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -24,7 +23,9 @@
 # as a field in a med file.
 # (gboulant - 27/06/2011)
 
-import MEDCoupling as MC
+import os
+
+import medcoupling as MC
 import MEDLoader as ML
 
 #
@@ -37,7 +38,8 @@ import scipy, numpy
 #image = scipy.lena()
 # We could either read a real image using the PIL python package.
 from scipy.misc import pilutil
-image = pilutil.imread("images/avatar.png",True)
+CURDIR = os.path.dirname(__file__)
+image = pilutil.imread(os.path.join(CURDIR, "images", "avatar.png"),True)
 
 
 #from PIL import Image
@@ -45,10 +47,10 @@ image = pilutil.imread("images/avatar.png",True)
 #im=Image.open("images/lena.png")
 #image=pilutil.fromimage(im,True)
 #image=numpy.asarray(im)
-#print image
+# print(image)
 
 dim  = len(image.shape)
-print "Image space dimension = %d"%dim
+print("Image space dimension = %d"%dim)
 sizeX = image.shape[1]
 sizeY = image.shape[0]
 
@@ -60,7 +62,7 @@ sizeY = image.shape[0]
 # double as required by the MEDCoupling field specification.
 import numpy
 imageDataNArray       = image.reshape(1,sizeX*sizeY)[0]
-print imageDataNArray
+print(imageDataNArray)
 
 imageDataNArrayDouble = numpy.array(imageDataNArray, dtype='float64')
 imageDataArrayDouble  = list(imageDataNArrayDouble)
@@ -95,10 +97,10 @@ coordsY=MC.DataArrayDouble.New()
 coordsY.setValues(arrY,nbNodesY,1)
 
 cmesh.setCoords(coordsX,coordsY)
-print "Imagem mesh dimension: %d"%cmesh.getSpaceDimension()
+print("Imagem mesh dimension: %d"%cmesh.getSpaceDimension())
 
 # WARN: In the current state of development of MEDLoader, only
-# unstructured meshes are supported for writting function in med
+# unstructured meshes are supported for writing function in med
 # files. We just have to convert the cartesian mesh in an unstructured
 # mesh before creating the field.
 umesh=cmesh.buildUnstructured();