Message Boards Message Boards


CloudDeploy issue with FormFunction and NSolve

Posted 5 years ago
8 Replies
5 Total Likes

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_] := 
      maxwind /. 
       NSolve[Probability[x >= maxwind, 
          x \[Distributed] 
            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["\

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["\

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

8 Replies

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

MaxWindSpeedRemoveQuantityDistribution[lat_, long_] := 
                        WeatherData[{lat, long}, "MaxWindSpeed", {{1990}, {2015}, "Year"}],
                        GumbelDistribution[\[Alpha], \[Beta]]]},
                              dist, GumbelDistribution[_, _],
                              dist, QuantityDistribution[GumbelDistribution[_, _], _], First[dist]]]]==0.02,
               maxwind, Reals]][[1]],

Update 4/17/2016

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

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

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"

Thank you Vitaly for your suggestion

Deploy modified function:

      "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

This will give you the desired FormPage behavior:

   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

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract