Source code for torch_brain.transforms.random_time_scaling
importcopyimporttorchfromtemporaldataimportIrregularTimeSeries,RegularTimeSeries,Interval,Datadefrescale(data:Data,scale:float,offset:float):r"""Rescale the time axis of the data by a factor and offset. Args: data (Data): The data to rescale. scale (float): The scaling factor. offset (float): The offset. """out=data.__class__.__new__(data.__class__)forkey,valueindata.__dict__.items():# todo update domainifkey!="_domain"andisinstance(value,IrregularTimeSeries):val=copy.copy(value)val.timestamps=val.timestamps*scale+offsetval._domain=copy.copy(value._domain)val._domain.start=val._domain.start*scale+offsetval._domain.end=val._domain.end*scale+offsetout.__dict__[key]=valelifkey!="_domain"andisinstance(value,RegularTimeSeries):val=copy.copy(value)val._sampling_rate=val._sampling_rate/scaleval._domain=copy.copy(value._domain)val._domain.start=val._domain.start*scale+offsetval._domain.end=val._domain.end*scale+offsetout.__dict__[key]=valelifkey!="_domain"andisinstance(value,Interval):val=copy.copy(value)val.start=val.start*scale+offsetval.end=val.end*scale+offsetout.__dict__[key]=valelse:out.__dict__[key]=copy.copy(value)# update domainout._domain=copy.copy(data._domain)out._domain.start=out._domain.start*scale+offsetout._domain.end=out._domain.end*scale+offset# update slice start timeout._absolute_start=data._absolute_startreturnout