Ejemplo n.º 1
0
def sunhis2initial(hisfile,icfile):
    """
    Main function
    """

    print '#####\nCreating initial condition file (%s) from history file (%s)...'%(icfile,hisfile)

    # Load the history file
    sunhis = Spatial(hisfile, tstep=-1, klayer=[-99])

    # Load the initial condition object
    timeic = datetime.strftime(sunhis.time[-1],'%Y%m%d.%H%M%S')
    sunic = InitialCond(hisfile,timeic)

    # Load the last time step into each variable
    sunic.h = sunhis.loadData(variable='eta').reshape((1,sunic.h.shape))
    sunic.T = sunhis.loadData(variable='temp').reshape((1,)+sunic.T.shape)
    sunic.S = sunhis.loadData(variable='salt').reshape((1,)+sunic.S.shape)
    sunic.uc = sunhis.loadData(variable='uc').reshape((1,)+sunic.uc.shape)
    sunic.vc = sunhis.loadData(variable='vc').reshape((1,)+sunic.vc.shape)

    print sunic.h.shape
    print sunic.T.shape

    # Load the age
    if sunhis.hasVar('agec'):
        sunic.agec = sunhis.loadData(variable='agec').reshape((1,)+sunic.agec.shape)       
        sunic.agealpha = sunhis.loadData(variable='agealpha').reshape((1,)+sunic.agealpha.shape)       

    # Write to the output file
    sunic.writeNC(icfile)
Ejemplo n.º 2
0
def sunhis2initial(hisfile, icfile):
    """
    Main function
    """

    print '#####\nCreating initial condition file (%s) from history file (%s)...' % (
        icfile, hisfile)

    # Load the history file
    sunhis = Spatial(hisfile, tstep=-1, klayer=[-99])

    # Load the initial condition object
    timeic = datetime.strftime(sunhis.time[-1], '%Y%m%d.%H%M%S')
    sunic = InitialCond(hisfile, timeic)

    # Load the last time step into each variable
    sunic.h = sunhis.loadData(variable='eta').reshape((1, sunic.h.shape))
    sunic.T = sunhis.loadData(variable='temp').reshape((1, ) + sunic.T.shape)
    sunic.S = sunhis.loadData(variable='salt').reshape((1, ) + sunic.S.shape)
    sunic.uc = sunhis.loadData(variable='uc').reshape((1, ) + sunic.uc.shape)
    sunic.vc = sunhis.loadData(variable='vc').reshape((1, ) + sunic.vc.shape)

    print sunic.h.shape
    print sunic.T.shape

    # Load the age
    if sunhis.hasVar('agec'):
        sunic.agec = sunhis.loadData(variable='agec').reshape((1, ) +
                                                              sunic.agec.shape)
        sunic.agealpha = sunhis.loadData(
            variable='agealpha').reshape((1, ) + sunic.agealpha.shape)

    # Write to the output file
    sunic.writeNC(icfile)
Ejemplo n.º 3
0
    def suntans2ic(self,hisfile,setUV=False,seth=False):
        """
        Uses data from another suntans file as initial conditions

        Data needs to be on the same grid

        """
        # Load the history file
        sunhis = Spatial(hisfile, tstep=-1, klayer=[-99])

        # Set the time step to grab from the history file
        #...
        tstep = sunhis.getTstep(self.time,self.time)
        sunhis.tstep = [tstep[0]]
        print 'Setting the intial condition with time step: %s\nfrom the file:%s'\
            %(datetime.strftime(sunhis.time[tstep[0]],\
            '%Y-%m-%d %H-%M-%S'),hisfile)

        # Npw grab each variable and save in the IC object
        if seth:
            self.h = sunhis.loadData(variable='eta').reshape((1,self.h.shape))

        if sunhis.hasVar('temp'):
            self.T = sunhis.loadData(variable='temp').reshape((1,)+self.T.shape)
        if sunhis.hasVar('salt'):
            self.S = sunhis.loadData(variable='salt').reshape((1,)+self.S.shape)

        if setUV:
            self.uc = sunhis.loadData(variable='uc').reshape((1,)+self.uc.shape)
            self.vc = sunhis.loadData(variable='vc').reshape((1,)+self.vc.shape)

        # Load the age
        if sunhis.hasVar('agec'):
            self.agec = sunhis.loadData(variable='agec').reshape((1,)+self.agec.shape)       
            self.agealpha = sunhis.loadData(variable='agealpha').reshape((1,)+self.agealpha.shape)       

        print 'Done setting initial condition data from file.'
Ejemplo n.º 4
0
# Get the flux values at the cell
face = sun.face[cellindex,:]
normal = 1.0*sun.normal[cellindex,:]
eta = eta[:,cellindex]
s_dz = s_dz[:,cellindex]
T_dz = T_dz[:,cellindex]

Mflux = Mflux[:,:,face]
Mflux*=normal
Sflux = Sflux[:,:,face]
Sflux*=normal
Tflux = Tflux[:,:,face]
Tflux*=normal

if sun.hasVar('Hs'):
    # Load the surface flux quantities
    Hs = sun.loadDataRaw(variable='Hs')
    Hsw = sun.loadDataRaw(variable='Hsw')
    Hl = sun.loadDataRaw(variable='Hl')
    Hlw = sun.loadDataRaw(variable='Hlw')

    Qs = (Hs+Hl+Hlw+Hsw)/fac

    # Surface flux contribution
    T_surf =    Qs[:,cellindex]*area # units [C m3 s-1]
    # Time-integrate
    #T_surf= T_surf[1:]
    #T_surf[0] = 0
    #T_surf = np.cumsum(T_surf*dt)
    #T_surf *= dt