Изменить: изначально вставлено как изображение, но преобразовано в текст.
Я пытаюсь открыть несколько файлов и рассчитать среднесуточные концентрации загрязняющих веществ.
Проблема
Когда я запускаю несколько дней, он создает отдельные карты вместо комбинированного среднего значения за все дни.
Например, если мне нужно среднее значение за неделю, я получаю 7 отдельных карт за один день вместо одной карты, усредненной для целую неделю.
Я считаю, что проблема связана только с l oop для открытия файлов netCDF, спасибо за помощь в продвинутом режиме.
Код:
# IMPORT ALL NECESSARY PACKAGES
import sys,os
import numpy as np
import Nio # for reading/manipulating netCDF files
import Ngl # NCL support functions
# USER INPUT
# This section contains all of the variables used in the rest of this script and should be the only code you have to modify before running.
data_dir = '/disk1/harkey/WHIPS/NO2_output/2019/' # path to WHIPS output
grid_dir = '/home/harkey/' # path to grid file
pollutant = 'NO2' # only works for NO2 right now, but framework of script allows for expansion if needed
month = '07'
days = ['01','02','03']
year = '2019'
wks_type = 'png' # desired output file type (PDF, PNG, JPG, x11, etc.)
domain = 'CONUS' # set plotting window
screen_negs = 'yes' # WHIPS output has negative values -- would you like to remove them?
# OPEN THE NETCDF FILE
# Using existing WHIPS OMI output as practice, located on lichen at: /disk1/harkey/WHIPS/NO2_output/2019/
for day in days:
netfile = Nio.open_file(data_dir+'WHIPS-NO2-12kmCONUS_'+month+'-'+day+'-'+year+'.nc','r')
print(netfile.variables.keys()) # print just the variable headers, so you can quickly see what's in the file
print(netfile) # print detailed information for each variable
# SELECT YOUR DESIRED NETCDF VARIABLE # Extract the variable you want to plot and print its associated information.
if (pollutant == 'NO2'):
var = netfile.variables['tropVCD'][:] # select variable for tropospheric vertical column density (VCD)
var_molec_cm2 = var/(10**15) # convert units to molec/cm^2
var_molec_cm2.Units = '10^15 molecules/cm^2' # update variable attribute "Units"
else:
print('Variable '+pollutant+' not recognized. Please add your desired variable or select another.')
print('Variable dimensions: '+str(var_molec_cm2.shape))
print('Variable in units of 10^15 molecules/cm^2:')
print(var_molec_cm2)
# SCREEN NEGATIVE VALUES
# WHIPS output has negative values, which can distract from the overall pattern/trend in the data.
# This section screens out the negative values in the data so they will not show up on the final plot.
if (screen_negs == 'yes'):
if (pollutant == 'NO2'):
var_molec_cm2._FillValue = -9999.0 # set a FillValue
var_molec_cm2[var_molec_cm2 < 0] = var_molec_cm2._FillValue # replace all negative values with FillValue
print('Variable with screened negatives: ')
print(var_molec_cm2)
else:
print('Variable '+pollutant+' not recognized. Please add your desired variable or select another.')
# OPEN THE GRID FILE
# Open the grid file and extract the latitude and longitude variables. This information helps
# correlate the grid points of the data with actual lat/lon coordinates on Earth.
gridfile = Nio.open_file(grid_dir+'GRIDCRO2D.2011121.12US2fromLADCO.nc','r')
lat2d = gridfile.variables['LAT'][0,0,:,:]
lon2d = gridfile.variables['LON'][0,0,:,:]
print('Dimensions of lat2d: '+str(lat2d.shape))
print('Dimensions of lon2d: '+str(lon2d.shape))
# OPEN A WORKSTATION
# Create/open a workstation, or output file, to store your plot. The first argument of this function
# specifies what type of output file you want (e.g. JPG, PDF, PNG, X11, etc.) and the second argument specifies the output filename.
wks = Ngl.open_wks(wks_type,('WHIPS_OMI_'+domain+'_'+pollutant+'_'+month+'-'+day+'-'+year)) # open workstation
Остальная часть кода просто указывает ресурсы построения