Ejemplo n.º 1
0
def test_advect_nemo(mode):
    data_path = path.join(path.dirname(__file__), 'test_data/')

    mesh_filename = data_path + 'mask_nemo_cross_180lon.nc'
    rotation_angles_filename = data_path + 'rotation_angles_nemo_cross_180lon.nc'
    variables = {
        'cosU': 'cosU',
        'sinU': 'sinU',
        'cosV': 'cosV',
        'sinV': 'sinV'
    }
    dimensions = {
        'U': {
            'lon': 'glamu',
            'lat': 'gphiu'
        },
        'V': {
            'lon': 'glamv',
            'lat': 'gphiv'
        },
        'F': {
            'lon': 'glamf',
            'lat': 'gphif'
        }
    }
    compute_curvilinearGrid_rotationAngles(mesh_filename,
                                           rotation_angles_filename, variables,
                                           dimensions)

    filenames = {
        'U': data_path + 'Uu_eastward_nemo_cross_180lon.nc',
        'V': data_path + 'Vv_eastward_nemo_cross_180lon.nc',
        'cosU': rotation_angles_filename,
        'sinU': rotation_angles_filename,
        'cosV': rotation_angles_filename,
        'sinV': rotation_angles_filename
    }
    variables = {
        'U': 'U',
        'V': 'V',
        'cosU': 'cosU',
        'sinU': 'sinU',
        'cosV': 'cosV',
        'sinV': 'sinV'
    }

    dimensions = {
        'U': {
            'lon': 'nav_lon_u',
            'lat': 'nav_lat_u'
        },
        'V': {
            'lon': 'nav_lon_v',
            'lat': 'nav_lat_v'
        },
        'cosU': {
            'lon': 'glamu',
            'lat': 'gphiu'
        },
        'sinU': {
            'lon': 'glamu',
            'lat': 'gphiu'
        },
        'cosV': {
            'lon': 'glamv',
            'lat': 'gphiv'
        },
        'sinV': {
            'lon': 'glamv',
            'lat': 'gphiv'
        }
    }

    field_set = FieldSet.from_netcdf(filenames,
                                     variables,
                                     dimensions,
                                     mesh='spherical',
                                     allow_time_extrapolation=True)

    lonp = 175.5
    latp = 81.5
    pset = ParticleSet.from_list(field_set,
                                 ptype[mode],
                                 lon=[lonp],
                                 lat=[latp])
    pset.execute(AdvectionRK4, runtime=delta(days=2), dt=delta(hours=6))
    assert abs(pset[0].lat - latp) < 1e-3
Ejemplo n.º 2
0
def test_nemo_grid(mode):
    data_path = path.join(path.dirname(__file__), 'test_data/')

    mesh_filename = data_path + 'mask_nemo_cross_180lon.nc'
    rotation_angles_filename = data_path + 'rotation_angles_nemo_cross_180lon.nc'
    compute_curvilinearGrid_rotationAngles(mesh_filename,
                                           rotation_angles_filename)

    filenames = {
        'U': data_path + 'Uu_eastward_nemo_cross_180lon.nc',
        'V': data_path + 'Vv_eastward_nemo_cross_180lon.nc',
        'cosU': rotation_angles_filename,
        'sinU': rotation_angles_filename,
        'cosV': rotation_angles_filename,
        'sinV': rotation_angles_filename
    }
    variables = {
        'U': 'U',
        'V': 'V',
        'cosU': 'cosU',
        'sinU': 'sinU',
        'cosV': 'cosV',
        'sinV': 'sinV'
    }

    dimensions = {
        'U': {
            'lon': 'nav_lon_u',
            'lat': 'nav_lat_u'
        },
        'V': {
            'lon': 'nav_lon_v',
            'lat': 'nav_lat_v'
        },
        'cosU': {
            'lon': 'glamu',
            'lat': 'gphiu'
        },
        'sinU': {
            'lon': 'glamu',
            'lat': 'gphiu'
        },
        'cosV': {
            'lon': 'glamv',
            'lat': 'gphiv'
        },
        'sinV': {
            'lon': 'glamv',
            'lat': 'gphiv'
        }
    }

    field_set = FieldSet.from_netcdf(filenames,
                                     variables,
                                     dimensions,
                                     mesh='spherical')

    def sampleVel(particle, fieldset, time, dt):
        (particle.zonal, particle.meridional) = fieldset.UV[time, particle.lon,
                                                            particle.lat,
                                                            particle.depth]

    class MyParticle(ptype[mode]):
        zonal = Variable('zonal', dtype=np.float32, initial=0.)
        meridional = Variable('meridional', dtype=np.float32, initial=0.)

    lonp = 175.5
    latp = 81.5
    pset = ParticleSet.from_list(field_set, MyParticle, lon=[lonp], lat=[latp])
    pset.execute(pset.Kernel(sampleVel), runtime=0, dt=0)
    u = field_set.U.units.to_source(pset[0].zonal, lonp, latp, 0)
    v = field_set.V.units.to_source(pset[0].meridional, lonp, latp, 0)
    assert abs(u - 1) < 1e-4
    assert abs(v) < 1e-4