pypest / pyemu

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

Whats the best way to deal with the long parameter names? #400

Closed RyanConway91 closed 1 year ago

RyanConway91 commented 1 year ago

I am going through the https://github.com/pypest/pyemu/tree/develop/examples/freyberg_mf6 example.

When I write my .pst file, it can't run because the par names are the long versions. I get why this done internally in pyemu to track parameter information, but obviously this creates a pst that PEST can't use.
image

Is the best practice just to manually make a dictionary (in Excel or something) and provide it to 'rename_parameters()' after using build_pst() or is there a better way to this in pyemu?

RyanConway91 commented 1 year ago

For now I just going with a simple par_0, ... ,par_n mapping.

pst = pf.build_pst()
d = {p: "par_%i"%i for (i,p) in enumerate(pst.par_names)}

However when I try 'rename_parameters' I get the error pst.rename_parameters(d,template_ws)

image

My pest file does not have any prior information equations:

image

My pyemu version comes back as '0+unknown'. Does this indicate an issue with my distribution?

jtwhite79 commented 1 year ago

I think the pstfrom constructor accepts a long_names flag...

briochh commented 1 year ago

Yup @RyanConway91, @jtwhite79 has it. longnames=False should get you what you need. It’ll give you really generic par names, but a mapping is stored so pyemu can keep all the metadata.

RyanConway91 commented 1 year ago

Thanks, this worked but I also had to change "par_name_base" from "wel_gr" to "wlgr" in

pf.add_parameters(filenames=wel_files,par_type="grid",par_name_base="wel_gr",
                      pargp="wel_gr", upper_bound = 1.5, lower_bound=0.5,
                  geostruct=grid_gs)

to avoid this error:

image

briochh commented 1 year ago

That’s a good catch @RyanConway91, I don’t think we are set up for the use case where a (relatively long) par_name_base is passed with longnames=False. That probs needs fixing. Maybe we only keep that base name on the short parname if it fits? Else we drop and replace with a generic p and just retain it in the mapping file for pyemu? Or maybe we leave it up to the user to pass a truncated base (as you have done), and maybe give a more informative error. I haven’t used short names too much lately so happy to take suggestions on this. Generalising is the hard bit which is why we went with generic names and mapping.

RyanConway91 commented 1 year ago

If you are not using short_names how are generating pst files to actually run? I tried remapping the long names using "rename_parameters" (see comment above) but got a different error related to prior information.

As for the naming with longnames=False, I don't have any good ideas at this time... coming with useful parnames that are less than 13 char long is always a challenge with lots of pars. I like the longnames thing and think its a great idea, I'm just stuck trying to get pst file written that is PEST compatible.