Beispiel #1
0
    def create_grd_objects(self):
        # NO EDIT BELOW ==============================================================================================
        if self.compile_all is True:
            import compile
            compile.compileallgfortran()

        if self.create_atmos_forcing or self.create_ocean_forcing:
            if self.use_esmf:
                try:
                    import ESMF
                except ImportError:
                    raise ImportError("Unable to import ESMF")
                logging.info('[M2R_configRunM2R] Starting logfile for ESMF')
                ESMF.Manager(debug=True)

            # Create the grid object for the output grid
            self.grdROMS = grd.Grd("ROMS", self)
            self.grdROMS.nlevels = self.nlevels
            self.grdROMS.vstretching = self.vstretching
            self.grdROMS.vtransform = self.vtransform
            self.grdROMS.theta_s = self.theta_s
            self.grdROMS.theta_b = self.theta_b
            self.grdROMS.tcline = self.tcline
            self.grdROMS.hc = self.hc
            self.grdROMS.lonname = 'lon_rho'
            self.grdROMS.latname = 'lat_rho'

            self.grdROMS.create_object(self, self.roms_grid_path)
            self.grdROMS.getdims()

            # Create the grid object for the input grid
            self.grdMODEL = grd.Grd("FORCINGDATA", self)
            self.grdMODEL.grdType = self.grd_type
            self.grdMODEL.lonName = self.lon_name
            self.grdMODEL.latName = self.lat_name
            self.grdMODEL.depthName = self.depth_name
            self.grdMODEL.fillval = self.fillvaluein
Beispiel #2
0
    def __init__(self):
        print('\n--------------------------\n')
        print('Started ' + time.ctime(time.time()))
        os.environ['WRAP_STDERR'] = 'true'

        # EDIT ===================================================================
        # Set showprogress to "False" if you do not want to see the progress
        # indicator for horizontal interpolation.
        self.showprogress = True
        # Set compileAll to True if you want automatic re-compilation of all the
        # fortran files necessary to run model2roms. Options are "gfortran" or "ifort". Edit
        # compile.py to add other Fortran compilers.
        self.compileall = False
        # Extract time-series of data for given longitude/latitude
        self.extractstations = False
        # Define a set of longitude/latitude positions with names to extract into
        # station files (using extractStations)
        if self.extractstations:
            #  stationNames = ['NorthSea', 'Iceland', 'EastandWestGreenland', 'Lofoten', 'Georges Bank']
            #  lonlist = [2.4301, -22.6001, -47.0801, 13.3801, -67.2001]
            #  latlist = [54.5601, 63.7010, 60.4201, 67.5001, 41.6423]

            self.stationnames = ["Ytre Utsira", "Indre Utsira", "Lista"]
            self.latlist = [59.316667, 59.316667, 58.016667]
            self.lonlist = [4.800000, 4.983333, 6.533333]
            self.numberofpoints = 4 # Number of points around lat/lon to extract and average as output

        # Create the bry, init, and clim files for a given grid and input data
        self.createoceanforcing = True
        # Create atmospheric forcing for the given grid
        self.createatmosforcing = False  # currently in beta stages and unavailable
        # Create a smaller resolution grid based on your original. Decimates every second for
        # each time run
        self.decimategridfile = False
        # Write ice values to file (for Arctic regions)
        self.writeice = False
        # Write biogeochemistry values to file
        self.writebcg = False
        # ROMS sometimes requires input of ice and ssh, but if you dont have these write zero files to file
        self.set2DvarsToZero=False
        # Use ESMF for the interpolation. This requires that you have ESMF and ESMPy installed (import ESMF)
        self.useesmf = True
        # Apply filter to smooth the 2D fields after interpolation (time consuming but enhances results)
        self.usefilter = True
        # Format to write the ouput to: 'NETCDF4', 'NETCDF4_CLASSIC', 'NETCDF3_64BIT', or 'NETCDF3_CLASSIC'
        # Using NETCDF4 automatically turns on compression of files (ZLIB)
        self.myformat = 'NETCDF4'
        self.myzlib = True
        # Frequency of the input data: usually monthly
        self.timefrequencyofinputdata = "month"  # , "month", "hour"

        # IN GRIDTYPES ------------------------------------------------------------------------------
        #  Define what grid type you wnat to interpolate from (input MODEL data)
        # Options:
        # 1. SODA, 2. SODAMONTHLY, 3.WOAMONTHLY, 4. NORESM, 4. GLORYS, 5. SODA3
        self.indatatype = 'SODA3'

        # Define contact info for final NetCDF files
        self.authorname = "Trond Kristiansen"
        self.authoremail = "trond.kristiansen (at) niva.no"

        # Define what grid type you wnat to interpolate from: Can be Z for SIGMA for ROMS
        # vertical coordinate system or ZLEVEL. also define the name of the dimensions in the input files.
        # Options:
        # 1. SIGMA (not prpoerly implemented yet), 2. ZLEVEL
        self.ingridtype = "ZLEVEL"

        # Define the names of the geographical variables in the input files
        self.grdtype = 'regular'
        self.lonname = "longitude"
        self.latname = "latitude"
        self.depthname = "depth"
        self.lonname_u = "longitude"
        self.latname_u = "latitude"
        self.lonname_v = "longitude"
        self.latname_v = "latitude"
        self.timename = "time"
        self.realm = "ocean"
        self.fillvaluein = -1.e20

        # OUT GRIDTYPES ------------------------------------------------------------------------------
        # Define what grid type you wnat to interpolate to
        # Options: This is just the name of your grid used to identify your selection later
        self.outgrid = "A20" #"ROHO800"
        self.outgridtype = "ROMS"

        # Subset input data. If you have global data you may want to seubset these to speed up reading. Make
        # sure that your input data are cartesian (0-360 or -180:180, -90:90)
        self.subsetindata = False
        if self.subsetindata:
            self.subset = self.definesubsetforindata()

        # Define nmber of output depth levels
        self.nlevels = 40
        # Define the grid stretching properties (leave default if uncertain what to pick)
        self.vstretching = 4
        self.vtransform = 2
        self.theta_s = 7.0
        self.theta_b = 0.1
        self.tcline = 250.0
        self.hc = 250

        # PATH TO FORCINGDATA --------------------------------------------------------------------
        # Define the path to the input data
        self.modelpath = self.defineforcingdatapath()

        # PATH TO GRID -----------------------------------------------------------------------------
        # Define the path to the grid file
        self.romsgridpath = self.defineromsgridpath()

        # Climatology is only monthly and model2roms needs to know this
        self.isclimatology = True if self.indatatype == 'WOAMONTHLY' else False

        # DATE AND TIME DETAILS ---------------------------------------------------------
        # Define the period to create forcing for
        self.start_year = 2006
        self.end_year = 2008
        self.start_month = 1
        self.end_month = 3
        self.start_day = 15
        self.end_day = 15

        if int(calendar.monthrange(self.start_year, self.start_month)[1]) < self.start_day:
            self.start_day = int(calendar.monthrange(self.start_year, self.start_month)[1])

        if int(calendar.monthrange(self.end_year, self.end_month)[1]) < self.end_day:
            self.end_day = int(calendar.monthrange(self.end_year, self.end_month)[1])

        self.startdate = datetime(self.start_year, self.start_month, self.start_day)
        self.enddate = datetime(self.end_year, self.end_month, self.end_day)
        self.years = [self.start_year + year for year in range(self.end_year + 1 - self.start_year)]

        # DEFINE VARIABLE NAMES ---------------------------------------------------------
        # Define what and name of variables to include in the forcing files
        # -> myvars is the name model2roms uses to identify variables
        # -> varNames is the name of the variable found in the NetCDF input files

        self.globalvarnames = self.defineglobalvarnames()
        self.inputdatavarnames = self.defineinputdatavarnames()

        # NO EDIT BELOW ====================================================================================================
        if self.compileall is True:
            import compile;
            compile.compileallgfortran()

        if self.createatmosforcing or self.createoceanforcing:
            self.abbreviation = self.defineabbreviation()

            self.climname, self.initname, self.bryname = self.defineoutputfilenames()

            if self.isclimatology is True:
                self.climname = self.abbreviation + '_' + str(self.indatatype) + '_climatology.nc'

            self.showinfo()

            if self.useesmf:
                try:
                    import ESMF
                except ImportError:
                    raise ImportError("Unable to import ESMF")
                print("Starting logfile for ESMF")
                ESMF.Manager(debug=True)

            # Create the grid object for the output grid
            self.grdROMS = grd.Grd("ROMS", self)
            self.grdROMS.nlevels =self.nlevels
            self.grdROMS.vstretching = self.vstretching
            self.grdROMS.vtransform = self.vtransform
            self.grdROMS.theta_s = self.theta_s
            self.grdROMS.theta_b = self.theta_b
            self.grdROMS.tcline = self.tcline
            self.grdROMS.hc = self.hc
            self.grdROMS.lonname = 'lon_rho'
            self.grdROMS.latname = 'lat_rho'

            self.grdROMS.opennetcdf(self.romsgridpath)
            self.grdROMS.createobject(self)
            self.grdROMS.getdims()

            # Create the grid object for the input grid
            self.grdMODEL = grd.Grd("FORCINGDATA", self)
            self.grdMODEL.grdType = self.grdtype
            self.grdMODEL.lonName = self.lonname
            self.grdMODEL.latName = self.latname
            self.grdMODEL.depthName = self.depthname
            self.grdMODEL.fillval = self.fillvaluein
Beispiel #3
0
    def __init__(self):
        print('\n--------------------------\n')
        print('Started ' + time.ctime(time.time()))

        # EDIT ===================================================================
        # Set show_progress to "False" if you do not want to see the progress
        # indicator for horizontal interpolation.
        self.showprogress = True
        # Set compileAll to True if you want automatic re-compilation of all the
        # fortran files necessary to run model2roms. Options are "gfortran" or "ifort". Edit
        # compile.py to add other Fortran compilers.
        self.compileall = False
        # Extract time-series of data for given longitude/latitude
        self.extractstations = False
        # Define a set of longitude/latitude positions with names to extract into
        # station files (using extractStations)
        if self.extractstations:
            #  stationNames = ['NorthSea', 'Iceland', 'EastandWestGreenland', 'Lofoten', 'Georges Bank']
            #  lonlist = [2.4301, -22.6001, -47.0801, 13.3801, -67.2001]
            #  latlist = [54.5601, 63.7010, 60.4201, 67.5001, 41.6423]

            self.stationnames = ["Ytre Utsira", "Indre Utsira", "Lista"]
            self.latlist = [59.316667, 59.316667, 58.016667]
            self.lonliost = [4.800000, 4.983333, 6.533333]

        # Create the bry, init, and clim files for a given grid and input data
        self.createoceanforcing = True
        # Create atmospheric forcing for the given grid
        self.createatmosforcing = False  # currently in beta stages and unavailable
        # Create a smaller resolution grid based on your original. Decimates every second for
        # each time run
        self.decimategridfile = False
        # Write ice values to file (for Arctic regions)
        self.writeice = True
        # Use ESMF for the interpolation. This requires that you have ESMF and ESMPy installed (import ESMF)
        self.useesmf = True
        # Apply filter to smooth the 2D fields after interpolation (time consuming but enhances results)
        self.usefilter = True
        # Format to write the ouput to: 'NETCDF4', 'NETCDF4_CLASSIC', 'NETCDF3_64BIT', or 'NETCDF3_CLASSIC'
        # Using NETCDF4 automatically turns on compression of files (ZLIB)
        self.myformat = 'NETCDF4'
        self.myzlib = True
        # Frequency of the input data: usually monthly
        self.timefrequencyofinputdata = "month"  # , "month", "hour"

        # IN GRIDTYPES ------------------------------------------------------------------------------
        #  Define what grid type you wnat to interpolate from (input MODEL data)
        # Options:
        # 1. SODA, 2. SODAMONTHLY, 3.WOAMONTHLY, 4. NORESM, 4. GLORYS, 5. SODA3
        self.indatatype = 'SODA3'

        # Define what grid type you wnat to interpolate from: Can be Z for SIGMA for ROMS
        # vertical coordinate system or ZLEVEL. also define the name of the dimensions in the input files.
        # Options:
        # 1. SIGMA (not prpoerly implemented yet), 2. ZLEVEL
        self.ingridtype = "SIGMA"

        # Define the names of ythe geographical variables in the input files
        self.grdType = 'regular'
        self.lonName = "longitude"
        self.latName = "latitude"
        self.depthName = "depth"
        self.fill_value = -1.e+20

        # OUT GRIDTYPES ------------------------------------------------------------------------------
        # Define what grid type you wnat to interpolate to
        # Options: This is just the name of your grid used to identify your selection later
        self.outgrid = "ROHO800"
        self.outgridtype = "ROMS"

        # Subset input data. If you have global data you may want to seubset these to speed up reading. Make
        # sure that your input data are cartesian (0-360 or -180:180, -90:90)
        self.subsetindata = False
        if self.subsetindata:
            self.subset = self.definesubsetforindata()

        # Define nmber of output depth levels
        self.nlevels = 40
        # Define the grid stretching properties (leave default if uncertain what to pick)
        self.vstretching = 4
        self.vtransform = 2
        self.theta_s = 7.0
        self.theta_b = 0.1
        self.tcline = 250.0
        self.hc = 250

        # PATH TO FORCINGDATA --------------------------------------------------------------------
        # Define the path to the input data
        self.modelpath = self.defineforcingdatapath()
        print("model path ", self.modelpath)

        # PATH TO GRID -----------------------------------------------------------------------------
        # Define the path to the grid file
        self.romsgridpath = self.defineromsgridpath()

        # Climatology is only monthly and model2roms needs to know this
        self.isclimatology = True if self.indatatype == 'WOAMONTHLY' else False

        # DATE AND TIME DETAILS ---------------------------------------------------------
        # Define the period to create forcing for
        self.start_year = 2013
        self.end_year = 2013
        self.start_month = 1
        self.end_month = 12
        self.start_day = 1
        self.end_day = 1

        if int(calendar.monthrange(self.start_year,
                                   self.start_month)[1]) < self.start_day:
            self.start_day = int(
                calendar.monthrange(self.start_year, self.start_month)[1])

        if int(calendar.monthrange(self.end_year,
                                   self.end_month)[1]) < self.end_day:
            self.end_day = int(
                calendar.monthrange(self.end_year, self.end_month)[1])

        print "hello, startdate here"
        self.startdate = datetime(self.start_year, self.start_month,
                                  self.start_day)
        self.enddate = datetime(self.end_year, self.end_month, self.end_day)
        self.years = [
            self.start_year + year
            for year in range(self.end_year + 1 - self.start_year)
        ]

        # DEFINE VARIABLE NAMES ---------------------------------------------------------
        # Define what and name of variables to include in the forcing files
        # -> myvars is the name model2roms uses to identify variables
        # -> varNames is the name of the variable found in the NetCDF input files

        self.globalvarnames = self.defineglobalvarnames()
        self.inputdatavarnames = self.defineinputdatavarnames()

        # NO EDIT BELOW ====================================================================================================
        if self.compileall is True:
            import compile
            compile.compileallgfortran()

        if self.createatmosforcing or self.createoceanforcing:
            self.abbreviation = self.defineabbreviation()

            self.climname, self.initname, self.bryname = self.defineoutputfilenames(
            )

            if self.isclimatology is True:
                self.climname = self.abbreviation + '_' + str(
                    self.indatatype) + '_climatology.nc'

            self.showinfo()

            if self.useesmf:
                import ESMF
                print("Starting logfile for ESMF")
                manager = ESMF.Manager(debug=True)

            # Create the grid object for the output grid
            self.grdROMS = grd.Grd("ROMS", self.outgridtype, self.useesmf,
                                   'ocean', self.outgrid)
            self.grdROMS.Nlevels = self.nlevels
            self.grdROMS.vstretching = self.vstretching
            self.grdROMS.vtransform = self.vtransform
            self.grdROMS.theta_s = self.theta_s
            self.grdROMS.theta_b = self.theta_b
            self.grdROMS.Tcline = self.tcline
            self.grdROMS.hc = self.hc
            self.grdROMS.vars = self.inputdatavarnames
            self.grdROMS.varNames = self.globalvarnames
            self.grdROMS.lonName = 'lon_rho'
            self.grdROMS.latName = 'lat_rho'

            self.grdROMS.openNetCDF(self.romsgridpath)
            self.grdROMS.createObject()
            self.grdROMS.getDims()

            # Create the grid object for the input grid
            self.grdMODEL = grd.Grd("FORCINGDATA", self.outgridtype,
                                    self.useesmf, 'ocean', self.outgrid)
            self.grdMODEL.grdType = self.grdType
            self.grdMODEL.lonName = self.lonName
            self.grdMODEL.latName = self.latName
            self.grdMODEL.depthName = self.depthName
            self.grdMODEL.fill_value = self.fill_value

            #if self.createoceanforcing:
            #    model2roms.convertMODEL2ROMS()

            #    clim2bry.writeBry(grdROMS, start_year, bryName, climname, writeice, indatatype, myformat)

            #if self.createAtmosForcing:
            #    atmosForcing.createAtmosFileUV(grdROMS, modelpath, atmospath, startdate, enddate, useESMF,
            #                                   myformat, abbreviation, indatatype, gridtype, show_progress)

        if self.decimategridfile:
            decimateGrid.createGrid(
                grdROMS,
                "/Users/trondkr/Projects/KINO/GRID/kino_1600m_18072015.nc",
                "/Users/trondkr/Projects/KINO/GRID/kino_1600m_18072015v2.nc",
                2)

        if self.extractstations:
            print(
                "Running in station mode and extracting pre-defined station locations"
            )
            IOstation.getStationData(years, IDS, modelpath, latlist, lonlist,
                                     stationNames)

        print('Finished ' + time.ctime(time.time()))
Beispiel #4
0
    def __init__(self):
        print('\n--------------------------\n')
        print('Started ' + time.ctime(time.time()))
        os.environ['WRAP_STDERR'] = 'true'

        # EDIT ===================================================================
        # Set showprogress to "False" if you do not want to see the progress
        # indicator for horizontal interpolation.
        self.showprogress = True
        # Set compileAll to True if you want automatic re-compilation of all the
        # fortran files necessary to run model2roms. Options are "gfortran" or "ifort". Edit
        # compile.py to add other Fortran compilers.
        self.compileall = False
        # Extract time-series of data for given longitude/latitude
        self.extractstations = False
        # Define a set of longitude/latitude positions with names to extract into
        # station files (using extractStations)
        if self.extractstations:
            #  stationNames = ['NorthSea', 'Iceland', 'EastandWestGreenland', 'Lofoten', 'Georges Bank']
            #  lonlist = [2.4301, -22.6001, -47.0801, 13.3801, -67.2001]
            #  latlist = [54.5601, 63.7010, 60.4201, 67.5001, 41.6423]

            self.stationnames = ["Ytre Utsira", "Indre Utsira", "Lista"]
            self.latlist = [59.316667, 59.316667, 58.016667]
            self.lonlist = [4.800000, 4.983333, 6.533333]
            self.numberofpoints = 4  # Number of points around lat/lon to extract and average as output

        # Create the bry, init, and clim files for a given grid and input data
        self.createoceanforcing = True
        # Create atmospheric forcing for the given grid
        self.createatmosforcing = False  # currently in beta stages
        # Create a smaller resolution grid based on your original. Decimates every second for
        # each time run
        self.decimategridfile = False
        # Write ice values to file (for Arctic regions)
        self.writeice = True
        # Write biogeochemistry values to file
        self.writebcg = False
        # ROMS sometimes requires input of ice and ssh, but if you dont have these write zero files to file
        self.set2DvarsToZero = True
        # Use ESMF for the interpolation. This requires that you have ESMF and ESMPy installed (import ESMF)
        self.useesmf = True
        # Apply filter to smooth the 2D fields after interpolation (time consuming but enhances results)
        self.usefilter = True
        # Format to write the ouput to: 'NETCDF4', 'NETCDF4_CLASSIC', 'NETCDF3_64BIT', or 'NETCDF3_CLASSIC'
        # Using NETCDF4 automatically turns on compression of files (ZLIB)
        self.myformat = 'NETCDF4'
        self.myzlib = True
        # Frequency of the input data: usually monthly
        self.timefrequencyofinputdata = "5days"  # , "month", "hour", "5days"

        # IN GRIDTYPES ------------------------------------------------------------------------------
        #  Define what grid type you wnat to interpolate from (input MODEL data)
        # Options:
        # 1. SODA, 2. SODAMONTHLY, 3.WOAMONTHLY, 4. NORESM, 4. GLORYS, 5. SODA3, 6. SODA3_5DAY
        self.ocean_indata_type = 'SODA3_5DAY'
        self.atmosindatatype = 'ERA5'

        # Define contact info for final NetCDF files
        self.authorname = "Trond Kristiansen"
        self.authoremail = "trond.kristiansen (at) niva.no"

        # Define what grid type you wnat to interpolate from: Can be Z for SIGMA for ROMS
        # vertical coordinate system or ZLEVEL. also define the name of the dimensions in the input files.
        # Options:
        # 1. SIGMA (not properly implemented yet), 2. ZLEVEL
        self.ingridtype = "ZLEVEL"

        # Define the names of the geographical variables in the input files. These may
        # differ depending how the variable is located in a grid (e.g. Arakawa C grid - ROMS). In
        # SODA 3.3.1 the u and v location is defined by xu_ocean,  yu_ocean while temperature is
        # located in xt_ocean, yt_ocean.
        self.grdtype = 'regular'
        self.lonname = "longitude"
        self.latname = "latitude"
        self.depthname = "depth"
        self.lonname_u = "longitude"
        self.latname_u = "latitude"
        self.lonname_v = "longitude"
        self.latname_v = "latitude"

        if self.ocean_indata_type == 'SODA3_5DAY':
            self.lonname = "xt_ocean"
            self.latname = "yt_ocean"
            self.depthname = "st_ocean"
            self.lonname_u = "xu_ocean"
            self.latname_u = "yu_ocean"
            self.lonname_v = "xu_ocean"
            self.latname_v = "yu_ocean"
            self.timeobject = []

        self.timename = "time"
        self.realm = "ocean"
        self.fillvaluein = -1.e20

        # OUT GRIDTYPES ------------------------------------------------------------------------------
        # Define what grid type you want to interpolate to
        # Options: This is just the name of your grid used to identify your selection later
        self.outgrid = 'ROHO800'  # "ROHO800", "A20"
        self.outgridtype = "ROMS"

        # Subset input data. If you have global data you may want to seubset these to speed up reading. Make
        # sure that your input data are cartesian (0-360 or -180:180, -90:90)
        self.subset_indata = False
        if self.subset_indata:
            self.subset = self.definesubsetforindata()

        # Define nmber of output depth levels
        self.nlevels = 40
        # Define the grid stretching properties (leave default if uncertain what to pick)
        self.vstretching = 4
        self.vtransform = 2
        self.theta_s = 7.0
        self.theta_b = 0.1
        self.tcline = 250.0
        self.hc = 250

        # PATH TO FORCING DATA --------------------------------------------------------------------
        # Define the path to the input data
        self.modelpath = self.define_ocean_forcing_data_path()
        self.atmosphericpath = self.define_atmospheric_forcing_path()

        # PATH TO GRID -----------------------------------------------------------------------------
        # Define the path to the grid file
        self.romsgridpath = self.define_roms_grid_path()

        # Climatology is only monthly and model2roms needs to know this
        self.isclimatology = True if self.ocean_indata_type == 'WOAMONTHLY' else False

        # DATE AND TIME DETAILS ---------------------------------------------------------
        # Define the period to create forcing for
        self.start_year = 2002
        self.end_year = 2003
        self.start_month = 5
        self.end_month = 12
        self.start_day = 15
        self.end_day = 31

        if int(calendar.monthrange(self.start_year,
                                   self.start_month)[1]) < self.start_day:
            self.start_day = int(
                calendar.monthrange(self.start_year, self.start_month)[1])

        if int(calendar.monthrange(self.end_year,
                                   self.end_month)[1]) < self.end_day:
            self.end_day = int(
                calendar.monthrange(self.end_year, self.end_month)[1])

        self.startdate = datetime(self.start_year, self.start_month,
                                  self.start_day)
        self.enddate = datetime(self.end_year, self.end_month, self.end_day)
        self.years = [
            self.start_year + year
            for year in range(self.end_year + 1 - self.start_year)
        ]

        # DEFINE VARIABLE NAMES ---------------------------------------------------------
        # Define what and name of variables to include in the forcing files
        # -> myvars is the name model2roms uses to identify variables
        # -> varNames is the name of the variable found in the NetCDF input files

        self.globalvarnames = self.define_global_varnames()
        self.inputdatavarnames = self.define_input_data_varnames()

        # NO EDIT BELOW ====================================================================================================
        if self.compileall is True:
            import compile
            compile.compileallgfortran()

        if self.createatmosforcing or self.createoceanforcing:
            self.abbreviation = self.define_abbreviation()

            self.clim_name, self.init_name, self.bry_name = self.define_output_filenames(
            )

            if self.isclimatology is True:
                self.clim_name = self.abbreviation + '_' + str(
                    self.ocean_indata_type) + '_climatology.nc'

            self.showinfo()

            if self.useesmf:
                try:
                    import ESMF
                except ImportError:
                    raise ImportError("Unable to import ESMF")
                print("Starting logfile for ESMF")
                ESMF.Manager(debug=True)

            # Create the grid object for the output grid
            self.grdROMS = grd.Grd("ROMS", self)
            self.grdROMS.nlevels = self.nlevels
            self.grdROMS.vstretching = self.vstretching
            self.grdROMS.vtransform = self.vtransform
            self.grdROMS.theta_s = self.theta_s
            self.grdROMS.theta_b = self.theta_b
            self.grdROMS.tcline = self.tcline
            self.grdROMS.hc = self.hc
            self.grdROMS.lonname = 'lon_rho'
            self.grdROMS.latname = 'lat_rho'

            self.grdROMS.opennetcdf(self.romsgridpath)
            self.grdROMS.createobject(self)
            self.grdROMS.getdims()

            # Create the grid object for the input grid
            self.grdMODEL = grd.Grd("FORCINGDATA", self)
            self.grdMODEL.grdType = self.grdtype
            self.grdMODEL.lonName = self.lonname
            self.grdMODEL.latName = self.latname
            self.grdMODEL.depthName = self.depthname
            self.grdMODEL.fillval = self.fillvaluein
