@@ -30,7 +30,7 @@ def run(
3030 Literal ["ggir" , "gradient" ],
3131 ] = "gradient" ,
3232 epoch_length : float = 5 ,
33- activity_metric : Literal ["enmo" , "mad" , "ag_count" ] = "enmo" ,
33+ activity_metric : Literal ["enmo" , "mad" , "ag_count" , "mims" ] = "enmo" ,
3434 nonwear_algorithm : Sequence [Literal ["ggir" , "cta" , "detach" ]] = ["ggir" ],
3535 verbosity : int = logging .WARNING ,
3636 output_filetype : Optional [Literal [".csv" , ".parquet" ]] = None ,
@@ -52,7 +52,7 @@ def run(
5252 path should end in the save file name in either .csv or .parquet formats.
5353 thresholds: The cut points for the light, moderate, and vigorous thresholds,
5454 given in that order. Values must be asscending, unique, and greater than 0.
55- Default values are optimized for subjects ages 7-11 [1].
55+ Default values are optimized for subjects ages 7-11 [1][3] .
5656 calibrator: The calibrator to be used on the input data.
5757 epoch_length: The temporal resolution in seconds, the data will be down sampled
5858 to. It must be > 0.0.
@@ -80,6 +80,10 @@ def run(
8080 Going S, Norman JE, Pate R. Defining accelerometer thresholds for activity
8181 intensities in adolescent girls. Med Sci Sports Exerc. 2004 Jul;36(7):1259-66.
8282 PMID: 15235335; PMCID: PMC2423321.
83+ [3] Karas M, Muschelli J, Leroux A, Urbanek J, Wanigatunga A, Bai J,
84+ Crainiceanu C, Schrack J Comparison of Accelerometry-Based Measures of Physical
85+ Activity: Retrospective Observational Data Analysis Study JMIR Mhealth Uhealth
86+ 2022;10(7):e38077 URL: https://mhealth.jmir.org/2022/7/e38077 DOI: 10.2196/38077
8387 """
8488 logger .setLevel (verbosity )
8589
@@ -92,8 +96,10 @@ def run(
9296 thresholds = thresholds or (0.029 , 0.338 , 0.604 )
9397 elif activity_metric == "ag_count" :
9498 thresholds = thresholds or (100 , 3000 , 5200 )
99+ elif activity_metric == "mims" :
100+ thresholds = thresholds or (10.558 , 15.047 , 19.614 )
95101
96- if not (0 <= thresholds [0 ] < thresholds [1 ] < thresholds [2 ]):
102+ if not (0 <= thresholds [0 ] < thresholds [1 ] < thresholds [2 ]): # type: ignore
97103 message = "Threshold values must be >=0, unique, and in ascending order."
98104 logger .error (message )
99105 raise ValueError (message )
@@ -123,6 +129,7 @@ def run(
123129 thresholds = thresholds ,
124130 calibrator = calibrator ,
125131 epoch_length = epoch_length ,
132+ activity_metric = activity_metric ,
126133 verbosity = verbosity ,
127134 output_filetype = output_filetype ,
128135 nonwear_algorithm = nonwear_algorithm ,
@@ -141,6 +148,7 @@ def _run_directory(
141148 nonwear_algorithm : Sequence [Literal ["ggir" , "cta" , "detach" ]] = ["ggir" ],
142149 verbosity : int = logging .WARNING ,
143150 output_filetype : Optional [Literal [".csv" , ".parquet" ]] = None ,
151+ activity_metric : Literal ["enmo" , "mad" , "ag_count" , "mims" ] = "enmo" ,
144152) -> Dict [str , writers .OrchestratorResults ]:
145153 """Runs main processing steps for wristpy on directories.
146154
@@ -156,13 +164,14 @@ def _run_directory(
156164 output: Path to directory data will be saved to.
157165 thresholds: The cut points for the light, moderate, and vigorous thresholds,
158166 given in that order. Values must be asscending, unique, and greater than 0.
159- Default values are optimized for subjects ages 7-11 [1].
167+ Default values are optimized for subjects ages 7-11 [1][2] .
160168 calibrator: The calibrator to be used on the input data.
161169 epoch_length: The temporal resolution in seconds, the data will be down sampled
162170 to. It must be > 0.0.
163171 nonwear_algorithm: The algorithm to be used for nonwear detection.
164172 verbosity: The logging level for the logger.
165173 output_filetype: Specifies the data format for the save files.
174+ activity_metric: The metric to be used for physical activity categorization.
166175
167176 Returns:
168177 All calculated data in a save ready format as a dictionary of
@@ -178,6 +187,10 @@ def _run_directory(
178187 [1] Hildebrand, M., et al. (2014). Age group comparability of raw accelerometer
179188 output from wrist- and hip-worn monitors. Medicine and Science in Sports and
180189 Exercise, 46(9), 1816-1824.
190+ [2] Karas M, Muschelli J, Leroux A, Urbanek J, Wanigatunga A, Bai J,
191+ Crainiceanu C, Schrack J Comparison of Accelerometry-Based Measures of Physical
192+ Activity: Retrospective Observational Data Analysis Study JMIR Mhealth Uhealth
193+ 2022;10(7):e38077 URL: https://mhealth.jmir.org/2022/7/e38077 DOI: 10.2196/38077
181194 """
182195 if output is None and output_filetype is not None :
183196 raise ValueError ("If no output is given, output_filetype must be None." )
@@ -220,6 +233,7 @@ def _run_directory(
220233 epoch_length = epoch_length ,
221234 verbosity = verbosity ,
222235 nonwear_algorithm = nonwear_algorithm ,
236+ activity_metric = activity_metric ,
223237 )
224238 except Exception as e :
225239 logger .error ("Did not run file: %s, Error: %s" , file , e )
@@ -236,7 +250,7 @@ def _run_file(
236250 Literal ["ggir" , "gradient" ],
237251 ] = "gradient" ,
238252 epoch_length : float = 5.0 ,
239- activity_metric : Literal ["enmo" , "mad" , "ag_count" ] = "enmo" ,
253+ activity_metric : Literal ["enmo" , "mad" , "ag_count" , "mims" ] = "enmo" ,
240254 nonwear_algorithm : Sequence [Literal ["ggir" , "cta" , "detach" ]] = ["ggir" ],
241255 verbosity : int = logging .WARNING ,
242256) -> writers .OrchestratorResults :
@@ -255,7 +269,7 @@ def _run_file(
255269 either .csv or .parquet formats.
256270 thresholds: The cut points for the light, moderate, and vigorous thresholds,
257271 given in that order. Values must be ascending, unique, and greater than 0.
258- Default values are optimized for subjects ages 7-11 [1].
272+ Default values are optimized for subjects ages 7-11 [1] - [3] .
259273 calibrator: The calibrator to be used on the input data.
260274 epoch_length: The temporal resolution in seconds, the data will be down sampled
261275 to. It must be > 0.0.
@@ -279,6 +293,10 @@ def _run_file(
279293 calculated from raw acceleration data: a novel method for classifying the
280294 intensity of adolescents' physical activity irrespective of accelerometer brand.
281295 BMC Sports Sci Med Rehabil 7, 18 (2015). https://doi.org/10.1186/s13102-015-0010-0.
296+ [3] Karas M, Muschelli J, Leroux A, Urbanek J, Wanigatunga A, Bai J,
297+ Crainiceanu C, Schrack J Comparison of Accelerometry-Based Measures of Physical
298+ Activity: Retrospective Observational Data Analysis Study JMIR Mhealth Uhealth
299+ 2022;10(7):e38077 URL: https://mhealth.jmir.org/2022/7/e38077 DOI: 10.2196/38077
282300 """
283301 logger .setLevel (verbosity )
284302 if output is not None :
@@ -328,7 +346,10 @@ def _run_file(
328346 calibrated_acceleration , epoch_length = epoch_length
329347 )
330348 activity_measurement = _compute_activity (
331- calibrated_acceleration , activity_metric , epoch_length
349+ calibrated_acceleration ,
350+ activity_metric ,
351+ epoch_length ,
352+ dynamic_range = watch_data .dynamic_range ,
332353 )
333354
334355 sleep_detector = analytics .GgirSleepDetection (anglez )
@@ -339,6 +360,7 @@ def _run_file(
339360 temperature = watch_data .temperature ,
340361 non_wear_algorithms = nonwear_algorithm ,
341362 )
363+
342364 nonwear_epoch = nonwear_utils .nonwear_array_cleanup (
343365 nonwear_array = nonwear_array ,
344366 reference_measurement = activity_measurement ,
@@ -383,8 +405,9 @@ def _run_file(
383405
384406def _compute_activity (
385407 acceleration : models .Measurement ,
386- activity_metric : Literal ["ag_count" , "mad" , "enmo" ],
408+ activity_metric : Literal ["ag_count" , "mad" , "enmo" , "mims" ],
387409 epoch_length : float ,
410+ dynamic_range : Optional [tuple [float , float ]],
388411) -> models .Measurement :
389412 """This is a helper function to organize the computation of the activity metric.
390413
@@ -396,6 +419,10 @@ def _compute_activity(
396419 activity_metric: The metric to be used for physical activity categorization.
397420 epoch_length: The temporal resolution in seconds, the data will be down sampled
398421 to.
422+ dynamic_range: Tuple of the minimum and maximum accelerometer values. This
423+ argument is only relevant to the mims metric. Values are taken from watch
424+ metadata, if no metadata could be extracted, the default
425+ values of (-8,8) are used.
399426
400427 Returns:
401428 A Measurement object with the computed physical activity metric.
@@ -407,4 +434,14 @@ def _compute_activity(
407434 )
408435 elif activity_metric == "mad" :
409436 return metrics .mean_amplitude_deviation (acceleration , epoch_length = epoch_length )
437+ elif activity_metric == "mims" :
438+ if dynamic_range is None :
439+ return metrics .monitor_independent_movement_summary_units (
440+ acceleration ,
441+ epoch = epoch_length ,
442+ )
443+ return metrics .monitor_independent_movement_summary_units (
444+ acceleration , epoch = epoch_length , dynamic_range = dynamic_range
445+ )
446+
410447 return metrics .euclidean_norm_minus_one (acceleration , epoch_length = epoch_length )
0 commit comments