def GCALTemporal(stimulus = None,
                 timestep=0.5,
                 ringParams = ('MAX','MAX'),
                 saveSnapshotTime = None,
                 plastic=True,

                 LGN_TC = None,
                 LGNFFStrength = 2.33,
                 GCStrength=0.6,
                 GCDelay=0.01,
                 LGNDistanceDelay=None,

                 # V1 Settings
                 V1_TC = None,
                 V1FFStrength=1.5,
                 ExcStrength=1.7,
                 InhStrength=-1.4,
                 LateralDelay=0.01,
                 V1DistanceDelay=None,

                 HomeoFactor=1.0, 
                 HomeoPlastic = False ): 

    VSDSheetFlag = True;  saveSnapshotFlag = False; LOAD = None

    ###################################################
    # Modifying sheets #
    ####################
                           
    modelName = 'fit-LGN-V1.py'
    (LGNRingNo,V1RingNo) = ringParams

    if LOAD is not None:
        typPath = '../models/snapshots/'
        load_snapshot(typPath+LOAD)
    else:   
        print "Modifying model loaded in memory"          
    
    ########################
    # Sheets Modifications #
    ########################

        p = gcal_vanilla.makeParams()
        gcal_vanilla.makeSheets(p)
        # Switch out the LISSOM sheets for continuous ones
        switchAllSheets(VSDSheetFlag)
        # Setup the input generator
        setupRetina(stimulus, timestep)
        # Connecting with original GCAL connections
        gcal_vanilla.connectGCAL(p,LGNRingNo,V1RingNo)
                             

    ############################
    # Connection Modifications #
    ############################
                             
    'Alternatively, could use topo.sheet[<name>].projection(<name>)'
    conns = dict([(el.name,el) for el in topo.sim.connections()])

    ''' AfferentToLGNOn, AfferentToLGNOff, LGNOnAfferent, LGNOffAfferent,
        GCLGNOn-*,  GCLGNOff-*, LateralInhibitory-*, LateralExcitatory-*
    '''

    #######
    # LGN #
    #######

    # FEEDFORWARD DELAY IS ABOUT 15MS FOR BOTH STAGES

    # Afferent from Retina to LGNOn/Off. Delay and strength.
    setConnDelay('AfferentToLGNOn',15.0,conns)
    setConnDelay('AfferentToLGNOff',15.0,conns)
    setConnStrength('AfferentToLGNOn', LGNFFStrength,conns)
    setConnStrength('AfferentToLGNOff', LGNFFStrength,conns)

    assert GCStrength > 0
    modifyLateralConnections(conns, 'GCLGNOn', GCStrength, GCDelay, LGNDistanceDelay)
    modifyLateralConnections(conns, 'GCLGNOff', GCStrength, GCDelay, LGNDistanceDelay)

    ######
    # V1 #
    ######
                             
    setConnDelay('LGNOnAfferent',15.0,conns)
    setConnDelay('LGNOffAfferent',15.0,conns)
    setConnStrength('LGNOnAfferent', V1FFStrength,conns)
    setConnStrength('LGNOffAfferent' ,V1FFStrength,conns)

    assert ExcStrength > 0;  assert InhStrength < 0
    modifyLateralConnections(conns, 'LateralExcitatory', ExcStrength, LateralDelay, V1DistanceDelay)
    modifyLateralConnections(conns, 'LateralInhibitory', InhStrength, LateralDelay, V1DistanceDelay)

    ##########################
    # Sheet output functions #
    ##########################

    setLGNOutputFns(LGN_TC)
    setV1OutputFns(V1_TC, HomeoFactor, HomeoPlastic) 

    ###############################
    # Plasticity and snapshotting #
    ###############################
    
    if saveSnapshotFlag:
        setSheetPlasticity(plastic=True) # No point making snapshot if plasticity if off                                
        saveSnapShot(saveSnapshotTime)

    setSheetPlasticity(plastic)      # Set as desired
    V1outputList = []

    if V1_TC is not None:
        V1outputList += [Hysteresis(time_constant=V1_TC)]
        
    # False for off and None for default
    if HomeoFactor is not False:
        learning_rate=0.001    * HomeoFactor
        smoothing=0.999 # Thanks to Jan for this conversion.
        smoothing = 1 - (1 - smoothing) / HomeoFactor  
        homeostaticFn = HomeostaticResponse(learning_rate=learning_rate)
        
        homeostaticFn.plastic = HomeoPlastic
        V1outputList += [homeostaticFn]
    else:
        print "\n*Warning*: Using half rectification instead of hysteresis!\n"
        V1outputList += [HalfRectify()] # If homeostatis is off, this non-linearity to be used instead
    
    OutputFns(V1outputList,['V1'])
    # Calibrate with homeostasis OFF - ensure balance err towards inhibition    
    # Check that learning is off properly


if __name__ == '__main__':

    # Should reproduce GCAL with delays and continuous sheets.
    # Note that tsettle has been removed.
    p = gcal_vanilla.makeParams()
    stimulus = gcal_vanilla.GCALStimulusPattern(p,'Gaussian')
    GCALTemporal(stimulus) # Using default (GCAL) parameters