pypest / pyemu

python modules for model-independent uncertainty analyses, data-worth analyses, and interfacing with PEST(++)
BSD 3-Clause "New" or "Revised" License
174 stars 95 forks source link

shortnames may still violate template file line length constraints in pest_hp #500

Closed wkitlasten closed 5 months ago

wkitlasten commented 5 months ago

Just ran into a line length limit (2000) in template files for pest_hp after converting from longnames and version=2 to short names and version=1. This is how I resolved it on my end... no doubt someone else can do it better, faster, and put it in the proper place within pyemu:

        for i, line in enumerate(lines[1:]):
            nloop = 0
            while len(line) > 2000 and nloop<10000:
                line = line.replace('~  ', '~ ')
                line = line.replace('  ~', ' ~')
                print(len(line), len(lines[i]), nloop)
                nloop = nloop+1
            lines[i] = line
            assert nloop<10000
        with open(os.path.join(model_ws, fname), 'w') as fcheck:
            for line in lines:
                fcheck.write(line)
briochh commented 5 months ago

Unfortunately, that 2000 line limit is a bit of a barrier to building .tpl files for "full-width" array like files (as is done with pstfrom). Even if your par names are only 10 chars, you'll only be able to fit 200 on a line (absolute max with no delimiter). Be careful if you are reducing the length of the chars between those '~' tags. If too small your par changes will be lost due to lack of precision.

wkitlasten commented 5 months ago

I agree, once again, it is probably best to just let it fail and have the user adjust for their particular situation or get the 2000 line limit changed. My dream of simple push button modelling dies once more!