Пример #1
0
#create variables
nc.createVariable('lon', 'f', ('lat', 'lon'))
nc.variables['lon'].long_name = 'longitude'
nc.variables['lon'].units = 'degrees_east'
nc.variables['lon'][:] = lon

nc.createVariable('lat', 'f', ('lat', 'lon'))
nc.variables['lat'].long_name = 'latitude'
nc.variables['lat'].units = 'degrees_north'
nc.variables['lat'][:] = lat

nc.createVariable('z', 'f', ('z'))
nc.variables['z'].long_name = 'depth'
nc.variables['z'].units = 'meter'
nc.variables['z'][:] = z

nc.createVariable('ocean_time', 'f', ('ocean_time'))
nc.variables['ocean_time'].units = 'days since 1900-01-01 00:00:00'
jday = pycnal_toolbox.date2jday(datetime(year, 1, 1)) + day - 1
nc.variables['ocean_time'][0] = jday

nc.createVariable(outvarname,
                  'f', ('ocean_time', 'z', 'lat', 'lon'),
                  fill_value=spval)
nc.variables[outvarname].long_name = long_name
nc.variables[outvarname].units = units
nc.variables[outvarname][0] = var

nc.close()
Пример #2
0
    print('Processing file for %s, day %d, year %04d' %
          (invarname, day_out * 3, year))
    #get data from server
    try:
        var = dataset.variables[invarname][day, :, 170:215, 195:265]
        #        spval = var.get_fill_value()
        #        dataset.close()
        print('Got %s from server...' % invarname)
    except:
        print('No file on the server... We skip this day.')
        retry_day.append((day, day_out))
        continue

    #create netCDF file
    nc.variables[outvarname][day_out] = var
    jday = pycnal_toolbox.date2jday(datetime(year, 1, 1)) + day_out * 73 / 24.
    nc.variables['ocean_time'][day_out] = jday
    day_out += 1

if retry == 'True':
    if len(retry_day) != 0:
        print("Some file have not been downloded... Let's try again")
    while len(retry_day) != 0:
        for (day, day_out) in retry_day:
            print('Retry file for %s, day %03d, year %04d' %
                  (invarname, day_out, year))
            #get data from server
            try:
                var = dataset.variables[invarname][day, :, 170:215, 195:265]
                #                spval = var.get_fill_value()
                print('Got %s from server...' % invarname)