Python netCDF4 模块,MFDataset() 实例源码

我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用netCDF4.MFDataset()

项目:gridded    作者:NOAA-ORR-ERD    | 项目源码 | 文件源码
def get_dataset(ncfile, dataset=None):
    """
    Utility to create a netCDF4 Dataset from a filename, list of filenames,
    or just pass it through if it's already a netCDF4.Dataset

    if dataset is not None, it should be a valid netCDF4 Dataset object,
    and it will simiply be returned
    """
    if dataset is not None:
        return dataset
    if isinstance(ncfile, nc4.Dataset):
        return ncfile
    elif isinstance(ncfile, collections.Iterable) and len(ncfile) == 1:
        return nc4.Dataset(ncfile[0])
    elif isstring(ncfile):
        return nc4.Dataset(ncfile)
    else:
        return nc4.MFDataset(ncfile)
项目:RapidMoc    作者:cdr30    | 项目源码 | 文件源码
def _opennc(self, f):
        """ Open netcdf data set either Dataset or MFDataset. """
        if len(glob.glob(f)) > 1:
            try:
                nc = MFDataset(f)
            except ValueError as err:
                print 'netcdf4.MFDataset incompatible with NETCDF4. Try concatenating data into a single file.'
                raise NetCDF4ERROR(err)
        else:
            nc = Dataset(f)

        return nc
项目:RapidMoc    作者:cdr30    | 项目源码 | 文件源码
def _opennc(self, f):
        """ Open netcdf data set either Dataset or MFDataset. """
        if len(glob.glob(f)) > 1:
            try:
                nc = MFDataset(f)
            except ValueError as err:
                print 'netcdf4.MFDataset incompatible with NETCDF4. Try concatenating data into a single file.'
                raise NetCDF4ERROR(err)
        else:
            nc = Dataset(f)

        return nc
项目:wa    作者:wateraccounting    | 项目源码 | 文件源码
def Convert_nc_to_tiff(input_nc, output_folder):
    """
    This function converts the nc file into tiff files

    Keyword Arguments:
    input_nc -- name, name of the adf file
    output_folder -- Name of the output tiff file
    """
    from datetime import date
    import wa.General.raster_conversions as RC

    #All_Data = RC.Open_nc_array(input_nc)

    if type(input_nc) == str:
        nc = netCDF4.Dataset(input_nc)
    elif type(input_nc) == list:
        nc = netCDF4.MFDataset(input_nc)

    Var = nc.variables.keys()[-1]
    All_Data = nc[Var]

    geo_out, epsg, size_X, size_Y, size_Z, Time = RC.Open_nc_info(input_nc)  

    if epsg == 4326:
        epsg = 'WGS84'

    # Create output folder if needed
    if not os.path.exists(output_folder):
        os.mkdir(output_folder)

    for i in range(0,size_Z):
        if not Time == -9999:
            time_one = Time[i]
            d = date.fromordinal(time_one)
            name = os.path.splitext(os.path.basename(input_nc))[0]
            nameparts = name.split('_')[0:-2]
            name_out = os.path.join(output_folder, '_'.join(nameparts) + '_%d.%02d.%02d.tif' %(d.year, d.month, d.day))
            Data_one = All_Data[i,:,:]
        else:
            name=os.path.splitext(os.path.basename(input_nc))[0]
            name_out = os.path.join(output_folder, name + '.tif')
            Data_one = All_Data[:,:]


        Save_as_tiff(name_out, Data_one, geo_out, epsg)

    return()