Reports and Images from Complex Models

56 views
Skip to first unread message

Chuck Rhode

unread,
Dec 8, 2020, 12:46:47 PM12/8/20
to weewx-user
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I've been toying with an xtypes extension to model insect and crop
development.

I have 200 temperature development models for over 100 species. I
don't want to calculate all but a handful of current interest. The
trouble is that I want to pass not only the calculated series but also
the parameter values for the chosen models to Cheetah for printing as
part of each report, but I can't see how.

Parameter values are two or three, but names and stages of development
can be two or three more.

I can duplicate walking the configobj dictionaries in both places (in
my xtypes module and my Cheetah template) to gather the necessary
info, but that seems inelegant.

Are there user-extensible structures in common between xtype engines
and report engines that I can exploit to pass a dictionary of
dictionaries of static values? Is there some stunt I can pull,
extending the Cheetah search_list or the config_dict as a side-effect
of instantiating my xtypes?

P. S.: I've resigned myself to writing my own image engine so, if I
can conquer the Cheetah beast, I should be able to build on that
experience.

- --
.. Be Seeing You,
.. Chuck Rhode, Sheboygan, WI, USA
.. Weather: http://LacusVeris.com/WX
.. 36° — Wind WSW 13 mph

-----BEGIN PGP SIGNATURE-----

iF0EARECAB0WIQT+MY/5I/LMPSswTbVg2/xipKOWUgUCX8+6xAAKCRBg2/xipKOW
UplRAJ90K9IqTbFCRoJ5oUOktb7U9cQ84wCfRflLahZFpTksyGkwG16F3ybsC00=
=j7sB
-----END PGP SIGNATURE-----

Tom Keffer

unread,
Dec 11, 2020, 7:51:37 AM12/11/20
to weewx-user
Hi, Chuck

I'm not understanding what you are asking. I gather you want to use an expression like

$f($x, $y, $z).

in a Cheetah template, where f() is your model, and x, y, and z are parameters? If so, what's to stop you from simply using $x, $y, and $z in the template?

Or, something else?

--
You received this message because you are subscribed to the Google Groups "weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to weewx-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-user/20201208114123.1e43e5b6%40wealthy.

Chuck Rhode

unread,
Dec 13, 2020, 12:17:50 AM12/13/20
to weewx...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Fri, 11 Dec 2020 04:51:05 -0800
Tom Keffer <tke...@gmail.com> wrote:

> I'm not understanding what you are asking. I gather you want to use an
> expression like

> $f($x, $y, $z).

> in a Cheetah template, where f() is your model, and x, y, and z are
> parameters? If so, what's to stop you from simply using $x, $y, and
> $z in the template?

Thanks for your reply to my rather muddled query.

I'm writing a WeeWX extension that lets the User choose from a suite of
models. There are too many to calculate, so I want to calculate only
those of interest.

I'm struggling to explain this to myself, too, and my conceptualization
of the problem is evolving, so I apologize for inconsistency with my
previous posts.

The models don't really have parameters. There are underlying
parameterized calculations, but the choice of the model dictates the
choice of the parameters. I expect the User to choose a handful of
models. I'll make each chosen model *name* the *name* of an XType
variable and ignore the models that are not chosen.

I'll provide a Cheetah template for a standard HTML report that
includes group breaks for each temperature development model and lines
for daily min/max temperatures, growing-degree-days, cumulative
degree-days, and development event horizons. In the model headers I'd
like to show the actual calculation parameters used by the model.
These are not in the User-defined part of the config, but in the
model-definition part of the config, which I'd rather the User kept his
paws out of, so I need to walk the various configs in the template in
the same way that I walk the same configs in the XType instantiation
code to look up parameters by model *name* ... unless there's a way to
get an XType variable to cough up metadata in addition to numerical
series.

I've settled on a solution, though. I'll include my Python XType
instantiation module in my Cheetah template and reference the same
config-walking code (a non-User-oriented class) in both places. (The
config-walking code should not need to be run on each evaluation of the
XType variable but only at instantiation. It will need to be run on
every Cheetah report generation.) Upon sober reflection, it doesn't
seem that that is too often or too expensive.

- --
.. Be Seeing You,
.. Chuck Rhode, Sheboygan, WI, USA
.. Weather: http://LacusVeris.com/WX
.. 30° — Wind NNW 9 mph — Sky overcast.

-----BEGIN PGP SIGNATURE-----

iF0EARECAB0WIQT+MY/5I/LMPSswTbVg2/xipKOWUgUCX9Wj7QAKCRBg2/xipKOW
UqnVAJ98hay31xSFw1mKDKQboCYRIu/+uwCfTKHWIicOQvbatTk8DebdznaU6D4=
=wqlq
-----END PGP SIGNATURE-----

Tom Keffer

unread,
Dec 13, 2020, 9:09:23 AM12/13/20
to weewx-user
As we used to say in my company, "Still confused, but at a higher level."

Something to keep in mind is that for an expression

$f($x, $y, $z)

the function $f() can actually be a "functor" --- an object that defines __call__(). While functors look like functions, they are actually objects. Because they are objects, they can have attributes, which can be your hidden, model-dependent, parameters. 

class Model(object):
  def __init__(self, secret_j, secret_k):
    self.secret_j = secret_j
    self.secret_k = secret_k
  ...
  def __call__(self, x, y, z):
    result = do_some_calculation(x, y, self.secret_j, self.secret_k)
    return result

You create the Model object in a search list extension:

class ModelSLE(SearchList):
  def __init__(self, generator):
    SearchList.__init__(self, generator)
   self.model = Model(secret_j=12.2, secret_k=-2.1)

Now you can do things like:

#def result = $model('moth', 'spring')
  <p>The result for species 'moth' is $result, using parameters $result.secret_j, $result.secret_k</p>

This is very similar to how the tag $almanac works. 

Needless to say, this is not tested, and there is ample room for improvement. My intention is to show how functors work. 

It's also entirely possible that I've completely misunderstood the problem you're trying to solve!

-tk


--
You received this message because you are subscribed to the Google Groups "weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to weewx-user+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages