コード例 #1
0
def prep_cmor():
    cmor.setup(inpath=ipth,set_verbosity=cmor.CMOR_QUIET, netcdf_file_action = cmor.CMOR_REPLACE, exit_control = cmor.CMOR_EXIT_ON_MAJOR);
    cmor.dataset(
        outpath = opth,
        experiment_id = "lgm",
        institution = "GICC (Generic International Climate Center, Geneva, Switzerland)",
        source = "GICCM1 (2002): atmosphere:  GICAM3 (gicam_0_brnchT_itea_2, T63L32); ocean: MOM (mom3_ver_3.5.2, 2x3L15); sea ice: GISIM4; land: GILSM2.5",
        calendar = "standard",
        realization = 1,
        contact = "Rusty Koder (koder@middle_earth.net)",
        history = "Output from archive/giccm_03_std_2xCO2_2256.",
        comment = "Equilibrium reached after 30-year spin-up after which data were output starting with nominal date of January 2030",
        references = "Model described by Koder and Tolkien (J. Geophys. Res., 2001, 576-591).  Also see http://www.GICC.su/giccm/doc/index.html  2XCO2 simulation described in Dorkey et al. '(Clim. Dyn., 2003, 323-357.)",
        leap_year=0,
        leap_month=0,
        institute_id="PCMDI",
        month_lengths=None,model_id="GICCM1",forcing="Nat",
        parent_experiment_id="N/A",
        parent_experiment_rip="N/A",
        branch_time=0.)
    
    tables=[]
    a = cmor.load_table("Tables/CMIP5_Omon")
    tables.append(a)
    tables.append(cmor.load_table("Tables/CMIP5_Amon"))
    return
コード例 #2
0
def path_test():
    cmor.setup(inpath='Test',netcdf_file_action=cmor.CMOR_REPLACE)

    cmor.dataset('mytest2010030812', 'ukmo', 'HadCM3', '360_day',
                 institute_id="PCMDI",
                 model_id='HadCM3',forcing='co2')
    
    table='CMIP5_Amon_YYYYMMDDHH'
    cmor.load_table(table)
    axes = [ {'table_entry': 'time',
              'units': 'days since 2000-01-01 00:00:00',
              'coord_vals': [15],
              'cell_bounds': [0, 30]
              },
             {'table_entry': 'latitude',
              'units': 'degrees_north',
              'coord_vals': [0],
              'cell_bounds': [-1, 1]},             
             {'table_entry': 'longitude',
              'units': 'degrees_east',
              'coord_vals': [90],
              'cell_bounds': [89, 91]},
             ]
              
    axis_ids = list()
    for axis in axes:
        axis_id = cmor.axis(**axis)
        axis_ids.append(axis_id)
    varid = cmor.variable('ts', 'K', axis_ids)
    cmor.write(varid, [273])
    path=cmor.close(varid, file_name=True)

    print "Saved file: ",path
コード例 #3
0
ファイル: jamie_hybrid_height.py プロジェクト: AZed/uvcdat
def main():

    cmor.setup(inpath='Tables',
               netcdf_file_action = cmor.CMOR_REPLACE)
    cmor.dataset('pre-industrial control', 'mohc', 'HadGEM2: source',
                 '360_day',
                 institute_id = 'ukmo',
                 model_id = 'HadGEM2',
                 history = 'some global history',
                 forcing = 'N/A',
                 parent_experiment_id = 'N/A',
                 parent_experiment_rip = 'N/A',
                 branch_time = 0.,
                 contact = 'bob')
 
    table = 'CMIP5_6hrLev'
    cmor.load_table(table)
    axes = [ {'table_entry': 'time1',
              'units': 'days since 2000-01-01 00:00:00',
              },
             {'table_entry': 'latitude',
              'units': 'degrees_north',
              'coord_vals': [0],
              'cell_bounds': [-1, 1]},             
             {'table_entry': 'longitude',
              'units': 'degrees_east',
              'coord_vals': [90],
              'cell_bounds': [89, 91]},
             {'table_entry': 'hybrid_height',
              'coord_vals': [0, 1],
              'cell_bounds': [[0., 0.5], [0.5, 1.]],
              'units': 'm',
              },
             ]

    values = numpy.array([1.2,1.2], numpy.float32)
    numpy.reshape(values, (2,1,1,1))
    axis_ids = list()
    for axis in axes:
        axis_id = cmor.axis(**axis)
        axis_ids.append(axis_id)

    print 'cmor.axis calls complete'

    cmor.zfactor(axis_ids[3], 'b', '', axis_ids[3:4], 'd', [0., 0.5], [[0., 0.25], [0.25, 1.]])
    cmor.zfactor(axis_ids[3], 'orog', 'm', axis_ids[1:3], 'd', [[0.]]) 
    print 'cmor.zfactor calls complete'
    varid = cmor.variable('ua',
                          'm s-1',
                          axis_ids,
                          missing_value = -99
                          )

    print 'cmor.variable call complete'
    
    cmor.write(varid, values, time_vals = [6.0])

    print 'cmor.write call complete'

    cmor.close()
コード例 #4
0
ファイル: test_python_fx.py プロジェクト: chaosphere2112/cmor
def test_mode(mode):
    cmor.setup(inpath="Tables", netcdf_file_action=mode)
    cmor.dataset(
        "pre-industrial control",
        "ukmo",
        "HadCM3",
        "360_day",
        institute_id="ukmo",
        model_id="HadCM3",
        forcing="TO",
        contact="Derek Jeter",
        history="some global history",
        parent_experiment_id="lgm",
        parent_experiment_rip="r1i1p1",
        branch_time=0,
    )

    table = "CMIP5_fx"
    cmor.load_table(table)
    axes = [
        {"table_entry": "latitude", "units": "degrees_north", "coord_vals": [0], "cell_bounds": [-1, 1]},
        {"table_entry": "longitude", "units": "degrees_east", "coord_vals": [90], "cell_bounds": [89, 91]},
    ]
    values = numpy.array([5000], numpy.float32)
    axis_ids = list()

    for axis in axes:
        axis_id = cmor.axis(**axis)
        axis_ids.append(axis_id)
    for var, units in (("deptho", "m"),):
        varid = cmor.variable(var, units, axis_ids, history="variable history")
        cmor.write(varid, values)
    fnm = cmor.close(varid, file_name=True)
    cmor.close()
    return fnm
コード例 #5
0
def prep_cmor():
    cmor.setup(inpath=ipth,
               set_verbosity=cmor.CMOR_QUIET,
               netcdf_file_action=cmor.CMOR_REPLACE,
               exit_control=cmor.CMOR_EXIT_ON_MAJOR)
    cmor.dataset(
        outpath=opth,
        experiment_id="lgm",
        institution=
        "GICC (Generic International Climate Center, Geneva, Switzerland)",
        source=
        "GICCM1 (2002): atmosphere:  GICAM3 (gicam_0_brnchT_itea_2, T63L32); ocean: MOM (mom3_ver_3.5.2, 2x3L15); sea ice: GISIM4; land: GILSM2.5",
        calendar="standard",
        realization=1,
        contact="Rusty Koder (koder@middle_earth.net)",
        history="Output from archive/giccm_03_std_2xCO2_2256.",
        comment=
        "Equilibrium reached after 30-year spin-up after which data were output starting with nominal date of January 2030",
        references=
        "Model described by Koder and Tolkien (J. Geophys. Res., 2001, 576-591).  Also see http://www.GICC.su/giccm/doc/index.html  2XCO2 simulation described in Dorkey et al. '(Clim. Dyn., 2003, 323-357.)",
        leap_year=0,
        leap_month=0,
        institute_id="PCMDI",
        month_lengths=None,
        model_id="GICCM1",
        forcing="Nat",
        parent_experiment_id="N/A",
        parent_experiment_rip="N/A",
        branch_time=0.)

    tables = []
    a = cmor.load_table("Tables/CMIP5_Omon")
    tables.append(a)
    tables.append(cmor.load_table("Tables/CMIP5_Amon"))
    return
コード例 #6
0
def main():

    cmor.setup(inpath='Tables', netcdf_file_action=cmor.CMOR_REPLACE_3)
    cmor.dataset('pre-industrial control',
                 'ukmo',
                 'HadCM3',
                 '360_day',
                 institute_id='ukmo',
                 model_id='HadCM3',
                 history='some global history',
                 forcing='N/A',
                 parent_experiment_id='N/A',
                 parent_experiment_rip='N/A',
                 branch_time=0.,
                 contact='bob')

    table = 'CMIP5_Amon'
    cmor.load_table(table)
    axes = [
        {
            'table_entry': 'time',
            'units': 'days since 2000-01-01 00:00:00',
        },
        {
            'table_entry': 'latitude',
            'units': 'degrees_north',
            'coord_vals': [0],
            'cell_bounds': [-1, 1]
        },
        {
            'table_entry': 'longitude',
            'units': 'degrees_east',
            'coord_vals': [90],
            'cell_bounds': [89, 91]
        },
    ]

    values = numpy.array([1.], numpy.float32) + 200
    axis_ids = list()
    for axis in axes:
        axis_id = cmor.axis(**axis)
        axis_ids.append(axis_id)

    for var, units, positive in (
        ('ts', 'K', ''),
        ('rsut', 'W m-2', 'up'),
        ('rlut', 'W m-2', 'down'),
    ):
        varid = cmor.variable(var,
                              units,
                              axis_ids,
                              history='variable history',
                              missing_value=-99,
                              positive=positive)
        cmor.write(varid, values, time_vals=[15], time_bnds=[[0, 30]])

    cmor.close()
コード例 #7
0
def main():
    
    cmor.setup(inpath='/git/cmip5-cmor-tables/Tables',
               netcdf_file_action = cmor.CMOR_REPLACE_3)
    cmor.dataset('pre-industrial control', 'ukmo', 'HadCM3', '360_day',
                 institute_id = 'ukmo',
                 model_id = 'HadCM3',
                 history = 'some global history',
                 forcing = 'N/A',
                 parent_experiment_id = 'N/A',
                 parent_experiment_rip = 'N/A',
                 branch_time = 0,
                 contact = 'brian clough')
 
    table = 'CMIP5_Oclim'
    cmor.load_table(table)
    axes = [ {'table_entry': 'time2',
              'units': 'days since 1850-01-01 00:00:00',
              'coord_vals' : [15.5, 45,],
              'cell_bounds':[[0,396],[31,424]]
              },
             {'table_entry': 'depth_coord',
              'units': 'm',
              'coord_vals': [5000., 3000., 2000., 1000.],
              'cell_bounds': [ 5000., 3000., 2000., 1000.,0]},
             {'table_entry': 'latitude',
              'units': 'degrees_north',
              'coord_vals': [0],
              'cell_bounds': [-1, 1]},             
             {'table_entry': 'longitude',
              'units': 'degrees_east',
              'coord_vals': [90],
              'cell_bounds': [89, 91]},
             ]


    axis_ids = list()
    for axis in axes:
        print 'doing:',axis
        axis_id = cmor.axis(**axis)
        axis_ids.append(axis_id)

    for var, units, value in (('difvso', 'm2 s-1', 274.),):
        values = numpy.ones(map(lambda x: len(x["coord_vals"]),axes))*value
        values=values.astype("f")
        varid = cmor.variable(var,
                              units,
                              axis_ids,
                              history = 'variable history',
                              missing_value = -99
                              )
        cmor.write(varid, values)

    cmor.close()
コード例 #8
0
ファイル: test_python_clim_bounds.py プロジェクト: PCMDI/cmor
def main():

    cmor.setup(inpath='/git/cmip5-cmor-tables/Tables',
               netcdf_file_action=cmor.CMOR_REPLACE_3)
    cmor.dataset('pre-industrial control', 'ukmo', 'HadCM3', '360_day',
                 institute_id='ukmo',
                 model_id='HadCM3',
                 history='some global history',
                 forcing='N/A',
                 parent_experiment_id='N/A',
                 parent_experiment_rip='N/A',
                 branch_time=0,
                 contact='brian clough')

    table = 'CMIP5_Oclim'
    cmor.load_table(table)
    axes = [{'table_entry': 'time2',
             'units': 'days since 2000-01-01 00:00:00',
             },
            {'table_entry': 'depth_coord',
             'units': 'm',
             'coord_vals': [500, 1000.],
             'cell_bounds': [0., 750., 1200.]},
            {'table_entry': 'latitude',
             'units': 'degrees_north',
             'coord_vals': [0],
             'cell_bounds': [-1, 1]},
            {'table_entry': 'longitude',
             'units': 'degrees_east',
             'coord_vals': [90],
             'cell_bounds': [89, 91]},
            ]

    axis_ids = list()
    for axis in axes:
        print('doing:', axis)
        axis_id = cmor.axis(**axis)
        axis_ids.append(axis_id)

    for var, units, value in (('tnpeot', 'W m-2', 274),):
        values = numpy.array([value, ] *
                             len(axes[1]['coord_vals']), numpy.float32)
        varid = cmor.variable(var,
                              units,
                              axis_ids,
                              history='variable history',
                              missing_value=-99
                              )
        for i in range(12):
            cmor.write(varid, values, time_vals=[
                       30 * i + 15], time_bnds=[[30 * i, 360 + 30 * (i + 1)]])

    cmor.close()
コード例 #9
0
def main():

    cmor.setup(inpath='Tables', netcdf_file_action=cmor.CMOR_REPLACE)
    cmor.dataset('historical',
                 'ukmo',
                 'HadCM3',
                 '360_day',
                 institute_id='ukmo',
                 forcing='SO',
                 model_id='HadCM3',
                 contact="Dusty Baker (even though he was a Dodgers",
                 parent_experiment_rip="r1i3p2",
                 parent_experiment_id="lgm",
                 branch_time=0)

    table = 'CMIP5_Amon'
    cmor.load_table(table)
    axes = [
        {
            'table_entry': 'time',
            'units': 'days since 2000-01-01 00:00:00',
        },
        {
            'table_entry': 'latitude',
            'units': 'degrees_north',
            'coord_vals': [0],
            'cell_bounds': [-1, 1]
        },
        {
            'table_entry': 'longitude',
            'units': 'degrees_east',
            'coord_vals': [90],
            'cell_bounds': [89, 91]
        },
    ]

    axis_ids = list()
    for axis in axes:
        axis_id = cmor.axis(**axis)
        axis_ids.append(axis_id)

    for var, units, val in (('ts', 'K', 278), ('ps', 'hPa', 974.2)):
        varid = cmor.variable(
            var,
            units,
            axis_ids,
        )

        values = numpy.array([val], numpy.float32)
        cmor.write(varid, values, time_vals=[15], time_bnds=[[0, 30]])

    cmor.close()
コード例 #10
0
ファイル: test_python_jamie_8.py プロジェクト: AZed/uvcdat
def cmor_ini():
    cmor.setup(inpath='Tables',
               netcdf_file_action = cmor.CMOR_REPLACE)
    cmor.dataset('pre-industrial control', 'mohc', 'HadGEM2: source',
                 '360_day',
                 institute_id = 'ukmo',
                 model_id = 'HadGEM2',
                 history = 'some global history',
                 forcing = 'N/A',
                 parent_experiment_id = 'N/A',
                 parent_experiment_rip = 'N/A',
                 branch_time = 0.,
                 contact = 'bob')
コード例 #11
0
ファイル: test_python_jamie_10.py プロジェクト: imclab/cmor
def main():
    
    cmor.setup(inpath='Tables',
               netcdf_file_action = cmor.CMOR_REPLACE_3)
    cmor.dataset('pre-industrial control', 'ukmo', 'HadCM3', '360_day',
                 institute_id = 'ukmo',
                 model_id = 'HadCM3',
                 history = 'some global history',
                 forcing = 'N/A',
                 parent_experiment_id = 'N/A',
                 parent_experiment_rip = 'N/A',
                 branch_time = 0,
                 contact = 'brian clough')
 
    table = 'CMIP5_Amon'
    cmor.load_table(table)
    axes = [ {'table_entry': 'time',
              'units': 'days since 2000-01-01 00:00:00',
              },
             {'table_entry': 'plevs',
              'units': 'Pa',
              'coord_vals': [100000., 92500., 85000., 70000., 60000., 50000., 40000., 30000., 25000., 20000., 15000., 10000., 7000., 5000., 3000., 2000., 1000.]},
             {'table_entry': 'latitude',
              'units': 'degrees_north',
              'coord_vals': [0],
              'cell_bounds': [-1, 1]},             
             {'table_entry': 'longitude',
              'units': 'degrees_east',
              'coord_vals': [90],
              'cell_bounds': [89, 91]},
             ]


    axis_ids = list()
    for axis in axes:
        print 'doing:',axis
        axis_id = cmor.axis(**axis)
        axis_ids.append(axis_id)

    for var, units, value in (('ta', 'K', 274), ('ua', 'm s-1', 10)):
        values = numpy.array([value,]*len(axes[1]['coord_vals']), numpy.float32)
        varid = cmor.variable(var,
                              units,
                              axis_ids,
                              history = 'variable history',
                              missing_value = -99
                              )
        cmor.set_variable_attribute(varid, 'cell_measures', 'BLABLABLA')
        cmor.write(varid, values, time_vals = [15], time_bnds = [ [0,30] ])

    cmor.close()
コード例 #12
0
def cmor_initialisation():
    cmor.setup(inpath='/git/cmip5-cmor-tables/Tables',
               netcdf_file_action=cmor.CMOR_REPLACE_3,
               create_subdirectories=0)
    cmor.dataset('pre-industrial control', 'ukmo', 'HadCM3', '360_day',
                 institute_id='ukmo',
                 model_id='HadCM3',
                 history='some global history',
                 forcing='N/A',
                 parent_experiment_id='N/A',
                 parent_experiment_rip='N/A',
                 branch_time=0.,
                 contact='bob',
                 outpath='./out')
コード例 #13
0
def cmor_initialisation():
    cmor.setup(inpath='/git/cmip5-cmor-tables/Tables',
               netcdf_file_action = cmor.CMOR_REPLACE_3,
               create_subdirectories = 0)
    cmor.dataset('pre-industrial control', 'ukmo', 'HadCM3', '360_day',
                 institute_id = 'ukmo',
                 model_id = 'HadCM3',
                 history = 'some global history',
                 forcing = 'N/A',
                 parent_experiment_id = 'N/A',
                 parent_experiment_rip = 'N/A',
                 branch_time = 0.,
                 contact = 'bob',
                 outpath = 'test_ltd')
コード例 #14
0
def cmor_ini():
    cmor.setup(inpath='Tables', netcdf_file_action=cmor.CMOR_REPLACE)
    cmor.dataset('pre-industrial control',
                 'mohc',
                 'HadGEM2: source',
                 '360_day',
                 institute_id='ukmo',
                 model_id='HadGEM2',
                 history='some global history',
                 forcing='N/A',
                 parent_experiment_id='N/A',
                 parent_experiment_rip='N/A',
                 branch_time=0.,
                 contact='bob')
コード例 #15
0
def setup_cmor() :
#---------------------------------------------------------------------------------------------------
   # Initialise CMOR library
   cmor.setup(inpath=MIP_TABLE_DIR, netcdf_file_action=cmor.CMOR_REPLACE_3,
      set_verbosity=cmor.CMOR_NORMAL, create_subdirectories=0)

   # Create CMOR dataset
   cmor.dataset(outpath='Test', institution='Met Office Hadley Centre', institute_id="MOHC",
      experiment_id='amip', model_id="HadGEM2-A", source='HadGEM2-A 2009',
      calendar='360_day', contact='*****@*****.**',
      realization=1, initialization_method=1, physics_version=1,
      history='history', comment='CMIP5 site axis test',
      references='references', forcing="GHG, TO (yeah or some think)",
      parent_experiment_id='N/A', parent_experiment_rip='N/A', branch_time=0
   )
コード例 #16
0
ファイル: jamie_positive.py プロジェクト: AZed/uvcdat
def main():
    
    cmor.setup(inpath='Tables',
               netcdf_file_action = cmor.CMOR_REPLACE_3)
    cmor.dataset('pre-industrial control', 'ukmo', 'HadCM3', '360_day',
                 institute_id = 'ukmo',
                 model_id = 'HadCM3',
                 history = 'some global history',
                 forcing = 'N/A',
                 parent_experiment_id = 'N/A',
                 parent_experiment_rip = 'N/A',
                 branch_time = 0.,
                 contact = 'bob')
 
    table = 'CMIP5_Amon'
    cmor.load_table(table)
    axes = [ {'table_entry': 'time',
              'units': 'days since 2000-01-01 00:00:00',
              },
             {'table_entry': 'latitude',
              'units': 'degrees_north',
              'coord_vals': [0],
              'cell_bounds': [-1, 1]},             
             {'table_entry': 'longitude',
              'units': 'degrees_east',
              'coord_vals': [90],
              'cell_bounds': [89, 91]},
             ]

    values = numpy.array([1.], numpy.float32)+200
    axis_ids = list()
    for axis in axes:
        axis_id = cmor.axis(**axis)
        axis_ids.append(axis_id)

    for var, units, positive in (('ts', 'K', ''),
                                 ('rsut', 'W m-2', 'up'),
                                 ('rlut', 'W m-2', 'down'),):
        varid = cmor.variable(var,
                              units,
                              axis_ids,
                              history = 'variable history',
                              missing_value = -99,
                              positive = positive
                              )
        cmor.write(varid, values, time_vals = [15], time_bnds = [ [0,30] ])

    cmor.close()
コード例 #17
0
def main():

    missing = -99.
    cmor.setup(inpath='Tables', netcdf_file_action=cmor.CMOR_REPLACE)
    cmor.dataset('historical',
                 'ukmo',
                 'HadCM3',
                 '360_day',
                 institute_id='ukmo',
                 forcing='Nat',
                 model_id='HadCM3',
                 contact="Bleachers 140",
                 parent_experiment_rip="r1i3p2",
                 parent_experiment_id="lgm",
                 branch_time=0.)

    table = 'CMIP5_Amon'
    cmor.load_table(table)
    axes = [
        {
            'table_entry': 'time',
            'units': 'days since 2000-01-01 00:00:00',
        },
        {
            'table_entry': 'latitude',
            'units': 'degrees_north',
            'coord_vals': [0],
            'cell_bounds': [-1, 1]
        },
        {
            'table_entry': 'longitude',
            'units': 'degrees_east',
            'coord_vals': [90],
            'cell_bounds': [89, 91]
        },
    ]

    values = numpy.array([missing], numpy.float32)
    myma = numpy.ma.masked_values(values, missing)
    axis_ids = list()
    for axis in axes:
        axis_id = cmor.axis(**axis)
        axis_ids.append(axis_id)
    varid = cmor.variable('ts', 'K', axis_ids, missing_value=myma.fill_value)

    cmor.write(varid, myma, time_vals=[15], time_bnds=[[0, 30]])

    cmor.close(varid)
コード例 #18
0
def path_test():
    cmor.setup(inpath='TestTables', netcdf_file_action=cmor.CMOR_REPLACE)

    cmor.dataset('historical',
                 'ukmo',
                 'HadCM3',
                 '360_day',
                 model_id='HadCM3',
                 forcing='Nat',
                 contact="J.T. Snow",
                 institute_id="PCMDI",
                 parent_experiment_id="N/A",
                 parent_experiment_rip="N/A",
                 branch_time=0)

    table = 'CMIP5_Amon'
    cmor.load_table(table)
    axes = [
        {
            'table_entry': 'time',
            'units': 'days since 2000-01-01 00:00:00',
            'coord_vals': [15],
            'cell_bounds': [0, 30]
        },
        {
            'table_entry': 'latitude',
            'units': 'degrees_north',
            'coord_vals': [0],
            'cell_bounds': [-1, 1]
        },
        {
            'table_entry': 'longitude',
            'units': 'degrees_east',
            'coord_vals': [90],
            'cell_bounds': [89, 91]
        },
    ]

    axis_ids = list()
    for axis in axes:
        axis_id = cmor.axis(**axis)
        axis_ids.append(axis_id)
    varid = cmor.variable('ts', 'K', axis_ids)
    cmor.write(varid, [275])
    path = cmor.close(varid, file_name=True)

    print path
コード例 #19
0
def cmor_initialisation():
    cmor.setup(inpath="/git/cmip5-cmor-tables/Tables", netcdf_file_action=cmor.CMOR_REPLACE_3, create_subdirectories=0)
    cmor.dataset(
        "pre-industrial control",
        "ukmo",
        "HadCM3",
        "360_day",
        institute_id="ukmo",
        model_id="HadCM3",
        history="some global history",
        forcing="N/A",
        parent_experiment_id="N/A",
        parent_experiment_rip="N/A",
        branch_time=0.0,
        contact="bob",
        outpath="hadju/test",
    )
コード例 #20
0
def path_test():
    cmor.setup(inpath='TestTables',netcdf_file_action=cmor.CMOR_REPLACE)

    cmor.dataset('historical', 'ukmo', 'HadCM3', '360_day',model_id='HadCM3',forcing='Nat',
                 contact="J.T. Snow",
                 institute_id="PCMDI",
                 parent_experiment_id="N/A",
                 parent_experiment_rip="N/A",
                 branch_time=0)
    
    table='CMIP5_Amon'
    cmor.load_table(table)
    axes = [ {'table_entry': 'time2',
              'units': 'months since 2000-01-01 00:00:00',
              'coord_vals':  times,
              'cell_bounds': times_bnds,
              },
             {'table_entry': 'plevs',
              'units': 'Pa',
              'coord_vals': [100000., 92500., 85000., 70000., 60000., 50000., 
                40000., 30000., 25000., 20000., 15000.,
                10000., 7000., 5000., 3000., 2000., 1000.]},
             {'table_entry': 'latitude',
              'units': 'degrees_north',
              'coord_vals': [0],
              'cell_bounds': [-1, 1]},             
             {'table_entry': 'longitude',
              'units': 'degrees_east',
              'coord_vals': [90],
              'cell_bounds': [89, 91]},
             ]
              
    axis_ids = list()
    for axis in axes:
        axis_id = cmor.axis(**axis)
        axis_ids.append(axis_id)
    varid = cmor.variable('co2Clim', '1.e-6', axis_ids)
    import numpy
    data =numpy.array([3,4,5])
    data.resize((3,17,1,1))
    cmor.write(varid, data)
    path=cmor.close(varid, file_name=True)

    print path
コード例 #21
0
ファイル: test_python_fx.py プロジェクト: imclab/cmor
def test_mode(mode):
    cmor.setup(inpath='Tables', netcdf_file_action=mode)
    cmor.dataset('pre-industrial control',
                 'ukmo',
                 'HadCM3',
                 '360_day',
                 institute_id='ukmo',
                 model_id='HadCM3',
                 forcing="TO",
                 contact="Derek Jeter",
                 history='some global history',
                 parent_experiment_id="lgm",
                 parent_experiment_rip="r1i1p1",
                 branch_time=0)

    table = 'CMIP5_fx'
    cmor.load_table(table)
    axes = [
        {
            'table_entry': 'latitude',
            'units': 'degrees_north',
            'coord_vals': [0],
            'cell_bounds': [-1, 1]
        },
        {
            'table_entry': 'longitude',
            'units': 'degrees_east',
            'coord_vals': [90],
            'cell_bounds': [89, 91]
        },
    ]
    values = numpy.array([5000], numpy.float32)
    axis_ids = list()

    for axis in axes:
        axis_id = cmor.axis(**axis)
        axis_ids.append(axis_id)
    for var, units in (('deptho', 'm'), ):
        varid = cmor.variable(var, units, axis_ids, history='variable history')
        cmor.write(varid, values)
    fnm = cmor.close(varid, file_name=True)
    cmor.close()
    return fnm
コード例 #22
0
def path_test():
    cmor.setup(inpath='Test', netcdf_file_action=cmor.CMOR_REPLACE)

    cmor.dataset('mytest2010030812',
                 'ukmo',
                 'HadCM3',
                 '360_day',
                 institute_id="PCMDI",
                 model_id='HadCM3',
                 forcing='co2')

    table = 'CMIP5_Amon_YYYYMMDDHH'
    cmor.load_table(table)
    axes = [
        {
            'table_entry': 'time',
            'units': 'days since 2000-01-01 00:00:00',
            'coord_vals': [15],
            'cell_bounds': [0, 30]
        },
        {
            'table_entry': 'latitude',
            'units': 'degrees_north',
            'coord_vals': [0],
            'cell_bounds': [-1, 1]
        },
        {
            'table_entry': 'longitude',
            'units': 'degrees_east',
            'coord_vals': [90],
            'cell_bounds': [89, 91]
        },
    ]

    axis_ids = list()
    for axis in axes:
        axis_id = cmor.axis(**axis)
        axis_ids.append(axis_id)
    varid = cmor.variable('ts', 'K', axis_ids)
    cmor.write(varid, [273])
    path = cmor.close(varid, file_name=True)

    print "Saved file: ", path
コード例 #23
0
ファイル: test_python_jamie_4.py プロジェクト: AZed/uvcdat
def main():
    
    cmor.setup(inpath='Tables',
               netcdf_file_action = cmor.CMOR_REPLACE)
    cmor.dataset('historical', 'ukmo', 'HadCM3', '360_day',
                 institute_id = 'ukmo',
                 forcing = 'SO',
                 model_id = 'HadCM3',contact="Dusty Baker (even though he was a Dodgers",
                 parent_experiment_rip="r1i3p2",
                 parent_experiment_id="lgm",branch_time=0)

    table = 'CMIP5_Amon'
    cmor.load_table(table)
    axes = [ {'table_entry': 'time',
              'units': 'days since 2000-01-01 00:00:00',
              },
             {'table_entry': 'latitude',
              'units': 'degrees_north',
              'coord_vals': [0],
              'cell_bounds': [-1, 1]},             
             {'table_entry': 'longitude',
              'units': 'degrees_east',
              'coord_vals': [90],
              'cell_bounds': [89, 91]},
             ]

    axis_ids = list()
    for axis in axes:
        axis_id = cmor.axis(**axis)
        axis_ids.append(axis_id)

    for var, units, val in (('ts', 'K',278),  ('ps', 'hPa',974.2)):
        varid = cmor.variable(var,
                              units,
                              axis_ids,
                              )

        values = numpy.array([val], numpy.float32)
        cmor.write(varid, values, time_vals = [15], time_bnds = [ [0,30] ])

    cmor.close()
コード例 #24
0
ファイル: test_python_jamie_2.py プロジェクト: AZed/uvcdat
def multi_call_test():
    cmor.setup(inpath='Tables',netcdf_file_action=cmor.CMOR_REPLACE)

    cmor.dataset('historical', 'ukmo', 'HadCM3', '360_day',
                 institute_id="PCMDI",
                 model_id='HadCM3',contact="Ron Nen",forcing='SO',
                 parent_experiment_id="lgm",
                 parent_experiment_rip="r1i3p2",
                 branch_time=0.)
    
    table='CMIP5_Amon'
    cmor.load_table(table)
    axes = [ {'table_entry': 'time',
              'units': 'days since 2000-01-01 00:00:00',
              },
             {'table_entry': 'latitude',
              'units': 'degrees_north',
              'coord_vals': [0],
              'cell_bounds': [-1, 1]},             
             {'table_entry': 'longitude',
              'units': 'degrees_east',
              'coord_vals': [90],
              'cell_bounds': [89, 91]},
             ]
              
    axis_ids = list()
    for axis in axes:
        axis_id = cmor.axis(**axis)
        axis_ids.append(axis_id)
    varid = cmor.variable('ts', 'K', axis_ids)
    cmor.write(varid, [275], time_vals = [15], time_bnds = [ [0,30] ])
    print 'First write worked as expected'
    try:
        cmor.write(varid, [275], time_vals = [15], time_bnds = [ [0], [30] ])
        raise Exception,"We shouldn't be getting in here"
    except:
        print 'Second write that should have failed did fail, good!'
        pass
    cmor.close(varid)
    print 'Success'
コード例 #25
0
ファイル: test_python_jamie_3.py プロジェクト: AZed/uvcdat
def main():
    
    missing = -99.
    cmor.setup(inpath='Tables',
               netcdf_file_action = cmor.CMOR_REPLACE)
    cmor.dataset('historical', 'ukmo', 'HadCM3', '360_day',
                 institute_id = 'ukmo',
                 forcing = 'Nat',
                 model_id = 'HadCM3',
                 contact="Bleachers 140",
                 parent_experiment_rip="r1i3p2",
                 parent_experiment_id="lgm",branch_time=0.)

    table = 'CMIP5_Amon'
    cmor.load_table(table)
    axes = [ {'table_entry': 'time',
              'units': 'days since 2000-01-01 00:00:00',
              },
             {'table_entry': 'latitude',
              'units': 'degrees_north',
              'coord_vals': [0],
              'cell_bounds': [-1, 1]},             
             {'table_entry': 'longitude',
              'units': 'degrees_east',
              'coord_vals': [90],
              'cell_bounds': [89, 91]},
             ]

    values = numpy.array([missing], numpy.float32)
    myma = numpy.ma.masked_values(values, missing)
    axis_ids = list()
    for axis in axes:
        axis_id = cmor.axis(**axis)
        axis_ids.append(axis_id)
    varid = cmor.variable('ts', 'K', axis_ids, missing_value = myma.fill_value)

    cmor.write(varid, myma, time_vals = [15], time_bnds = [ [0,30] ])

    cmor.close(varid)
コード例 #26
0
ファイル: test_python_jamie.py プロジェクト: AZed/uvcdat
def path_test():
    cmor.setup(inpath='TestTables',netcdf_file_action=cmor.CMOR_REPLACE)

    cmor.dataset('historical', 'ukmo', 'HadCM3', '360_day',model_id='HadCM3',forcing='Nat',
                 contact="J.T. Snow",
                 institute_id="PCMDI",
                 parent_experiment_id="N/A",
                 parent_experiment_rip="N/A",
                 branch_time=0)
    
    table='CMIP5_Amon'
    cmor.load_table(table)
    axes = [ {'table_entry': 'time',
              'units': 'days since 2000-01-01 00:00:00',
              'coord_vals': [15],
              'cell_bounds': [0, 30]
              },
             {'table_entry': 'latitude',
              'units': 'degrees_north',
              'coord_vals': [0],
              'cell_bounds': [-1, 1]},             
             {'table_entry': 'longitude',
              'units': 'degrees_east',
              'coord_vals': [90],
              'cell_bounds': [89, 91]},
             ]
              
    axis_ids = list()
    for axis in axes:
        axis_id = cmor.axis(**axis)
        axis_ids.append(axis_id)
    varid = cmor.variable('ts', 'K', axis_ids)
    cmor.write(varid, [275])
    path=cmor.close(varid, file_name=True)

    print path
コード例 #27
0
ファイル: test_python_joerg_3.py プロジェクト: AZed/uvcdat
def prep(mode):
    error_flag = cmor.setup(inpath='Test', netcdf_file_action=mode                       )

    error_flag = cmor.dataset(                                   
           outpath='Test',                                         
           experiment_id='noVolc2000',
           institution= 'GICC (Generic International Climate Center, Geneva, Switzerland)',                                 
           source='GICCM1 (2002): ',
           calendar='standard',                                      
           realization=1,                                          
           contact = 'Rusty Koder (koder@middle_earth.net) ',      
           history='Output from archivcl_A1.nce/giccm_03_std_2xCO2_2256.', 
           comment='Equilibrium reached after 30-year spin-up ',                                 
           references='Model described by Koder and Tolkien ',
           institute_id="PCMDI",
           model_id="GICCM1", 
           forcing="TO, SO, Nat",
           ## month_lengths=[30,28,30,30,30,30,30,31,30,31,30,30],
           ## leap_year=3,
           ## leap_month=1,
           parent_experiment_rip="r1i3p2",
           parent_experiment_id="N/A",branch_time=1)
コード例 #28
0
ファイル: test_python_joerg_3.py プロジェクト: imclab/cmor
def prep(mode):
    error_flag = cmor.setup(inpath='Test', netcdf_file_action=mode)

    error_flag = cmor.dataset(
        outpath='Test',
        experiment_id='noVolc2000',
        institution=
        'GICC (Generic International Climate Center, Geneva, Switzerland)',
        source='GICCM1 (2002): ',
        calendar='standard',
        realization=1,
        contact='Rusty Koder (koder@middle_earth.net) ',
        history='Output from archivcl_A1.nce/giccm_03_std_2xCO2_2256.',
        comment='Equilibrium reached after 30-year spin-up ',
        references='Model described by Koder and Tolkien ',
        institute_id="PCMDI",
        model_id="GICCM1",
        forcing="TO, SO, Nat",
        ## month_lengths=[30,28,30,30,30,30,30,31,30,31,30,30],
        ## leap_year=3,
        ## leap_month=1,
        parent_experiment_rip="r1i3p2",
        parent_experiment_id="N/A",
        branch_time=1)
コード例 #29
0
def test_mode(mode,i,suffix=''):
    cmor.setup(inpath='Tables',
               netcdf_file_action = mode)
    cmor.dataset('pre-industrial control', 'ukmo', 'HadCM3', '360_day',
                 institute_id = 'ukmo',
                 model_id = 'HadCM3',
                 forcing="TO",
                 contact="Derek Jeter",
                 history = 'some global history',
                 parent_experiment_rip="r1i3p2",
                 parent_experiment_id="lgm",branch_time=0)
    
    table = 'CMIP5_Amon'
    cmor.load_table(table)
    levels = [100000.,
              92500.,
              85000.,
              70000.,
              60000.,
              50000.,
              40000.,
              30000.,
              25000.,
              20000.,
              15000.,
              10000.,
              7000.,
              5000.,
              3000.,
              2000.,
              1000.,
              999,
              998,
              997,
              996,
              995,
              994]
    
    axes = [ {'table_entry': 'time',
              'units': 'months since 2000-01-01 00:00:00',
              },
             {'table_entry': 'latitude',
              'units': 'degrees_north',
              'coord_vals': [0],
              'cell_bounds': [-1, 1]},             
             {'table_entry': 'longitude',
              'units': 'degrees_east',
              'coord_vals': [90],
              'cell_bounds': [89, 91]},
             {'table_entry': 'plevs',
              'units': 'Pa',
              'coord_vals': levels},
             ]
    
    values = numpy.array(range(len(levels)), numpy.float32)+195
    axis_ids = list()
    for axis in axes:
        axis_id = cmor.axis(**axis)
        axis_ids.append(axis_id)

    for var, units in (('ta', 'K'),):
        varid = cmor.variable(var,
                              units,
                              axis_ids,
                              history = 'variable history',
                              missing_value = -99
                              )
        print 'suffix is:',suffix
        print "Sending time bounds:",[[i,i+1]]
        cmor.write(varid, values, time_vals = [i], time_bnds = [ [i,i+1] ],file_suffix=suffix)

    fnm = cmor.close(varid,file_name=True)
    cmor.close()
    return fnm
コード例 #30
0
dlon = 360./nlon
nlev = 24
dlev = 1000./nlev
ntimes = 1

lats = numpy.arange(-90+dlat/2.,90,dlat)
blats = numpy.arange(-90,90+dlat,dlat)
lons = numpy.arange(0+dlon/2.,360.,dlon)
blons = numpy.arange(0,360.+dlon,dlon)

levs = numpy.array([1000.,925,900,850,800,700,600,500,400,300,250,200,150,100,75,70,50,30,20,10,7.5,5,2.5,1])
alllevs = numpy.arange(1000,0,-dlev).tolist()
print len(alllevs)

cmor.setup(inpath='.',netcdf_file_action=cmor.CMOR_REPLACE)
cmor.dataset('historical', 'ukmo', 'pcmdi-10b HadCM3', 'gregorian',model_id='pcmdi-10b',outpath='Test',forcing='N/A', parent_experiment_id="lgm", parent_experiment_rip="r1i1p1",contact="Bruce Bochy",branch_time=0,institute_id="yep")
table='Tables/CMIP5_Amon'
cmor.load_table(table)


ilat = cmor.axis(table_entry='latitude',coord_vals=lats,cell_bounds=blats,units='degrees_north')
ilon = cmor.axis(table_entry='longitude',coord_vals=lons,cell_bounds=blons,units='degrees_east')
itim = cmor.axis(table_entry='time',units='months since 2010')#,coord_vals=numpy.arange(ntimes,dtype=numpy.float),cell_bounds=numpy.arange(ntimes+1,dtype=float),units='months since 2000')
ilev = cmor.axis(table_entry='plevs',coord_vals=levs,units='hPa')
    
axes=[itim,ilev,ilat,ilon]

var = cmor.variable(table_entry='ta',units='K',axis_ids=axes)

print "allocating mem for data"
data = numpy.random.random((nlev,nlat,nlon))*30+273.15
コード例 #31
0
import cmor, numpy

ipth = "Test"
cmor.setup(inpath=ipth,
           set_verbosity=cmor.CMOR_NORMAL,
           netcdf_file_action=cmor.CMOR_REPLACE,
           logfile=None)

cmor.dataset(outpath=ipth,
             experiment_id="lgm",
             institution="PCMDI",
             source="GICCM1 2002",
             institute_id="PCMDI",
             calendar="standard",
             contact="Bengie Molina",
             model_id="GICCM1",
             forcing="SO",
             parent_experiment_id="historical",
             parent_experiment_rip="r3i8p1",
             branch_time=0.)

cmor.load_table("Tables/CMIP5_Amon")

nlat = 90
dlat = 180 / nlat
nlon = 180
dlon = 360. / nlon

lats = numpy.arange(-90 + dlat / 2., 90, dlat)
blats = numpy.arange(-90, 90 + dlat, dlat)
lons = numpy.arange(0 + dlon / 2., 360., dlon)
コード例 #32
0
def mywrite(data=None, time_vals=None, append_to=None, cell_bounds=None):
    breq = "100000. 80000. 80000. 68000. 68000. 56000. 56000. 44000. 44000. 31000. 31000. 18000. 18000.  0.".split(
    )

    bnds_req = []
    for b in breq:
        bnds_req.append(float(b))

    bnds_req = numpy.array(bnds_req)
    bnds_req.shape = (7, 2)

    print bnds_req[-2], bnds_req.shape

    levs = []

    for b in bnds_req:
        levs.append((b[0] + b[1]) / 2.)

    levs = numpy.array(levs)

    print levs

    ipth = "Test"
    if append_to is None:
        mode = cmor.CMOR_REPLACE
    else:
        mode = cmor.CMOR_APPEND
    print 'Mode in python:', mode
    cmor.setup(inpath=ipth,
               set_verbosity=cmor.CMOR_NORMAL,
               netcdf_file_action=mode,
               logfile=None)

    cmor.dataset(outpath=ipth,
                 experiment_id="lgm",
                 institution="PCMDI",
                 source="GICCM1 2002",
                 institute_id="PCMDI",
                 calendar="standard",
                 contact="Pablo Sandoval",
                 model_id="GICCM1",
                 forcing="Nat",
                 parent_experiment_id="historical",
                 parent_experiment_rip="r1i3p2",
                 branch_time=3.14159)

    cmor.load_table("Tables/CMIP5_Amon")

    dlat = 180 / nlat
    dlon = 360. / nlon
    lats = numpy.arange(-90 + dlat / 2., 90, dlat)
    bnds_lat = numpy.arange(-90, 90 + dlat, dlat)
    lons = numpy.arange(0 + dlon / 2., 360., dlon) - 180.
    bnds_lon = numpy.arange(0, 360. + dlon, dlon) - 180.

    plevs = numpy.array([
        100000., 92500., 85000., 70000., 60000., 50000., 40000., 30000.,
        25000., 20000., 15000., 10000., 7000., 5000., 3000., 2000., 1000.
    ])

    itim = cmor.axis(table_entry='time', units='month since 2008')
    #itim = cmor.axis(table_entry='time',units='month since 2008',coord_vals=numpy.arange(0,12,1))
    ilat = cmor.axis(table_entry='latitude',
                     coord_vals=lats,
                     units='degrees_north',
                     cell_bounds=bnds_lat)
    ilon = cmor.axis(table_entry='longitude',
                     coord_vals=lons,
                     units='degrees_east',
                     cell_bounds=bnds_lon)
    print 'so far', itim, ilat, ilon
    ilev = cmor.axis(table_entry="plevs", coord_vals=plevs, units="Pa")

    iv = cmor.variable(table_entry='ta',
                       axis_ids=numpy.array((itim, ilev, ilat, ilon)),
                       units='K')

    #cmor.write(iv,data)
    if append_to is None:
        print 'time:', time_vals
        print 'bnds:', cell_bounds
        cmor.write(iv, data, time_vals=time_vals,
                   time_bnds=cell_bounds)  #,file_suffix="with-appending")
    else:
        print 'Ok writing with a suffix', append_to
        cmor.write(iv,
                   data,
                   time_vals=time_vals,
                   file_suffix=append_to,
                   time_bnds=cell_bounds)
        print 'and back'
    file = cmor.close(iv, file_name=True)
    print 'Ok dumped to:', file
    cmor.close()
    return file
コード例 #33
0
    lat = lat()

# import cmor module
import cmor

contact = 'cmbe: Renata McCoy, [email protected], ARM Archive user services: [email protected]'
model = 'cmbe'  #+ site_location[site_fac]
# setup cmor before doing anything else with cmor
error_flag = cmor.setup(netcdf_file_action=cmor.CMOR_REPLACE,
                        create_subdirectories=0)
# define dataset for all variables from one site
cmor.dataset(
    experiment_id='obs',
    institution='ARM',
    institute_id="ARM",
    source=
    'CMBE (Climate Modeling Best Estimate), ARM (Atmospheric Radiation Measurement Program)',
    calendar='proleptic_gregorian',
    model_id=model,
    contact=contact,
    outpath=out_path)
# add those additional global attributes to the output file

# --- this did not work------, neede to put contact info in cmor.dataset setup
#contact = "cmbe: Renata McCoy, [email protected], ARM Archive user services: [email protected]"
#cmor.set_cur_dataset_attribute('contact',contact)

# copy some global attributes from the original cmbe files
# read some global attributes and put into the cmor created netcdf file
title = fid.title
description = fid.description
project = fid.project
コード例 #34
0
def main():

    cmor.setup(inpath='/git/cmip5-cmor-tables/Tables',
               netcdf_file_action=cmor.CMOR_REPLACE_3)
    cmor.dataset('pre-industrial control', 'ukmo', 'HadCM3', 'noleap',
                 institute_id='ukmo',
                 model_id='HadCM3',
                 history='some global history',
                 forcing='N/A',
                 parent_experiment_id='N/A',
                 parent_experiment_rip='N/A',
                 branch_time=0,
                 contact='brian clough')

    table = 'CMIP5_Oclim'
    cmor.load_table(table)
    axes = [{'table_entry': 'time2',
             'units': 'days since 1861',
             },
            {'table_entry': 'depth_coord',
             'units': 'm',
             'coord_vals': [500, 1000.],
             'cell_bounds': [0., 750., 1200.]},
            {'table_entry': 'latitude',
             'units': 'degrees_north',
             'coord_vals': [0],
             'cell_bounds': [-1, 1]},
            {'table_entry': 'longitude',
             'units': 'degrees_east',
             'coord_vals': [90],
             'cell_bounds': [89, 91]},
            ]

    axes2 = {'coord_vals': [48925.5, 48955, 48984.5, 49015, 49045.5, 49076, 49106.5, 49137.5, 49168, 49198.5, 49229, 49259.5],
             'cell_bounds': [[45625, 52591],
                             [45656, 52619, ],
                             [45684, 52650, ],
                             [45715, 52680, ],
                             [45745, 52711, ],
                             [45776, 52741, ],
                             [45806, 52772, ],
                             [45837, 52803, ],
                             [45868, 52833, ],
                             [45898, 52864, ],
                             [45929, 52894, ],
                             [45959, 52925]], }
    axis_ids = list()
    for axis in axes:
        print('doing:', axis)
        axis_id = cmor.axis(**axis)
        axis_ids.append(axis_id)

    for var, units, value in (('tnpeot', 'W m-2', 274),):
        values = numpy.array([value, ] *
                             len(axes[1]['coord_vals']), numpy.float32)
        varid = cmor.variable(var,
                              units,
                              axis_ids,
                              history='variable history',
                              missing_value=-99
                              )
        for i in range(12):
            cmor.write(
                varid,
                values,
                time_vals=axes2["coord_vals"][i],
                time_bnds=axes2["cell_bounds"][i])

    cmor.close()
コード例 #35
0
                pass
        cal = data.getTime().getCalendar()  # cmor understand cdms calendars
        if A.verbose:
            cmor_verbose = cmor.CMOR_NORMAL
        else:
            cmor_verbose = cmor.CMOR_QUIET
        error_flag = cmor.setup(
            inpath='.',
            netcdf_file_action=cmor.CMOR_REPLACE,
            set_verbosity=cmor_verbose,
            exit_control=cmor.CMOR_NORMAL,
            #            logfile='logfile',
            create_subdirectories=int(A.drs))
        error_flag = cmor.dataset(experiment_id=exp,
                                  outpath=A.output_directory,
                                  institution=inst,
                                  source=src,
                                  calendar=cal,
                                  **xtra)
        if not os.path.exists(A.tables):
            raise RuntimeError("No such file or directory for tables: %s" %
                               A.tables)
        if os.path.isdir(A.tables):
            table = os.path.join(A.tables, "pcmdi_metrics_table")
        else:
            table = A.tables
        table = cmor.load_table(table)

        # Ok CMOR is ready let's create axes
        cmor_axes = []
        for ax in s.getAxisList():
            if ax.isLatitude():
コード例 #36
0
def main():

    cmor.setup(inpath='/git/cmip5-cmor-tables/Tables',
               netcdf_file_action=cmor.CMOR_REPLACE_3)
    cmor.dataset('pre-industrial control',
                 'ukmo',
                 'HadCM3',
                 'noleap',
                 institute_id='ukmo',
                 model_id='HadCM3',
                 history='some global history',
                 forcing='N/A',
                 parent_experiment_id='N/A',
                 parent_experiment_rip='N/A',
                 branch_time=0,
                 contact='brian clough')

    table = 'CMIP5_Oclim'
    cmor.load_table(table)
    axes = [
        {
            'table_entry':
            'time2',
            'units':
            'days since 1861',
            'coord_vals': [
                48925.5, 48955, 48984.5, 49015, 49045.5, 49076, 49106.5,
                49137.5, 49168, 49198.5, 49229, 49259.5
            ],
            'cell_bounds': [[45625, 52591], [
                45656,
                52619,
            ], [
                45684,
                52650,
            ], [
                45715,
                52680,
            ], [
                45745,
                52711,
            ], [
                45776,
                52741,
            ], [
                45806,
                52772,
            ], [
                45837,
                52803,
            ], [
                45868,
                52833,
            ], [
                45898,
                52864,
            ], [
                45929,
                52894,
            ], [45959, 52925]],
        },
        {
            'table_entry': 'depth_coord',
            'units': 'm',
            'coord_vals': [500, 1000.],
            'cell_bounds': [0., 750., 1200.]
        },
        {
            'table_entry': 'latitude',
            'units': 'degrees_north',
            'coord_vals': [0],
            'cell_bounds': [-1, 1]
        },
        {
            'table_entry': 'longitude',
            'units': 'degrees_east',
            'coord_vals': [90],
            'cell_bounds': [89, 91]
        },
    ]

    axis_ids = list()
    for axis in axes:
        print('doing:', axis)
        axis_id = cmor.axis(**axis)
        axis_ids.append(axis_id)

    for var, units, value in (('tnpeot', 'W m-2', 274), ):
        values = numpy.array([
            value,
        ] * len(axes[1]['coord_vals']), numpy.float32)
        varid = cmor.variable(var,
                              units,
                              axis_ids,
                              history='variable history',
                              missing_value=-99)
        for i in range(12):
            cmor.write(varid, values, ntimes_passed=1)

    cmor.close()
コード例 #37
0
ファイル: atmos.py プロジェクト: arildoosilva/cmor_xlstoyaml
dt = (bounds[1] - bounds[0])
bounds.append(bounds[-1] + dt)
bounds = np.array([ to_udunits(v, TIME) for v in bounds ])
time = (bounds[:-1] + bounds[1:])/2.

# now save data
start_for_variable = datetime.datetime.now()
for variable in config['variables'].values():
    start_this_variable = datetime.datetime.now()
    if variable['realm'] in ['atmos', 'land']:
        data = np.concatenate(vars[ variable['output variable name'] ], axis=0)
        print variable['output variable name']

        # setup output file
        cmor.setup(inpath=TABLES, netcdf_file_action=cmor.CMOR_REPLACE)
        cmor.dataset( **config['description'] )
        cmor.load_table( variable['table'] )

        cell_methods = variable['cell_methods'] or ''
        if re.search('3hr', variable['table']):
            #if not re.match('time:\s*mean', cell_methods):
            #    bounds = None
            time_ = time
            bounds_ = bounds
        elif re.search('6hr', variable['table']):
            if re.match('time:\s*mean', cell_methods):
                data = average_data(data, 2)
                time_ = average_data(time, 2)
                bounds_ = bounds[::2]
            else:
                data = data[::2]  # sample every 6hr
コード例 #38
0
def path_test():
    cmor.setup(inpath='TestTables', netcdf_file_action=cmor.CMOR_REPLACE)

    cmor.dataset('historical',
                 'ukmo',
                 'HadCM3',
                 '360_day',
                 model_id='HadCM3',
                 forcing='Nat',
                 contact="J.T. Snow",
                 institute_id="PCMDI",
                 parent_experiment_id="N/A",
                 parent_experiment_rip="N/A",
                 branch_time=0)

    table = 'CMIP6_Amon.json'
    cmor.load_table(table)
    axes = [
        {
            'table_entry': 'time2',
            'units': 'months since 2000-01-01 00:00:00',
            'coord_vals': times,
            'cell_bounds': times_bnds,
        },
        {
            'table_entry':
            'plevs',
            'units':
            'Pa',
            'coord_vals': [
                100000., 92500., 85000., 70000., 60000., 50000., 40000.,
                30000., 25000., 20000., 15000., 10000., 7000., 5000., 3000.,
                2000., 1000.
            ]
        },
        {
            'table_entry': 'latitude',
            'units': 'degrees_north',
            'coord_vals': [0],
            'cell_bounds': [-1, 1]
        },
        {
            'table_entry': 'longitude',
            'units': 'degrees_east',
            'coord_vals': [90],
            'cell_bounds': [89, 91]
        },
    ]

    axis_ids = list()
    for axis in axes:
        axis_id = cmor.axis(**axis)
        axis_ids.append(axis_id)
    varid = cmor.variable('co2Clim', '1.e-6', axis_ids)
    import numpy
    data = numpy.array([3, 4, 5])
    data.resize((3, 17, 1, 1))
    cmor.write(varid, data)
    path = cmor.close(varid, file_name=True)

    print path
