Actually you are doing nothing wrong. But in general it would be better to process the data line wise.
More like in this example.
Setting the memory in the snappy.ini should be sufficient.
Actually I wanted to suggest the following little script to detect if the memory settings are effective:
Runtime = jpy.get_type('java.lang.Runtime')
max_memory = Runtime.getRuntime().maxMemory()
total_memory = Runtime.getRuntime().totalMemory()
free_memory = Runtime.getRuntime().freeMemory()
mb = 1024 * 1024
print('max memory:', max_memory / mb, "MB")
print('total memory:', total_memory / mb, "MB")
print('free memory:', free_memory / mb, "MB")
You can notice the change in the value of max_memory when you edit the java_max_mem property. Unfortunately, the values are only correct up to ~2GB. Above they are wrong. This is caused by an issue in jpy which is already fixed but not yet released. At least you can see if the setting has an effect.
Maybe you can send me the file. I'll send you a ftp location in a separate message.