I know DFHack has drainaquifer. Is the reverse possible? Could a layer be turned into an aquifer layer?
Yes. On the map block level, there are three flags to set: flags.has_aquifer, flags.check_aquifer, and designation[x%16][y%16].water_table for each tile you want to turn into a water source. In addition, df.global.world.raws.inorganics[].flags.AQUIFER for that tile's rock/soil type needs to be true. (Or perhaps the tile's layer type; I haven't experimented with veins and inclusions.)
Even after all four flags are set, it might take a few steps for the new aquifer to start leaking.
It also appears that the drainaquifer script might be slightly wrong; it can miss aquifers that happen to miss the two tiles it checks, and it ignores the two block-level flags. Is that a problem in practice?
Thanks. I had to dig around for how to access some of the relevant data, but this was enough for me to put together a toggleaquifer script that suits my purposes. It seems that the rock/soil type does not in fact need to be tagged as aquifer for this to work, and in particular the veins and inclusions can be made into aquifer. So, it was necessary to test that the tiletype is not MineralWall. I also added checks for surrounding open blocks, so that exposed edges don't begin to leak. (Though it is amusing for a slope to just start leaking all over the landscape.)
Presumably, the drainaquifer script is checking the corner and center of the block as a quick test if there are any aquifer tiles in the block. It should probably be checking the block-level flags, instead. And then, as you note, turning them off. (I suspect the only harm leaving them set does is causing some small amount of lag from extra checks for exposed aquifer cells. I'm not sure what has_aquifer does; check_aquifer seems to be necessary and sufficient for aquifer tiles in the block to function.)
Edit: I spoke too soon; check_aquifer doesn't apply to the aquifer tiles within a block, but to the tiles in the block which are adjacent to aquifer tiles. That makes a rigorous script for altering the aquifer status of individual layers a bit more complicated. Just when I thought I was done.