コード例 #39
0
tables = """CMIP5_3hr     CMIP5_6hrPlev CMIP5_LImon   CMIP5_OImon   CMIP5_Omon    CMIP5_aero    CMIP5_cfDay   CMIP5_cfOff   CMIP5_day     CMIP5_grids CMIP5_6hrLev  CMIP5_Amon    CMIP5_Lmon    CMIP5_Oclim   CMIP5_Oyr     CMIP5_cf3hr   CMIP5_cfMon   CMIP5_cfSites CMIP5_fx"""
tables = """CMIP5_3hr     CMIP5_6hrPlev CMIP5_LImon   CMIP5_OImon   CMIP5_Omon    CMIP5_aero    CMIP5_cfDay   CMIP5_cfOff   CMIP5_day      CMIP5_6hrLev  CMIP5_Amon    CMIP5_Lmon    CMIP5_Oclim   CMIP5_Oyr    CMIP5_cfMon    CMIP5_fx"""

for t in tables.split():
    print 'Table:',t
    tnm = "Tables/%s" % t
    tbl = readTable(tnm)
    vr = tbl['variable']
    ax = tbl['axis']
    g = tbl['general']
    cmor.setup(inpath='Tables',set_verbosity=cmor.CMOR_QUIET,
               netcdf_file_action = cmor.CMOR_REPLACE,exit_control=cmor.CMOR_EXIT_ON_MAJOR)
    cmor.dataset('pre-industrial control', 'ukmo', 'HadCM3', '360_day',
                 institute_id = 'ukmo',
                 model_id = 'HadCM3',
                 forcing="TO",
                 contact="Derek Jeter",
                 history = 'some global history',
                 parent_experiment_id="lgm",branch_time=0)
    cmor.load_table(tnm)
    dims={}
    print '\tDimensions:'
    for a in ax:
        A=ax[a]
        print '\t\t',a,A.get('type','notype')
        mn = float(A.get("valid_min",-1.e20))
        mx = float(A.get("valid_max",1.e20))
        val = (mn+mx)/2.
        try:
            val = numpy.array([float(A.get("value",val)),])
        except:
コード例 #40
0
def save(opts, threeD=True):

    cmor.setup(
        inpath=opts["table_path"],
        netcdf_file_action=cmor.CMOR_REPLACE_3,
        set_verbosity=cmor.CMOR_NORMAL,
        exit_control=cmor.CMOR_NORMAL,
        logfile=None,
        create_subdirectories=1,
    )

    cmor.dataset(
        outpath=opts["outpath"],
        experiment_id="historical",
        institution="CMOR-test",
        source="CMOR-test",
        calendar="gregorian",
        realization=1,
        contact="dummy",
        history="dummy",
        model_id="CMOR-test",
        forcing="GHG",
        institute_id="CMOR-test",
        parent_experiment_id="piControl",
        branch_time=109207.0,
        parent_experiment_rip="r1i1p1",
    )

    # Load the CMIP tables into memory.
    tables = []
    tables.append(cmor.load_table("CMIP5_grids"))
    tables.append(cmor.load_table(opts["cmip_table"]))

    # Create the dimension axes

    # Monthly time axis
    min_tvals = []
    max_tvals = []
    cmor_tName = "time"
    tvals = []
    axis_ids = []
    for year in range(1850, 1851):
        for mon in range(1, 13):
            tvals.append(datetime.date(year, mon, 15).toordinal() - 1)
    # set up time values and bounds
    for i, ordinaldate in enumerate(tvals):
        model_date = datetime.date.fromordinal(int(ordinaldate) + 1)
        # min bound is first day of month
        model_date = model_date.replace(day=1)
        min_tvals.append(model_date.toordinal() - 1)
        # max_bound is first day of next month
        tyr = model_date.year + model_date.month / 12
        tmon = model_date.month % 12 + 1
        model_date = model_date.replace(year=tyr, month=tmon)
        max_tvals.append(model_date.toordinal() - 1)
        # correct date to middle of month
        mid = (max_tvals[i] - min_tvals[i]) / 2.0
        tvals[i] = min_tvals[i] + mid
    tval_bounds = np.column_stack((min_tvals, max_tvals))
    cmor.set_table(tables[1])
    time_axis_id = cmor.axis(
        table_entry=cmor_tName,
        units="days since 0001-01-01",
        length=len(tvals),
        coord_vals=tvals[:],
        cell_bounds=tval_bounds[:],
        interval=None,
    )
    axis_ids.append(time_axis_id)

    if not threeD:
        # Pressure
        plev = np.array(
            [
                100000,
                92500,
                85000,
                70000,
                60000,
                50000,
                40000,
                30000,
                25000,
                20000,
                15000,
                10000,
                7000,
                5000,
                3000,
                2000,
                1000,
            ]
        )
        plev_bounds = np.array(
            [
                [103750, 96250],
                [96250, 88750],
                [88750, 77500],
                [77500, 65000],
                [65000, 55000],
                [55000, 45000],
                [45000, 35000],
                [35000, 27500],
                [27500, 22500],
                [22500, 17500],
                [17500, 12500],
                [12500, 8500],
                [8500, 6000],
                [6000, 4000],
                [4000, 2500],
                [2500, 1500],
                [1500, 500],
            ]
        )
        plev_axis_id = cmor.axis(
            table_entry="plevs",
            units="Pa",
            length=len(plev),
            coord_vals=plev[:],
            cell_bounds=plev_bounds[:],
            interval=None,
        )
        axis_ids.append(plev_axis_id)

    # 1 degree resolution latitude and longitude
    lat = np.linspace(-89.5, 89.5, 180)
    lat_bounds = np.column_stack((np.linspace(-90.0, 89.0, 180.0), np.linspace(-89.0, 90.0, 180.0)))
    lat_axis_id = cmor.axis(
        table_entry="latitude",
        units="degrees_north",
        length=len(lat),
        coord_vals=lat[:],
        cell_bounds=lat_bounds[:],
        interval=None,
    )
    axis_ids.append(lat_axis_id)

    lon = np.linspace(0.5, 359.5, 360)
    lon_bounds = np.column_stack((np.linspace(0.0, 359.0, 360.0), np.linspace(1.0, 360.0, 360.0)))
    lon_axis_id = cmor.axis(
        table_entry="longitude",
        units="degrees_north",
        length=len(lon),
        coord_vals=lon[:],
        cell_bounds=lon_bounds[:],
        interval=None,
    )
    axis_ids.append(lon_axis_id)

    #
    # Define the CMOR variable.
    #
    cmor.set_table(tables[1])
    in_missing = float(1.0e20)
    if threeD:
        variable_id = cmor.variable(table_entry="ts", units="K", axis_ids=axis_ids, type="f", missing_value=in_missing)
    else:
        variable_id = cmor.variable(table_entry="ta", units="K", axis_ids=axis_ids, type="f", missing_value=in_missing)

    #
    # Write the data
    #
    if threeD:
        data_vals = np.zeros((len(tvals), len(lat), len(lon)), np.float32) + 290.0
    else:
        data_vals = np.zeros((len(tvals), len(plev), len(lat), len(lon)), np.float32) + 290.0
    try:
        print "writing..."
        cmor.write(
            variable_id, data_vals[:], ntimes_passed=np.shape(data_vals)[0]
        )  # assuming time is the first dimension
    except Exception, e:
        raise Exception("ERROR writing data!")
コード例 #41
0
def main():

    cmor.setup(inpath='/git/cmip5-cmor-tables/Tables',
               netcdf_file_action=cmor.CMOR_REPLACE_3)
    cmor.dataset('pre-industrial control',
                 'ukmo',
                 'HadCM3',
                 '360_day',
                 institute_id='ukmo',
                 model_id='HadCM3',
                 history='some global history',
                 forcing='N/A',
                 parent_experiment_id='N/A',
                 parent_experiment_rip='N/A',
                 branch_time=0,
                 contact='brian clough')

    table = 'CMIP5_Oclim'
    cmor.load_table(table)
    axes = [
        {
            'table_entry': 'time2',
            'units': 'days since 2000-01-01 00:00:00',
        },
        {
            'table_entry': 'depth_coord',
            'units': 'm',
            'coord_vals': [500, 1000.],
            'cell_bounds': [0., 750., 1200.]
        },
        {
            'table_entry': 'latitude',
            'units': 'degrees_north',
            'coord_vals': [0],
            'cell_bounds': [-1, 1]
        },
        {
            'table_entry': 'longitude',
            'units': 'degrees_east',
            'coord_vals': [90],
            'cell_bounds': [89, 91]
        },
    ]

    axis_ids = list()
    for axis in axes:
        print 'doing:', axis
        axis_id = cmor.axis(**axis)
        axis_ids.append(axis_id)

    for var, units, value in (('tnpeot', 'W m-2', 274), ):
        values = numpy.array([
            value,
        ] * len(axes[1]['coord_vals']), numpy.float32)
        varid = cmor.variable(var,
                              units,
                              axis_ids,
                              history='variable history',
                              missing_value=-99)
        for i in range(12):
            cmor.write(varid,
                       values,
                       time_vals=[30 * i + 15],
                       time_bnds=[[30 * i, 360 + 30 * (i + 1)]])

    cmor.close()
コード例 #42
0
ファイル: test_python_2Gb_file.py プロジェクト: AZed/uvcdat
nlat = 360
dlat = 180./nlat
nlon = 720
dlon = 360./nlon
nlev = 17
ntimes = 12

lats = numpy.arange(-90+dlat/2.,90,dlat)
blats = numpy.arange(-90,90+dlat,dlat)
lons = numpy.arange(0+dlon/2.,360.,dlon)
blons = numpy.arange(0,360.+dlon,dlon)


cmor.setup(inpath='.',netcdf_file_action=cmor.CMOR_REPLACE)
cmor.dataset('historical', 'ukmo', 'HadCM3', 'gregorian',model_id='HadCM3',outpath='Test',forcing='N/A', parent_experiment_id="lgm", parent_experiment_rip="r1i1p1",branch_time=0,contact="Juan Uribe",institute_id="myinst")
table='Tables/CMIP5_Amon'
cmor.load_table(table)


ilat = cmor.axis(table_entry='latitude',coord_vals=lats,cell_bounds=blats,units='degrees_north')
ilon = cmor.axis(table_entry='longitude',coord_vals=lons,cell_bounds=blons,units='degrees_east')
itim = cmor.axis(table_entry='time',units='months since 2010')#,coord_vals=numpy.arange(ntimes,dtype=numpy.float),cell_bounds=numpy.arange(ntimes+1,dtype=float),units='months since 2000')
ilev = cmor.axis(table_entry='plevs',coord_vals=numpy.array([1000.,925,850,700,600,500,400,300,250,200,150,100,70,50,30,20,10]),units='hPa')
    
axes=[itim,ilev,ilat,ilon]

var = cmor.variable(table_entry='ta',units='K',axis_ids=axes)
ntimes=250

data = numpy.random.random((nlev,nlat,nlon))*30+273.15
コード例 #43
0
f = cdms2.open("Test/GR30s_halo.nc")

nlon = f['grid_center_lat'].shape[1]
nlat = f['grid_center_lat'].shape[0]


error_flag = cmor.setup(inpath='Test', netcdf_file_action=cmor.CMOR_APPEND)

error_flag = cmor.dataset(
    outpath='Joerg',
    experiment_id='DcppC2',
    institution='GICC (Generic International Climate Center, Geneva, Switzerland)',
    institute_id="GICC",
    source='GICCM1 (2002): ',
    calendar='360_day',
    realization=1,
    contact='Rusty Koder (koder@middle_earth.net) ',
    history='Output from archivcl_A1.nce/giccm_03_std_2xCO2_2256.',
    comment='Equilibrium reached after 30-year spin-up ',
    references='Model described by Koder and Tolkien ',
    model_id="GICCM1",
    forcing="Ant",
    parent_experiment_id="lgm", branch_time=0)

ntables = [cmor.load_table("Tables/CMIP6_grids")]
ntables.append(cmor.load_table("Tables/CMIP5_OImon"))


cmor.set_table(ntables[0])
axes = numpy.zeros(2, numpy.int32)
コード例 #44
0
    levs.append((b[0]+b[1])/2.)

levs=numpy.array(levs)

print levs

ipth="Test"
cmor.setup(inpath=ipth,
           set_verbosity=cmor.CMOR_NORMAL,
           netcdf_file_action = cmor.CMOR_REPLACE,
           logfile = None)

cmor.dataset(
    outpath = ipth,
    experiment_id = "present-day control experiment",
    institution = "PCMDI",
    source = "PCMDI",
    calendar = "standard",
    model_id="pcmdi-09a",forcing="forcing")

cmor.load_table("python_test_table_A")

nlat = 90
dlat = 180/nlat
nlon = 180
dlon = 360./nlon

lats = numpy.arange(-90+dlat/2.,90,dlat)
lons = numpy.arange(0,360.,dlon)

ntime = 12
コード例 #45
0
myaxes=numpy.zeros(9,dtype='i')
myaxes2=numpy.zeros(9,dtype='i')
myvars=numpy.zeros(9,dtype='i')


cmor.setup(inpath=ipth,set_verbosity=cmor.CMOR_NORMAL, netcdf_file_action = cmor.CMOR_REPLACE, exit_control = cmor.CMOR_EXIT_ON_MAJOR);
cmor.dataset(
    outpath = opth,
    experiment_id = "historical",
    institution = "GICC (Generic International Climate Center, Geneva, Switzerland)",
    source = "GICCM1 2002: atmosphere:  GICAM3 (gicam_0_brnchT_itea_2, T63L32); ocean: MOM (mom3_ver_3.5.2, 2x3L15); sea ice: GISIM4; land: GILSM2.5",
    calendar = "standard",
    realization = 1,
    contact = "Tim Lincecum",
    history = "Testing noncartesian grid and ocn sigma",
    comment = "trying to see if it core dumps",
    references = "ref",
    leap_year=0,
    leap_month=0,
    month_lengths=None,
    model_id="GICCM1",
    forcing="Ant, Nat",
    institute_id="pcmdi",
    parent_experiment_id="piControl",
    parent_experiment_rip="r1i2p3",
    branch_time=18336.33)

tables=[]
a = cmor.load_table("Tables/CMIP5_grids")
tables.append(a)
tables.append(cmor.load_table("Tables/CMIP5_Omon"))
print 'Tables ids:',tables
コード例 #46
0

filename = sys.argv[1]
config = load(open(filename).read())

if not os.path.exists('cmip5'):
    os.mkdir('cmip5')

start_for_variable = datetime.datetime.now()
for variable in config['variables'].values():
    start_this_variable = datetime.datetime.now()
    if variable['realm'] in ['atmos', 'land', 'landIce land']:
        # setup output file
        cmor_setup_start = datetime.datetime.now()
        cmor.setup(inpath=TABLES, netcdf_file_action=cmor.CMOR_REPLACE)
        cmor.dataset(**config['description'])
        cmor.load_table(variable['table'])
        print "####prof cmor setup", datetime.datetime.now() - cmor_setup_start

        # read ctls
        files = glob.glob('*.ctl')
        n = len(files)
        bounds = []
        data = []
        for i, filename in enumerate(files):
            f = ctler.CTLReader(filename)
            values = f.variables[variable['name in BMGCS'].upper()][:]
            data.append(values * adjust_units(variable['units in BMGCS'],
                                              variable['desired units']))
            bounds.append(f.variables['time'][0])
        data = np.concatenate(data, axis=0)
コード例 #47
0
def process(rc):
    '''
    Convert netcdf/matlab/grads files into CMIP5 format.
    '''
    pdb.set_trace()
    # ----------------------------
    #  Loop yearly on file list.
    # ----------------------------
    file_template = rc['file_template'].split(",")
    if (len(file_template) == 2):
        template_parameter = file_template[1]
        rc['file_template'] = file_template[0]
    else:
        template_parameter = 'years'

    for year in rc[template_parameter].split(","):
        if (year == ''):
            files = os.popen("ls " + rc['file_template']).readlines()
        else:
            # ------------------------------------------------
            # Use string formating for path with same argument
            # ------------------------------------------------
            try:
                tmplFile = rc['file_template'] % (year)
            except:
                tmplFile = rc['file_template'].format(year)
            if (not os.path.isfile(tmplFile)):
                print "**** Warning %s not found\n" % (tmplFile)
                continue
            files = os.popen("ls " + tmplFile).readlines()

        if (files == []):
            print "No file found: Check your resource file"
            return -1
        # ------------------------------------------------
        # Get the right handler to manage this file format
        # ------------------------------------------------
        Handler = factory.HandlerFormats(files[0].strip())

        # -----------------------------------
        # Take care of cmor initialization.
        # -----------------------------------
        cmor.setup(inpath=rc['inpath'], netcdf_file_action=cmor.CMOR_REPLACE)

        cmor.dataset(experiment_id=rc['experiment_id'],
                     institution=rc['institution'],
                     calendar=rc['calendar'],
                     institute_id=rc['institute_id'],
                     model_id=rc['model_id'],
                     source=rc['source'],
                     contact=rc['contact'],
                     references=rc['references'])

        # -----------------------------------------
        # add extra Global Attributes for obs4MIPs.
        # -----------------------------------------
        cmor.set_cur_dataset_attribute('instrument', rc['instrument'])
        cmor.set_cur_dataset_attribute('mip_specs', rc['mip_specs'])
        cmor.set_cur_dataset_attribute('data_structure', rc['data_structure'])
        cmor.set_cur_dataset_attribute('source_type', rc['source_type'])
        cmor.set_cur_dataset_attribute('source_id', rc['source_id'])
        cmor.set_cur_dataset_attribute('realm', rc['realm'])
        cmor.set_cur_dataset_attribute('obs_project', rc['obs_project'])
        cmor.set_cur_dataset_attribute('processing_version',
                                       rc['processing_version'])
        cmor.set_cur_dataset_attribute('processing_level',
                                       rc['processing_level'])

        cmor.load_table(rc['table'])

        # ---------------------------------------------------------------------
        # We loop on each file found, a new cmor file will be create on each
        # iteration.  If you want to aggregate, you need to use Grads ctl file
        # or NeCDF list of file.
        # ---------------------------------------------------------------------
        for file in files:

            fnm = file.strip()  # Get rid of \n
            aVariable = eval(rc['original_var'])
            nbVariable = len(aVariable)

            # -----------------------------------------------------
            # ECMWF needs synoptic time 00z and 12z in he filename.
            # We extract it from the first file in the list.
            # -----------------------------------------------------
            if (rc['source_fn'] == 'SYNOPTIC'):
                index = fnm.find('z.')
                rc['SYNOPTIC'] = fnm[index - 2:index]

            # -----------------------
            # Work on all variables
            # -------------------------
            for j in arange(nbVariable):
                # ----------------------------------------------------
                # Fetch the variable directly or excute equation.
                # ----------------------------------------------------
                try:
                    variable = aVariable[j]
                    Handler.open(fnm, variable=variable)
                    rc['cvrt_original_var'] = aVariable[j]
                    print "Working on variable %s " % variable
                except:
                    if (aVariable[j] != 'equation'):
                        print "Variable %s can't open" % variable
                        continue
                    else:
                        print "Executing %s " % eval(rc['equation'])[j]

#                pdb.set_trace()
                rc['cvrt_original_units'] = eval(rc['original_units'])[j]
                rc['cvrt_cmor_var'] = eval(rc['cmor_var'])[j]
                rc['cvrt_equation'] = eval(rc['equation'])[j]
                rc['cvrt_level'] = eval(rc['level'])[j]

                data = Handler.getData()

                # ----------------------------------------------------------
                # Evaluate equation if needed. Usually used to change units
                # ----------------------------------------------------------
                if (rc['cvrt_equation'][0] == '@'):
                    fncName = rc['cvrt_equation'][1:]
                    fnc = import_equation("equations.%s" % fncName)
                    data[:] = fnc(Handler)
                else:
                    data[:] = eval(rc['cvrt_equation'])

                # -------------------------------------------------------------
                # Save filled value in case data type is changed in createAxes
                # -------------------------------------------------------------
                fill_value = data.fill_value

                #  ---------------------------------------------
                #  Extract latitude/longitude
                #  ---------------------------------------------
                lonvals = Handler.getLongitude()
                latvals = Handler.getLatitude()
                # ---------------------
                # Create cmor time axis
                # ----------------------
                (rel_time, rel_time_bnds) = createTime(Handler, rc)

                # ---------------------------------------------------
                # Create cmor axes and add an axis to data if needed
                # ---------------------------------------------------
                (axes, data) = createAxes(rc, latvals, lonvals, data)

                axis_ids = list()
                for axis in axes:
                    axis_id = cmor.axis(**axis)
                    axis_ids.append(axis_id)

                # ----------------------------------------------------------
                # Create cmor variable
                # Note: since this is in the loop, a new cmor file will be
                # create for each cmor write command.
                # ----------------------------------------------------------
                varid = cmor.variable(table_entry=rc['cvrt_cmor_var'],
                                      axis_ids=axis_ids,
                                      history='',
                                      missing_value=fill_value,
                                      original_name=rc['cvrt_original_var'],
                                      units=rc['cvrt_original_units'])
                # -------------------------------
                # Write data for this time frame.
                # -------------------------------
                cmor.write(varid,data,\
                           time_vals=rel_time,time_bnds=rel_time_bnds)
                cmor.close(varid, file_name=True)

                # ---------------------------------------
                # Rename cmor files according to project.
                # ---------------------------------------
                if (movefiles(rc)):
                    return -2

        cmor.close()
    return 0
コード例 #48
0
cmor.setup(inpath="Test",
           set_verbosity=cmor.CMOR_NORMAL,
           netcdf_file_action=cmor.CMOR_REPLACE,
           exit_control=cmor.CMOR_EXIT_ON_MAJOR)
cmor.dataset(
    outpath="Test",
    experiment_id="historical",
    institution=
    "GICC (Generic International Climate Center, Geneva, Switzerland)",
    source=
    "GICCM1 (2002): atmosphere:  GICAM3 (gicam_0_brnchT_itea_2, T63L32); ocean: MOM (mom3_ver_3.5.2, 2x3L15); sea ice: GISIM4; land: GILSM2.5",
    calendar="standard",
    realization=1,
    contact="Charles Doutriaux ([email protected])",
    history="Test for speed and compression.",
    comment="NetCDF4 vs NetCDF3 testing",
    references="http://cdat.sf.net",
    leap_year=0,
    leap_month=0,
    institute_id="PCMDI",
    month_lengths=None,
    model_id="GICCM1",
    forcing="SO",
    parent_experiment_id="lgm",
    branch_time=4.)

