def test_hwm(): t = datetime(2013, 3, 31, 12) glat = 65 glon = -148 altkm = 150 f107a = 100 f107 = 100 ap = 4 wind = hwm93.run(t, altkm, glat, glon, f107a, f107, ap) assert wind['meridional'] == approx(-110.16133881, rel=1e-4) # gfortran 4.6 vs 5.2 assert wind['zonal'] == approx(-12.40071201, rel=1e-4) # gfortran 4.6 vs 5.2
def main(): p = ArgumentParser(description='calls HWM93 from Python, a basic demo') p.add_argument('simtime', help='yyyy-mm-ddTHH:MM:SS time of sim', nargs='?', default='2016-01-01T12') p.add_argument('-a', '--altkm', help='altitude (km) (start,stop,step)', type=float, nargs='+', default=(60, 1000, 5)) p.add_argument('-c', '--latlon', help='geodetic latitude (deg)', type=float, default=(65, -148)) p.add_argument('f107a', help=' 81 day AVERAGE OF F10.7 FLUX (centered on day DDD)', type=float, nargs='?', default=150) p.add_argument('f107', help='DAILY F10.7 FLUX FOR PREVIOUS DAY', type=float, nargs='?', default=150) p.add_argument('ap', help='daily ap', type=int, nargs='?', default=4) p.add_argument('-o', '--outfn', help='write NetCDF (HDF5) of data') p = p.parse_args() altkm = arange(p.altkm[0], p.altkm[1], p.altkm[2]) glat, glon = p.latlon T = parse(p.simtime) winds = hwm93.run(T, altkm, glat, glon, p.f107a, p.f107, p.ap) if p.outfn: outfn = Path(p.outfn).expanduser() print('writing', outfn) winds.to_netcdf(outfn) plothwm(winds) show()
def main(): p = ArgumentParser(description="calls HWM93 from Python, a basic demo") p.add_argument("simtime", help="yyyy-mm-ddTHH:MM:SS time of sim", nargs="?", default="2016-01-01T12") p.add_argument("-a", "--altkm", help="altitude (km) (start,stop,step)", type=float, nargs="+", default=(60, 1000, 5)) p.add_argument("-c", "--latlon", help="geodetic latitude (deg)", type=float, default=(65, -148)) p.add_argument("f107a", help=" 81 day AVERAGE OF F10.7 FLUX (centered on day DDD)", type=float, nargs="?", default=150) p.add_argument("f107", help="DAILY F10.7 FLUX FOR PREVIOUS DAY", type=float, nargs="?", default=150) p.add_argument("ap", help="daily ap", type=int, nargs="?", default=4) p.add_argument("-o", "--outfn", help="write NetCDF (HDF5) of data") p = p.parse_args() altkm = arange(p.altkm[0], p.altkm[1], p.altkm[2]) glat, glon = p.latlon T = parse(p.simtime) winds = hwm93.run(T, altkm, glat, glon, p.f107a, p.f107, p.ap) if p.outfn: outfn = Path(p.outfn).expanduser() print("writing", outfn) winds.to_netcdf(outfn) plothwm(winds) show()
def getHWM(dt, lat, lon, elev): """ Gets the zonal and meridional winds at a specifc time and space dt - datetime obj lat, lon, elev - floats of position given in deg, deg, km """ if MODE == 93: winds = hwm93.run(dt, altkm=elev, glat=lat, glon=lon, f107a=150, f107=150, ap=4) u, v = winds.zonal.values[0], winds.meridional.values[0] else: dec_ut = dt.hour + dt.minute/60 + dt.second/3600 doy = dt.timetuple().tm_yday winds = HWM14(alt=elev, glat=lat, glon=lon, ut=dec_ut, \ year=dt.year, day=doy) print(winds) return u, v
def air_drag_par(df, filename, sw_data, gcrs_filename, date_i): """ This function is designed to calculate the wind speed for the satellite. Args: df (dask.datafram): dataframe containing different information filename (str): the output file name """ # extract year month date hour minute second year = np.int(filename[-11:-7]) year = np.dot(np.ones(df.__len__()), year).astype(np.int) month = np.int(filename[-6:-4]) month = np.dot(np.ones(df.__len__()), month).astype(np.int) utc_time = df.utc_time.compute().to_numpy() xpos = df.xpos.compute().to_numpy() ypos = df.ypos.compute().to_numpy() zpos = df.zpos.compute().to_numpy() date = np.floor((utc_time - utc_time[0]) / 86400.).astype(np.int) + date_i hour = np.floor((utc_time - utc_time[0] - (date - date_i) * 86400.) / 3600.).astype(np.int) minute = np.floor((utc_time - utc_time[0] - hour * 3600.0 - (date - date_i) * 86400.) / 60.).astype(np.int) second = np.mod((utc_time - utc_time[0] - hour * 3600.0 - (date - date_i) * 86400. - minute * 60.0), 60.).astype(np.int) # using astropy transform ecef to geodetic pos_el = el.from_geocentric(x=xpos, y=ypos, z=zpos, unit='km') lla_el = pos_el.to_geodetic() lat = np.asarray(lla_el.lat) lon = np.asarray(lla_el.lon) alt = np.asarray(lla_el.height) # wind speed winds = np.zeros([df.__len__(), 2]) air_density = np.zeros(df.__len__()) for i, y in enumerate(year): y = np.int(y) h = np.int(hour[i]) mon = np.int(month[i]) d = np.int(date[i]) minu = np.int(minute[i]) sec = np.int(second[i]) date_time = datetime.datetime(y, mon, d, h, minu, sec) para_input, para_output = nrlmsise00(date_time, lat[i], lon[i], alt[i], sw_data) air_density[i] = para_output['Density'][ 'RHO[kg/m^3]'] # unit = km / m^(-3) reg = hwm93.run(date_time, altkm=alt[i], glat=lat[i], glon=lon[i], f107=para_input['f107Daily[10^-22 W/m^2/Hz]'], f107a=para_input['f107Average[10^-22 W/m^2/Hz]'], ap=para_input['ApDaily']) winds[i, 0] = reg.meridional.values winds[i, 1] = reg.zonal.values # cartesian 2 spherical slat, slon = transform.cartesian_to_spherical(xpos, ypos, zpos, with_radius=False) # lat ns_morethan_0 = np.where(winds[:, 0] >= 0) ns_lessthan_0 = np.where(winds[:, 0] < 0) slat[ns_morethan_0] = np.abs(slat[ns_morethan_0] - np.pi / 2.0) slat[ns_lessthan_0] = -np.abs(slat[ns_lessthan_0] - np.pi / 2.0) ns_x, ns_y, ns_z = transform.spherical_to_cartesian( winds[:, 0], slat, slon) # lon lon_lessthan_0 = np.where(slon < 0) slon[lon_lessthan_0] = 2 * np.pi + slon[lon_lessthan_0] slon[ns_morethan_0] = slon[ns_morethan_0] + np.pi / 2.0 slon[ns_lessthan_0] = slon[ns_lessthan_0] - np.pi / 2.0 lon_lessthan_0 = np.where(slon < 0) slon[lon_lessthan_0] = 2 * np.pi + slon[lon_lessthan_0] lon_morethan_2 = np.where(slon >= 2 * np.pi) slon[lon_morethan_2] = slon[lon_morethan_2] - 2 * np.pi lon_morethan_p = np.where(slon > np.pi) slon[lon_morethan_p] = slon[lon_morethan_p] - 2 * np.pi ew_x, ew_y, ew_z = transform.spherical_to_cartesian( winds[:, 1], np.zeros(slon.__len__()), slon) winds_x = ew_x + ns_x winds_y = ew_y + ns_y winds_z = ew_z + ns_z winds_vector = np.c_[winds_x, winds_y, winds_z] angular_vector = np.asarray([0.0, 0.0, 7.2921158553e-5]) spos = np.c_[xpos, ypos, zpos] svel = np.c_[df.xvel.compute().to_numpy(), df.yvel.compute().to_numpy(), df.zvel.compute().to_numpy()] relative_velocity = (svel * 1000. - winds_vector - np.cross(angular_vector, spos * 1000.)) / 1000. itrs2gcrs(year, month, date, hour, minute, second, spos, relative_velocity, utc_time, gcrs_filename) return relative_velocity, air_density