def test_FM_add_remove(self): """ test FM add() and remove() """ fm = admit.Flow() # connection map diagram: a0->a1->a2->a3 # structure of an element of the triple-nested dictionary of connmap: # src_taskid: {des_taskid: {des_bdpport: (si,sp, di,dp)}} self.correct_connmap = {0: {1: {0: (0, 0, 1, 0)}}, 1: {2: {0: (1, 0, 2, 0)}}, 2: {3: {0: (2, 0, 3, 0)}}} tasklist= list() for i in range(0,4): a = AT() a._baseDir = admit.Project.baseDir # Each AT needs an output BDP b = File_BDP(); b.type="TEST_BDP%d" % i a._bdp_out.append( b ) tasklist.append( a ) if i == 0: taskid = fm.add( tasklist[i] ) else: taskid = fm.add( tasklist[i], [(tasklist[i-1]._taskid,0)]) self.assertEqual(fm._connmap, self.correct_connmap) # Remove a2 and its downstream from a0->a1->a2->a3 # The result diagram is a0->a1 self.correct_connmap = {0: {1: {0: (0, 0, 1, 0)}}} fm.remove(2) self.assertEqual(fm._connmap, self.correct_connmap)
def test_baseDir(self): at = AT({'alias': 'g'}) basedir = at.baseDir("/tmp/") if(self.verbose): print "\nAT Class base directory", basedir self.assertEqual(basedir, "/tmp/")
def test_AT_loggername(self): """ test AT set/getloggername() """ at = AT({'alias': 'log'}) name = "admit_logger" at.setloggername(name) ret = at.getloggername() self.assertEqual(ret, name)
def test_AT_baseDir(self): """ test AT baseDir(), dir() """ at = AT({'alias': 'g'}) basedir = at.baseDir("/tmp/") self.assertEqual(basedir, "/tmp/") fullpath = at.dir("test.test") self.assertEqual(fullpath, "/tmp/test.test")
def test_checktype(self): at = AT() bdp = BDP() ret = at.checktype(bdp) self.assertEquals(ret, None) # should be None without raising an exception
def test_len2(self): at = AT({'alias': 'c'}) tuple = at.len2() # bdp_in and bdp_out tuple if (self.verbose): print "\nAT Class (bdp_in, bdp_out):", tuple self.assertEqual(tuple, (0, 0)) ## should be (0,0)
def test_baseDir(self): at = AT({'alias': 'g'}) basedir = at.baseDir("/tmp/") if (self.verbose): print "\nAT Class base directory", basedir self.assertEqual(basedir, "/tmp/")
def test_AT_markUpToDate(self): """ test AT isstale(), markUpToDate() """ at = AT({'alias': 'n'}) self.assertTrue(at.isstale()) at.markUpToDate() self.assertFalse(at.isstale())
def test_len2(self): at = AT({'alias': 'c'}) tuple = at.len2() # bdp_in and bdp_out tuple if(self.verbose): print "\nAT Class (bdp_in, bdp_out):", tuple self.assertEqual(tuple, (0,0)) ## should be (0,0)
def test_key(self): at = AT({'alias': 't', 'test_key': 'at_test'}) key = "test_key" val = "TEST" t1 = at.haskey("testtesttest") # invalid key self.assertEqual(t1, False) # test haskey() t1 = at.haskey(key) # AT should have the key set at init self.assertTrue(t1) # test setkey() at.setkey(name=key, value=val, isinit=True) # test getkey() ret = at.getkey(key) if (self.verbose): print "\n test key:", ret self.assertEqual(ret, "TEST") # test {key:val} way of setting a key at.setkey(name={key: "TEST2"}) ret = at.getkey(key) if (self.verbose): print "\n alias key:", ret self.assertEqual(ret, "TEST2")
def __init__(self, **keyval): keys = { 'file': "", # fitsfile cube or map (or casa/miriad) 'basename': "", # override basename (useful for shorter names) 'pb': "", # PB cube or map 'usepb': True, # use PB, or was it just given for downstream 'mask': True, # define a mask where data==0.0 if no mask present 'box': [], # [] or z1,z2 or x1,y1,x2,y2 or x1,y1,z1,x2,y2,z2 'edge': [], # [] or zl,zr - number of edge channels 'smooth': [], # pixel smoothing size applied to data (can be slow) - see also Smooth_AT 'variflow': False, # requires manual sub-flow management for now 'vlsr': -999999.99, # force a VLSR (see also LineID) 'restfreq': -1.0, # alternate VLSRf specification # 'symlink' : False, # # 'autobox' : False, # automatically cut away spatial and spectral slices that are masked # 'cbeam' : 0.5, # channel beam variation allowed in terms of pixel size to use median beam } AT.__init__(self, keys, keyval) self._version = "1.1.5" self.set_bdp_in() # no input BDP self.set_bdp_out([ (SpwCube_BDP, 1), # one or two output BDPs (Image_BDP, 0), # optional PB if there was an pb= input ])
def __init__(self, **keyval): keys = { "basename" : "", # defaults to BDP derived } AT.__init__(self,keys,keyval) self._version = "1.0.0" self.set_bdp_in([(Image_BDP, 1, bt.REQUIRED)]) self.set_bdp_out([])
def test_effectivelevel(self): at = AT({'alias': 'f'}) at.seteffectivelevel(40) level = at.geteffectivelevel() if (self.verbose): print "\nAT Class effective logging level", level self.assertEqual(level, 40)
def test_isAutoAlias(self): at = AT() ret = at.isAutoAlias() self.assertTrue(ret) # should be true at = AT({'alias': 'alias_test', 'test_key': 'at_test'}) ret = at.isAutoAlias(withEmpty=False) self.assertFalse(ret) # should be false
def test_enabled(self): at = AT({'alias': 'm'}) at.enabled(False) after = at._enabled if (self.verbose): print "\nAT Class state _enabled", after self.assertEqual(after, False)
def test_AT_isAutoAlias(self): """ test AT isAutoAlias() """ at = AT() self.assertTrue(at.isAutoAlias()) at = AT({'alias': 'alias_test', 'test_key': 'at_test'}) ret = at.isAutoAlias(withEmpty=False) self.assertFalse(ret)
def test_AT_logginglevel(self): """ test AT setlogginglevel and getlogginglevel methods """ # CRITICAL 50 at = AT({'alias': 'e'}) at.setlogginglevel(50) level = at.getlogginglevel() self.assertEqual(level, 50) self.assertEqual(level, logging.CRITICAL)
def __init__(self, **keyval): keys = { "basename": "", # defaults to BDP derived } AT.__init__(self, keys, keyval) self._version = "1.0.0" self.set_bdp_in([(Image_BDP, 1, bt.REQUIRED)]) self.set_bdp_out([])
def test_dir(self): at = AT({'alias': 'h'}) basedir = at.baseDir("/tmp/") fullpath = at.dir("test.test") if(self.verbose): print "\nAT Fullpath:", fullpath self.assertEqual(fullpath, "/tmp/test.test")
def __init__(self,**keyval): keys = { } AT.__init__(self,keys,keyval) self._version = "0.0.1" self.set_bdp_in([(Image_BDP,1,bt.REQUIRED), (CubeStats_BDP,1,bt.OPTIONAL)]) self.set_bdp_out([])
def test_effectivelevel(self): at = AT({'alias': 'f'}) at.seteffectivelevel(40) level = at.geteffectivelevel() if(self.verbose): print "\nAT Class effective logging level", level self.assertEqual(level, 40)
def __init__(self,**keyval): keys = {"file" : "", "touch": True, "exist": True} AT.__init__(self,keys,keyval) self._version = "1.0.0" self.set_bdp_in ([(File_BDP,1,bt.REQUIRED)]) self.set_bdp_out([(File_BDP,1)])
def test_markChanged(self): at = AT({'alias': 'p'}) at.markChanged() state = at._stale if (self.verbose): print "\nAT Class state _stale", state self.assertEqual(state, True)
def test_dir(self): at = AT({'alias': 'h'}) basedir = at.baseDir("/tmp/") fullpath = at.dir("test.test") if (self.verbose): print "\nAT Fullpath:", fullpath self.assertEqual(fullpath, "/tmp/test.test")
def test_enabled(self): at = AT({'alias': 'm'}) at.enabled(False) after = at._enabled if(self.verbose): print "\nAT Class state _enabled", after self.assertEqual(after, False)
def test_markChanged(self): at = AT({'alias': 'p'}) at.markChanged() state = at._stale if(self.verbose): print "\nAT Class state _stale", state self.assertEqual(state, True)
def test_loggername(self): at = AT({'alias': 'log'}) name = "admit_logger" at.setloggername(name) ret = at.getloggername() if(self.verbose): print "\nAT Class Logger Name:", name self.assertEqual(ret, name)
def test_mkext(self): at = AT({'alias': 'k'}) t1 = at.mkext("x","z") # return 'x-k.z' t2 = at.mkext("x.y","z") # return 'x-k.z' t3 = at.mkext("x.y","z", "a") # return 'x-a.z' self.assertEqual(t1, "x-k.z") self.assertEqual(t2, "x-k.z") self.assertEqual(t3, "x-a.z")
def __init__(self, **keyval): keys = {"equalize" : False, # default to no equalization and no regridding "pad" : 5, # default to 5 channels on either side } AT.__init__(self, keys, keyval) self._version = "1.0.2" self.set_bdp_in([(Image_BDP, 1, bt.REQUIRED), (LineList_BDP, 1, bt.REQUIRED)]) self.set_bdp_out([(LineCube_BDP, 0)])
def test_loggername(self): at = AT({'alias': 'log'}) name = "admit_logger" at.setloggername(name) ret = at.getloggername() if (self.verbose): print "\nAT Class Logger Name:", name self.assertEqual(ret, name)
def test_mkext(self): at = AT({'alias': 'k'}) t1 = at.mkext("x", "z") # return 'x-k.z' t2 = at.mkext("x.y", "z") # return 'x-k.z' t3 = at.mkext("x.y", "z", "a") # return 'x-a.z' self.assertEqual(t1, "x-k.z") self.assertEqual(t2, "x-k.z") self.assertEqual(t3, "x-a.z")
def __init__(self, **keyval): keys = { "equalize": False, # default to no equalization and no regridding "pad": 5, # default to 5 channels on either side } AT.__init__(self, keys, keyval) self._version = "1.0.2" self.set_bdp_in([(Image_BDP, 1, bt.REQUIRED), (LineList_BDP, 1, bt.REQUIRED)]) self.set_bdp_out([(LineCube_BDP, 0)])
def __init__(self,**keyval): keys = {"robust" : [], # signal rejection parameters "ppp" : False, # PeakPointPlot "maxvrms" : 2.0, # clip varying RMS (-1 to skip) "psample" : -1, # if > 0, spatial sampling rate for PeakStats } AT.__init__(self,keys,keyval) self._version = "1.0.6" self.set_bdp_in([(Image_BDP, 1, bt.REQUIRED)]) self.set_bdp_out([(CubeStats_BDP, 1)])
def __init__(self,**keyval): keys = {"file" : "", "m" : 0, "n" : 2, "touch" : False, "exist" : False} AT.__init__(self,keys,keyval) self._version = "1.0.0" self.set_bdp_in ([(File_BDP,self._keys.pop('m'),bt.REQUIRED)]) self.set_bdp_out([(File_BDP,1), (File_BDP,0)])
def test_key(self): at = AT({'alias': 't', 'test_key': 'at_test'}) key = "test_key" val = "TEST" t1 = at.haskey("testtesttest") # invalid key self.assertEqual(t1, False) # test haskey() t1 = at.haskey(key) # AT should have the key set at init self.assertTrue(t1) # test setkey() at.setkey(name=key, value=val, isinit=True) # test getkey() ret = at.getkey(key) if(self.verbose): print "\n test key:", ret self.assertEqual(ret, "TEST") # test {key:val} way of setting a key at.setkey(name={key:"TEST2"}) ret = at.getkey(key) if(self.verbose): print "\n alias key:", ret self.assertEqual(ret, "TEST2")
def __init__(self,**keyval): keys = {"numsigma" : 3.0, # N-sigma "range" : [], # optional channel range "nchan" : 0, # number of channels around the channel where the peak is } AT.__init__(self,keys,keyval) self._version = "1.0.1" self.set_bdp_in([(Image_BDP,1,bt.REQUIRED), # @todo optional 2nd PVSlice can be used to draw the template from (CubeStats_BDP,1,bt.REQUIRED)]) self.set_bdp_out([(PVCorr_BDP,1)])
def test_AT_projectID(self): """ test AT setProject(), getProject(), id() """ at = AT({'alias': 'q'}) self.project.addtask(at) # get the taskid before adding project id tid = at._taskid # now set the project id at.setProject(2) self.assertEqual(at.getProject(), 2) # now strip out the project id from _taskid self.assertEqual(at.id(True), tid)
def __init__(self,**keyval): keys = {"pos" : [], # one or more pairs of int's or ra/dec strings "sources" : [0], # select which sources from a SourceList "xaxis" : "", # currently still ignored } AT.__init__(self,keys,keyval) self._version = "1.0.3" self.set_bdp_in( [(Image_BDP, 1,bt.REQUIRED), # 0: cube: SpwCube or LineCube allowed (CubeStats_BDP, 1,bt.OPTIONAL), # 1: stats, uses maxpos (Moment_BDP, 1,bt.OPTIONAL), # 2: map, uses the max in this image as pos= (SourceList_BDP, 1,bt.OPTIONAL)]) # 3: source list, for positions self.set_bdp_out([(CubeSpectrum_BDP,1)])
def __init__(self, **keyval): keys = { "do_spatial_regrid": True, "pix_scale": -1.0, "do_freq_regrid": False, "chan_width": -1.0 } AT.__init__(self, keys, keyval) self._version = "1.0.0" self.set_bdp_in([(SpwCube_BDP, 0, bt.REQUIRED)]) self.set_bdp_out([(SpwCube_BDP, 0)])
def __init__(self, **keyval): keys = { "do_spatial_regrid": True, "pix_scale" : -1.0, "do_freq_regrid": False, "chan_width" : -1.0 } AT.__init__(self,keys,keyval) self._version = "1.0.0" self.set_bdp_in([(SpwCube_BDP,0,bt.REQUIRED)]) self.set_bdp_out([(SpwCube_BDP,0)])
def __init__(self, **keyval): keys = { "bmaj" : {'value': -1.0, 'unit': 'arcsec'}, "bmin" : {'value': -1.0, 'unit': 'arcsec'}, "bpa" : -1.0, "velres" : {'value': -1.0, 'unit': 'pixel'}, } AT.__init__(self,keys,keyval) self._version = "1.0.5" self.set_bdp_in([(SpwCube_BDP,0,bt.REQUIRED)]) self.set_bdp_out([(SpwCube_BDP,0)])
def __init__(self, **keyval): keys = { "file": "", "n": 2, "subdir": False, "touch": False, "exist": False } AT.__init__(self, keys, keyval) self._version = "1.0.0" self.set_bdp_in([(File_BDP, 1, bt.REQUIRED)]) self.set_bdp_out([(File_BDP, 1), (File_BDP, 0)])
def test_flow(self): # Test insertion of tasks (FM method: add(at, stuples, dtuples)) if (self.verbose) : print "\n------- Test Insertion ------------" # connection map diagram: a0->a1->a2->a3 # structure of an element of the triple-nested dictionary of connmap: # src_taskid: {des_taskid: {des_bdpport: (si,sp, di,dp)}} self.correct_connmap = {0: {1: {0: (0, 0, 1, 0)}}, 1: {2: {0: (1, 0, 2, 0)}}, 2: {3: {0: (2, 0, 3, 0)}}} for i in range(0,4): name = "TEST_AT%d" % i; if (self.verbose) : print "inserting task %s " % name a = AT() a._baseDir = admit.Project.baseDir # Each AT needs an output BDP b = BDP(); b.type="TEST_BDP%d" % i a._bdp_out.append( b ) self.task.append( a ) if i == 0: taskid = self.fm.add( self.task[i] ) else: taskid = self.fm.add( self.task[i], [(self.task[i-1]._taskid,0)]) if (self.verbose) : self.fm.show() self.assertEqual(self.fm._connmap, self.correct_connmap) if (self.verbose) : print "-------- End of Test Insertion ------------" # Print the 4-tuples of the connection map if (self.verbose) : print "\n------- Print Connection Map ------------" cm = self.fm._connmap if (self.verbose) : print cm for si in cm.keys(): for di in cm[si].keys(): for dp in cm[si][di].keys(): if (self.verbose) : print cm[si][di][dp] if (self.verbose) : print "-------- End of Print ConnMap ------------" # Remove a2 and its downstream from a0->a1->a2->a3 # The result diagram is a0->a1 if (self.verbose) : print "\n------- Test Remove ------------" self.correct_connmap = {0: {1: {0: (0, 0, 1, 0)}}} self.fm.remove(2) if (self.verbose): self.fm.show() self.assertEqual(self.fm._connmap, self.correct_connmap) if (self.verbose) : print "-------- End of Test Remove ------------"
def __init__(self, **keyval): keys = {"numsigma" : 6.0, # default to 5 sigma "sigma" : -1.0, # default to grab sigma from CubeStats BDP "region" : "", # default to entire map "robust" : ['hin',1.5], # default to classic MAD "snmax" : 35.0, # default to limit dynamic range to 100 } AT.__init__(self,keys,keyval) self._version = "1.0.5" self.set_bdp_in([(Image_BDP,2,bt.OPTIONAL), (CubeStats_BDP,1,bt.OPTIONAL)]) self.set_bdp_out([(SourceList_BDP, 1)])
def __init__(self, **keyval): keys = { "numsigma" : 2.0, # default to 2.0*sigma cutoff "sigma" : -1.0, # default to CubeStats rms(freq) "linesum" : True, # Select line segments for from the (optional) LineList "pad" : 5, # number of channels to pad onto the line segments from LineList } AT.__init__(self,keys,keyval) self._version = "1.0.2" self.set_bdp_in([(Image_BDP, 1, bt.REQUIRED), (CubeStats_BDP, 1, bt.OPTIONAL), (LineList_BDP, 1, bt.OPTIONAL)]) # LineSegment_BDP also allowed self.set_bdp_out([(Moment_BDP,1)])
def __init__(self, **keyval): # set the key words up with default values keys = {"yourname": "", "planet": ""} AT.__init__(self, keys, keyval) self._version = "1.0.0" # must call even if task takes no input bdp, so that # various internal AT values are set correctly self.set_bdp_in() self.set_bdp_out([(HelloWorld_BDP, 1)]) self._bdp_in_order_list = [] self._bdp_in_order_type = []
def __init__(self, **keyval): keys = { "chans" : [], # 0-based channel range, e.g. [5,10] "normalize" : False, "method" : ("", {"key1": 0, "key2": 1.0, "key3": "abc"}), "cmap" : "jet", } AT.__init__(self,keys,keyval) self._version = "1.0.1" self.set_bdp_in([(Image_BDP, 0, bt.REQUIRED)]) # 2 or more should be input # @TODO: Why is OverlapIntegral_BDP not used here, # since the output is a Table and an Image self.set_bdp_out([(Image_BDP,1)]) # 1 is output
def test_AT_getsetAlias(self): """ test AT get(), set(), setAlias """ at = AT({'alias': 'test'}) self.assertEqual(at.get('_alias'), 'test') at.set('_alias', 'alias_test') self.assertEqual(at.get('_alias'), 'alias_test') alias = ({'w': 0}, 0) at.setAlias(alias, 'alias_test_2') self.assertEqual(at.get('_alias'), 'alias_test_2')
def __init__(self,**keyval): keys = {"slice" : [], # x0,y0,x1,y1 ? could be line= ? "slit" : [], # xc,yc,len,pa pick one of slice= or slit= "width" : 1, # odd integer! "clip" : 0.0, # clip value (in terms of sigma) "gamma" : 1.0, # gamma factor for analyzing map MOI "pvsmooth" : [], # P and V smoothing (in pixel) #"major" : True, # (TODO) major or minor axis, not used yet } AT.__init__(self,keys,keyval) self._version = "1.0.3" self.set_bdp_in([(Image_BDP, 1, bt.REQUIRED), # SpwCube (Moment_BDP, 1, bt.OPTIONAL), # Moment0 or CubeSum (CubeStats_BDP, 1, bt.OPTIONAL)]) # was: PeakPointPlot self.set_bdp_out([(PVSlice_BDP, 1)])
def __init__(self, **keyval): keys = { "numsigma": 3.0, # N-sigma "range": [], # optional channel range "nchan": 0, # number of channels around the channel where the peak is } AT.__init__(self, keys, keyval) self._version = "1.0.1" self.set_bdp_in([ (Image_BDP, 1, bt.REQUIRED), # @todo optional 2nd PVSlice can be used to draw the template from (CubeStats_BDP, 1, bt.REQUIRED) ]) self.set_bdp_out([(PVCorr_BDP, 1)])
def test_get_set(self): at = AT({'alias': 'test'}) ret = at.get('_alias') self.assertTrue(ret == 'test') at.set('_alias', 'alias_test') ret = at.get('_alias') self.assertEqual(ret, 'alias_test') at.setAlias(({'w': 0}, 0), 'alias_test_2') ret = at.get('_alias') self.assertEqual(ret, 'alias_test_2')
def __init__(self, **keyval): keys = { "moments": [0], # default to moment 0 "numsigma": [2.0], # default to 2 sigma "sigma": -1.0, # default to determine sigma internally "chans": "", # default to select all channels "mom0clip": 0.0, # default to not clip "variflow": False, # default to manual sub-flow management } AT.__init__(self, keys, keyval) self._version = "1.0.3" # set input types self.set_bdp_in([(Image_BDP, 1, bt.REQUIRED), (CubeStats_BDP, 1, bt.OPTIONAL)]) # set output types self.set_bdp_out([(Moment_BDP, 0)])
def test_output(self): at = AT({'alias': 'b'}) bdpout = len(at) if (self.verbose): print "\nAT Class number of BDP out:", bdpout self.assertEqual(bdpout, 0) ## should have no output bdp
def test_input(self): at = AT({'alias': 'a'}) bdpin = len(at._bdp_in) if (self.verbose): print "\nAT Class number of BDP in:", bdpin self.assertEqual(bdpin, 0) ## should have no input bdp