tables = []
tables.append(cmor.load_table("mytable"))
print 'Tables ids:', tables
コード例 #49
0
ntimes = 1

lats = numpy.arange(90 - dlat / 2., -90, -dlat)
blats = numpy.arange(90, -90 - dlat, -dlat)
lats2 = numpy.arange(-90 + dlat / 2., 90, dlat)
blats2 = numpy.arange(-90, 90 + dlat, dlat)
lons = numpy.arange(0 + dlon / 2., 360., dlon)
blons = numpy.arange(0, 360. + dlon, dlon)

cmor.setup(inpath='.', netcdf_file_action=cmor.CMOR_REPLACE)
cmor.dataset('historical',
             'ukmo',
             'HadCM3',
             'gregorian',
             model_id='HadCM3',
             outpath='Test',
             forcing='TO, Nat',
             contact="Jonathan sanchez",
             parent_experiment_id="lgm",
             parent_experiment_rip="r1i1p1",
             branch_time=0,
             institute_id='pcmdi')
table = 'Tables/CMIP5_Amon'
cmor.load_table(table)

data = lats[:, numpy.newaxis] * lons[numpy.newaxis, :]

data = (data + 29000) / 750. + 233.2

ilat = cmor.axis(table_entry='latitude',
                 coord_vals=lats,
                 cell_bounds=blats,
コード例 #50
0

filename = sys.argv[1]
config = load(open(filename).read())

if not os.path.exists("cmip5"):
    os.mkdir("cmip5")

start_for_variable = datetime.datetime.now()
for variable in config["variables"].values():
    start_this_variable = datetime.datetime.now()
    if variable["realm"] in ["atmos", "land", "landIce land"]:
        # setup output file
        cmor_setup_start = datetime.datetime.now()
        cmor.setup(inpath=TABLES, netcdf_file_action=cmor.CMOR_REPLACE)
        cmor.dataset(**config["description"])
        cmor.load_table(variable["table"])
        print "####prof cmor setup", datetime.datetime.now() - cmor_setup_start

        # read ctls
        files = glob.glob("*.ctl")
        n = len(files)
        bounds = []
        data = []
        for i, filename in enumerate(files):
            f = ctler.CTLReader(filename)
            values = f.variables[variable["name in BMGCS"].upper()][:]
            data.append(values * adjust_units(variable["units in BMGCS"], variable["desired units"]))
            bounds.append(f.variables["time"][0])
        data = np.concatenate(data, axis=0)
        dt = bounds[1] - bounds[0]
コード例 #51
0
def main():

    cmor.setup(inpath='/git/cmip5-cmor-tables/Tables',
               netcdf_file_action=cmor.CMOR_REPLACE_3)
    cmor.dataset('pre-industrial control',
                 'ukmo',
                 'HadCM3',
                 '360_day',
                 institute_id='ukmo',
                 model_id='HadCM3',
                 history='some global history',
                 forcing='N/A',
                 parent_experiment_id='N/A',
                 parent_experiment_rip='N/A',
                 branch_time=0,
                 contact='brian clough')

    table = 'CMIP5_Oclim'
    cmor.load_table(table)
    axes = [
        {
            'table_entry': 'time2',
            'units': 'days since 1850-01-01 00:00:00',
            'coord_vals': [
                15.5,
                45,
            ],
            'cell_bounds': [[0, 396], [31, 424]]
        },
        {
            'table_entry': 'depth_coord',
            'units': 'm',
            'coord_vals': [5000., 3000., 2000., 1000.],
            'cell_bounds': [5000., 3000., 2000., 1000., 0]
        },
        {
            'table_entry': 'latitude',
            'units': 'degrees_north',
            'coord_vals': [0],
            'cell_bounds': [-1, 1]
        },
        {
            'table_entry': 'longitude',
            'units': 'degrees_east',
            'coord_vals': [90],
            'cell_bounds': [89, 91]
        },
    ]

    axis_ids = list()
    for axis in axes:
        print 'doing:', axis
        axis_id = cmor.axis(**axis)
        axis_ids.append(axis_id)

    for var, units, value in (('difvso', 'm2 s-1', 274.), ):
        values = numpy.ones(map(lambda x: len(x["coord_vals"]), axes)) * value
        values = values.astype("f")
        varid = cmor.variable(var,
                              units,
                              axis_ids,
                              history='variable history',
                              missing_value=-99)
        cmor.write(varid, values)

    cmor.close()
コード例 #52
0
s=s.replace("${DEFLATE_LEVEL}",str(level))
s=s.replace("${DEFLATE}",str(deflate))
s=s.replace("${SHUFFLE}",str(shuffle))
f=open("mytable","w")
f.write(s)
f.close()

cmor.setup(inpath="Test",set_verbosity=cmor.CMOR_NORMAL, netcdf_file_action = cmor.CMOR_REPLACE, exit_control = cmor.CMOR_EXIT_ON_MAJOR);
cmor.dataset(
    outpath = "Test",
    experiment_id = "lgm",
    institution = "GICC (Generic International Climate Center, Geneva, Switzerland)",
    source = "GICCM1 (2002): atmosphere:  GICAM3 (gicam_0_brnchT_itea_2, T63L32); ocean: MOM (mom3_ver_3.5.2, 2x3L15); sea ice: GISIM4; land: GILSM2.5",
    calendar = "standard",
    realization = 1,
    contact = "Charles Doutriaux ([email protected])",
    history = "Test for speed and compression.",
    comment = "NetCDF4 vs NetCDF3 testing",
    references = "http://cdat.sf.net",
    leap_year=0,
    leap_month=0,
    institute_id="PCMDI",
    month_lengths=None,model_id="GICCM1",forcing="SO",parent_experiment_id="N/A",branch_time=0.)

tables=[]
tables.append(cmor.load_table("mytable"))
print 'Tables ids:',tables


## read in data, just one slice
f=cdms2.open(cdat_info.get_prefix()+'/sample_data/tas_ccsr-95a.xml')
コード例 #53
0
ファイル: test_compression.py プロジェクト: govtmirror/uvcdat
pth = os.path.split(os.path.realpath(os.curdir))
if pth[-1] == 'Test':
    ipth = opth = '.'
else:
    ipth = opth = 'Test'
cmor.setup(inpath=ipth,
           set_verbosity=cmor.CMOR_NORMAL,
           netcdf_file_action=cmor.CMOR_REPLACE)

cmor.dataset(outpath=opth,
             experiment_id="historical",
             institution="PCMDI",
             source="GICCM1 2002",
             calendar="standard",
             contact="Tim Lincecum",
             institute_id="PCMDI",
             model_id="GICCM1",
             forcing="Nat",
             parent_experiment_id="N/A",
             parent_experiment_rip="N/A",
             branch_time=0.)

cmor.load_table("Tables/CMIP5_Amon")

s = f("clt", slice(14))
Saxes = s.getAxisList()

axes = []
for ax in Saxes[1:]:
    tmp = cmor.axis(ax.id,
                    coord_vals=ax[:],
コード例 #54
0
import cmor
import numpy

ipth = "Test"
cmor.setup(inpath=ipth,
           set_verbosity=cmor.CMOR_NORMAL,
           netcdf_file_action=cmor.CMOR_REPLACE,
           logfile=None)

cmor.dataset(outpath=ipth,
             experiment_id="lgm",
             institution="PCMDI",
             source="PCMDI",
             calendar="standard",
             model_id="pcmdi-09a",
             forcing="forcing")

cmor.load_table("Tables/CMIP6_Omon.json")

nlat = 90
dlat = 180 / nlat
nlon = 180
dlon = 360. / nlon
nlev = 5

lats = numpy.arange(-90 + dlat / 2., 90, dlat)
blats = numpy.arange(-90, 90 + dlat, dlat)
lons = numpy.arange(0 + dlon / 2., 360., dlon)
blons = numpy.arange(0, 360. + dlon, dlon)

ntime = 12
コード例 #55
0
ファイル: test_python_appending.py プロジェクト: AZed/uvcdat
def mywrite(data = None, time_vals = None, append_to = None,cell_bounds=None):
    breq = "100000. 80000. 80000. 68000. 68000. 56000. 56000. 44000. 44000. 31000. 31000. 18000. 18000.  0.".split()

    bnds_req = []
    for b in breq:
        bnds_req.append(float(b))

    bnds_req=numpy.array(bnds_req)
    bnds_req.shape=(7,2)

    print bnds_req[-2], bnds_req.shape

    levs=[]

    for b in bnds_req:
        levs.append((b[0]+b[1])/2.)

    levs=numpy.array(levs)

    print levs

    ipth="Test"
    if append_to is None:
        mode = cmor.CMOR_REPLACE
    else:
        mode = cmor.CMOR_APPEND
    print 'Mode in python:',mode
    cmor.setup(inpath=ipth,
               set_verbosity=cmor.CMOR_NORMAL,
               netcdf_file_action = mode,
               logfile = None)

    cmor.dataset(
        outpath = ipth,
        experiment_id = "lgm",
        institution = "PCMDI",
        source = "GICCM1 2002",
        institute_id="PCMDI",
        calendar = "standard",
        contact="Pablo Sandoval",
        model_id="GICCM1",forcing="Nat",
        parent_experiment_id="historical",
        parent_experiment_rip="r1i3p2",
        branch_time=3.14159)

    cmor.load_table("Tables/CMIP5_Amon")

    dlat = 180/nlat
    dlon = 360./nlon
    lats = numpy.arange(-90+dlat/2.,90,dlat)
    bnds_lat = numpy.arange(-90,90+dlat,dlat)
    lons = numpy.arange(0+dlon/2.,360.,dlon)-180.
    bnds_lon = numpy.arange(0,360.+dlon,dlon)-180.

    plevs = numpy.array([100000., 92500., 85000., 70000.,
                         60000., 50000., 40000., 30000., 25000., 20000.,
                         15000., 10000., 7000., 5000., 3000., 2000., 1000.])

    itim = cmor.axis(table_entry='time',units='month since 2008')
    #itim = cmor.axis(table_entry='time',units='month since 2008',coord_vals=numpy.arange(0,12,1))
    ilat = cmor.axis(table_entry='latitude',coord_vals=lats,units='degrees_north',cell_bounds=bnds_lat)
    ilon = cmor.axis(table_entry='longitude',coord_vals=lons,units='degrees_east',cell_bounds=bnds_lon)
    print 'so far',itim,ilat,ilon
    ilev = cmor.axis(table_entry="plevs",coord_vals=plevs,units="Pa")

    iv = cmor.variable(table_entry='ta',axis_ids=numpy.array((itim,ilev,ilat,ilon)),units='K')

    #cmor.write(iv,data)
    if append_to is None:
        print 'time:',time_vals
        print 'bnds:',cell_bounds
        cmor.write(iv,data,time_vals=time_vals,time_bnds=cell_bounds)#,file_suffix="with-appending")
    else:
        print 'Ok writing with a suffix',append_to
        cmor.write(iv,data,time_vals=time_vals,file_suffix=append_to,time_bnds=cell_bounds)
        print 'and back'
    file = cmor.close(iv,file_name=True)
    print 'Ok dumped to:',file
    cmor.close()
    return file