Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #271 using deepcopy() #272

Merged
merged 3 commits into from
Aug 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Lib/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1708,7 +1708,9 @@ def clone(self, copyData=1):
else:
mycopy = createAxis(self[:])
mycopy.id = self.id
mycopy.__dict__.update(self.__dict__.copy())
mydict = self.__dict__
newdict = {k: mydict[k] for k in mydict if k not in ['_data_']}
mycopy.__dict__.update(newdict)
mycopy._obj_ = None # Erase Cdfile object if exist
try:
mycopy.setBounds(b, isGeneric=isGeneric[0])
Expand Down
4 changes: 3 additions & 1 deletion run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ def __setup_cdms(self):
cookies = "-c {h}/.esg/.dods_cookies".format(h=home)
cert_opt = "--cert {h}/.esg/esgf.cert".format(h=home)
key_opt = "--key {h}/.esg/esgf.cert".format(h=home)
dds = "https://aims3.llnl.gov/thredds/dodsC/cmip5_css02_data/cmip5/output1/CMCC/CMCC-CM/decadal2005/mon/atmos/Amon/r1i1p1/cct/1/cct_Amon_CMCC-CM_decadal2005_r1i1p1_202601-203512.nc.dds"
# dds = "https://aims3.llnl.gov/thredds/dodsC/cmip5_css02_data/cmip5/output1/CMCC/CMCC-CM/decadal2005/mon/atmos/Amon/r1i1p1/cct/1/cct_Amon_CMCC-CM_decadal2005_r1i1p1_202601-203512.nc.dds"
dds = "https://esgf-node.cmcc.it/thredds/dodsC/esg_dataroot/cmip5/output1/CMCC/CMCC-CM/decadal1960/6hr/atmos/6hrPlev/r1i1p1/v20170725/psl/psl_6hrPlev_CMCC-CM_decadal1960_r1i1p1_1990120100-1990123118.nc.dds"

cmd = "curl -L -v {cacert} {cookies} {cert} {key} \"{dds}\"".format(cacert=cacert_pem,
cookies=cookies,
cert=cert_opt,
Expand Down
9 changes: 5 additions & 4 deletions tests/test_all_formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ def testESGF(self):
file.write("HTTP.SSL.KEY="+os.environ['HOME']+"/.esg/esgf.cert\n")
file.write("HTTP.SSL.CAPATH="+os.environ['HOME']+"/.esg/\n")
file.close()
f = cdms2.open("https://aims3.llnl.gov/thredds/dodsC/cmip5_css01_data/cmip5/output1/BCC/bcc-csm1-1-m/1pctCO2/day/ocean/day/r1i1p1/v20120910/tos/tos_day_bcc-csm1-1-m_1pctCO2_r1i1p1_02800101-02891231.nc")
self.assertIn('tos', f.listvariables())
data=f['tos']
self.assertEqual(data[1,84,4], 303.6062927246094)
# f = cdms2.open("https://aims3.llnl.gov/thredds/dodsC/cmip5_css01_data/cmip5/output1/BCC/bcc-csm1-1-m/1pctCO2/day/ocean/day/r1i1p1/v20120910/tos/tos_day_bcc-csm1-1-m_1pctCO2_r1i1p1_02800101-02891231.nc")
f = cdms2.open("https://esgf-node.cmcc.it/thredds/dodsC/esg_dataroot/cmip5/output1/CMCC/CMCC-CM/decadal1960/6hr/atmos/6hrPlev/r1i1p1/v20170725/psl/psl_6hrPlev_CMCC-CM_decadal1960_r1i1p1_1990120100-1990123118.nc")
self.assertIn('psl', f.listvariables())
data=f['psl']
self.assertEqual(data[1,84,4], 101826.1875)

if __name__ == "__main__":
basetest.run()
23 changes: 23 additions & 0 deletions tests/test_cdms_axis_clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from subprocess import Popen, PIPE
import shlex
import MV2, cdms2
import cdat_info


class TestAxis(unittest.TestCase):
Expand All @@ -26,3 +27,25 @@ def testCloneUnits(self):
f = cdms2.open('tmp.nc')
assert f['time'].clone().units == f['time'].units
f.close()


def testCloneUnits(self):

f= cdms2.open(cdat_info.get_sampledata_path()+"/clt.nc")
s = f("clt", **{})
#s.info()

s = s(
latitude=(
20, 20, "cob"), longitude=(
112, 112, "cob"), squeeze=1)
s2 = MV2.sin(s)

ax = s2.getTime()
ax2 = ax.clone()
ax2[0]=4
ax2.toRelativeTime("days since 30000")
self.assertNotEqual(ax[0], ax2[0])
self.assertNotEqual(ax.__dict__['_data_'].ctypes.data, ax2.__dict__['_data_'].ctypes.data)