Ejemplo n.º 1
0
def regionDailyTimeSeries(C, region):
	""""
	Returns a summed time series the length of axis 0 for C subet by the passed
	region name
	"""
	minLat, maxLat, minLon, maxLon, resolution  = cnm.getRegionBounds(region)
	C_PNW, ynew, xnew = cnm.mask2dims(C, longitude, latitude, 0, minLon, maxLon, minLat, maxLat)
	C_PNW_daily = np.sum(C_PNW, axis=(1,2))
	return C_PNW_daily
Ejemplo n.º 2
0
print 'Final merged var size: ' + str(varBase.shape)
print 'Final merged time array: ' + str(len(tBase))


#######################################################################
# Handle making the spatial subset
#######################################################################
if region  != '_':

	# Get the chosen region bounds
	minLat, maxLat, minLon, maxLon, resolution = cnm.getRegionBounds(region)

	# Subset the data based on the bounds of this region.
	varBase, latitude, longitude = cnm.mask2dims(varBase, longitude[:], latitude[:], 0,\
							                     xmin=minLon, xmax=maxLon,\
							                     ymin=minLat, ymax=maxLat)

	print 'Data subset to region ' + region



#######################################################################
# Write the merged file
#######################################################################
if ncVARType == 'era_interim':
	outputFile = outDir + ncVAR + region + \
		     str(startYear) + '_' + str(endYear) + '.nc'

elif ncVARType == 'GFED4s':
	outputFile = dataDir + 'GFED4.1s_ecmwf_' + ncVAR + region + \
Ejemplo n.º 3
0
figureDir = '../Figures/GFED_era_interm_analysis/' # always relativ to /Python

# Get emissions, use this to get dimensions
ncFile  = drive + "rebuild/GFED4.1s_METGrid_C_NA_2003_2016.nc"
nc = Dataset(ncFile, 'r')
latitude = nc.variables['latitude'][:]
longitude = nc.variables['longitude'][:]
time = nc.variables['time'][:]
C = nc.variables['C'][:]
nc.close()

# Make time into datetime arrays
time, month, year = cnm.get_era_interim_time(time)

# Spatially subset the data
C, ynew, xnew = cnm.mask2dims(C, longitude, latitude, 0, minLon, maxLon, minLat, maxLat)

################################################################################
# Show emissions time series for the domain
################################################################################
C_daily_total = np.sum(C,axis=(1,2)) # sums daily value for all lon lat
C_cumulative = np.cumsum(C_daily_total)

fig = plt.figure(figsize=(12,8))
ax = plt.subplot(111)
plt.plot(time, C_daily_total)
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.tick_params(axis='y', labelsize=20)
ax.tick_params(axis='x', labelsize=20)
plt.xlabel("date", fontsize=26)
Ejemplo n.º 4
0
    lon = lon1

###############################################################################
# Handle making the spatial subset
###############################################################################
x1 = GFED_nc.variables['C'][:]
x2 = FINN_nc.variables['CO2'][:] * gramsCarbonPerCO2

if region != '_':

    # Get the chosen region bounds
    minLat, maxLat, minLon, maxLon, resolution = cnm.getRegionBounds(region)

    # Subset the data based on the bounds of this region.
    x1, latNew, lonNew = cnm.mask2dims(x1, lon, lat, 0,\
               xmin=minLon, xmax=maxLon,\
               ymin=minLat, ymax=maxLat)

    x2, latNew, lonNew = cnm.mask2dims(x2, lon, lat, 0,\
                     xmin=minLon, xmax=maxLon,\
                     ymin=minLat, ymax=maxLat)

    # Need to use the subset dimensions moving forward
    lon = lonNew
    lat = latNew

###############################################################################
# Begin comparisons
###############################################################################

# x1_ = x1.ravel()
Ejemplo n.º 5
0
###############################################################################
# Handle spatially subsetting the data to be written.
###############################################################################
if domain == "_NA_":

	# These are the same _NA_ "North America" subset region used by
	# merge_yearly_nc.py

	minLat     = 30.
	maxLat     = 50.
	minLon     = 234.
	maxLon     = 259.

	dailyVAR, lat, lon = cnm.mask2dims(dailyVAR, lon[:], lat[:], tDim=0,
										xmin=minLon, xmax=maxLon,
										ymin=minLat, ymax=maxLat)

	outputFile = os.path.join(outputDir, 'z_all_NA_daily.nc')

else:
	outputFile = os.path.join(outputDir, 'z_all_daily.nc')


print '----------------------------------------------------------------------'
print 'outputFile used:'
print outputFile
print '----------------------------------------------------------------------'

###############################################################################
# Write the daily averaged netCDF data
Ejemplo n.º 6
0
print '-----------------------------------------------------------------------'
print 'It took ' + str(dt) + ' minutes to regrid (lons) of the emissions array'
print '-----------------------------------------------------------------------'

######################################################################################
# Subset this grid, by the maximum and minimum bounds of fires, for HMS inventory. No
# need to loop all over the world when there are only recorded fires in North America.
# This dramatically improves performance when HMS fires are those being regridded.
######################################################################################
if inventory == 'HMS':
    minLat = 10.
    maxLat = 85.
    minLon = 190.
    maxLon = 325.

    emissions, fire_lat, fire_lon = cnm.mask2dims(emissions, fire_lon, fire_lat,\
                 0, minLon, maxLon, minLat, maxLat)

######################################################################################
# Sanity plot for interactive analysis mode
######################################################################################
if sanityCheck:

    emissions_new_sum = np.sum(emissions, axis=0)
    emissions_ma = np.ma.masked_where(emissions_new_sum == 0,
                                      emissions_new_sum,
                                      copy=True)
    m = Basemap(projection='robin', lon_0=0, resolution='c')
    lons, lats = np.meshgrid(fire_lon, fire_lat)
    x, y = m(lons, lats)

    m = Basemap(projection='robin', lon_0=0, resolution='c')
m_f = str(endMonth)

# Get region lat lon range
minLat, maxLat, minLon, maxLon, resolution  = cnm.getRegionBounds(region)

# Get emissions, use this to get dimensions
ncFile = drive  + "GFED4s/GFED4.1s_ecmwf_C_2003_2016.nc"
nc = Dataset(ncFile, 'r')
latitude = nc.variables['latitude'][:]
longitude = nc.variables['longitude'][:]
time = nc.variables['time'][:]
C = nc.variables['C'][:]
nc.close()

# Spatially subset the GFED4s data
C, ynew, xnew = cnm.mask2dims(C, longitude, latitude, 0, minLon, maxLon, minLat, maxLat)

# Get burn area
ncFile = drive  + "GFED4s/GFED4.1s_ecmwf_burned_area_2003_2016.nc"
nc = Dataset(ncFile, 'r')
latitude = nc.variables['latitude'][:]
longitude = nc.variables['longitude'][:]
time = nc.variables['time']
time, month, year = cnm.get_era_interim_time(time)
BA = nc.variables['burned_area'][:]
nc.close()

BA, ynew, xnew = cnm.mask2dims(BA, longitude, latitude, 0, minLon, maxLon, minLat, maxLat)


################################################################################