From 3c9cf65dbf2b0cac0a6216ffb1b7326c343070e3 Mon Sep 17 00:00:00 2001 From: hectornieto Date: Wed, 11 May 2016 12:20:02 +0200 Subject: [PATCH] Include a 'Run PyTSEB' button to avoid some user confusion in the jupyter notebooks --- ProcessLocalImage.ipynb | 36 +++++++------------------------ ProcessPointTimeSeries.ipynb | 42 ++++++++++++++---------------------- src/pyTSEB.py | 25 +++++++++++++++++++++ 3 files changed, 49 insertions(+), 54 deletions(-) diff --git a/ProcessLocalImage.ipynb b/ProcessLocalImage.ipynb index 76f9a34..99c9f57 100644 --- a/ProcessLocalImage.ipynb +++ b/ProcessLocalImage.ipynb @@ -41,12 +41,13 @@ { "cell_type": "markdown", "metadata": { - "collapsed": false, - "scrolled": true + "collapsed": true }, "source": [ "# Run TSEB\n", - "Once TSEB is configured we will parse all the information in the widgets and run the selected model. A progress bar will show up and once the processing is done two GeoTiff files will be saved:\n", + "Once TSEB is configured we parse all the information in the widgets and run the selected model. \n", + "\n", + "Once the processing is done two GeoTiff files will be saved:\n", "\n", "- < Main Output File > whose name is specified in the cell *Output File* will contain the bulk estimated fluxes:\n", " 1. Sensible heat flux (W m-2)\n", @@ -64,29 +65,8 @@ " 6. Net shortwave radiation (W m-2)\n", " 7. Net longwave radiation (W m-2)\n", " 8. Friction velocity (m s-1)\n", - " 9. Monin-Obukhov lenght (m)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "# Get the data from the widgets\n", - "setup.GetDataTSEBWidgets(isImage = True)\n", - "# Run TSEB\n", - "setup.RunTSEBLocalImage()" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "collapsed": true - }, - "source": [ + " 9. Monin-Obukhov lenght (m)\n", + "\n", "# Display results\n", "Now we can open the image and display the TSEB outputs:" ] @@ -162,7 +142,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "IPython (Python 3)", "language": "python", "name": "python3" }, @@ -176,7 +156,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.4.4" + "version": "3.5.1" } }, "nbformat": 4, diff --git a/ProcessPointTimeSeries.ipynb b/ProcessPointTimeSeries.ipynb index 295187f..7e71205 100644 --- a/ProcessPointTimeSeries.ipynb +++ b/ProcessPointTimeSeries.ipynb @@ -42,35 +42,16 @@ }, { "cell_type": "markdown", - "metadata": { - "collapsed": false - }, + "metadata": {}, "source": [ "# Run TSEB\n", - "Once TSEB is configured we will parse all the information in the widgets and run the selected model. A progress bar will show up and once the processing is done an ASCII table with the following variables will be written in the output txt file:\n", + "Once TSEB is configured we parsed all the information in the widgets and run the selected model. \n", + "\n", + "Once the processing is done an ASCII table with the following variables will be written in the output txt file:\n", ">Year, DOY, Time, LAI, f_g, skyl, VZA, SZA, SAA, Ldn, Rn_model, Rn_sw_veg, Rn_sw_soil, Rn_lw_veg, Rn_lw_soil, Tc, Ts, Tac, LE_model, H_model, LE_c, H_c, LE_s, H_s, flag, zo, d, G_model, R_s, R_x, R_a, u_friction, L, n_iterations\n", "\n", - "where variables with the same name as input variables have the same meaning, and for the others: *skyl* is the ratio of diffuse radiation, *Rn_model* is net radiation (W m-2; *sw* and *lw* subscripts stand for shortwave and longwave, *veg* and *soil* for canopy and soil), *Tc*, *Ts* and *Tac* are canopy, soil and inter-canopy-air temperatures (K), *LE_model* is latent heat flux and *H_model* is sensible heat flux (W m-2; subscripts *c* and *s* stand for canopy and soil respectively), *flag* is a quality flag (255==BAD), *zo* and *d* are roughness length and zero-plane displacement height (m), *R_s*, *R_x* and *R_a* are resistances to heat and momentum transport (s m-1), *u_friction* is friction velocity (m s-1), *L* is the Monin-Obukhov length (m) and *n_iterations* is the number of iterations of TSEB needed to achieve model convergence." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "# Get the data from the widgets\n", - "setup.GetDataTSEBWidgets(isImage = False)\n", - "#run TSEB\n", - "setup.RunTSEBPointSeriesArray()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ + "where variables with the same name as input variables have the same meaning, and for the others: *skyl* is the ratio of diffuse radiation, *Rn_model* is net radiation (W m-2; *sw* and *lw* subscripts stand for shortwave and longwave, *veg* and *soil* for canopy and soil), *Tc*, *Ts* and *Tac* are canopy, soil and inter-canopy-air temperatures (K), *LE_model* is latent heat flux and *H_model* is sensible heat flux (W m-2; subscripts *c* and *s* stand for canopy and soil respectively), *flag* is a quality flag (255==BAD), *zo* and *d* are roughness length and zero-plane displacement height (m), *R_s*, *R_x* and *R_a* are resistances to heat and momentum transport (s m-1), *u_friction* is friction velocity (m s-1), *L* is the Monin-Obukhov length (m) and *n_iterations* is the number of iterations of TSEB needed to achieve model convergence.\n", + "\n", "# Display results\n", "Now we can open the output and plot the TSEB outputs:" ] @@ -135,11 +116,20 @@ "\n", "show(p);" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "IPython (Python 3)", "language": "python", "name": "python3" }, diff --git a/src/pyTSEB.py b/src/pyTSEB.py index 8009982..a109206 100644 --- a/src/pyTSEB.py +++ b/src/pyTSEB.py @@ -140,6 +140,9 @@ def PointTimeSeriesWidget(self): self.w_inputtxt=widgets.Text(description='Input File :', value=self.InputFile, width=500) self.w_output=widgets.Button(description='Select Output File') self.w_outputtxt=widgets.Text(description='Output File :', value=self.OutputTxtFile,width=500) + + self.w_runmodel=widgets.Button(description='Run pyTSEB', background_color='green') + # Create TSEB options widgets self.SelectModel() self.DefineSiteDescription() @@ -160,6 +163,7 @@ def PointTimeSeriesWidget(self): display(widgets.HBox([self.w_output,self.w_outputtxt])) display(tabs) display(self.w_saveconfig) + display(self.w_runmodel) # Handle interactions self.w_CalcG.on_trait_change(self._on_G_change, 'value') self.w_input.on_click(self._on_input_clicked) @@ -167,6 +171,7 @@ def PointTimeSeriesWidget(self): self.isImage=False self.w_loadconfig.on_click(self._on_loadconfig_clicked) self.w_saveconfig.on_click(self._on_saveconfig_clicked) + self.w_runmodel.on_click(self._on_runmodel_clicked) def LocalImageWidget(self): '''Creates a jupyter notebook GUI for running TSEB for an image''' @@ -194,6 +199,8 @@ def LocalImageWidget(self): self.w_masktxt=widgets.Text(description='Mask:',value='0', width=500) self.w_output=widgets.Button(description='Select Output File') self.w_outputtxt=widgets.Text(description='Output File :', value=self.OutputImageFile, width=500) + + self.w_runmodel=widgets.Button(description='Run pyTSEB', background_color='green') # Create TSEB options widgets self.SelectModel() self.DefineSiteDescription() @@ -230,6 +237,8 @@ def LocalImageWidget(self): display(widgets.HBox([self.w_output,self.w_outputtxt])) display(tabs) display(self.w_saveconfig) + display(self.w_runmodel) + # Handle interactions self.w_LST.on_click(self._on_inputLST_clicked) self.w_VZA.on_click(self._on_inputVZA_clicked) @@ -244,6 +253,7 @@ def LocalImageWidget(self): self.w_CalcG.on_trait_change(self._on_G_change, 'value') self.w_loadconfig.on_click(self._on_loadconfig_clicked) self.w_saveconfig.on_click(self._on_saveconfig_clicked) + self.w_runmodel.on_click(self._on_runmodel_clicked) self.isImage=True @@ -635,6 +645,21 @@ def _on_G_change(self,name, value): self.w_Gphase.visible=True self.w_Gshape.visible=True + def _on_runmodel_clicked(self, b): + # Change the colour of the button to know it is running + self.w_runmodel.background_color='yellow' + # Get the data from the widgets + self.GetDataTSEBWidgets(isImage = self.isImage) + #run TSEB + if self.isImage: + self.RunTSEBLocalImage() + else: + self.RunTSEBPointSeriesArray() + # Change the colour of the button to know it is running + self.w_runmodel.background_color='green' + + + def GetDataTSEBWidgets(self,isImage): '''Parses the parameters in the GUI to TSEB variables for running TSEB''' self.TSEB_MODEL=self.w_model.value