@@ -117,8 +117,13 @@ func (r *ReferenceBundle) IsJND() bool {
117
117
return res
118
118
}
119
119
120
+ var ErrNoMOSAvailable = fmt .Errorf ("no MOS scores available" )
121
+
120
122
// MOSScaler returns a function that scales MOS scores of this bundle to the range 1-5.
121
123
func (r * ReferenceBundle ) MOSScaler () (func (float64 ) float64 , error ) {
124
+ if _ , found := r .ScoreTypes [MOS ]; ! found {
125
+ return nil , ErrNoMOSAvailable
126
+ }
122
127
if r .mosScaler == nil {
123
128
if math .Abs (* r .ScoreTypeLimits [MOS ][0 ]- 1 ) < 0.2 && math .Abs (* r .ScoreTypeLimits [MOS ][1 ]- 5 ) < 0.2 {
124
129
r .mosScaler = func (mos float64 ) float64 {
@@ -1093,16 +1098,17 @@ func (s *Study) Copy(dir string, refs []*Reference, minMOS float64, mosScaler fu
1093
1098
if err := os .Symlink (filepath .Join (dir , ref .Path ), filepath .Join (s .dir , newRefPath )); err != nil {
1094
1099
return err
1095
1100
}
1096
- for index , dist := range ref .Distortions {
1097
- distCopy := & Distortion {}
1098
- if mosScaler == nil || mosScaler (distCopy .Scores [MOS ]) >= minMOS {
1101
+ refCopy .Distortions = nil
1102
+ for _ , dist := range ref .Distortions {
1103
+ if mosScaler == nil || mosScaler (dist .Scores [MOS ]) >= minMOS {
1104
+ distCopy := & Distortion {}
1099
1105
* distCopy = * dist
1100
1106
newDistPath := fmt .Sprintf ("%v_%v" , filepath .Base (dir ), filepath .Base (dist .Path ))
1101
1107
distCopy .Path = newDistPath
1102
1108
if err := os .Symlink (filepath .Join (dir , dist .Path ), filepath .Join (s .dir , newDistPath )); err != nil {
1103
1109
return err
1104
1110
}
1105
- refCopy .Distortions [ index ] = distCopy
1111
+ refCopy .Distortions = append ( refCopy . Distortions , distCopy )
1106
1112
}
1107
1113
}
1108
1114
if len (refCopy .Distortions ) > 0 {
0 commit comments