In [1]:
import tensorflow as tf
import numpy
import scipy.io
#from tensorflow.python.client import timeline
import time

quantiMesi = 1
quantiHertz = 1



percorsoDati = "/home/protoss/Documenti/TESI/DATI/in_O2LL_02_0187_.mat"
#percorsoDati = "/home/protoss/Documenti/TESI/DATI/dati9mesi052HWI.mat"
#percorsoDati = "/home/protoss/Documenti/TESI/DATI/datiOLDmesi108HWI.mat"
#percorsoDati = "/home/protoss/wn100bkp/dati/datiunmese.mat"


#tFft = 8192
tFft = 4096
tObs = quantiMesi #mesi
tObs = tObs*30*24*60*60

#carico file dati
struttura = scipy.io.loadmat(percorsoDati)['job_pack_0']

#peakmap = struttura['peaks'][0,0]
#print(peakmap)
#tempiIndiciSorted = numpy.argsort(peakmap[0,:])
#tempi = peakmap[0, tempiIndiciSorted]
#frequenze = peakmap[1, tempiIndiciSorted]
#pesi =peakmap[4, tempiIndiciSorted] + 1 #numpy.ones(peakmap[4].size)#

#print(tempi)
#print(frequenze)
#print(pesi)

tempi = struttura['peaks'][0,0][0].astype(numpy.float32)
frequenze = struttura['peaks'][0,0][1].astype(numpy.float32)
pesi = (struttura['peaks'][0,0][4]+1).astype(numpy.float32)



print((numpy.amax(tempi)-numpy.amin(tempi))*24*60*60)


filtro1 = numpy.where(tempi>57800)
tempi = tempi[filtro1]
frequenze = frequenze[filtro1]
filtro2 = numpy.where(tempi<57831)
tempi = tempi[filtro2]
frequenze = frequenze[filtro2]
filtro3 = numpy.where(frequenze<188)
tempi = tempi[filtro3]
frequenze = frequenze[filtro3]

frequenze.size


23129887.5
Out[1]:
258203

In [2]:
tempiVecchi = tempi
freqVecchi = frequenze
pesiVecchi = pesi
for i in numpy.arange(1,quantiMesi):
    tempiNuovi = tempiVecchi + i*30
    freqNuovi = freqVecchi
    pesiNuovi = pesiVecchi 
    tempi = numpy.concatenate((tempi,tempiNuovi))
    frequenze = numpy.concatenate((frequenze,freqNuovi))
    pesi = numpy.concatenate((pesi,pesiNuovi))

    
tempiVecchi = tempi
freqVecchi = frequenze
pesiVecchi = pesi    
for j in numpy.arange(1,quantiHertz):
    tempiNuovi = tempiVecchi
    freqNuovi = freqVecchi + j
    pesiNuovi = pesiVecchi
    tempi = numpy.concatenate((tempi,tempiNuovi))
    frequenze = numpy.concatenate((frequenze,freqNuovi))
    pesi = numpy.concatenate((pesi,pesi))

In [95]:
from matplotlib import pyplot
%matplotlib notebook
a = pyplot.scatter(tempi,frequenze, s=0.1)



In [3]:
#nb: picchi ha 0-tempi
#              1-frequenze
#              2-pesi

#headers vari
securbelt = 4000


#frequenze
#frequenze
stepFrequenza = 1/tFft
enhancement = 10
stepFreqRaffinato =  stepFrequenza/enhancement

freqMin = numpy.amin(frequenze)
freqMax = numpy.amax(frequenze)
freqIniz = freqMin- stepFrequenza/2 - stepFreqRaffinato
freqFin = freqMax + stepFrequenza/2 + stepFreqRaffinato
nstepFrequenze = numpy.ceil((freqFin-freqIniz)/stepFreqRaffinato)

#tempi
#epoca definita come mediana di tempi di tutto il run
epoca = (57722+57990)/2 #0
#epoca = 0

#spindowns
spindownMin = -1e-9
spindownMax = 2e-10
stepSpindown = stepFrequenza/tObs 

nstepSpindown = numpy.round((spindownMax-spindownMin)/stepSpindown).astype(numpy.int32)

# riarrangio gli array in modo che abbia i dati 
# nel formato che voglio io
frequenze = frequenze-freqIniz
frequenze = (frequenze/stepFreqRaffinato)-round(enhancement/2+0.001)

tempi = tempi-epoca
tempi = ((tempi)*3600*24/stepFreqRaffinato)
#tempi = numpy.round(tempi/1e8)*1e8

spindowns = numpy.arange(0, nstepSpindown)
spindowns = numpy.multiply(spindowns,stepSpindown)
spindowns = numpy.add(spindowns, spindownMin)
# così ho i tre array delle tre grandezze, 
#più i pesi e la fascia di sicurezza
 



