예제 #1
0
def director(self, option, dest, file=None, verbose=True):
    '''
    director: Function to move, remove, and copy files and directories
    option: 'mk', 'ch', 'mv', 'rm', and 'cp' are supported
    dest: Destination of a file or directory to move to
    file: Which file to move or copy, otherwise None
    '''
    subs.setinit.setinitdirs(self)
    if option == 'mk':
        if os.path.exists(dest):
            pass
        else:
            os.makedirs(dest)
            if verbose == True:
                self.logger.debug('# Creating directory ' + str(dest) + ' #')
    elif option == 'ch':
        if os.getcwd() == dest:
            pass
        else:
            self.lwd = os.getcwd(
            )  # Save the former working directory in a variable
            try:
                os.chdir(dest)
            except:
                os.makedirs(dest)
                if verbose == True:
                    self.logger.debug('# Creating directory ' + str(dest) +
                                      ' #')
                os.chdir(dest)
            self.cwd = os.getcwd(
            )  # Save the current working directory in a variable
            if verbose == True:
                self.logger.debug('# Moved to directory ' + str(dest) + ' #')
    elif option == 'mv':  # Move
        if os.path.exists(dest):
            lib.basher("mv " + str(file) + " " + str(dest))
        else:
            os.mkdir(dest)
            lib.basher("mv " + str(file) + " " + str(dest))
    elif option == 'rn':  # Rename
        lib.basher("mv " + str(file) + " " + str(dest))
    elif option == 'cp':  # Copy
        lib.basher("cp -r " + str(file) + " " + str(dest))
    elif option == 'rm':  # Remove
        lib.basher("rm -r " + str(dest))
    else:
        self.logger.warning(
            '### Option not supported! Only mk, ch, mv, rm, rn, and cp are supported! ###'
        )
예제 #2
0
def getbpaimage(infile):
    '''
    getbmpaimage: Get the beam angle from a MIRIAD image
    infile (string): input image file in MIRIAD format
    returns (float): BPA in degrees of the image
    '''
    bpa = np.float(lib.basher('gethd in=' + infile + '/bpa')[0])
    return bpa
예제 #3
0
def getbminimage(infile):
    '''
    getbminimage: Get the minor beam size from a MIRIAD image
    infile (string): input image file in MIRIAD format
    returns (float): BMIN in arcseconds of the image
    '''
    bmin = np.float(lib.basher('gethd in=' + infile +
                               '/bmin')[0]) * 3600.0 * (360.0 / (2.0 * np.pi))
    return bmin
예제 #4
0
def getradecsex(infile):
    '''
    skycoords: The astropy SkyCoord instance values to covert to a string
    returns: String with the RA and DEC in format hh:mm:ss,dd:mm:ss
    '''
    prthd = lib.basher('prthd in=' + infile)
    regex = re.compile(".*(J2000).*")
    coordline = [m.group(0) for l in prthd for m in [regex.search(l)]
                 if m][0].split()
    coords = coordline[3].split('.')[0] + ',' + coordline[5].split('.')[0]
    return coords
예제 #5
0
파일: lsm.py 프로젝트: gijzelaerr/apercal
def getnchan(infile):
    '''
	getnchan: module to extract the number of channels from an observation
	param infile: infile (name of file)
	return: the number of channels of the observation
	'''
    prthd = lib.basher('prthd in=' + infile)
    regex = re.compile(".*(GHz).*")
    nchanline = [m.group(0) for l in prthd for m in [regex.search(l)]
                 if m][0].split()
    nchan = int(nchanline[1])
    return nchan
예제 #6
0
파일: lsm.py 프로젝트: gijzelaerr/apercal
def getfreq(infile):
    '''
	getfreq: module to extract the central freqeuncy of the observing band
	param infile: infile (name of file)
	returns: the central frequency of the visibility file
	'''
    prthd = lib.basher('prthd in=' + infile)
    regex = re.compile(".*(GHz).*")
    freqline = [m.group(0) for l in prthd for m in [regex.search(l)]
                if m][0].split()
    freq = float(freqline[2]) + (float(freqline[1]) / 2.0) * float(freqline[3])
    return freq
예제 #7
0
def getdecimage(infile):
    '''
    getdecimage: Get the DEC from a MIRIAD image
    infile (string): input image file in MIRIAD format
    returns: DEC coordinates dd:mm:ss.sss
    '''
    prthd = lib.basher('prthd in=' + infile)
    regex = re.compile(".*(DEC--NCP).*")
    coordline = [m.group(0) for l in prthd for m in [regex.search(l)]
                 if m][0].split()
    dec = coordline[2]
    return dec
예제 #8
0
def getraimage(infile):
    '''
    getraimage: Get the RA cooridinate from a miriad image
    infile (string): input image file in MIRIAD format
    returns: RA coordinates of the image in hh:mm:ss.sss
    '''
    prthd = lib.basher('prthd in=' + infile)
    regex = re.compile(".*(RA---NCP).*")
    coordline = [m.group(0) for l in prthd for m in [regex.search(l)]
                 if m][0].split()
    ra = coordline[2]
    return ra
예제 #9
0
def getradec(infile):
    '''
    getradec: module to extract the pointing centre ra and dec from a miriad image file. Uses the PRTHD task in miriad
    inputs: infile (name of file)
    returns: coords, an instance of the astropy.coordinates SkyCoord class which has a few convenient attributes.
    '''
    prthd = lib.basher('prthd in=' + infile)
    regex = re.compile(".*(J2000).*")
    coordline = [m.group(0) for l in prthd for m in [regex.search(l)]
                 if m][0].split()
    rastr = coordline[3]
    decstr = coordline[5]
    rastr = fixra(rastr)
    coords = SkyCoord(FK5, ra=rastr, dec=decstr, unit=(u.deg, u.deg))
    return coords