def set_target(): from random import random outfile1 = open("ideal_wrap.dat","w") dx = 200.0/10000.0 dx = dx*1e-6 for x in range(10000): #print(' '.join(str(x) for x in [x*dx*1e6, refCylin(x*dx), "\n"])) outfile1.write(' '.join(str(x) for x in [x*dx*1e6, refCylin_wrapped(x*dx), "\n"])) outfile1.close() outfile2 = open("ideal_unwrap.dat","w") for x in range(10000): #print(' '.join(str(x) for x in [x*dx*1e6, refCylin(x*dx), "\n"])) outfile2.write(' '.join(str(x) for x in [x*dx*1e6, refCylin(x*dx), "\n"])) outfile2.close() peaks = find_peaks("ideal_wrap.dat") return peaks
import data_in_direct import smooth_curve import find_peaks import get_weight import data_out def get_accel_data(data): return [x[0] for x in data] def get_weight_data(data): return [x[1] for x in data] data = data_in_direct.start_collection() accel_data = get_accel_data(data) weight_data = get_weight_data(data) smooth_data = smooth_curve.smoothListGaussian(accel_data, 35) peaks = find_peaks.find_peaks(smooth_data) weight = get_weight.get_weight(weight_data) data = { "reps": len(peaks), "weight": weight } print len(peaks) print weight data_out.start_server(data)
plt.title('Convolution') plt.savefig('convolution.png') map_positive = map_filt - map_filt.min() map_normal = map_positive/map_positive.max() my_map = map_normal if trace ==1: fidx=fidx+1 plt.figure(fidx) plt.imshow(my_map/my_map.max()) plt.title('maplot(), map image') plt.savefig('map_image.png') plt.show() [peakInf_node_isLeaf_sort_am,peakInf_node_isLeaf_sort_energy_sum,peakInf_node_isLeaf,peakInf_node_all] =find_peaks.find_peaks(my_map) # # Found the highest point in the image # [x0_pix, y0_pix] is the axis of highest point, unit:pixel, axis original point locate left-up corner # my_map_max = max(my_map(:)); # [c r] = find(my_map>=my_map_max); # y0_pix= c(1); # x0_pix= r(1); centerPos = peakInf_node_isLeaf_sort_am[0]['centerPos'] y0_pix = centerPos[0] x0_pix = centerPos[1] #%%
map_positive = map_filt - map_filt.min() map_normal = map_positive / map_positive.max() my_map = map_normal if trace == 1: fidx = fidx + 1 plt.figure(fidx) plt.imshow(my_map / my_map.max()) plt.title('maplot(), map image') plt.savefig('map_image.png') plt.show() [ peakInf_node_isLeaf_sort_am, peakInf_node_isLeaf_sort_energy_sum, peakInf_node_isLeaf, peakInf_node_all ] = find_peaks.find_peaks(my_map) # # Found the highest point in the image # [x0_pix, y0_pix] is the axis of highest point, unit:pixel, axis original point locate left-up corner # my_map_max = max(my_map(:)); # [c r] = find(my_map>=my_map_max); # y0_pix= c(1); # x0_pix= r(1); centerPos = peakInf_node_isLeaf_sort_am[0]['centerPos'] y0_pix = centerPos[0] x0_pix = centerPos[1] #%% #% change the axis[x0_mas,y0_mas] unit: mas,axis original point in the image center
# This implements a phase vocoder for time-stretching/compression
band = 'r' chisq_min = 1e4 lcs = l2_service.get_SN_candidate_lcs(band, chisq_min) mjds = l2_service.mjds[band] print("# SNe candidates:", len(lcs)) # Define a +/-30 day window around the peak flux. dt = 30 outfile = 'tmp.txt' with open(outfile, 'w') as output: output.write('#objectId chisq ndof z t0 x0 x1 c\n') for objectId, fluxes in lcs.items()[:5]: peak_indexes = find_peaks(fluxes)[0][0] lc = lc_factory.create(objectId) for ipeak in peak_indexes: print("fitting object %i, peak index %i" % (objectId, ipeak)) mjd_peak = mjds[ipeak] mask = np.where((lc.data['mjd'] > mjd_peak - dt) & (lc.data['mjd'] < mjd_peak + dt) & (lc.data['bandpass'] != 'lsstu')) sn_data = lc.data[mask] model = sncosmo.Model(source='salt2-extended') model.set(t0=mjd_peak, z=0.2) try: res, fitted_model =\ sncosmo.fit_lc(sn_data, model, 'z t0 x0 x1 c'.split(), bounds=dict(z=(0.01, 1.))) except (RuntimeError, sncosmo.fitting.DataQualityError):