How to change dimensions a mesh in blender python

I am trying to change the dimensions of a mesh (not the scale) based on the size of the pixels in an image.

I share with you the script that I have done so far, the script does change the dimensions of the mesh, but the scale still changes and that is what I do not want.

#Cargar HeightMap, aplicar modificador de dezplazamiento.
tex =“HeightMap”, type=“IMAGE”)
tex.image =[‘heightmap’])
hmWidth = tex.image.size[0]
hmHeight = tex.image.size[1]

— --- — --- — --- — ---#

#Crear Grid
def create_mesh():
#Añadir Mesh de Tipo Grid
bpy.ops.mesh.primitive_grid_add(x_subdivisions = 512 , y_subdivisions = 512, size = 1.0)
grid = bpy.context.active_object = ‘MapGrid’
tex.extension = ‘EXTEND’
mod ="", ‘DISPLACE’)
mod.strength = 0.080
mod.mid_level = 0
mod.texture = tex
#return grid

Could someone help me correct this?