def simulationRun(t, running): loop = 0 delta_t = 100. r_offset = [0., 0., 0.] v_offset = [0., 0., 0.] while running: for objCount in range(0, maxObjCount): r_true, v_true, h_true = p[objCount].propagate(t) # print "r,v,h: ",t, r_true, v_true, h_true r_obs, v_obs, h_obs = p[objCount].observe(r_true, v_true, r_offset, v_offset) # Evaluation process # - when new data is received compute element set # - attempt to correlate element set with previously received data # - if correlates, then evaluate statistics of data for this object # - determine if any other object represents a collision hazard with this object obs.model(t, r_obs, v_obs, h_obs) t = t + delta_t loop = loop + 1 if loop > 4: running = False return t
def __init__(self,fieldid,cadence,X1,Color,telescope): X1_Color=[(X1,Color)] zrange=[0.01] zrange+=[val for val in np.arange(0.1,1.5,0.1)] DayMax_step=0.5 filename='Observations/Obs_'+str(fieldid)+'_'+str(cadence)+'.txt' obs_tot=Observations(fieldid=fieldid, filename=filename) season=0 obs=obs_tot.seasons[season] r=[] mjds=np.arange(min(obs['mjd']),max(obs['mjd']),DayMax_step) for z in zrange: for mjd in mjds: for (x1,c) in X1_Color: r.append((z,x1,c,mjd)) params=np.rec.array(r, dtype=[('z', 'f8'),('X1', 'f8'), ('Color', 'f8'),('DayMax','f8')]) name='Light_Curves/Simul_'+str(fieldid)+'_Cadence_'+str(cadence)+'_X1_'+str(X1_Color[0][0])+'_Color_'+str(X1_Color[0][1])+'.pkl' #simulate self.Simul_LCs(params,obs,telescope,fname=name)
def Median_log_summary(fi, bands, j, out_q=None): r = [] fieldid = (fi.split('/')[-1]).split('_')[1] fieldid = int(fieldid.split('.')[0]) obs = Observations(fieldid, filename=fi, season_length=120., names=['observationStartMJD', 'fieldRA', 'fieldDec']) #print(fi,len(obs.seasons)) for i in range(len(obs.seasons)): season = obs.seasons[i] duration_tot = np.max(season['observationStartMJD']) - np.min( season['observationStartMJD']) #print(i,season) for band in bands: idx = season['filter'] == band sel = season[idx] if len(sel) >= 1: m5 = np.median(sel['fiveSigmaDepth']) airmass = np.median(sel['airmass']) sky = np.median(sel['skyBrightness']) seeing = np.median(sel['finSeeing']) moon = np.median(sel['moonPhase']) moondist = np.median(sel['moonDistance']) moonRA = np.median(sel['moonRA']) moonDec = np.median(sel['moonDec']) moonAlt = np.median(sel['moonAlt']) moonAz = np.median(sel['moonAz']) cloud = np.median(sel['cloud']) cadence = np.median(sel['observationStartMJD'][1:] - sel['observationStartMJD'][:-1]) ra_sn = np.median(sel['RA_SN']) dec_sn = np.median(sel['Dec_SN']) nvisits = np.median(sel['Nvisits']) duration_band = np.max(sel['observationStartMJD']) - np.min( sel['observationStartMJD']) r.append( (fieldid, ra_sn, dec_sn, band, cadence, m5, airmass, sky, seeing, moon, nvisits, moondist, moonRA, moonDec, moonAlt, moonAz, cloud, duration_band, duration_tot)) res = None if len(r) > 0: res = np.rec.fromrecords(r, names=[ 'fieldid', 'RA_SN', 'Dec_SN', 'band', 'cadence', 'm5', 'airmass', 'skyBrightness', 'finSeeing', 'moonPhase', 'Nvisits', 'moonDistance', 'moonRA', 'moonDec', 'moonAlt', 'moonAz', 'cloud', 'seas_length_band', 'seas_length_all' ]) if out_q is not None: out_q.put({j: res}) else: return res
def Process(fieldname, fieldids, simu_name, thedir, ifirst, ilast, inum, season, coadd=True): myobs = {} mylist = {} season_loop = [season] if season == -1: season_loop = range(10) print('season loop', season_loop) for seasonl in season_loop: mylist[seasonl] = [] for i, fieldid in enumerate(fieldids[ifirst:ilast]): name = 'Observations_' + fieldname + '_' + str(fieldid) + '.txt' obs = Observations(fieldid=fieldid, filename=thedir + '/' + name, season_length=50.) #print('Nseasons',len(obs.seasons)) myobs[fieldid] = {} for seasonl in season_loop: #myobs[fieldid][season]=obs.seasons[season] if seasonl in range(len(obs.seasons)): mylist[seasonl].append((fieldid, obs.seasons[seasonl])) #print(len(fieldids),ifirst,ilast,len(myobs)) bands = 'ugrizy' tot_tab = None tab_all = None coadd = coadd suffend = '' if coadd: suffend = '_all' ifile = 0 """ mylist=[] for key,valb in myobs.items(): print(key,valb.keys()) if season in valb.keys(): mylist.append((key,valb[season])) """ #print('hello',len(mylist)) #inum=1 name = 'Cadence' + extent + '_' + fieldname + suffend #tot_tab=Multi(mylist,tot_tab,coadd,season,name) for seasonl in season_loop: print('processing', seasonl) Multi(mylist[seasonl], coadd, seasonl, name) """
def Get_duration(fieldname, fieldid, season, OpSim_Logs_dir): filename = OpSim_Logs_dir + '/Observations_' + fieldname + '_' + str( fieldid) + '.txt' myobs = Observations(fieldid=fieldid, filename=filename) myseason = myobs.seasons[season] iddx = myseason['band'] != 'LSSTPG::u' mysel = myseason[iddx] min_season = np.min(mysel['mjd']) max_season = np.max(mysel['mjd']) return min_season, max_season
def Median_log_summary_old(files, bands, j, out_q=None): r = [] #print('files',files) #for fi in files[:1000]: for fi in files: print('hello', fi) fieldid = (fi.split('/')[-1]).split('_')[1] fieldid = int(fieldid.split('.')[0]) obs = Observations( fieldid, filename=fi, season_length=365., names=['observationStartMJD', 'fieldRA', 'fieldDec']) #print(fi,len(obs.seasons)) for i in range(len(obs.seasons)): season = obs.seasons[i] #print(i,season) for band in bands: idx = season['filter'] == band sel = season[idx] if len(sel) >= 2: m5 = np.median(sel['fiveSigmaDepth']) airmass = np.median(sel['airmass']) sky = np.median(sel['skyBrightness']) seeing = np.median(sel['finSeeing']) moon = np.median(sel['moonPhase']) cadence = np.median(sel['observationStartMJD'][1:] - sel['observationStartMJD'][:-1]) ra_sn = np.median(sel['RA_SN']) dec_sn = np.median(sel['Dec_SN']) r.append((fieldid, ra_sn, dec_sn, band, cadence, m5, airmass, sky, seeing, moon)) res = np.rec.fromrecords(r, names=[ 'fieldid', 'RA_SN', 'Dec_SN', 'band', 'cadence', 'm5', 'airmass', 'skyBrightness', 'finSeeing', 'moonPhase' ]) if out_q is not None: out_q.put({j: res}) else: return res
def Load_file(fi, j, out_q=None): #print('here',fi) fieldid = (fi.split('/')[-1]).split('_')[1] fieldid = int(fieldid.split('.')[0]) obs = Observations(fieldid, filename=fi, season_length=365., names=['observationStartMJD', 'fieldRA', 'fieldDec']) #print(len(obs.seasons)) res = None if len(obs.seasons) > 0: res = obs.seasons[0] if out_q is not None: out_q.put({j: res}) else: return res
def generate_graph(self, postal_code, country_code, start, end, selected_metrics, graph_type, grid): observations = Observations.Observations(postal_code, country_code, start, end) figure(num=None, figsize=(18, 6), dpi=80, facecolor='w', edgecolor='k') vs_titles = '' for metric in selected_metrics: title = stringcase.titlecase(metric) metric_values = observations.get_values_by_key(metric) label = title + ' ' + metric_values['unit_code'] if graph_type == 'bar': plt.bar(metric_values['timestamps'], metric_values['values'], label=label) elif graph_type == 'barh': plt.barh(metric_values['timestamps'], metric_values['values'], label=label) elif graph_type == 'scatter': plt.scatter(metric_values['timestamps'], metric_values['values'], label=label) else: plt.plot(metric_values['timestamps'], metric_values['values'], label=label) if vs_titles == '': vs_titles += title else: vs_titles += ' vs. ' + title plt.xlabel("Date") plt.ylabel("Value") plt.title( f"{vs_titles}\n{postal_code}, {country_code}\nFrom {start} to {end}" ) plt.legend() plt.grid(grid) plt.show() self.update_status('Graph Successfully Created!', 'green')
min_rf_phase = opts.min_rf_phase max_rf_phase = opts.max_rf_phase T0min = opts.T0min T0max = opts.T0max dirout = opts.dirout multiproc = opts.multiproc X1C = opts.X1C T0step = opts.T0step OpSim_Logs_dir = os.getenv('OPSIM_LOGS') filename = OpSim_Logs_dir + '/' + opts.dirmeas + '/Observations_' + opts.fieldname + '_' + str( fieldid) + '.txt' #filename='OpSimLogs/WFD/Observations_WFD_'+str(fieldid)+'.txt' myobs = Observations(fieldid=fieldid, filename=filename) dirout += '_' + str(T0step).replace('.', '_') if X1C != '': dirout += X1C outdir = '/sps/lsst/data/dev/pgris/' + dirout + '/' + opts.dirmeas + '/' + str( fieldid) + '/Season_' + str(num_season) if not os.path.exists(outdir): os.makedirs(outdir) print(len(myobs.seasons)) tab_X1_c = None if X1 == -999. or Color == -999.: pkl_file = open('Map_X1_C' + X1C + '.pkl', 'rb') tab_X1_c = pkl.load(pkl_file)
import numpy as np from Observations import * import pylab as plt import heapq import pickle as pkl thedir = '/sps/lsst/users/gris/Files_from_OpSim/OpSimLogs' fieldname = 'WFD' fieldid = 586 name = 'Observations_' + fieldname + '_' + str(fieldid) + '.txt' myobs = Observations(fieldid=fieldid, filename=thedir + '/' + fieldname + '/' + name) """ dir_pkl='/sps/lsst/data/dev/pgris/sims_operations/SN_LC/Obs_minion_1016' name_pkl='Observations_'+fieldname+'_'+str(fieldid)+'.pkl' pkl_file = open(dir_pkl+'/'+name_pkl,'rb') thedict=pkl.load(pkl_file) obser_orig=thedict['dataSlice'] """ #print len(myobs.seasons),obser_orig.dtype for seas in range(10): obs_tot = myobs.seasons[seas] for band in 'g': idx = obs_tot['band'] == 'LSSTPG::' + band obs = obs_tot[idx] obs = obs_tot diff = obs['mjd'][1:] - obs['mjd'][:-1]
#thedir='/sps/lsst/users/gris/Files_from_OpSim/OpSimLogs' thedir = '/pbs/throng/lsst/users/gris/SN_Simulation/Analyze_OpSim/OpSimLogs' thedir += simuname files = glob.glob(thedir + '/WFD/Year_2/N_healpix_64_coadd/*.txt') #print(files) r = [] num = -1 for fi in files: spl = fi.split('/')[-1] fieldid = spl.split('_')[-1].split('.')[0] myobs = Observations(fieldid=int(fieldid), filename=fi, season_length=365.) if len(myobs.seasons) >= 1: season = myobs.seasons[0] if len(season) >= 100: #print fieldid,len(season) num += 1 rcad = [] for band in 'ugrizy': idx = season['band'] == 'LSSTPG::' + band sel = season[idx] diff = sel['mjd'][1:] - sel['mjd'][:-1] if len(sel) >= 2: #print fieldid,band,len(season),np.median(diff) #r.append((fieldid,band,np.median(diff))) rcad.append(np.median(diff)) else:
import Projectile as proj import Observations as obs import numpy as np maxObjCount = 4 t = 0.0 obs = obs.Observations() p = [None] * maxObjCount def createObject(objCount): # initialize element set with this TLE # 1 05398U 71067E 17237.19596243 .00000191 00000-0 60767-4 0 9996 # 2 05398 87.6282 147.4622 0065864 59.7371 301.0323 14.33603389412679 # Semi-major axis a = 7157.e3 # eccentricity e = 0.0065864 # inclination if (objCount == 1): i = proj.deg2radian(1.0) else: i = proj.deg2radian(87.6282) # argument of perigee omega_AP = proj.deg2radian(59.7371) # longitude of the acsending node if (objCount < 2):
ra=[] corresp=dict(zip(bands+'a',[i for i in range(len(bands)+1)])) corresp_inverted=dict(zip([i for i in range(len(bands)+1)],bands+'a')) field_radec=[] thedir='OpSimLogs'+suffix+'/'+fieldname files=glob.glob(thedir+'/*_'+fieldname+'_*.txt') print 'alors',files,thedir+'/*_'+fieldname+'_*.txt' myobs={} for fi in files: splita=fi.split('/')[-1] splitb=splita.split('_') rav=float(splitb[-2]) decv=float(splitb[-1].split('.txt')[0]) fieldid=str(rav)+'_'+str(decv) myobs[fieldid]=Observations(fieldid=fieldid, filename=fi) all_diff={} for key, vals in myobs.items(): print key,len(vals.seasons) all_diff[key]={} print 'nombre de saison',key,len(vals.seasons) for season in range(10): myseason=vals.seasons[season] all_diff[key][season]={} full_season=myseason.copy() full_season.sort(order='mjd') idx = full_season['band'] != 'LSSTPG::u'
oob = obs['mjd'][1:] - obs['mjd'][:-1] return np.median(oob) def sel(tab, band): idx = tab['band'] == 'LSSTPG::' + band return tab[idx] filea = '../../Ana_Cadence/OpSimLogs_test/DD/Observations_DD_290.txt' fileb = 'OpSimLogs/DD/Observations_DD_290.txt' obsa = Observations(fieldid=290, filename=filea) obsb = Observations(fieldid=290, filename=fileb) bands = 'g' print len(obsa.seasons), len(obsb.seasons) for season in range(len(obsa.seasons)): seasa = obsa.seasons[season] seasb = obsb.seasons[season] #print seasa for band in bands: sela = sel(seasa, band) selb = sel(seasb, band) print Cadence(sela), Cadence(selb), len(sela), len(selb) for i in range(len(sela)):