def inner_loop(mspice, ls_res, vector,time_res=3600): """ This is the inner loop that samples over <ls_res> L_s values and returns the integral for that time interval. Parameters: ls_res - Resolution of L_s over which to sample vector - attribute string for the vector to use as normal. Choice between (surface normal: snormal, tilted normal: tnormal, tilted and rotated normal: trnormal) time_res - seconds over which to sample the energy, default is 1 hour """ start_ls = mspice.l_s old_ls = 0 data = [] # while summing up within required ls_res and not crossing 360 while (mspice.l_s < start_ls + ls_res) and (mspice.l_s > old_ls): old_ls = mspice.l_s diff_angle = vsep(getattr(mspice,vector), mspice.sun_direction) if (mspice.illum_angles.dsolar > 90) or (np.degrees(diff_angle) > 90): to_append = 0 else: to_append = mspice.solar_constant * time_res * np.cos(diff_angle) # to_append = mspice.solar_constant*np.cos(diff_angle) data.append(to_append) mspice.advance_time_by(time_res) # create the best possible value for the integration by summing: energy = (np.sum(data[:-1]) + np.sum(data[1:]))/2.0 return energy, (old_ls - start_ls)
def test_smap(self): target = 'SMAP' et0 = spice.utc2et( '2016-06-01T12:00:00' ) dpr = spice.dpr() a,b,c = [spice.gdpool('BODY399_RADII',i,1)[1] for i in range(3)] ods = [] for deltatime in [0.1 * i for i in range(1080)]: et = et0 + deltatime stSmap,lsSmap = spice.spkezr( target, et, 'IAU_EARTH', 'NONE', 'EARTH' ) posn, veloc = stSmap[:3], stSmap[3:] stSun,lsSun = spice.spkezr( 'SUN', et0, 'IAU_EARTH', 'LT', 'EARTH' ) mtx = spice.pxform( 'SMAP_REFLECTOR', 'IAU_EARTH', et) boreEbf = spice.mxv( mtx, [1.0,0,0] ) point = spice.surfpt( posn, boreEbf, a, b, c) rsurfpt,lon,lat = spice.reclat( point ) utc = spice.et2utc( et, 'ISOC', 3 ) ods += [ OD(deltatime=deltatime,posn=posn,veloc=veloc,boreEbf=boreEbf ,utc=utc,point=point,rsurfpt=rsurfpt ,rsmap=spice.vnorm(posn),lat=lat,lon=lon ,raynge=spice.vnorm(spice.vsub(point,posn)) ,sunsep=spice.vsep( spice.ucrss(posn,veloc), stSun[:3] ) ) ] try: ### Moved matplotlib import to here so test runs to here at least from matplotlib import pyplot as plt plt.figure(1) keys = 'lat lon raynge'.split() secs = [od['deltatime'] for od in ods] for idx in range(len(keys)): scal = 1.0 if keys[idx] in 'rsurfpt rsmap raynge sunsep rp ecc t0 mu a P eccmean amean Pmean'.split() else dpr ordinate = [od[keys[idx]]*scal for od in ods] plt.subplot( 221+idx ) plt.plot( secs, ordinate ) plt.plot( secs, ordinate, '.') plt.title( keys[idx] ) plt.ylabel( '%s%s' % (keys[idx],'' if scal==1.0 else ', deg') ) if idx>1: plt.xlabel( 'T-T0, s' ) abscissa = [od['lon']*dpr for od in ods] ordinate = [od['lat']*dpr for od in ods] plt.subplot( 221+idx+1 ) plt.title( 'lon vs. lat' ) plt.plot( abscissa, ordinate ) plt.xlabel( 'lon, deg' ) plt.ylabel( 'lat, deg' ) plt.show() except: print( "Bypassed, or failed, matplotlib tests" )
def create_trnormal_arrays(mspicer, N, dt): ets = [] energies = [] for _ in range(N): ets.append(mspicer.et) diff_angle = vsep(mspicer.trnormal, mspicer.sun_direction) if (mspicer.illum_angles.dsolar > 90) or (np.degrees(diff_angle) > 90): to_append = 0 else: to_append = mspicer.solar_constant * dt.seconds * math.cos(diff_angle) energies.append(to_append) mspicer.time += dt return np.array((ets, energies))
def glintangle(scAltKm, scLonDeg, scLatDeg, surfLonDeg, surfLatDeg, uvEarth2Sun): """Function to calculate glint angle Inputs: S/C altitude, Longitude, Latitude Surface point Longitude, Latitude (altitude is zero by definition) Ephemeris time, s past J2000 EPOCH """ toms_alt_km = scAltKm toms_lon_rad = rpd * scLonDeg ### Scale degrees to radians toms_lat_rad = rpd * scLatDeg ### Scale degrees to radians surf_lon_rad = rpd * surfLonDeg surf_lat_rad = rpd * surfLatDeg ### Convert TOMS and surface points geodetic positions to ECEF vectors toms_vec = spice.georec(toms_lon_rad, toms_lat_rad, toms_alt_km, re, flattening) surfPoint = spice.georec(surf_lon_rad, surf_lat_rad, 0., re, flattening) ### Get normal at surface point, ECEF unit vector uvSurfNormal = spice.surfnm(re, re, rp, surfPoint) ### Get cosine of incidence angle (angle between Sun & surface normal vector) mu = spice.vdot(uvEarth2Sun, uvSurfNormal) if mu <= 0.: return 999.9 uvReflect = spice.vsub(spice.vscl(2. * mu, uvSurfNormal), uvEarth2Sun) ### Get specular reflection vector ### Return glint angle return dpr * spice.vsep(uvReflect, spice.vsub(toms_vec, surfPoint))
def test_horizons(self): import horizons target = 'C/2013 S1' target = 'C/2011 L4' spkFilename,spiceId,status = horizons.gomain(target) spice.furnsh( spkFilename ) self.kernels += [spkFilename] target_ = '_'.join( target.split() ) et0 = spice.utc2et( '2013-01-10T12:00:00' ) ls2au = spice.convrt( spice.clight(), 'KM', 'AU' ) dpr = spice.dpr() spd = spice.spd() deltatime = None while deltatime is None or abs(deltatime) > 5e-7: stS2I,lsS2I = spice.spkgeo( spiceId, et0, 'J2000', 10 ) posn, veloc = stS2I[:3], stS2I[3:] deltatime = - spice.vdot( posn, veloc ) / spice.vdot( veloc, veloc ) et0 += deltatime valarrs = [ ] print( (deltatime,spice.et2utc(et0,'ISOC',3),) ) deltatime = 1.0 sixmonths = spice.pi() * 1e7 while deltatime < sixmonths: for pmdet in (-deltatime,deltatime): et = et0 + pmdet utc = spice.et2utc(et,'ISOC',1) stD2I,lsD2I = spice.spkgeo( spiceId, et, 'J2000', -140) stI2S,lsI2S = spice.spkgeo( 10, et, 'J2000', spiceId ) stD2S,lsD2S = spice.spkgeo( 10, et, 'J2000', -140 ) rD2I, rI2S = [ ls * ls2au for ls in [lsD2I,lsI2S] ] aDIS, aSDI = [ ang * dpr for ang in [ spice.vsep( spice.vminus(stD2I[:3]), stI2S[:-3] ) , spice.vsep( stD2S[:3], stD2I[:-3] ) ] ] valarrs += [ (et,pmdet,rD2I,rI2S,aDIS,aSDI,utc,) ] deltatime *= 1.2 valarrs.sort() for valarr in valarrs: print( '%12.1f %9.3f %9.3f %7.2f %7.2f %s' % valarr[1:] ) days = [i[1]/spd for i in valarrs] titles = [ i % (target_,) for i in """ Range, %s-DI, AU Range, %s-Sun, AU Phase, DI-%s-Sun, deg Elongation, Sun-DI-%s, deg """.strip().split('\n')] try: ### Moved matplotlib import to here so test runs to here at least from matplotlib import pyplot as plt plt.figure(1) for idx in range(len(titles)): ordinate = [i[idx+2] for i in valarrs] plt.subplot( 221+idx ) plt.plot( days, ordinate ) plt.plot( days, ordinate, '.') plt.title( titles[idx] ) plt.ylabel( titles[idx] ) if idx>1: plt.xlabel( 'T-Tperi, d' ) plt.show() except: print( "Bypassed, or failed, matplotlib tests" )
def test_horizons(self): import horizons target = 'C/2013 S1' target = 'C/2011 L4' spkFilename, spiceId, status = horizons.gomain(target) spice.furnsh(spkFilename) self.kernels += [spkFilename] target_ = '_'.join(target.split()) et0 = spice.utc2et('2013-01-10T12:00:00') ls2au = spice.convrt(spice.clight(), 'KM', 'AU') dpr = spice.dpr() spd = spice.spd() deltatime = None while deltatime is None or abs(deltatime) > 5e-7: stS2I, lsS2I = spice.spkgeo(spiceId, et0, 'J2000', 10) posn, veloc = stS2I[:3], stS2I[3:] deltatime = -spice.vdot(posn, veloc) / spice.vdot(veloc, veloc) et0 += deltatime valarrs = [] print(( deltatime, spice.et2utc(et0, 'ISOC', 3), )) deltatime = 1.0 sixmonths = spice.pi() * 1e7 while deltatime < sixmonths: for pmdet in (-deltatime, deltatime): et = et0 + pmdet utc = spice.et2utc(et, 'ISOC', 1) stD2I, lsD2I = spice.spkgeo(spiceId, et, 'J2000', -140) stI2S, lsI2S = spice.spkgeo(10, et, 'J2000', spiceId) stD2S, lsD2S = spice.spkgeo(10, et, 'J2000', -140) rD2I, rI2S = [ls * ls2au for ls in [lsD2I, lsI2S]] aDIS, aSDI = [ ang * dpr for ang in [ spice.vsep(spice.vminus(stD2I[:3]), stI2S[:-3]), spice.vsep(stD2S[:3], stD2I[:-3]) ] ] valarrs += [( et, pmdet, rD2I, rI2S, aDIS, aSDI, utc, )] deltatime *= 1.2 valarrs.sort() for valarr in valarrs: print('%12.1f %9.3f %9.3f %7.2f %7.2f %s' % valarr[1:]) days = [i[1] / spd for i in valarrs] titles = [ i % (target_, ) for i in """ Range, %s-DI, AU Range, %s-Sun, AU Phase, DI-%s-Sun, deg Elongation, Sun-DI-%s, deg """.strip().split('\n') ] try: ### Moved matplotlib import to here so test runs to here at least from matplotlib import pyplot as plt plt.figure(1) for idx in range(len(titles)): ordinate = [i[idx + 2] for i in valarrs] plt.subplot(221 + idx) plt.plot(days, ordinate) plt.plot(days, ordinate, '.') plt.title(titles[idx]) plt.ylabel(titles[idx]) if idx > 1: plt.xlabel('T-Tperi, d') plt.show() except: print("Bypassed, or failed, matplotlib tests")
uvSurfNormal = spice.surfnm(re, re, rp, surfPoint) ### Get cosine of incidence angle (angle between Sun & surface normal vector) mu = spice.vdot(uvEarth2Sun, uvSurfNormal) if mu <= 0.: print('%s => %7s' % ( linestrip, 'Surface point is dark', )) ### Sun is below surface horizon continue uvReflect = spice.vsub(spice.vscl(2. * mu, uvSurfNormal), uvEarth2Sun) ### Get specular reflection vector glint_angle_deg = dpr * spice.vsep(uvReflect, spice.vsub(toms_vec, surfPoint)) print('%s => %7.2f %s' % ( linestrip, glint_angle_deg, '=Inputs[TOMS(alt,lon,lat),(Earth2Sun),Surface(lon,lat),UTC],GlintAngle', )) """ - Longitude and Latitude in degrees - Altitude in metres [Altitude,Lon,Lat;Geodet] [Earth-Sun Unit Vec, ECEF] [SurfGeodLonLat] [UTC] data: 766000 -10.743 -27.129 -.2577401 .8836004 -.3909224 -10.01 -26.768 2001-01-01T12:12:53 data: 766000 -10.743 -27.129 -.2577401 .8836004 -.3909224 -2.76 -25.307 2001-01-01T12:12:53 data: 766000 -10.743 -27.129 -.2577401 .8836004 -.3909224 2.76 -25.307 2001-01-01T12:12:53 data: 766000 -10.743 -27.129 -.2577401 .8836004 -.3909224 10.01 -26.768 2001-01-01T12:12:53 data: 766000 -10.743 -27.129 -.2577401 .8836004 -.3909224 30.01 -26.768 2001-01-01T12:12:53
def test_smap(self): target = 'SMAP' et0 = spice.utc2et('2016-06-01T12:00:00') dpr = spice.dpr() a, b, c = [spice.gdpool('BODY399_RADII', i, 1)[1] for i in range(3)] ods = [] for deltatime in [0.1 * i for i in range(1080)]: et = et0 + deltatime stSmap, lsSmap = spice.spkezr(target, et, 'IAU_EARTH', 'NONE', 'EARTH') posn, veloc = stSmap[:3], stSmap[3:] stSun, lsSun = spice.spkezr('SUN', et0, 'IAU_EARTH', 'LT', 'EARTH') mtx = spice.pxform('SMAP_REFLECTOR', 'IAU_EARTH', et) boreEbf = spice.mxv(mtx, [1.0, 0, 0]) point = spice.surfpt(posn, boreEbf, a, b, c) rsurfpt, lon, lat = spice.reclat(point) utc = spice.et2utc(et, 'ISOC', 3) ods += [ OD(deltatime=deltatime, posn=posn, veloc=veloc, boreEbf=boreEbf, utc=utc, point=point, rsurfpt=rsurfpt, rsmap=spice.vnorm(posn), lat=lat, lon=lon, raynge=spice.vnorm(spice.vsub(point, posn)), sunsep=spice.vsep(spice.ucrss(posn, veloc), stSun[:3])) ] try: ### Moved matplotlib import to here so test runs to here at least from matplotlib import pyplot as plt plt.figure(1) keys = 'lat lon raynge'.split() secs = [od['deltatime'] for od in ods] for idx in range(len(keys)): scal = 1.0 if keys[ idx] in 'rsurfpt rsmap raynge sunsep rp ecc t0 mu a P eccmean amean Pmean'.split( ) else dpr ordinate = [od[keys[idx]] * scal for od in ods] plt.subplot(221 + idx) plt.plot(secs, ordinate) plt.plot(secs, ordinate, '.') plt.title(keys[idx]) plt.ylabel('%s%s' % (keys[idx], '' if scal == 1.0 else ', deg')) if idx > 1: plt.xlabel('T-T0, s') abscissa = [od['lon'] * dpr for od in ods] ordinate = [od['lat'] * dpr for od in ods] plt.subplot(221 + idx + 1) plt.title('lon vs. lat') plt.plot(abscissa, ordinate) plt.xlabel('lon, deg') plt.ylabel('lat, deg') plt.show() except: print("Bypassed, or failed, matplotlib tests")
incidences = [] rev_srfvec = spice.vminus(mspice.srfvec) for sample in xrange(phase.shape[0]): if sample % 10 == 0: print('Sample {0}'.format(sample)) for line in xrange(phase.shape[1]): slope = float(slopes.data[sample, line]) aspect = float(aspects.data[sample, line]) # newPoint = Point(sample, line) # newPoint.pixel_to_lonlat(dem.geotransform, dem.projection) # mspice.set_spoint_by(lat = newPoint.lat, lon = newPoint.lon) mspice.tilt = slope mspice.aspect = aspect trnormal = mspice.tilted_rotated_normal incidence = spice.vsep(trnormal, mspice.sun_direction) emission = spice.vsep(trnormal, rev_srfvec) emissions.append(emission) incidences.append(incidence) # print("Inc: %f" % incidence) # print("Emis: %f" % emission) # phase[sample,line] = emissions = np.degrees(np.array(emissions)) incidences = np.degrees(np.array(incidences)) plt.hist(emissions, 90, label = 'emissions') plt.hist(incidences, 90, label = 'incidences') plt.legend()