def SH_kgkg_sur(self, ni=10): ''' Specific humidity [kg/kg] https://crudata.uea.ac.uk/cru/pubs/thesis/2007-willett/2INTRO.pdf ''' # temporary variable, interpolate station by station dewp = np.zeros((self.nt, self.nstation), dtype=np.float32) time_in = self.nc_sa.variables['time'][:].astype(np.int64) values = self.getValues(self.nc_sa, 'd2m', ni) # self.nc_sa.variables['d2m'][:] for n, s in enumerate(self.rg.variables['station'][:].tolist()): dewp[:, n] = series_interpolate(self.times_out_nc, time_in * 3600, values[:, n] - 273.15) # compute SH = spec_hum_kgkg(dewp[:, :], self.rg.variables['PRESS_pl'][:, :]) # add variable to ncdf file vn = 'SH_sur' # variable name var = self.rg.createVariable(vn, 'f4', ('time', 'station')) var.long_name = 'Specific humidity ERA-5 surface only' var.units = '1' var.standard_name = 'specific_humidity' self.rg.variables[vn][:, :] = SH
def WIND_sur(self): """ Wind speed and direction at 10 metre derived from surface data, exclusively. """ # temporary variable, interpolate station by station U = np.zeros((self.nt, self.nstation), dtype=np.float32) time_in = self.nc_sa.variables['time'][:].astype(np.int64) values = self.nc_sa.variables['U10M'][:] for n, s in enumerate(self.rg.variables['station'][:].tolist()): U[:, n] = series_interpolate(self.times_out_nc, time_in * 3600, values[:, n]) # temporary variable, interpolate station by station V = np.zeros((self.nt, self.nstation), dtype=np.float32) time_in = self.nc_sa.variables['time'][:].astype(np.int64) values = self.nc_sa.variables['V10M'][:] for n, s in enumerate(self.rg.variables['station'][:].tolist()): V[:, n] = series_interpolate(self.times_out_nc, time_in * 3600, values[:, n]) # add variable to ncdf file vn = 'WSPD_sur' # variable name var = self.rg.createVariable(vn, 'f4', ('time', 'station')) var.long_name = '10 metre wind speed {} surface only'.format(self.NAME) var.units = 'm s-1' var.standard_name = 'wind_speed' # add variable to ncdf file vn = 'WDIR_sur' # variable name var = self.rg.createVariable(vn, 'f4', ('time', 'station')) var.long_name = '10 metre wind direction {} surface only'.format( self.NAME) var.units = 'degree' var.standard_name = 'wind_from_direction' for n, s in enumerate(self.rg.variables['station'][:].tolist()): WS = np.sqrt(np.power(V[:, n], 2) + np.power(U[:, n], 2)) WD = [ atan2(V[i, n], U[i, n]) * (180 / pi) + 180 for i in np.arange(V.shape[0]) ] self.rg.variables['WSPD_sur'][:, n] = WS self.rg.variables['WDIR_sur'][:, n] = WD
def WIND_sur(self, ni=10): """ Wind speed and direction temperature derived from surface data, exclusively. """ # temporary variable, interpolate station by station U = np.zeros((self.nt, self.nstation), dtype=np.float32) time_in = self.nc_sa.variables['time'][:].astype(np.int64) values = self.getValues(self.nc_sa, 'u10', ni) # self.nc_sa.variables['u10'][:] for n, s in enumerate(self.rg.variables['station'][:].tolist()): U[:, n] = series_interpolate(self.times_out_nc, time_in * 3600, values[:, n]) # temporary variable, interpolate station by station V = np.zeros((self.nt, self.nstation), dtype=np.float32) time_in = self.nc_sa.variables['time'][:].astype(np.int64) values = self.getValues(self.nc_sa, 'v10', ni) # self.nc_sa.variables['v10'][:] for n, s in enumerate(self.rg.variables['station'][:].tolist()): V[:, n] = series_interpolate(self.times_out_nc, time_in * 3600, values[:, n]) # wind speed, add variable to ncdf file, convert vn_spd = 'WSPD_sur' # variable name var = self.rg.createVariable(vn_spd, 'f4', ('time', 'station')) var.long_name = '10 wind speed ERA-5 surface only' var.units = 'm s-1' var.standard_name = 'wind_speed' # wind direction, add variable to ncdf file, convert, relative to North vn_dir = 'WDIR_sur' # variable name var = self.rg.createVariable(vn_dir, 'f4', ('time', 'station')) var.long_name = '10 wind direction ERA-5 surface only' var.units = 'degree' var.standard_name = 'wind_from_direction' WS = np.sqrt(np.power(V, 2) + np.power(U, 2)) self.rg.variables[vn_spd][:, :] = WS # Wind direction: # U - easterly component V - northerly component # convert to "clockwise from north" from "anti-clockwise from x-axis" : 90 - angle # convert "from direction" : + 180 WD = 90 - (np.arctan2(V, U) * (180 / np.pi)) + 180 self.rg.variables[vn_dir][:, :] = WD
def AIRT_C_sur(self): """ Air temperature derived from surface data, exclusively. """ # add variable to ncdf file vn = 'AIRT_sur' # variable name var = self.rg.createVariable(vn, 'f4', ('time', 'station')) var.long_name = '2_metre_temperature {} surface only'.format(self.NAME) var.units = self.nc_sa.variables['t2m'].units.encode('UTF8') # interpolate station by station time_in = self.nc_sa.variables['time'][:].astype(np.int64) values = self.nc_sa.variables['t2m'][:] for n, s in enumerate(self.rg.variables['station'][:].tolist()): self.rg.variables[vn][:, n] = series_interpolate( self.times_out_nc, time_in * 3600, values[:, n] - 273.15)
def AIRT_C_pl(self): """ Air temperature derived from pressure levels, exclusively. """ vn = 'AIRT_pl' # variable name var = self.rg.createVariable(vn, 'f4', ('time', 'station')) var.long_name = 'air_temperature {} pressure levels only'.format( self.NAME) var.units = 'degrees_C' var.standard_name = 'air_temperature' # interpolate station by station time_in = self.nc_pl.variables['time'][:].astype(np.int64) values = self.nc_pl.variables['T'][:] for n, s in enumerate(self.rg.variables['station'][:].tolist()): self.rg.variables[vn][:, n] = series_interpolate( self.times_out_nc, time_in * 3600, values[:, n] - 273.15)
def PRESS_Pa_pl(self, ni=10): """ Surface air pressure from pressure levels. """ # add variable to ncdf file vn = 'PRESS_pl' # variable name var = self.rg.createVariable(vn, 'f4', ('time', 'station')) var.long_name = 'air_pressure ERA-5 pressure levels only' var.units = 'Pa' var.standard_name = 'surface_air_pressure' # interpolate station by station time_in = self.nc_pl.variables['time'][:].astype(np.int64) values = self.getValues(self.nc_pl, 'air_pressure', ni) for n, s in enumerate(self.rg.variables['station'][:].tolist()): # scale from hPa to Pa self.rg.variables[vn][:, n] = series_interpolate( self.times_out_nc, time_in * 3600, values[:, n]) * 100
def SH_kgkg_sur(self): ''' Specific humidity [kg/kg] derived from surface data, exclusively. ''' # add variable to ncdf file vn = 'SH_sur' # variable name var = self.rg.createVariable(vn, 'f4', ('time', 'station')) var.long_name = 'Specific humidity {} surface only'.format(self.NAME) var.units = '1' var.standard_name = 'specific_humidity' # interpolate station by station time_in = self.nc_sa.variables['time'][:].astype(np.int64) values = self.nc_sa.variables['QV2M'][:] for n, s in enumerate(self.rg.variables['station'][:].tolist()): self.rg.variables[vn][:, n] = series_interpolate( self.times_out_nc, time_in * 3600, values[:, n])
def LW_Wm2_sur(self): """ Long-wave radiation downwards derived from surface data, exclusively. """ # add variable to ncdf file vn = 'LW_sur' # variable name var = self.rg.createVariable(vn, 'f4', ('time', 'station')) var.long_name = 'Surface thermal radiation downwards {} surface only'.format( self.NAME) var.units = 'W m-2' var.standard_name = 'surface_downwelling_longwave_flux' # interpolate station by station time_in = self.nc_sf.variables['time'][:].astype(np.int64) values = self.nc_sf.variables['LWGDN'][:] for n, s in enumerate(self.rg.variables['station'][:].tolist()): self.rg.variables[vn][:, n] = series_interpolate( self.times_out_nc, time_in * 3600, values[:, n])
def RH_per_pl(self, ni=10): """ Relative humdity derived from pressure-level. """ # temporary variable, interpolate station by station rh = np.zeros((self.nt, self.nstation), dtype=np.float32) time_in = self.nc_sa.variables['time'][:].astype(np.int64) values = self.getValues(self.nc_pl, 'r', ni) for n, s in enumerate(self.rg.variables['station'][:].tolist()): rh[:, n] = series_interpolate(self.times_out_nc, time_in * 3600, values[:, n]) # add variable to ncdf file vn = 'RH_pl' # variable name var = self.rg.createVariable(vn, 'f4', ('time', 'station')) var.long_name = 'Relative humidity ERA-5 pressure-levels' var.units = 'percent' var.standard_name = 'relative_humidity' self.rg.variables[vn][:, :] = rh
def PRECCORR_mm_sur(self): """ Corrected Precipitation derived from surface data, exclusively. Convert units: kg/m2/s to mm/time_step (hours) 1 kg/m2 = 1mm """ # add variable to ncdf file vn = 'PRECCORR_sur' # variable name var = self.rg.createVariable(vn, 'f4', ('time', 'station')) var.long_name = 'Corrected Total precipitation {} surface only'.format( self.NAME) var.units = 'kg m-2 s-1' var.comment = "units [kg m-2 s-1] corresponds to [mm/s] for water (density 1000 [kg m-3])" var.standard_name = 'precipitation_flux' # interpolate station by station time_in = self.nc_sf.variables['time'][:].astype(np.int64) values = self.nc_sf.variables['PRECTOTCORR'][:] for n, s in enumerate(self.rg.variables['station'][:].tolist()): self.rg.variables[vn][:, n] = series_interpolate( self.times_out_nc, time_in * 3600, values[:, n]) * self.scf
def RH_per_pl(self): """ Relative Humdity derived from pressure level data, exclusively.Clipped to range [0.1,99.9]. """ # temporary variable, interpolate station by station time_in = self.nc_pl.variables['time'][:].astype(np.int64) values = self.nc_pl.variables['RH'][:] # add variable to ncdf file vn = 'RH_pl' # variable name var = self.rg.createVariable(vn, 'f4', ('time', 'station')) var.long_name = 'Relative humidity {} surface only'.format(self.NAME) var.units = 'percent' var.standard_name = 'relative_humidity' for n, s in enumerate(self.rg.variables['station'][:].tolist()): rh = series_interpolate(self.times_out_nc, time_in * 3600, values[:, n]) rh *= 100 # Convert to % self.rg.variables[vn][:, n] = rh
def RH_per_sur(self): """ Relative Humdity derived from surface data, exclusively.Clipped to range [0.1,99.9]. """ # temporary variable, interpolate station by station time_in = self.nc_sf.variables['time'][:].astype(np.int64) dewp = self.nc_sf.variables['T2MDEW'][:] t = self.nc_sa.variables['T2M'][:] relhu = relhu_approx_lawrence(t, dewp) # add variable to ncdf file vn = 'RH_sur' # variable name var = self.rg.createVariable(vn, 'f4', ('time', 'station')) var.long_name = 'Relative humidity {} surface only'.format(self.NAME) var.units = 'percent' var.standard_name = 'relative_humidity' for n, s in enumerate(self.rg.variables['station'][:].tolist()): rh = series_interpolate(self.times_out_nc, time_in * 3600, relhu[:, n]) self.rg.variables[vn][:, n] = rh
def RH_per_sur(self): """ Relative humdity derived from surface data, exclusively. Clipped to range [0.001, 0.999]. Kernel AIRT_ERAI_C_sur must be run before. """ # temporary variable, interpolate station by station dewp = np.zeros((self.nt, self.nstation), dtype=np.float32) time_in = self.nc_sa.variables['time'][:].astype(np.int64) values = self.nc_sa.variables['d2m'][:] for n, s in enumerate(self.rg.variables['station'][:].tolist()): dewp[:, n] = series_interpolate(self.times_out_nc, time_in * 3600, values[:, n] - 273.15) # add variable to ncdf file vn = 'RH_sur' # variable name var = self.rg.createVariable(vn, 'f4', ('time', 'station')) var.long_name = 'Relative humidity {} surface only'.format(self.NAME) var.units = 'percent' var.standard_name = 'relative_humidity' # simple: https://doi.org/10.1175/BAMS-86-2-225 RH = 100 - 5 * (self.rg.variables['AIRT_sur'][:, :] - dewp[:, :]) self.rg.variables[vn][:, :] = RH.clip(min=0.1, max=99.9) / 100
def RH_per_sur(self, ni=10): """ Relative humdity derived from surface data, exclusively. Clipped to range [0.1,99.9]. Kernel AIRT_C_sur must be run before. """ # temporary variable, interpolate station by station dewp = np.zeros((self.nt, self.nstation), dtype=np.float32) time_in = self.nc_sa.variables['time'][:].astype(np.int64) values = self.getValues(self.nc_sa, 'd2m', ni) # self.nc_sa.variables['d2m'][:] for n, s in enumerate(self.rg.variables['station'][:].tolist()): dewp[:, n] = series_interpolate(self.times_out_nc, time_in * 3600, values[:, n] - 273.15) # add variable to ncdf file vn = 'RH_sur' # variable name var = self.rg.createVariable(vn, 'f4', ('time', 'station')) var.long_name = 'Relative humidity ERA-5 surface only' var.units = 'percent' var.standard_name = 'relative_humidity' RH = relhu_approx_lawrence(self.rg.variables['AIRT_sur'][:, :], dewp[:, :]) self.rg.variables[vn][:, :] = RH.clip(min=0.1, max=99.9)