#ora uso Tensorflow
securbeltTF = tf.constant(securbelt,dtype=tf.float32)
tempiTF = tf.constant(tempi,dtype=tf.float32)
pesiTF = tf.constant(pesi,dtype=tf.float32)
spindownsTF = tf.constant(spindowns, dtype=tf.float32)
frequenzeTF = tf.constant(frequenze, dtype=tf.float32)

nRows = nstepSpindown
nColumns = numpy.int32(nstepFrequenze)
print(nColumns,nRows)

def frequencyHough(nu,t, nuDot, w, numRows, numColumns):
	numColumns = numColumns + securbelt

	def rowTransform(ithSD):
		sdTimed = tf.multiply(nuDot[ithSD], t)

		transform = tf.round(nu-sdTimed+securbeltTF/2)
		transform = tf.cast(transform, dtype=tf.int32)
		values = tf.unsorted_segment_sum(w, transform, numColumns)
		#values = tf.cast(values, dtype=tf.float32)
		return values

	houghLeft = tf.map_fn(rowTransform, tf.range(0, numRows), 
					dtype=tf.float32, parallel_iterations=10)
	houghRight = houghLeft[:,enhancement:numColumns]-houghLeft[:,0:numColumns - enhancement]
	houghDiff = tf.concat([houghLeft[:,0:enhancement],houghRight],1)
	houghMap = tf.cumsum(houghDiff, axis = 1)
	print(sessione.run(houghMap).shape)
	return houghMap 

sessione = tf.Session()

start = time.time()

hough  = frequencyHough(frequenzeTF, tempiTF, spindownsTF,pesiTF,nRows,nColumns)

image = sessione.run(hough)

stop = time.time()
print(stop-start)


from matplotlib import pyplot

pyplot.figure(figsize=(12, 8))

a = pyplot.imshow(image, origin = 'lower', interpolation = 'none', aspect = 300)
pyplot.colorbar(shrink = 0.5,aspect = 15)
pyplot.show()


42492 13
---------------------------------------------------------------------------
InvalidArgumentError                      Traceback (most recent call last)
~/.local/lib/python3.5/site-packages/tensorflow/python/framework/common_shapes.py in _call_cpp_shape_fn_impl(op, input_tensors_needed, input_tensors_as_shapes_needed, debug_python_shape_fn, require_shape_fn)
    670           graph_def_version, node_def_str, input_shapes, input_tensors,
--> 671           input_tensors_as_shapes, status)
    672   except errors.InvalidArgumentError as err:

/usr/lib/python3.5/contextlib.py in __exit__(self, type, value, traceback)
     65             try:
---> 66                 next(self.gen)
     67             except StopIteration:

~/.local/lib/python3.5/site-packages/tensorflow/python/framework/errors_impl.py in raise_exception_on_not_ok_status()
    465           compat.as_text(pywrap_tensorflow.TF_Message(status)),
--> 466           pywrap_tensorflow.TF_GetCode(status))
    467   finally:

InvalidArgumentError: Dimensions must be equal, but are 8744670 and 258203 for 'map/while/UnsortedSegmentSum' (op: 'UnsortedSegmentSum') with input shapes: [8744670], [258203], [].

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
<ipython-input-3-000ea5119b50> in <module>()
     86 start = time.time()
     87 
---> 88 hough  = frequencyHough(frequenzeTF, tempiTF, spindownsTF,pesiTF,nRows,nColumns)
     89 
     90 image = sessione.run(hough)

<ipython-input-3-000ea5119b50> in frequencyHough(nu, t, nuDot, w, numRows, numColumns)
     75 
     76 	houghLeft = tf.map_fn(rowTransform, tf.range(0, numRows), 
---> 77 					dtype=tf.float32, parallel_iterations=10)
     78         houghRight = houghLeft[:,enhancement:numColumns]-houghLeft[:,0:numColumns - enhancement]
     79         houghDiff = tf.concat([houghLeft[:,0:enhancement],houghRight],1)

~/.local/lib/python3.5/site-packages/tensorflow/python/ops/functional_ops.py in map_fn(fn, elems, dtype, parallel_iterations, back_prop, swap_memory, infer_shape, name)
    387         parallel_iterations=parallel_iterations,
    388         back_prop=back_prop,
--> 389         swap_memory=swap_memory)
    390     results_flat = [r.stack() for r in r_a]
    391 

~/.local/lib/python3.5/site-packages/tensorflow/python/ops/control_flow_ops.py in while_loop(cond, body, loop_vars, shape_invariants, parallel_iterations, back_prop, swap_memory, name)
   2768     context = WhileContext(parallel_iterations, back_prop, swap_memory, name)
   2769     ops.add_to_collection(ops.GraphKeys.WHILE_CONTEXT, context)
-> 2770     result = context.BuildLoop(cond, body, loop_vars, shape_invariants)
   2771     return result
   2772 

~/.local/lib/python3.5/site-packages/tensorflow/python/ops/control_flow_ops.py in BuildLoop(self, pred, body, loop_vars, shape_invariants)
   2597       self.Enter()
   2598       original_body_result, exit_vars = self._BuildLoop(
-> 2599           pred, body, original_loop_vars, loop_vars, shape_invariants)
   2600     finally:
   2601       self.Exit()

~/.local/lib/python3.5/site-packages/tensorflow/python/ops/control_flow_ops.py in _BuildLoop(self, pred, body, original_loop_vars, loop_vars, shape_invariants)
   2547         structure=original_loop_vars,
   2548         flat_sequence=vars_for_body_with_tensor_arrays)
-> 2549     body_result = body(*packed_vars_for_body)
   2550     if not nest.is_sequence(body_result):
   2551       body_result = [body_result]

~/.local/lib/python3.5/site-packages/tensorflow/python/ops/functional_ops.py in compute(i, tas)
    377       """
    378       packed_values = input_pack([elem_ta.read(i) for elem_ta in elems_ta])
--> 379       packed_fn_values = fn(packed_values)
    380       nest.assert_same_structure(dtype or elems, packed_fn_values)
    381       flat_fn_values = output_flatten(packed_fn_values)

<ipython-input-3-000ea5119b50> in rowTransform(ithSD)
     70                 transform = tf.round(nu-sdTimed+securbeltTF/2)
     71                 transform = tf.cast(transform, dtype=tf.int32)
---> 72                 values = tf.unsorted_segment_sum(w, transform, numColumns)
     73                 #values = tf.cast(values, dtype=tf.float32)
     74                 return values

~/.local/lib/python3.5/site-packages/tensorflow/python/ops/gen_math_ops.py in unsorted_segment_sum(data, segment_ids, num_segments, name)
   2701   result = _op_def_lib.apply_op("UnsortedSegmentSum", data=data,
   2702                                 segment_ids=segment_ids,
-> 2703                                 num_segments=num_segments, name=name)
   2704   return result
   2705 

~/.local/lib/python3.5/site-packages/tensorflow/python/framework/op_def_library.py in apply_op(self, op_type_name, name, **keywords)
    765         op = g.create_op(op_type_name, inputs, output_types, name=scope,
    766                          input_types=input_types, attrs=attr_protos,
--> 767                          op_def=op_def)
    768         if output_structure:
    769           outputs = op.outputs

~/.local/lib/python3.5/site-packages/tensorflow/python/framework/ops.py in create_op(self, op_type, inputs, dtypes, input_types, name, attrs, op_def, compute_shapes, compute_device)
   2506                     original_op=self._default_original_op, op_def=op_def)
   2507     if compute_shapes:
-> 2508       set_shapes_for_outputs(ret)
   2509     self._add_op(ret)
   2510     self._record_op_seen_by_control_dependencies(ret)

~/.local/lib/python3.5/site-packages/tensorflow/python/framework/ops.py in set_shapes_for_outputs(op)
   1871       shape_func = _call_cpp_shape_fn_and_require_op
   1872 
-> 1873   shapes = shape_func(op)
   1874   if shapes is None:
   1875     raise RuntimeError(

~/.local/lib/python3.5/site-packages/tensorflow/python/framework/ops.py in call_with_requiring(op)
   1821 
   1822   def call_with_requiring(op):
-> 1823     return call_cpp_shape_fn(op, require_shape_fn=True)
   1824 
   1825   _call_cpp_shape_fn_and_require_op = call_with_requiring

~/.local/lib/python3.5/site-packages/tensorflow/python/framework/common_shapes.py in call_cpp_shape_fn(op, input_tensors_needed, input_tensors_as_shapes_needed, debug_python_shape_fn, require_shape_fn)
    608     res = _call_cpp_shape_fn_impl(op, input_tensors_needed,
    609                                   input_tensors_as_shapes_needed,
--> 610                                   debug_python_shape_fn, require_shape_fn)
    611     if not isinstance(res, dict):
    612       # Handles the case where _call_cpp_shape_fn_impl calls unknown_shape(op).

~/.local/lib/python3.5/site-packages/tensorflow/python/framework/common_shapes.py in _call_cpp_shape_fn_impl(op, input_tensors_needed, input_tensors_as_shapes_needed, debug_python_shape_fn, require_shape_fn)
    674       missing_shape_fn = True
    675     else:
--> 676       raise ValueError(err.message)
    677 
    678   if missing_shape_fn:

ValueError: Dimensions must be equal, but are 8744670 and 258203 for 'map/while/UnsortedSegmentSum' (op: 'UnsortedSegmentSum') with input shapes: [8744670], [258203], [].

In [ ]: