Ejemplo n.º 1
0
            "dimensions": ["time", "level"],
            "attributes": {"units": "meters s-1", "long_name": "Velocity error magnitude"},
        },
        "speed": {
            "data": ADCP[:, -2, :],
            "dimensions": ["time", "level"],
            "attributes": {"units": "meters s-1", "long_name": "Current speed"},
        },
        "direction": {
            "data": ADCP[:, -1, :],
            "dimensions": ["time", "level"],
            "attributes": {"units": "degrees North", "long_name": "Current direction"},
        },
    }

    ncwrite(nc, out, Quiet=False)

    # Check everything looks sensible

    # Load in the NetCDF file and overlay on the input data.
    NC = readFVCOM(out, noisy=True)

    fig0 = plt.figure(figsize=(10, 7.5))
    n = 10
    for i in xrange(n):
        yyyy, mm, dd, HH, MM, SS = ADCP[i, 0:6, 0].astype(int)
        plt.clf()
        plt.subplot2grid((2, 2), (0, 0))
        plt.plot(ADCP[i, -2, :], -np.sort(bins), ".-")
        plt.plot(NC["speed"][i, :], -np.sort(bins), "bx:")
        plt.xlim(ADCP[:n, -2, :].min(), ADCP[:n, -2, :].max())
Ejemplo n.º 2
0
def dump(data, fout, noisy=False):
    """
    Dump the data from the GRIB files into a netCDF file.

    Parameters
    ----------
    data : dict
        The data from the GRIB files. This is the output of `gread'.
    fout : str
        Output file name.
    noisy : bool, optional
        Set to True for verbose output (defaults to False).

    """

    tmpvar = data.keys()[0]
    lon, lat = data[tmpvar]['lon'], data[tmpvar]['lat']
    mjdtime = data[tmpvar]['time']
    Times = [i.strftime('%Y-%m-%dT%H:%M:%S') for i in data[tmpvar]['Times']]
    ny, nx, _ = data[data.keys()[0]]['data'].shape
    datestrlen = 19

    nc = {}
    nc['dimensions'] = {
        'lat': ny,
        'lon': nx,
        'time': None,
        'datestrlen': datestrlen
    }
    nc['global attributes'] = {
        'description': 'ECMWF ERA-20C data for FVCOM from ecmwf-era20c.py',
        'source': 'http://apps.ecmwf.int/datasets/data/era20c-daily/',
        'history': 'Created by Pierre Cazenave on {}'.format(
            time.ctime(time.time())
        )
    }
    nc['variables'] = {
        'lat': {'data': [lat],
                     'dimensions': ['lon', 'lat'],
                     'attributes': {'units': 'degrees_north',
                                    'standard_name': 'latitude',
                                    'long_name': 'Latitude',
                                    'axis': 'Y'}
                     },
        'lon': {'data': [lon],
                      'dimensions': ['lon', 'lat'],
                      'attributes': {'units': 'degrees_east',
                                     'standard_name': 'longitude',
                                     'long_name': 'Longitude',
                                     'axis': 'X'}
                      },
        'time': {'data': mjdtime,
                 'dimensions': ['time'],
                 'attributes': {'format': 'Modified Julian Day (MJD)',
                                'longname': 'time',
                                'units': 'days since 1858-11-17 00:00:00',
                                'time_zone': 'UTC'}
                 },
        'Times': {'data': Times,
                  'dimensions': ['time', 'datestrlen'],
                  'attributes': {'time_zone': 'UTC'},
                  'data_type': 'c'
                  }
    }

    # Add the rest of the variables and their data.
    for var in data.keys():
        # Use the shortname as the variable name (no spaces).
        sname = data[var]['shortName']
        new = {sname: {'data': data[var]['data'].transpose(2, 0, 1),
                       'dimensions': ['time', 'lat', 'lon'],
                       'attributes': {'shortname': data[var]['shortName'],
                                      'longname': data[var]['longName'],
                                      'units': data[var]['units']
                                      }
                       }}
        nc['variables'].update(new)

    ncwrite(nc, fout, Quiet=False)