sharppy / SHARPpy

Sounding/Hodograph Analysis and Research Program in Python
https://sharppy.github.io/SHARPpy/index.html
Other
216 stars 112 forks source link

[BUG] mixed-layer parcel in parcelx and DefineParcel #250

Open Chun-ChihWang opened 1 year ago

Chun-ChihWang commented 1 year ago

In SharpPy 1.4.0, when I tried to define a mixed-layer parcel object using parcelx in sharptab.params, it didn't seem to work as described. In the description, it sounds like a user should be able to specify a custom depth of the mixed-layer parcel by specifying mlpcl = params.parcelx(prof, flag=4, pres=xxx), where xxx is the depth (in mb) of the parcel from the surface to mix.

The parcel depth is then supposed to be passed to DefineParcel, which is called within parcelx, as a kwarg when lplvals is not specified, but it didn't get passed because the DefineParcel call does not have any kwarg in it. Line 1777 of params.py " pcl.lplvals = kwargs.get('lplvals', DefineParcel(prof, flag)) " Therefore, any specification of pres in parcelx has no effect. When I tried printing out the mixed-layer parcel depth in __ml (in DefineParcel; assigned to self.presval), it always gave me the default lowest 100 mb even when I specified pres=50 in my parcelx call.

Simply adding pres to the DefineParcel call in Line 1777 of params.py created another issue where the specified pres was taken as the parcel starting pressure. For example, if pres=50, then the parcel starting pressure is taken as 50 mb, which doesn't make sense and will mess up the mixed-layer parcel calculations (e.g., MLCAPE, MLLCL, etc). I believe this is a variable name conflict issue- the variable "pres" is used to represent two completely different variables in parcelx and DefineParcel. As a temporary fix, I created a new kwarg named "pcl_dp" that gets passed to my modified DefineParcel call in parcelx (in params) that includes a kwarg. " pcl_dp = kwargs.get('pcl_dp', None) if pcl_dp is not None: pcl.lplvals = kwargs.get('lplvals', DefineParcel(prof, flag, pcl_dp=pcl_dp)) else: pcl.lplvals = kwargs.get('lplvals', DefineParcel(prof, flag)) " This gave me the desired pbot and ptop for layer averaging in __ml. However, I am not sure if this is the best way to get around this problem.

The above isn't really an issue if a user wishes to compute the default lowest 100 mb mixed-layer parameters. It is only an issue if a user wants to define his/her own mixed-layer parcel.

Cheers, David