Beispiel #5
0
    def __init__(self):
        print('model2roms started ' + time.ctime(time.time()))
        os.environ['WRAP_STDERR'] = 'true'

        # Set compileAll to True if you want automatic re-compilation of all the
        # fortran files necessary to run model2roms. Options are "gfortran" or "ifort". Edit
        # compile.py to add other Fortran compilers.
        self.compileall = False
         # Create the bry, init, and clim files for a given grid and input data
        self.createoceanforcing = True
        # Create atmospheric forcing for the given grid
        self.createatmosforcing = False  # currently in beta stages and unavailable
        # Write ice values to file (for Arctic regions)
        self.writeice = True
        # ROMS sometimes requires input of ice and ssh, but if you dont have these write zero files to file
        self.set2DvarsToZero= False
        # Use ESMF for the interpolation. This requires that you have ESMF and ESMPy installed (import ESMF)
        self.useesmf = True
        # Apply filter to smooth the 2D fields after interpolation (time consuming but enhances results)
        self.usefilter = False
        # Format to write the ouput to: 'NETCDF4', 'NETCDF4_CLASSIC', 'NETCDF3_64BIT', or 'NETCDF3_CLASSIC'
        # Using NETCDF4 automatically turns on compression of files (ZLIB)
        self.myformat = 'NETCDF4'
        self.myzlib = True
        # Frequency of the input data: usually monthly
        self.timefrequencyofinputdata = "day"  # , "month", "hour"
        #  Define what grid type you wnat to interpolate from (input MODEL data)
        # Options:
        # 1. SODA3, GLORYS
        self.indatatype = 'GLORYS'
        # Define the names of the geographical variables in the input files
        if self.indatatype == "SODA3":
            self.grdtype     = 'regular'
            self.lonname     = "xt_ocean"
            self.latname     = "yt_ocean"
            self.depthname   = "st_ocean"
            self.lonname_u   = "xu_ocean"
            self.latname_u   = "yu_ocean"
            self.lonname_v   = "xu_ocean"
            self.latname_v   = "yu_ocean"
            self.timename    = "time"
            self.realm       = "ocean"
            self.fillvaluein = -1.e20
        if self.indatatype == "GLORYS":   
            self.grdtype     = 'regular'
            self.lonname     = "longitude"
            self.latname     = "latitude"
            self.depthname   = "depth"
            self.lonname_u   = "longitude"
            self.latname_u   = "latitude"
            self.lonname_v   = "longitude"
            self.latname_v   = "latitude"
            self.timename    = "time"
            self.realm       = "ocean"
            self.fillvaluein = -1.e20
        # Define contact info for final NetCDF files
        self.authorname  = "Ueslei Adriano Sutil"
        self.authoremail = "ueslei.sutil (at) inpe.br"
        # Define what grid type you want to interpolate from: Can be Z for SIGMA for ROMS
        # vertical coordinate system or ZLEVEL. Also define the name of the dimensions in the input files.
        # Options:
        # 1. SIGMA (not propoerly implemented yet), 2. ZLEVEL
        self.ingridtype = "ZLEVEL"
        # Define what grid type you want to interpolate to
        # Options: This is just the name of your grid used to identify your selection later
        self.outgrid     = "antarctic"
        self.outgridtype = "ROMS"
        # Define nmber of output depth levels
        self.nlevels     = 30
        # Define the grid stretching properties (leave default if uncertain what to pick)
        self.vstretching = 4
        self.vtransform  = 2
        self.theta_s     = 7.0
        self.theta_b     = 0.2
        self.tcline      = 20
        self.hc          = 20
        # Define the period to create forcing for
        self.start_year  = 2021
        self.end_year    = 2021
        self.start_month = 1
        self.end_month   = 1
        self.start_day   = 17
        self.end_day     = 18 

        if int(calendar.monthrange(self.start_year, self.start_month)[1]) < self.start_day:
            self.start_day = int(calendar.monthrange(self.start_year, self.start_month)[1])

        if int(calendar.monthrange(self.end_year, self.end_month)[1]) < self.end_day:
            self.end_day = int(calendar.monthrange(self.end_year, self.end_month)[1])

        self.startdate = datetime(self.start_year, self.start_month, self.start_day)
        self.enddate   = datetime(self.end_year, self.end_month, self.end_day)
        self.years     = [self.start_year + year for year in range(self.end_year + 1 - self.start_year)]
        
        self.globalvarnames    = self.defineglobalvarnames()
        self.inputdatavarnames = self.defineinputdatavarnames()
    
        self.modelpath    = self.defineforcingdatapath()
        self.romsgridpath = self.defineromsgridpath()

        if self.compileall is True:
            import compile;
            compile.compileallgfortran()

        if self.createatmosforcing or self.createoceanforcing:
            self.abbreviation = self.defineabbreviation()

            self.climname, self.initname, self.bryname = self.defineoutputfilenames()

            self.showinfo()

            if self.useesmf:
                try:
                    import ESMF
                except ImportError:
                    raise ImportError("Unable to import ESMF")
                ESMF.Manager(debug=True)

            # Create the grid object for the output grid
            self.grdROMS             = grd.Grd("ROMS", self)
            self.grdROMS.nlevels     = self.nlevels
            self.grdROMS.vstretching = self.vstretching
            self.grdROMS.vtransform  = self.vtransform
            self.grdROMS.theta_s     = self.theta_s
            self.grdROMS.theta_b     = self.theta_b
            self.grdROMS.tcline      = self.tcline
            self.grdROMS.hc          = self.hc
            self.grdROMS.lonname     = 'lon_rho'
            self.grdROMS.latname     = 'lat_rho'

            self.grdROMS.opennetcdf(self.romsgridpath)
            self.grdROMS.createobject(self)
            self.grdROMS.getdims()

            # Create the grid object for the input grid
            self.grdMODEL           = grd.Grd("FORCINGDATA", self)
            self.grdMODEL.grdType   = self.grdtype
            self.grdMODEL.lonName   = self.lonname
            self.grdMODEL.latName   = self.latname
            self.grdMODEL.depthName = self.depthname
            self.grdMODEL.fillval   = self.fillvaluein