Grid generation using python