deepcopy issue

hello all,

i have some issues with deep copies of stream objects.

it looks like format-specific dicts are "linked" in deep copy operations
instead of being duplicated.

this happened after some obspy upgrades, since i'm pretty sure my code
using deep copy functions worked correctly (and was not changed) until
some months ago.

here's a sample session.

$ ipython
Python 2.6.6 (r266:84292, Dec 26 2010, 22:31:48)
Type "copyright", "credits" or "license" for more information.

IPython 0.10 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object'. ?object also works, ?? prints more.

In [1]: from obspy import read

In [2]: from obspy.arclink.client import Client

In [3]: from obspy.core import UTCDateTime

In [4]: client = Client(user="test@obspy.de")

In [5]: t = UTCDateTime("2009-08-24 00:20:03")

# let's grab some data first:

In [6]: st = client.getWaveform('BW', 'RJOB', '', 'EHZ', t, t + 30,
route=False)

In [7]: st[0].stats
Out[7]: Stats({'network': 'BW', '_format': 'MSEED', 'mseed':
AttribDict({'dataquality': 'D', 'record_length': 512, 'byteorder': '>',
'encoding': 'STEIM1'}), 'sampling_rate': 200.0, 'station': 'RJOB',
'location': '', 'starttime': UTCDateTime(2009, 8, 24, 0, 20, 3), 'delta':
0.0050000000000000001, 'calib': 1.0, 'npts': 6001, 'endtime':
UTCDateTime(2009, 8, 24, 0, 20, 33), 'channel': 'EHZ'})

# here comes the weird stuff:

In [8]: from copy import deepcopy as copy_deepcopy

In [9]: ct = copy_deepcopy(st)

In [10]: st[0].stats.mseed.dataquality = 'X'

In [11]: st[0].stats.mseed.dataquality
Out[11]: 'X'

In [12]: ct[0].stats.mseed.dataquality
Out[12]: 'X'

# BUT, dict data in common header is deep-copied as expected:

In [13]: st[0].stats.network = 'XX'

In [14]: st[0].stats.network
Out[14]: 'XX'

In [15]: ct[0].stats.network
Out[15]: 'BW'

Dear Emiliano,

thanks for reporting this issue - it should be fixed now in the current
master - see https://github.com/obspy/obspy/issues/554

Cheers,
Robert

PS: please try to submit bug reports directly via GitHub, thanks!

hello all,

i have some issues with deep copies of stream objects.

it looks like format-specific dicts are "linked" in deep copy operations
instead of being duplicated.

this happened after some obspy upgrades, since i'm pretty sure my code
using deep copy functions worked correctly (and was not changed) until
some months ago.

here's a sample session.

$ ipython
Python 2.6.6 (r266:84292, Dec 26 2010, 22:31:48)
Type "copyright", "credits" or "license" for more information.

IPython 0.10 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object'. ?object also works, ?? prints more.

In [1]: from obspy import read

In [2]: from obspy.arclink.client import Client

In [3]: from obspy.core import UTCDateTime

In [4]: client = Client(user="test@obspy.de")

In [5]: t = UTCDateTime("2009-08-24 00:20:03")

# let's grab some data first:

In [6]: st = client.getWaveform('BW', 'RJOB', '', 'EHZ', t, t + 30,
route=False)

In [7]: st[0].stats
Out[7]: Stats({'network': 'BW', '_format': 'MSEED', 'mseed':
AttribDict({'dataquality': 'D', 'record_length': 512, 'byteorder': '>',
'encoding': 'STEIM1'}), 'sampling_rate': 200.0, 'station': 'RJOB',
'location': '', 'starttime': UTCDateTime(2009, 8, 24, 0, 20, 3), 'delta':
0.0050000000000000001, 'calib': 1.0, 'npts': 6001, 'endtime':
UTCDateTime(2009, 8, 24, 0, 20, 33), 'channel': 'EHZ'})

# here comes the weird stuff:

In [8]: from copy import deepcopy as copy_deepcopy

In [9]: ct = copy_deepcopy(st)

In [10]: st[0].stats.mseed.dataquality = 'X'

In [11]: st[0].stats.mseed.dataquality
Out[11]: 'X'

In [12]: ct[0].stats.mseed.dataquality
Out[12]: 'X'

# BUT, dict data in common header is deep-copied as expected:

In [13]: st[0].stats.network = 'XX'

In [14]: st[0].stats.network
Out[14]: 'XX'

In [15]: ct[0].stats.network
Out[15]: 'BW'

_______________________________________________
obspy-users mailing list
obspy-users@lists.sevor.de
http://lists.obspy.org/cgi-bin/mailman/listinfo/obspy-users

- --
Dr. Robert Barsch

EGU Office Munich
Luisenstr. 37
80333 Munich
Germany

Phone: +49-89-21806549
Fax: +49-89-218017855
eMail: barsch@egu.eu