#open a new blank netcdf file to which we will be writting data outRootGrp = Dataset(outNetCDF_File, 'w', format='NETCDF3_CLASSIC') if (inRootGrp.start_year != startDate.year): raise Exception("Specified simulation start year ({0}) does not match with input vapor pressure data file data year.".format(startDate.year)) exit() # DEBUG: print global attributes of the original file: ## for gAttribute in inRootGrp.ncattrs(): ## print 'Global attribute name:', gAttribute, '=', getattr(inRootGrp,gAttribute) # add global file level attributes to the new netcdf file outRootGrp.start_year = inRootGrp.start_year outRootGrp.data_variable_name = inRootGrp.data_variable_name outRootGrp.data_time_step = inTimeStep outRootGrp.orginal_data_source = 'Daymet Software Version 2.0' outRootGrp.conventions = 'CF-1.0' outRootGrp.modified_data_source = 'CI Water System' outRootGrp.spatial_reference = 'NAD83_UTM_Zone_12N' outRootGrp.datum = 'D_North_America_1983' # get dimension values from the original netcdf file inputTimeVar = inRootGrp.variables['time'] inputXvar = inRootGrp.variables['x'] inputYvar = inRootGrp.variables['y'] inputVpVar = inRootGrp.variables[inRootGrp.data_variable_name] print(inputTimeVar.shape[0]) print(inputXvar.shape[0]) print(inputYvar.shape[0])
inputTaTimeVar = inRootGrpTa.variables['time'] inputVpVar = inRootGrpVp.variables[inRootGrpVp.data_variable_name] inputVpTimeVar = inRootGrpVp.variables['time'] #DEBUG: print netcdf variable diemensions print('Dimension of Temp var: ' + str(inputTaVar.shape)) print('Dimension of Vp var: ' + str(inputVpVar.shape)) #open a new blank netcdf file to which we will be writting data outRootGrp = Dataset(outRH_NetCDFFile, 'w', format='NETCDF3_CLASSIC') # add global file level attributes to the new netcdf file outRootGrp.start_year = inRootGrpTa.start_year outRootGrp.data_variable_name = outNetCDFDataVariableName outRootGrp.data_time_step = inRootGrpTa.data_time_step outRootGrp.orginal_data_source = 'Daymet Software Version 2.0' outRootGrp.conventions = 'CF-1.0' outRootGrp.modified_data_source = 'CI Water System' outRootGrp.spatial_reference = 'NAD83_UTM_Zone_12N' outRootGrp.datum = 'D_North_America_1983' # create 3 dimensions for the output netcdf file outTimeDimensionSize = inputVpVar.shape[0] outYvarDimensionSize = inputVpVar.shape[1] outXvarDimensionSize = inputVpVar.shape[2] outRootGrp.createDimension('time', outTimeDimensionSize) outRootGrp.createDimension('x', outXvarDimensionSize) outRootGrp.createDimension('y', outYvarDimensionSize)