Why de-trend and de-mean not properly working on the rotated waveforms?

Hi everyone,
My script works perfectly, but the output waveform is not properly de-trend and demean after rotation. May someone suggest how I can fix this.
My script is as below:

st = client.get_waveforms(net, sta, loc, chan, starttime, endtime, attach_response= True);
st_tr=st_rem.remove_response(output = ‘VEL’,plot=False);
dist_in_m, az, baz = gps2dist_azimuth(event_latitude, event_longitude, station_latitude, station_longitude)

st_filt=st_tr.filter('bandpass', freqmin =0.001, freqmax=0.1)
st_TRV=st_f.rotate('NE->RT', back_azimuth=baz)
st_TRV.plot(equal_scale=False, automerge=False);


Can you clarify what you are expecting to happen please? In your script you are detrending on the un-rotated waveforms, not the rotated waveforms.

Also - if you want to include code you need to use three back-ticks (`) not quotes (').

What calum said, you probably want to put the rotation to ZRT as the first step in your processing workflow (or, well, if you plan on instrument correction, likely after that)