def demosuncor(T, glat, glon, alt_m): #%% Solar location with GLOW yd, utsec = datetime2yd(T)[:2] solar = Panel(items=['glow', 'astropy'], major_axis=T, minor_axis=['dec', 'ra', 'gst']) tic = time() for d, s, t in zip(yd, utsec, T): solar['glow'].loc[t] = glowfort.suncor(d, s) fortsec = time() - tic solar.ix['glow', :, 'dec'] = degrees(solar.ix['glow', :, 'dec']) solar.ix['glow', :, 'ra'] = degrees(solar.ix['glow', :, 'ra']) solar.ix['glow', :, 'gst'] = degrees(solar.ix['glow', :, 'gst']) #%% solar location with AstroPy tic = time() sza, sun, sunobs = solarzenithangle(T, glat, glon, alt_m) pysec = time() - tic solar.ix['astropy', :, 'dec'] = sun.dec.degree solar.ix['astropy', :, 'ra'] = sun.ra.degree solar.ix['astropy', :, 'gst'] = sunobs.obstime.sidereal_time('apparent', 'greenwich').degree print('in seconds, fortran time: {:.3f} python time: {:.3f} '.format( fortsec, pysec)) return solar, sza
def demosuncor(T, glat, glon, alt_m): # %% Solar location with GLOW yd, utsec = datetime2yd(T)[:2] solar = xarray.DataArray(np.empty((T.size, 2, 4)), dims=['time', 'algorithm', 'coord'], coords={ 'time': T, 'algorithm': ['glow', 'astropy'], 'coord': ['dec', 'ra', 'gst', 'sza'] }) tic = time() for d, s, t in zip(yd, utsec, T): solar.loc[t, 'glow', ['dec', 'ra', 'gst']] = glowfort.sun_angles.suncor(d, s) fortsec = time() - tic solar.loc[:, 'glow', ['dec', 'ra', 'gst']] = np.degrees( solar.loc[:, 'glow', ['dec', 'ra', 'gst']]) # %% solar location with AstroPy tic = time() sza, sun, sunobs = solarzenithangle(T, glat, glon, alt_m) pysec = time() - tic solar.loc[:, 'astropy', 'dec'] = sun.dec.degree solar.loc[:, 'astropy', 'ra'] = sun.ra.degree solar.loc[:, 'astropy', 'gst'] = sunobs.obstime.sidereal_time('apparent', 'greenwich').degree solar.loc[:, 'astropy', 'sza'] = sza print( f'in seconds, fortran time: {fortsec:.3f} python time: {pysec:.3f} ') return solar
def demosolzen(dtime, glat, glon): #%% SZA with glow yd, utsec = datetime2yd(dtime)[:2] sza_glow = empty_like(dtime, dtype=float) for j, (d, s) in enumerate(zip(yd, utsec)): sza_glow[j] = glowfort.solzen(d, s, glat, glon) return DataFrame(index=dtime, data=sza_glow, columns=['glow'])
def demosolzen(t: datetime, glat: float, glon: float): """demo the solar zenith angle calclation vs AstroPy""" # %% SZA with glow yd, utsec = datetime2yd(dtime) sza_glow = np.empty_like(dtime, dtype=float) for j, (d, s) in enumerate(zip(yd, utsec)): sza_glow[j] = glowfort.sun_angles.solzen(d, s, glat, glon) return sza_glow
def test_yearint(): for t in T: yd, utsec = sd.datetime2yd(t) utsec2 = sd.dt2utsec(t) if isinstance(t, datetime.datetime): assert sd.yd2datetime(yd, utsec) == t elif isinstance(t, np.datetime64): assert sd.yd2datetime(yd, utsec) == sd.forceutc( t.astype(datetime.datetime)) else: assert sd.yd2datetime(yd, utsec).date() == t assert utsec == utsec2
nbins = 190 jmax = 170 #glow.h eflux = 1. e0 = 1e3 maxind = 112 glat = 70 glon = 0 #like aurora.in ap = 4 f107 = 100 f107a = 100 nmaj = 3 nst = 6 dtime = datetime(1999, 12, 21) # yd, utsec = datetime2yd(dtime)[:2] def test_egrid_maxt(): ener, dE = glowfort.egrid() assert_allclose(ener[[maxind, maxind + 10, -1]], [1017.7124, 1677.9241, 1.004643e+08], rtol=1e-5) #%% test of maxt phi = glowfort.maxt(eflux, e0, ener, dE, itail=0, fmono=nan, emono=nan) assert phi.argmax() == maxind assert_allclose(phi[[maxind, maxind + 10]], [114810.6, 97814.438]) #%% test vquart (quartic root) KNOWN DEFECTIVE FORTRAN ALGORITHM #Aquart = tile([-1,0,0,0,1],(jmax,1))
def runglowaurora(eflux,e0,dt,glat,glon,f107a,f107,f107p,ap,mass): chdir(glowpath) yd,utsec = datetime2yd(dt)[:2] z = arange(80,110+1,1) z = append(z,array([111.5,113.,114.5,116.,118.,120.,122.,124.,126., 128.,130.,132.,134.,136.,138.,140.,142.,144.,146., 148.,150.,153.,156.,159.,162.,165.,168.,172.,176., 180.,185.,190.,195.,200.,205.,211.,217.,223.,230.,237.,244.,252.,260.,268.,276.,284.,292.,300.,309., 318.,327.,336.,345.,355.,365.,375.,385.,395.,406., 417.,428.,440.,453.,467.,482.,498.,515.,533.,551., 570.,590.,610.,630.,650.,670.,690.,710.,730.,750., 770.,790.,810.,830.,850.,870.,890.,910.,930.,950.])) glowfort.cglow.zz = z*1e5 glowfort.cglow.znd[:]=0. # Set other parameters and switches: glowfort.cglow.jlocal = 0 glowfort.cglow.kchem = 4 glowfort.cglow.iscale = 1 glowfort.cglow.xuvfac = 3. glowfort.cglow.hlybr = 0. glowfort.cglow.fexvir = 0. glowfort.cglow.hlya = 0. glowfort.cglow.heiew = 0. #%% (1) setup flux at top of ionosphere ener,dE = glowfort.egrid() phitop = glowfort.maxt(eflux,e0,ener, dE, itail=0, fmono=0, emono=0) phi = hstack((ener[:,None],dE[:,None],phitop[:,None])) glowfort.cglow.zz = z*1e5 glowfort.cglow.znd[:]=0. #%% (2) call MSIS tselecopts = (1,)*25 dens,temp=rungtd1d(dt,z,glat,glon,f107a,f107,ap,mass,tselecopts) glowfort.cglow.zo = dens['O'] glowfort.cglow.zn2 = dens['N2'] glowfort.cglow.zo2 = dens['O2'] glowfort.cglow.zrho = dens['Total'] glowfort.cglow.zns = dens['N'] glowfort.cglow.ztn = temp['heretemp'] #%% (3) call snoem """ Call SNOEMINT to obtain NO profile from the Nitric Oxide Empirical Model (NOEM) """ glowfort.cglow.zno = glowfort.snoemint(dt.strftime('%Y%j'), glat,glon,f107,ap,z,temp['heretemp']) #%% (4a) call iri-90 outf,oarr = runiri(dt,z,glat,glon,f107,f107a,ap,mass=48) chdir(glowpath) #need this since iri90 changes path #%% (4b) store iri90 in COMMON blocks, after unit conversion glowfort.cglow.ze = outf['ne']/1e6 # M-3 -> CM-3 glowfort.cglow.ze[glowfort.cglow.ze<100.] = 100. glowfort.cglow.zti = outf['Ti'] i = glowfort.cglow.zti<glowfort.cglow.ztn glowfort.cglow.zti[i] = glowfort.cglow.ztn[i] glowfort.cglow.zte = outf['Te'] i = glowfort.cglow.zte<glowfort.cglow.ztn glowfort.cglow.zte[i] = glowfort.cglow.ztn[i] glowfort.cglow.zxden[2,:] = outf['nO+']/1e6 glowfort.cglow.zxden[5,:] = outf['nO2+']/1e6 glowfort.cglow.zxden[6,:] = outf['nNO+']/1e6 #%% glow model ion,ecalc,photI,ImpI,isr = glowfort.aurora(z,yd,utsec,glat,glon%360, f107a,f107,phi) #%% handle the outputs including common blocks zeta=glowfort.cglow.zeta.T #columns 11:20 are identically zero ver = DataFrame(index=z, data=zeta[:,:11], columns=[3371, 4278, 5200, 5577, 6300,7320,10400,3466, 7774, 8446,3726]) photIon = DataFrame(index=z, data=hstack((photI[:,None],ImpI[:,None],ecalc[:,None],ion)), columns=['photoIoniz','eImpactIoniz','ne', 'nO+(2P)','nO+(2D)','nO+(4S)','nN+','nN2+','nO2+','nNO+', 'nO','nO2','nN2','nNO']) isrparam = DataFrame(index=z, data=isr, columns=['ne','Te','Ti']) phitop = DataFrame(index=phi[:,0], #eV data=phi[:,2], #diffnumflux columns=['diffnumflux']) zceta = glowfort.cglow.zceta.T return ver,photIon,isrparam,phitop,zceta