Changeset 2707 for trunk/python


Ignore:
Timestamp:
12/26/12 16:35:37 (11 years ago)
Author:
Kana Sugimoto
Message:

New Development: Yes

JIRA Issue: Yes (CAS-4141)

Ready for Test: Yes

Interface Changes: Yes

What Interface Changed:

  • a new c++ class, STSideBandSep and its python interface.
  • a new method set_lo1 in the sbseparator module.

Test Programs: manual tests by CSV scientists.

Put in Release Notes: No

Module(s): STSidebandSep (a new class) and sbseparator

Description:

Added a new c++ class, STSideBandSep, and its python interface (python_STSideBandSep.cpp).
The class works on calculating frequency information of image side band and fill scantable.
Also added a new python method, set_lo1(double), in sbseparator module. This is to allow
user to set LO1 frequency to solve frequencies of image side band manually.


File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/sbseparator.py

    r2685 r2707  
    99from asap.selector import selector
    1010from asap.asapgrid import asapgrid2
    11 #from asap._asap import sidebandsep
     11from asap._asap import SBSeparator
    1212
    1313class sbseparator:
     
    4949        self.solveother = False
    5050        self.dirtol = [1.e-5, 1.e-5] # direction tolerance in rad (2 arcsec)
     51        self.lo1 = 0.
    5152
    5253        self.tables = []
     
    166167        Set shift mode and channel shift of image band.
    167168
    168         mode       : shift mode ['DSB'|'SSB']
     169        mode       : shift mode ['DSB'|'SSB'(='2SB')]
    169170                     When mode='DSB', imageshift is assumed to be equal
    170171                     to the shift of signal sideband but in opposite direction.
     
    172173                     each scantable. valid only mode='SSB'
    173174        """
    174         if mode.upper().startswith("S"):
     175        if mode.upper().startswith("D"):
     176            # DSB mode
     177            self.dsbmode = True
     178            self.imageShift = []
     179        else:
    175180            if not imageshift:
    176181                raise ValueError, "Need to set shift value of image sideband"
     
    178183            self.imageShift = imageshift
    179184            asaplog.push("Image sideband shift is set manually: %s" % str(self.imageShift))
    180         else:
    181             # DSB mode
    182             self.dsbmode = True
    183             self.imageShift = []
    184185
    185186    @asaplog_post_dec
     
    213214        if flag:
    214215            asaplog.push("Expert mode: solution are obtained by subtraction of the other sideband.")
     216
     217    def set_lo1(self,lo1):
     218        """
     219        Set LO1 frequency to calculate frequency of image sideband.
     220
     221        lo1 : LO1 frequency in float
     222        """
     223        if isinstance(lo1, dict) and lo1["unit"] == "Hz":
     224            self.lo1 = lo1["value"]
     225        else:
     226            self.lo1 = float(lo1)
     227        if self.lo1 <= 0.:
     228            asaplog.push("Got negative LO1 frequency. It will be ignored.")
     229            asaplog.post("WARN")
    215230
    216231
     
    229244
    230245        nshift = len(self.tables)
    231         signaltab = self._grid_outtable(self.tables[0].copy())
     246        signaltab = self._grid_outtable(self.tables[0])
    232247        if self.getboth:
    233248            imagetab = signaltab.copy()
     
    249264            signal = self._solve_signal(spec_array, tabidx)
    250265            signaltab.set_spectrum(signal, irow)
     266
     267            # Solve image side side band
    251268            if self.getboth:
    252269                image = self._solve_image(spec_array, tabidx)
    253270                imagetab.set_spectrum(image, irow)
    254        
     271
    255272        # TODO: Need to remove rejrow form scantables here
    256273        signaltab.flag_row(rejrow)
     
    267284                shutil.rmtree(signalname)
    268285        signaltab.save(signalname)
     286
    269287        if self.getboth:
    270288            # Warnings
     
    281299                else:
    282300                    shutil.rmtree(imagename)
     301            # Update frequency information
     302            sbsep = SBSeparator()
     303            sbsep.set_imgtable(imagetab)
     304            if self.lo1 > 0.:
     305                sbsep.set_lo1(self.lo1)
     306            sbsep.solve_imgfreq()
    283307            imagetab.save(imagename)
     308            del sbsep
    284309
    285310
     
    340365        gridder = asapgrid2(table)
    341366        gridder.setIF(self.baseif)
    342        
     367
    343368        cellx = str(self.dirtol[0])+"rad"
    344369        celly = str(self.dirtol[1])+"rad"
     
    346371        mapx = dirarr[0].max() - dirarr[0].min()
    347372        mapy = dirarr[1].max() - dirarr[1].min()
    348         nx = max(1, numpy.ceil(mapx/self.dirtol[0]))
     373        centy = 0.5 * (dirarr[1].max() + dirarr[1].min())
     374        nx = max(1, numpy.ceil(mapx*numpy.cos(centy)/self.dirtol[0]))
    349375        ny = max(1, numpy.ceil(mapy/self.dirtol[0]))
    350376
     
    393419                seltab = tab.copy()
    394420                seltab.set_selection(selector(rows=selrow))
    395            
     421
    396422            if tab.nrow() > 1:
    397423                asaplog.push("table %d - More than a spectrum selected. averaging rows..." % (itab))
     
    414440
    415441        return spec_array[0:nspec], tabidx
    416            
     442
    417443
    418444    @asaplog_post_dec
     
    452478            asaplog.post()
    453479            asaplog.push("IFNO is not selected. Using the first IF in the first scantable. Reference IFNO = %d" % (self.baseif))
    454        
     480
    455481        if not (self.baseif in valid_ifs):
    456482            asaplog.post()
     
    460486
    461487        asaplog.push("Start selecting tables and IFNOs to solve.")
    462         asaplog.push("Cheching frequency of the reference IF")
     488        asaplog.push("Checking frequency of the reference IF")
    463489        unit_org = stab.get_unit()
    464490        coord = stab._getcoordinfo()
     
    473499        baseinc = spx[1]-spx[0]
    474500        self.nchan = len(spx)
    475         if isinstance(self.freqtol, float):
    476             vftol = abs(baseinc * self.freqtol)
     501        # frequency tolerance
     502        if isinstance(self.freqtol, dict) and self.freqtol['unit'] == "Hz":
     503            vftol = abs(self.freqtol['value'])
     504        else:
     505            vftol = abs(baseinc * float(self.freqtol))
    477506            self.freqtol = dict(value=vftol, unit="Hz")
    478         else:
    479             vftol = abs(self.freqtol['value'])
     507        # tolerance of frequency increment
    480508        inctol = abs(baseinc/float(self.nchan))
    481509        asaplog.push("Reference frequency setup (Table = 0, IFNO = %d):  nchan = %d, chan0 = %f Hz, incr = %f Hz" % (self.baseif, self.nchan, basech0, baseinc))
    482510        asaplog.push("Allowed frequency tolerance = %f Hz ( %f channels)" % (vftol, vftol/baseinc))
    483511        poltype0 = stab.poltype()
    484        
     512
    485513        self.tables = []
    486514        self.signalShift = []
     
    545573            asaplog.post()
    546574            errmsg = "User defined channel shift of image sideband has %d elements, while selected IFNOs are %d" % (len(self.imageShift), len(self.signalShift))
     575            errmsg += "\nThe frequency tolerance (freqtol) you set may be too small."
    547576            raise RuntimeError, errmsg
    548577
     
    557586        for itab in range(len(self.tables)):
    558587            self.tables[itab] = self.tables[itab].average_time(scanav=False, weight="tintsys")
    559        
     588
     589#     @asaplog_post_dec
     590#     def _setup_image_freq(self, table):
     591#         # User defined coordinate
     592#         # Get from associated MS
     593#         # Get from ASDM
     594#         lo1 = -1.
     595#         if self.lo1 > 0.:
     596#             asaplog.push("Using user defined LO1 frequency %e16.12 [Hz]" % self.lo1)
     597#             lo1 = self.lo1
     598#         else:
     599#             print "NOT IMPLEMENTED YET!!!"
    560600
    561601#     def save(self, outfile, outform="ASAP", overwrite=False):
Note: See TracChangeset for help on using the changeset viewer.