1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Combining a large amount of netCDF files

Discussão em 'Python' iniciado por Stack, Setembro 16, 2025.

  1. Stack

    Stack Membro Participativo

    I have a large folder of netCDF (.nc) files each one with a similar name. The data files contain variables of time, longitude, latitude, and monthly precipitation. The goal is to get the average monthly precipitation over X amount of years for each month. So in the end I would have 12 values representing the average monthly precipitation over X amount of years for each lat and long. Each file is the same location over many years. Each file starts with the same name and ends in a “date.sub.nc” for example:

    'data1.somthing.somthing1.avg_2d_Ind_Nx.200109.SUB.nc'
    'data1.somthing.somthing1.avg_2d_Ind_Nx.200509.SUB.nc'
    'data2.somthing.somthing1.avg_2d_Ind_Nx.201104.SUB.nc'
    'data2.somthing.somthing1.avg_2d_Ind_Nx.201004.SUB.nc'
    'data2.somthing.somthing1.avg_2d_Ind_Nx.201003.SUB.nc'
    'data2.somthing.somthing1.avg_2d_Ind_Nx.201103.SUB.nc'
    'data1.somthing.somthing1.avg_2d_Ind_Nx.201203.SUB.nc'


    The ending is YearMonth.SUB.nc What I have so far is:

    array=[]
    f = nc.MFDataset('data*.nc')
    precp = f.variables['prectot']
    time = f.variables['time']
    array = f.variables['time','longitude','latitude','prectot']


    I get a KeyError: ('time', 'longitude', 'latitude', 'prectot'). Is there a way to combine all this data so I am able to manipulate it?

    Continue reading...

Compartilhe esta Página