Message Boards Message Boards

CloudDeploy issue with FormFunction and NSolve

I try to deploy some extreme value analysis in windspeed to the cloud for computing. In notebook works fine but after deployment the server answer is an error.

This is the code in notebook which works fine:

In[10]:= myMaxWindSpeed[lat_, lon_] := 
 UnitConvert[
  Quantity[Part[
      maxwind /. 
       NSolve[Probability[x >= maxwind, 
          x \[Distributed] 
           EstimatedDistribution[
            WeatherData[{lat, lon}, 
             "MaxWindSpeed", {{1990}, {2015}, "Year"}], 
            GumbelDistribution[\[Alpha], \[Beta]]]] == 0.02, maxwind, 
        Reals]][[1]], "Kilometers"/"Hours"]*1.66, "Meters"/"Seconds"]

In[19]:= myMaxWindSpeed[-20, 30]

Out[19]= Quantity[43.3222, ("Meters")/("Seconds")]

So, I can call the function passing two arguments. But when trying to deploy to the Wolfram Cloud the code and answer are the below:

In[20]:= CloudDeploy[
 FormFunction[{"lat" -> Restricted["Number", {-180, 180}], 
   "lon" -> Restricted["Number", {-180, 180}]}, 
  myMaxWindSpeed[#lat, #lon] &]]

Out[20]= CloudObject["https://www.wolframcloud.com/objects/182e0f97-\
b6ff-49bd-8e64-627a27540513"]

The answer is this:

If[Floor[0.461111 maxwind] == 0.461111 maxwind, Floor[0.461111 maxwind], N[0.461111 maxwind]] "Meters"/"Seconds"

Testing cloud deployment with similar functions I have the below one, which works fine. So, what can be the problem here? Why the similar function doesn't work?

In[21]:= testfunction[lati_, longi_] := 
 WeatherData[{lati, longi}, "WindSpeed"]

In[22]:= CloudDeploy[
 FormFunction[{"lati" -> Restricted["Number", {-180, 180}], 
   "longi" -> Restricted["Number", {-180, 180}]}, 
  testfunction[#lati, #longi] &]]

Out[22]= CloudObject["https://www.wolframcloud.com/objects/1ba5d447-\
ed36-42db-8d89-0300f10c452a"]

Server answer after fill out the form with some coordinates: 9.7 "Kilometers"/"Hours"

POSTED BY: Balazs Kisfali
8 Replies

Just pointing out a relevant post: Modeling wind speed distributions with machine learning

POSTED BY: Vitaliy Kaurov

Thank you Vitaly for your suggestion

POSTED BY: Balazs Kisfali

I’m running Mathematica version 10.4 on my desktop and your code runs on my desktop only if modified:

MaxWindSpeedRemoveQuantityDistribution[lat_, long_] := 
   UnitConvert[
      Quantity[
         Part[maxwind/.
            NSolve[
               Probability[x>=maxwind,
                  x\[Distributed]
                     With[{dist=EstimatedDistribution[
                        WeatherData[{lat, long}, "MaxWindSpeed", {{1990}, {2015}, "Year"}],
                        GumbelDistribution[\[Alpha], \[Beta]]]},
                           Switch[
                              dist, GumbelDistribution[_, _],
                              dist, QuantityDistribution[GumbelDistribution[_, _], _], First[dist]]]]==0.02,
               maxwind, Reals]][[1]],
         "Kilometers"/"Hours"]*1.66,
      "Meters"/"Seconds"];

Update 4/17/2016

I’ve verified that this code also works in the Wolfram Cloud, see below.

Thank you Christopher, I tried with your modified code and the deployed version has the same answer unfortunately. I have similar "symptoms" since my original code is running on my desktop Mathematica 10.2 (with OSx El Capitan) but not in the cloud. There should be something wrong around the deployment.

This was the server answer with your modified code in the browser (Safari or Chrome, the same):

If[Floor[0.461111 maxwind] == 0.461111 maxwind, Floor[0.461111 maxwind], N[0.461111 maxwind]] "Meters"/"Seconds"
POSTED BY: Balazs Kisfali

Deploy modified function:

CloudDeploy[
   FormFunction[{
      "lat" -> Restricted["Number", {-90, 90}],
      "long" -> Restricted["Number", {-180, 180}] }, 
      MaxWindSpeedRemoveQuantityDistribution[#lat, #long] & ], 
   FileNameJoin[{$CloudRootDirectory, "MaxWindSpeedRemoveQuantityDistribution"} ] ]

Open FormFunction in browser and enter latitude and longitude:

FormFunction input

And here’s the FormFunction output:

enter image description here

thank you @Christopher Haydock I did the same thing as you and I have got that strange results still. Then I have upgraded my Mathematica from 10.2 to latest 10.4 (as per today) and works fine :)

However I was believe that another small issue will disappear with the upgrade. If I use FormPage (as I want in my finial app) instead of FormFunction then the first field, Latitude, will behave as AutoSubmitting would be on. With other words, after moving out from that field to the next one, the form wants to be loaded, thus error msg will appear on the screen.

enter image description here

But otherwise works fine

enter image description here

so now I'd like to "rid-off" the auto-submitting-like behaviour

POSTED BY: Balazs Kisfali

This will give you the desired FormPage behavior:

CloudDeploy[
   FormPage[ {
      "lat" -> <|"Interpreter" -> Restricted["Number", {-90, 90}], "AutoSubmitting" -> False|>,
      "long" -> <|"Interpreter" -> Restricted["Number", {-180, 180}], "AutoSubmitting" -> False|> },
      MaxWindSpeedRemoveQuantityDistribution[#lat, #long] & ],
   FileNameJoin[{$CloudRootDirectory, "MaxWindSpeedAutoSubmittingFalse"} ] ]

For details, see FormObject documentation.

Exactly as desired, thank you @Christopher Haydock

Ps.: FormObject has a rich documentation, somehow I was focused on CloudObject and FormFunction

POSTED BY: Balazs Kisfali
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract