libsim  Versione6.3.0

◆ vol7d_recompute_stat_proc_agg()

subroutine vol7d_class_compute::vol7d_recompute_stat_proc_agg ( type(vol7d), intent(inout)  this,
type(vol7d), intent(out)  that,
integer, intent(in)  stat_proc,
type(timedelta), intent(in)  step,
type(datetime), intent(in), optional  start,
real, intent(in), optional  frac_valid,
type(vol7d), intent(inout), optional  other,
integer, intent(in), optional  stat_proc_input 
)

Specialized method for statistically processing a set of data already processed with the same statistical processing, on a different time interval.

This method performs statistical processing by aggregation of shorter intervals. Only floating point single or double precision data are processed.

The output that vol7d object contains elements from the original volume this satisfying the conditions

  • real single or double precision variables
  • timerange (vol7d_timerange_class::vol7d_timerange::timerange) of type stat_proc (or stat_proc_input if provided)
  • any p1 (analysis/observation or forecast)
  • p2 > 0 (processing interval non null, non instantaneous data) and equal to a multiplier of step

Output data will have timerange of type stat_proc and p2 = step. The supported statistical processing methods (parameter stat_proc) are:

  • 0 average
  • 1 accumulation
  • 2 maximum
  • 3 minimum
  • 4 difference
  • 6 standard deviation

The start of processing period can be computed automatically from the input intervals as the first possible interval modulo step, or, for a better control, it can be specified explicitly by the optional argument start. Notice that start indicates the beginning of the processing interval, so in the final volume, the first datum may have time equal to start + step, e.g. in the case when time is the verification time, which is typical for observed datasets.

The purpose of the optional argument stat_proc_input is to allow processing with a certain statistical processing operator a dataset already processed with a different operator, by specifying the latter as stat_proc_input; this is useful, for example, if one wants to compute the monthly average of daily maximum temperatures; however this has to be used with care since the resulting data volume will not carry all the information about the processing which has been done, in the previous case, for example, the temperatures will simply look like monthly average temperatures.

Parametri
[in,out]thisvolume providing data to be recomputed, it is not modified by the method, apart from performing a vol7d_alloc_vol on it
[out]thatoutput volume which will contain the recomputed data
[in]stat_proctype of statistical processing to be recomputed (from grib2 table), only data having timerange of this type will be recomputed and will appear in the output volume
[in]steplength of the step over which the statistical processing is performed
[in]startstart of statistical processing interval
[in]frac_validminimum fraction of valid data required for considering acceptable a recomputed value, default=1.
[in,out]otheroptional volume that, on exit, is going to contain the data that did not contribute to the statistical processing
[in]stat_proc_inputto be used with care, type of statistical processing of data that has to be processed (from grib2 table), only data having timerange of this type will be recomputed, the actual statistical processing performed and which will appear in the output volume, is however determined by stat_proc argument

Definizione alla linea 457 del file vol7d_class_compute.F90.

457 !! - any p1 (analysis/observation or forecast)
458 !! - p2 = 0 (processing interval null, instantaneous data)
459 !!
460 !! Output data will have timerange of type \a stat_proc, and p2 = \a
461 !! step. The supported statistical processing methods (parameter \a
462 !! stat_proc) are:
463 !!
464 !! - 0 average
465 !! - 2 maximum
466 !! - 3 minimum
467 !! - 4 difference
468 !! - 6 standard deviation
469 !! - 201 mode (only for wind direction sectors)
470 !!
471 !! In the case of average, it is possible to weigh the data
472 !! proportionally to the length of the time interval for which every
473 !! single value is valid, i.e. halfway between the time level of the
474 !! value itself and the time of its nearest valid neighbours (argument
475 !! \a weighted). A maximum distance in time for input valid data can
476 !! be assigned with the optional argument \a max_step, in order to
477 !! filter datasets with too long "holes".
478 SUBROUTINE vol7d_compute_stat_proc_agg(this, that, stat_proc, &
479  step, start, max_step, weighted, other)
480 TYPE(vol7d),INTENT(inout) :: this
481 TYPE(vol7d),INTENT(out) :: that
482 INTEGER,INTENT(in) :: stat_proc
483 TYPE(timedelta),INTENT(in) :: step
484 TYPE(datetime),INTENT(in),OPTIONAL :: start
485 TYPE(timedelta),INTENT(in),OPTIONAL :: max_step
486 LOGICAL,INTENT(in),OPTIONAL :: weighted
487 TYPE(vol7d),INTENT(inout),OPTIONAL :: other
488 !INTEGER,INTENT(in),OPTIONAL :: stat_proc_input !< to be used with care, type of statistical processing of data that has to be processed (from grib2 table), only data having timerange of this type will be recomputed, the actual statistical processing performed and which will appear in the output volume, is however determined by \a stat_proc argument
489 
490 TYPE(vol7d) :: v7dtmp
491 INTEGER :: tri
492 INTEGER :: i, j, n, ninp, ndtr, i1, i3, i5, i6, vartype, maxsize
493 TYPE(timedelta) :: lmax_step, act_max_step
494 TYPE(datetime) :: pstart, pend, reftime
495 TYPE(arrayof_ttr_mapper),POINTER :: map_ttr(:,:)
496 REAL,ALLOCATABLE :: tmpvolr(:)
497 DOUBLE PRECISION,ALLOCATABLE :: tmpvold(:), weights(:)
498 LOGICAL,ALLOCATABLE :: lin_mask(:)
499 LOGICAL :: lweighted
500 CHARACTER(len=8) :: env_var
501 
502 IF (PRESENT(max_step)) THEN
503  lmax_step = max_step
504 ELSE
505  lmax_step = timedelta_max
506 ENDIF
507 lweighted = optio_log(weighted)
508 tri = 254
509 ! enable bad behavior for climat database
510 env_var = ''
511 CALL getenv('LIBSIM_CLIMAT_BEHAVIOR', env_var)
512 lweighted = lweighted .AND. len_trim(env_var) == 0
513 ! only average can be weighted
514 lweighted = lweighted .AND. stat_proc == 0
515 
516 ! be safe
517 CALL vol7d_alloc_vol(this)
518 ! initial check
519 
520 ! cleanup the original volume
521 CALL vol7d_smart_sort(this, lsort_time=.true.) ! time-ordered volume needed
522 CALL vol7d_reform(this, miss=.false., sort=.false., unique=.true.)
523 ! copy everything except time and timerange
524 CALL vol7d_copy(this, v7dtmp, ltime=(/.false./), ltimerange=(/.false./))
525 
526 ! create new volume
527 CALL init(that, time_definition=this%time_definition)
528 ! compute the output time and timerange and all the required mappings
529 CALL recompute_stat_proc_agg_common(this%time, this%timerange, stat_proc, tri, &
530  step, this%time_definition, that%time, that%timerange, map_ttr, start=start)
531 ! merge with information from original volume
532 CALL vol7d_merge(that, v7dtmp)
533 
534 maxsize = maxval(map_ttr(:,:)%arraysize)
535 ALLOCATE(tmpvolr(maxsize), tmpvold(maxsize), lin_mask(maxsize), weights(maxsize))
536 do_otimerange: DO j = 1, SIZE(that%timerange)
537  do_otime: DO i = 1, SIZE(that%time)
538  ninp = map_ttr(i,j)%arraysize
539  IF (ninp <= 0) cycle do_otime
540 ! required for some computations
541  CALL time_timerange_get_period(that%time(i), that%timerange(j), &
542  that%time_definition, pstart, pend, reftime)
543 
544  IF (ASSOCIATED(this%voldatir)) THEN
545  DO i1 = 1, SIZE(this%ana)
546  DO i3 = 1, SIZE(this%level)
547  DO i6 = 1, SIZE(this%network)
548  DO i5 = 1, SIZE(this%dativar%r)
549 ! stat_proc difference treated separately here
550  IF (stat_proc == 4) THEN
551  IF (ninp >= 2) THEN
552  IF (map_ttr(i,j)%array(1)%extra_info == 1 .AND. &
553  map_ttr(i,j)%array(n)%extra_info == 2) THEN
554  IF (c_e(this%voldatir(i1,map_ttr(i,j)%array(1)%it,i3, &
555  map_ttr(i,j)%array(1)%itr,i5,i6)) .AND. &
556  c_e(this%voldatir(i1,map_ttr(i,j)%array(ninp)%it,i3, &
557  map_ttr(i,j)%array(ninp)%itr,i5,i6))) THEN
558  that%voldatir(i1,i,i3,j,i5,i6) = &
559  this%voldatir(i1,map_ttr(i,j)%array(ninp)%it,i3, &
560  map_ttr(i,j)%array(ninp)%itr,i5,i6) - &
561  this%voldatir(i1,map_ttr(i,j)%array(1)%it,i3, &
562  map_ttr(i,j)%array(1)%itr,i5,i6)
563  ENDIF
564  ENDIF
565  ENDIF
566  cycle
567  ENDIF
568 ! other stat_proc
569  vartype = vol7d_vartype(this%dativar%r(i5))
570  lin_mask = .false.
571  ndtr = 0
572  DO n = 1, ninp
573  IF (c_e(this%voldatir(i1,map_ttr(i,j)%array(n)%it,i3, &
574  map_ttr(i,j)%array(n)%itr,i5,i6))) THEN
575  ndtr = ndtr + 1
576  tmpvolr(ndtr) = this%voldatir(i1,map_ttr(i,j)%array(n)%it,i3, &
577  map_ttr(i,j)%array(n)%itr,i5,i6)
578  lin_mask(n) = .true.
579  ENDIF
580  ENDDO
581  IF (ndtr == 0) cycle
582  IF (lweighted) THEN
583  CALL compute_stat_proc_agg_sw(map_ttr(i,j)%array(1:ninp)%time, &
584  pstart, pend, lin_mask(1:ninp), act_max_step, weights)
585  ELSE
586  CALL compute_stat_proc_agg_sw(map_ttr(i,j)%array(1:ninp)%time, &
587  pstart, pend, lin_mask(1:ninp), act_max_step)
588  ENDIF
589  IF (act_max_step > lmax_step) cycle
590 
591  SELECT CASE(stat_proc)
592  CASE (0) ! average
593  IF (lweighted) THEN
594  that%voldatir(i1,i,i3,j,i5,i6) = &
595  sum(REAL(weights(1:ndtr))*tmpvolr(1:ndtr))
596  ELSE
597  that%voldatir(i1,i,i3,j,i5,i6) = &
598  sum(tmpvolr(1:ndtr))/ndtr
599  ENDIF
600  CASE (2) ! maximum
601  that%voldatir(i1,i,i3,j,i5,i6) = &
602  maxval(tmpvolr(1:ndtr))
603  CASE (3) ! minimum
604  that%voldatir(i1,i,i3,j,i5,i6) = &
605  minval(tmpvolr(1:ndtr))
606  CASE (6) ! stddev
607  that%voldatir(i1,i,i3,j,i5,i6) = &
608  stat_stddev(tmpvolr(1:ndtr))
609  CASE (201) ! mode
610 ! mode only for angles at the moment, with predefined histogram
611  IF (vartype == var_dir360) THEN
612 ! reduce to interval [-22.5,337.5]
613  WHERE (tmpvolr(1:ndtr) > 337.5)
614  tmpvolr(1:ndtr) = tmpvolr(1:ndtr) - 360.
615  END WHERE
616  that%voldatir(i1,i,i3,j,i5,i6) = &
617  stat_mode_histogram(tmpvolr(1:ndtr), &
618  8, -22.5, 337.5)
619  ENDIF
620  END SELECT
621  ENDDO
622  ENDDO
623  ENDDO
624  ENDDO
625  ENDIF
626 
627  IF (ASSOCIATED(this%voldatid)) THEN
628  DO i1 = 1, SIZE(this%ana)
629  DO i3 = 1, SIZE(this%level)
630  DO i6 = 1, SIZE(this%network)
631  DO i5 = 1, SIZE(this%dativar%d)
632 ! stat_proc difference treated separately here
633  IF (stat_proc == 4) THEN
634  IF (n >= 2) THEN
635  IF (map_ttr(i,j)%array(1)%extra_info == 1 .AND. &
636  map_ttr(i,j)%array(ninp)%extra_info == 2) THEN
637  IF (c_e(this%voldatid(i1,map_ttr(i,j)%array(1)%it,i3, &
638  map_ttr(i,j)%array(1)%itr,i5,i6)) .AND. &
639  c_e(this%voldatid(i1,map_ttr(i,j)%array(ninp)%it,i3, &
640  map_ttr(i,j)%array(ninp)%itr,i5,i6))) THEN
641  that%voldatid(i1,i,i3,j,i5,i6) = &
642  this%voldatid(i1,map_ttr(i,j)%array(ninp)%it,i3, &
643  map_ttr(i,j)%array(ninp)%itr,i5,i6) - &
644  this%voldatid(i1,map_ttr(i,j)%array(1)%it,i3, &
645  map_ttr(i,j)%array(1)%itr,i5,i6)
646  ENDIF
647  ENDIF
648  ENDIF
649  cycle
650  ENDIF
651 ! other stat_proc
652  vartype = vol7d_vartype(this%dativar%d(i5))
653  lin_mask = .false.
654  ndtr = 0
655  DO n = 1, ninp
656  IF (c_e(this%voldatid(i1,map_ttr(i,j)%array(n)%it,i3, &
Costruttori per le classi datetime e timedelta.

Generated with Doxygen.