##// END OF EJS Templates
Some refac on Spectrograms...
jeandet -
r1472:8b544a6af98d
parent child
Show More
@@ -1,1 +1,1
1 Subproject commit 70d6748a06620f865b683c86c89cc27e1cb0d4b9
1 Subproject commit c6cf2dba079da680390ae2de0522a39964c5e629
@@ -337,76 +337,62 inline ColomapProperties CMAxisAnalysis(const TimeSeriesUtils::axis_properties&
337 colormap_v_resolution };
337 colormap_v_resolution };
338 }
338 }
339
339
340
341 template <bool condition, typename T, typename U>
342 std::enable_if_t<condition, T> constexpr conditional_v(T first, U second)
343 {
344 return first;
345 }
346
347 template <bool condition, typename T, typename U>
348 std::enable_if_t<!condition, U> constexpr conditional_v(T first, U second)
349 {
350 return second;
351 }
352
353 template <bool reversedAxis = true, bool reversedData = true>
340 inline std::vector<std::pair<int, int>> build_access_pattern(const std::vector<double>& axis,
354 inline std::vector<std::pair<int, int>> build_access_pattern(const std::vector<double>& axis,
341 const TimeSeriesUtils::axis_properties& axisProperties,
355 const TimeSeriesUtils::axis_properties& axisProperties,
342 const ColomapProperties& colormap_properties)
356 const ColomapProperties& colormap_properties)
343 {
357 {
344 std::vector<std::pair<int, int>> access_pattern;
358 std::vector<std::pair<int, int>> access_pattern;
345 for (int index = 0, cel_index = axis.size() - 1; index < colormap_properties.v_size_px; index++)
359 for (int index = 0, axis_index = conditional_v<reversedAxis>(axis.size() - 1, 0),
360 data_index = conditional_v<reversedData>(axis.size() - 1, 0);
361 index < colormap_properties.v_size_px; index++)
346 {
362 {
347 double current_y = pow(10., (axisProperties.max_resolution * index) + axisProperties.min);
363 double current_y = (axisProperties.max_resolution * index) + axisProperties.min;
348 if (current_y > axis[cel_index])
364 if (current_y > axis[axis_index])
349 cel_index--;
365 {
350 access_pattern.push_back({ index, cel_index });
366 conditional_v<reversedAxis>(
367 [&axis_index]() { axis_index--; }, [&axis_index]() { axis_index++; })();
368 conditional_v<reversedData>(
369 [&data_index]() { data_index--; }, [&data_index]() { data_index++; })();
370 }
371 access_pattern.push_back({ index, data_index });
351 }
372 }
352 return access_pattern;
373 return access_pattern;
353 }
374 }
354
375
355 /*=============================================================*/
376 inline bool is_log(const std::vector<double>& axis)
356
357 /**
358 * Specialization of PlottablesUpdater for spectrograms
359 * @sa SpectrogramSeries
360 */
361 template <typename T>
362 struct PlottablesUpdater<T,
363 typename std::enable_if_t<std::is_base_of<SpectrogramTimeSerie, T>::value>>
364 {
377 {
365 static void setPlotYAxisRange(T& dataSeries, const DateTimeRange& xAxisRange, QCustomPlot& plot)
378 if (axis.size() > 2)
366 {
379 {
367 auto [minValue, maxValue] = dataSeries.axis_range(1);
380 auto first = axis.front(), midle = axis[axis.size() / 2], last = axis.back();
368 std::cout << "min=" << minValue << " max=" << maxValue << std::endl;
381 auto error_linear = (midle - (last + first) / 2) / midle;
369 plot.yAxis->setRange(QCPRange { minValue, maxValue });
382 first = log10(first);
383 midle = log10(midle);
384 last = log10(last);
385 auto error_log = (midle - (last + first) / 2) / midle;
386 return error_log < error_linear;
370 }
387 }
371
388 return false;
372 static void updatePlottables(
373 T& dataSeries, PlottablesMap& plottables, const DateTimeRange& range, bool rescaleAxes)
374 {
375 if (plottables.empty())
376 {
377 qCDebug(LOG_VisualizationGraphHelper())
378 << QObject::tr("Can't update spectrogram: no colormap has been associated");
379 return;
380 }
389 }
381
390
382 // Gets the colormap to update (normally there is only one colormap)
391 template <typename accessPattern_t, typename colomapT, typename axProp_t, typename cmProp_t>
383 Q_ASSERT(plottables.size() == 1);
392 inline void fill_data(SpectrogramTimeSerie* serie, colomapT* colormap,
384 auto colormap = dynamic_cast<QCPColorMap*>(plottables.at(0));
393 const accessPattern_t& y_access_pattern, const axProp_t& xAxisProperties,
385 Q_ASSERT(colormap != nullptr);
394 const cmProp_t& colormap_properties)
386 auto plot = colormap->parentPlot();
387 auto [minValue, maxValue] = dataSeries.axis_range(1);
388 plot->yAxis->setRange(QCPRange { minValue, maxValue });
389 if (auto serie = dynamic_cast<SpectrogramTimeSerie*>(&dataSeries))
390 {
395 {
391 if (serie->size(0) > 2)
392 {
393 const auto& xAxis = serie->axis(0);
394 auto yAxis = serie->axis(1); // copy for in place reverse order
395 std::reverse(std::begin(yAxis), std::end(yAxis));
396 auto xAxisProperties = TimeSeriesUtils::axis_analysis<TimeSeriesUtils::IsLinear,
397 TimeSeriesUtils::CheckMedian>(xAxis, serie->min_sampling);
398 auto yAxisProperties = TimeSeriesUtils::axis_analysis<TimeSeriesUtils::IsLog,
399 TimeSeriesUtils::DontCheckMedian>(yAxis);
400 auto colormap_properties = CMAxisAnalysis(xAxisProperties, yAxisProperties);
401
402 colormap->data()->setSize(
403 colormap_properties.h_size_px, colormap_properties.v_size_px);
404 colormap->data()->setRange(
405 QCPRange { xAxisProperties.min, xAxisProperties.max }, { minValue, maxValue });
406
407 auto y_access_pattern
408 = build_access_pattern(serie->axis(1), yAxisProperties, colormap_properties);
409
410 auto line = serie->begin();
396 auto line = serie->begin();
411 auto next_line = line + 1;
397 auto next_line = line + 1;
412 double current_time = xAxisProperties.min;
398 double current_time = xAxisProperties.min;
@@ -437,8 +423,8 struct PlottablesUpdater<T,
437 if (line->t() + x_min_resolution > current_time)
423 if (line->t() + x_min_resolution > current_time)
438 {
424 {
439 {
425 {
440 std::transform(std::begin(*line), std::end(*line),
426 std::transform(std::begin(*line), std::end(*line), std::cbegin(line_values),
441 std::cbegin(line_values), std::begin(line_values),
427 std::begin(line_values),
442 [](const auto& input, auto output) { return input.v() + output; });
428 [](const auto& input, auto output) { return input.v() + output; });
443 }
429 }
444 avg_coef += 1.;
430 avg_coef += 1.;
@@ -456,6 +442,67 struct PlottablesUpdater<T,
456 current_time += xAxisProperties.max_resolution * 0.9;
442 current_time += xAxisProperties.max_resolution * 0.9;
457 }
443 }
458 }
444 }
445
446 /*=============================================================*/
447
448 /**
449 * Specialization of PlottablesUpdater for spectrograms
450 * @sa SpectrogramSeries
451 */
452 template <typename T>
453 struct PlottablesUpdater<T,
454 typename std::enable_if_t<std::is_base_of<SpectrogramTimeSerie, T>::value>>
455 {
456 static void setPlotYAxisRange(T& dataSeries, const DateTimeRange& xAxisRange, QCustomPlot& plot)
457 {
458 auto [minValue, maxValue] = dataSeries.axis_range(1);
459 plot.yAxis->setRange(QCPRange { minValue, maxValue });
460 }
461
462 static void updatePlottables(
463 T& dataSeries, PlottablesMap& plottables, const DateTimeRange& range, bool rescaleAxes)
464 {
465 if (plottables.empty())
466 {
467 qCDebug(LOG_VisualizationGraphHelper())
468 << QObject::tr("Can't update spectrogram: no colormap has been associated");
469 return;
470 }
471
472 // Gets the colormap to update (normally there is only one colormap)
473 Q_ASSERT(plottables.size() == 1);
474 auto colormap = dynamic_cast<QCPColorMap*>(plottables.at(0));
475 Q_ASSERT(colormap != nullptr);
476 auto plot = colormap->parentPlot();
477 auto [minValue, maxValue] = dataSeries.axis_range(1);
478 plot->yAxis->setRange(QCPRange { minValue, maxValue });
479 if (auto serie = dynamic_cast<SpectrogramTimeSerie*>(&dataSeries))
480 {
481 if (serie->size(0) > 2)
482 {
483 if (serie->y_is_log)
484 colormap->setDataScaleType(QCPAxis::stLogarithmic);
485 else
486 colormap->setDataScaleType(QCPAxis::stLinear);
487 const auto& xAxis = serie->axis(0);
488 auto yAxis = serie->axis(1); // copy for in place reverse order
489 auto y_is_log = is_log(yAxis);
490 std::reverse(std::begin(yAxis), std::end(yAxis));
491 auto xAxisProperties = TimeSeriesUtils::axis_analysis<TimeSeriesUtils::IsLinear,
492 TimeSeriesUtils::CheckMedian>(xAxis, serie->min_sampling);
493 auto yAxisProperties = TimeSeriesUtils::axis_analysis<TimeSeriesUtils::IsLog,
494 TimeSeriesUtils::DontCheckMedian>(yAxis);
495 auto colormap_properties = CMAxisAnalysis(xAxisProperties, yAxisProperties);
496
497 colormap->data()->setSize(
498 colormap_properties.h_size_px, colormap_properties.v_size_px);
499 colormap->data()->setRange(
500 QCPRange { xAxisProperties.min, xAxisProperties.max }, { minValue, maxValue });
501
502 auto y_access_pattern = build_access_pattern<false, true>(
503 yAxis, yAxisProperties, colormap_properties);
504 fill_data(serie, colormap, y_access_pattern, xAxisProperties, colormap_properties);
505 }
459 colormap->rescaleDataRange(true);
506 colormap->rescaleDataRange(true);
460 if (rescaleAxes)
507 if (rescaleAxes)
461 {
508 {
@@ -44,7 +44,7 def amda_make_spectro(var=None):
44 y = (max_v + min_v)/2.
44 y = (max_v + min_v)/2.
45 else:
45 else:
46 y = np.logspace(1,3,var.data.shape[1])[::-1]
46 y = np.logspace(1,3,var.data.shape[1])[::-1]
47 return pysciqlopcore.SpectrogramTimeSerie(var.time,y,var.data,min_sampling,max_sampling)
47 return pysciqlopcore.SpectrogramTimeSerie(var.time,y,var.data,min_sampling,max_sampling,True)
48
48
49 def amda_get_sample(metadata,start,stop):
49 def amda_get_sample(metadata,start,stop):
50 ts_type = amda_make_scalar
50 ts_type = amda_make_scalar
@@ -64,7 +64,7 def get_data(metadata,start,stop):
64 ts_type = pysciqlopcore.MultiComponentTimeSerie
64 ts_type = pysciqlopcore.MultiComponentTimeSerie
65 default_ctor_args = (0,2)
65 default_ctor_args = (0,2)
66 elif value == 'spectrogram':
66 elif value == 'spectrogram':
67 ts_type = lambda t,values: pysciqlopcore.SpectrogramTimeSerie(t,np.logspace(1,3,32)[::-1],values,np.nan,np.nan)
67 ts_type = lambda t,values: pysciqlopcore.SpectrogramTimeSerie(t,np.logspace(1,3,32)[::-1],values,np.nan,np.nan,True)
68 default_ctor_args = (0,2)
68 default_ctor_args = (0,2)
69 if key == 'cache' and value == 'true':
69 if key == 'cache' and value == 'true':
70 use_cache = True
70 use_cache = True
General Comments 0
You need to be logged in to leave comments. Login now