def get_profile(self, date, minh, maxh, params): # create filename: filename = archive_config.highres_sonde_dir + "/" + \ date.strftime("%Y%m%d%H") + "_physical" (samples, station) = self.read_sonde(filename) size = 0 for hgt in samples.iterkeys(): if minh <= hgt <= maxh: size = size + 1 # convert to numpy arrays: hgts = np.zeros((size), dtype=float) vals = {} for param in params: vals[param] = np.zeros((size), dtype=float) vals[param][:] = np.nan idx = 0 for hgt in samples.iterkeys(): if minh <= hgt <= maxh: hgts[idx] = hgt for param in params: if param == 'wvel_knt': if (samples[hgt]["wvel_knt"] < 2): vals[param][idx] = None else: vals[param][idx] = samples[hgt]["wvel_knt"] if param == 'u_knt': if (samples[hgt]["wvel_knt"] is None or samples[hgt]["wdir_deg"] is None): vals[param][idx] = None else: vals[param][idx] = -1. * samples[hgt][ "wvel_knt"] * math.sin( math.radians(samples[hgt]["wdir_deg"])) elif param == 'v_knt': if (samples[hgt]["wvel_knt"] is None or samples[hgt]["wdir_deg"] is None): vals[param][idx] = None else: vals[param][idx] = -1. * samples[hgt][ "wvel_knt"] * math.cos( math.radians(samples[hgt]["wdir_deg"])) elif param == 'wdir_deg': # remove wind dir values when wind speed is < 1 m/s if (samples[hgt]["wvel_knt"] < 2): vals[param][idx] = None else: vals[param][idx] = samples[hgt][param] else: vals[param][idx] = samples[hgt][param] idx = idx + 1 return VerticalProfile(hgts, vals, station)
def get_station_profile(self, wmoid, datetime, minh, maxh, param): # load sonde data: (samples, station) = self.load_sonde(wmoid, datetime) # convert to numpy arrays: # calculate size: size = 0 for hgt in samples.iterkeys(): if minh <= hgt <= maxh: size = size + 1 # create arrays: hgts = np.zeros((size), dtype=float) vals = np.zeros((size), dtype=float) # fill arrays: idx = 0 for hgt in samples.iterkeys(): if minh <= hgt <= maxh: hgts[idx] = hgt vals[idx] = samples[hgt][param] idx = idx + 1 # providing resulting profile: return VerticalProfile(hgts, vals, station)
test_date = dt.datetime(2016, 07, 01, 00, 00) wmoId = 40179 station = stations_list.stations[wmoId] stations = [station] minh = 15000 maxh = 25000 params = ["wvel_knt", "wdir_deg", "u_knt", "v_knt", "pres_hpa"] #param = "wdir_deg" db = ProfileDatabase() wrf_profile = db.get_profile("WRF", station, test_date, minh, maxh, params) hi_sonde_profile = db.get_profile("HIRES", station, test_date, minh, maxh, params) lo_sonde_profile = db.get_profile("LORES", station, test_date, minh, maxh, params) rescaled_hi_profile = hi_sonde_profile.interpolate(wrf_profile.heights) rescaled_lo_profile = lo_sonde_profile.interpolate(wrf_profile.heights) plot_profile(VerticalProfile( wrf_profile.heights, { "WRF WD(knot)": wrf_profile.values["wvel_knt"], "HIRES WD(knot)": rescaled_hi_profile.values["wvel_knt"], "LORES WD(knot)": rescaled_lo_profile.values["wvel_knt"] }, station), None, None, title="")