Generate a Latin Hypercube of parameters for a given FUSE model

In the previous post I showed how to get information regarding model building options and used parameters for a given FUSE model. In this post I’ll show how to sample (for the given model) a set of 100 parameters uniformly using the Latin Hypercube Sampling method.

Each FUSE model uses different parameters therefore, in order to sample uniformly, we need to remove the unused parameters and then sample. Here is how I achieve this.

Install/load the fuse package:

    install.packages("fuse", repos="http://R-Forge.R-project.org")
    library(fuse)

Now load devtools and source the gist below (it contains a function called GenerateFUSEParameters)

    require(devtools)
    devtools::source_gist("https://gist.github.com/cvitolo/9574a0cef0bf4f2cd28b")

Choose one of FUSE’s models and get model/parameters info using the FUSEinfo function described in the previous post:

    mid <- 60 # This is TOPMODEL
    x <- FUSEinfo(mid)

Now a Latin Hypercube of 100 samples for the above model (mid=60) is defined as follows:

    parameters <- GenerateFUSEParameters(NumberOfRuns = 100, 
                                         params2remove = names(x)[which(x==FALSE)])

FUSE model and parameters information

A quick post to show how to find what model building decisions, options (name and ID number) and depending parameters are associated with a given FUSE model.

First of all, install/load the fuse package:

    install.packages("fuse", repos="http://R-Forge.R-project.org")
    library(fuse)

Load devtools and source the gist below (it contains a function called FUSEinfo)

    require(devtools)
    devtools::source_gist("https://gist.github.com/cvitolo/65d72b4f756126839f85")

Choose one of FUSE’s models:

    mid <- 60 # This is TOPMODEL

Run the function FUSEinfo using mid as input:

    FUSEinfo(mid=60)

The result of FUSEinfo is a dataframe containing 32 columns.

  rferr arch1 arch2 qsurf qperc esoil qintf q_tdh rferr_add rferr_mlt maxwatr_1 maxwatr_2 fracten
1    12    21    34    43    51    62    71    82     FALSE      TRUE      TRUE      TRUE    TRUE
  frchzne fprimqb rtfrac1 percrte percexp sacpmlt sacpexp percfrac iflwrte baserte qb_powr qb_prms
1   FALSE   FALSE   FALSE    TRUE    TRUE   FALSE   FALSE    FALSE   FALSE    TRUE    TRUE   FALSE
  qbrate_2a qbrate_2b sareamax axv_bexp loglamb tishape timedelay
1     FALSE     FALSE    FALSE    FALSE    TRUE    TRUE      TRUE

The first 8 columns contain the model building decisions: rferr (rainfall error), arch1 (upper soil layer), arch2 (lower soil layer), qsurf (runoff mechanism), qperc (percolation), esoil (evaporation), qintfl (interflow) and q_tdh (routing). See the table below for more information:

The remaining 24 columns list the parameters (see table below). If the value of a parameter is TRUE, it means that parameter is used by the model, FALSE means the parameter is not used.

parameters

The TextInFooter macro

This post is for my friend Sue and all the people that use Microsoft Word and want to add to the footer of their documents a reminder to the file location and the timestamp when the document was last saved. This can be achieved using a small VBA macro, and here is how to do it. 

Copy the content in the box below

Sub FileSaveAs()

    Dialogs(wdDialogFileSaveAs).Show
    
    Dim i As Long
    Dim ThisPath As String
    Dim pName As String
    Dim TextInFooter As String
    Dim FullName As String

    ThisPath = ActiveDocument.Path
    pName = ActiveDocument.Name
    FullName = ThisPath & "\" & pName
    TextInFooter = "This file was saved in: " & FullName & " on the " & Now

    For i = 1 To ActiveDocument.Sections.Count
        With ActiveDocument.Sections(i)
            .Footers(wdHeaderFooterPrimary).Range.Text = TextInFooter
        End With
    Next
End Sub

To save the macro:

  1. Open an existing word document, then press ALT+F11.
  2. Right-Click on Normal in the file explorer in the left hand side panel. Click on INSERT, then click on MODULE.
  3. Copy the text at the bottom of this email and paste it in the empty window that opens on the top-right panel.
  4. Click on SaveNormal.

If you want to save a document without changing the footer, you either press the save button or CTRL+S. These will not run the macro.

If you want to save a document with path+date&time in the footer, you either press FILE -> SaveAs button or F12. These will run the macro.

Remember, you have to save the macro only once. After that, the macro will work on any new or existing document on your computer. However if you change computer or reset it, you will need to re-save the macro.