Example #1
0
    def getAOS(self, antennaToRemove=[], all12=False, all7=False):
        "Get the current AOS configuration (only 12-m yet)"

        try:
            resp = requests.get(
                'https://asa.alma.cl/dashboard2-backend/service/api/antennas')

        except:
            print("### Error on getting the current AOS configuration ....")

        dataAOS = json.loads(resp.content)

        faos = open(self.aosFile, 'w')

        listPossibleAnt = ['DV', 'DA']

        if all12:
            listPossibleAnt.append('PM')

        elif all7:
            listPossibleAnt = ['CM']

        for key in dataAOS:
            if key['antenna-functional-status'] == 'AVAILABLE' and (key['name'][0:2] in listPossibleAnt)  \
              and key['name'] not in antennaToRemove:

                faos.write("%s  %s \n" % (key['pad'], key['name']))

        faos.close()

        a = aC.ArrayConfigurationCasaFile(padPositionFile=PAD_CFG_FILE)
        a.createCasaConfig(self.aosFile)

        return (self.aosFile + '.cfg')
Example #2
0
    def createConfigurationFile(self):
        "create the uid.cfg configuration file"

        dish = []
        antName = []
        stationId = []
        padName = []

        xml_object = etree.fromstring(self.antenna_xml)
        rows_ant = xml_object.findall('row')

        ## testing ...
        ftest = open("test.cin", "w")

        for row in rows_ant:
            res = row.find('dishDiameter').text.strip()
            dish.append(res)

            res = row.find('name').text.strip()
            antName.append(res)

            res = row.find('stationId').text.strip()

            position = row.find('position').text.strip()
            ftest.write(position)

            stationId.append(res)

            padName.append('none')

        ##testing
        ftest.close()

        ## find the match of stationId with Padname
        xml_object = etree.fromstring(self.station_xml)
        rows_station = xml_object.findall('row')

        for row in rows_station:
            pad = row.find('name').text.strip()
            id = row.find('stationId').text.strip()

            for i in range(len(dish)):
                if stationId[i] == id:
                    padName[i] = pad

        ## creation of the array configuration file
        aCasa = act.ArrayConfigurationCasaFile()
        listpad = []

        ## for 12-m array
        for i in range(len(dish)):
            if int(float(dish[i])) == 12:
                listpad.append(padName[i])

            if int(float(dish[i])) == 7:
                listpad.append(padName[i])

        # rm any possible uid.cfg

        # aaguirre
        cmd = "rm %s.cfg" % self.conf_filename
        os.system(cmd)

        aCasa.createCasaConfig(self.conf_filename, listPads=listpad)

        return (0)
Example #3
0
    def run(self):
        "Produce the main report"
        
        
        ## Reading the options
        
        parser = OptionParser()

        parser.add_option("-f", "--frequency", dest = "frequency", default = '100.',
                  help="Observation frequency (GHz) ")
                  
        parser.add_option("-i", "--inputfile", dest = "inputfile", 
                  help="Input file with the pad list")
        
        parser.add_option("-t", "--type", dest = "type", default = 'casa' ,
                  help="Input file type: ascii, casa")
        
                
        parser.add_option("-o","--outputfile", dest = "outputfile", default = 'arrayConfigurationResults.txt',
                          help = "Outputfile with the results")
        
        parser.add_option("-a","--hourAngle", dest = "hourangle", default = 'transit',
                          help = "Hour angle of the observation  (transit is the default)")
        
        parser.add_option("-l","--length", dest = "length", default = "1h",
                          help = "Track duration (1h is the default)")
        
        
        parser.add_option("-d","--declination", dest = "declination", default = "-23",
                          help = "Declination (-23 is the default)")
        
        parser.add_option("-k","--disk", dest = "disk", default = "1",
                          help = "Size in arcsec of the disk component")
        
        parser.add_option("-w","--weighting", dest = "weight", default = "briggs",
                          help = "Weighting (uniform, briggs, natural) to compute the array properties")
        
        parser.add_option("-p","--plot", dest = "online", default = "no",
                          help = "to produce automatic/standard plots for the online version (yes/no)")
        
        
        parser.add_option("-x","--cycle", dest = "cycle", default = "3",
                          help = "Configuration standard for Cycle nn")
        
        parser.add_option("-r","--timeRatio", dest = "timeRatio", default = "no",
                          help = "Compute the time ration if combined with standard configurations (yes|no)")
        
        
        parser.add_option("-c","--critical", dest = "critical", default = "10",
                          help = "Number of critical pads to be computed")       
        
        parser.add_option("-j","--jason", dest = "jasonFile", default = "report.json",
                          help = "Add a json file for the output.")   
        
        parser.add_option("-y","--aos", dest = "aos", default = False, action = "store_true", help = "Use the current aos configuration.")   

        
        parser.add_option("-s", "--standard", dest = "standard", default = False, action = "store_true" , help="Compare with a standard configuration")

        
        parser.add_option("--rA", dest = "removeAntenna", default = "", help = "Only for AOS ! Remove antenna from the configuration file. Enter  the list as a string") 

        
        parser.add_option("--twelve", dest = "all12m", default = False, action = "store_true" , help = "Only for AOS ! Select all 12-m antennas (DV, DA, PM)") 

        parser.add_option("--seven", dest = "all7m", default = False, action = "store_true" , help = "Only for AOS ! Select all 7-m antennas (CM)") 

        parser.add_option("--casa", dest = "casaExec", default = "casa", help = "Executable for casa (/path/casa) ") 
        
        parser.add_option("--project", dest = "project", default = "sim", help = "project name for the CASA simulation") 


        parser.add_option("--cleandisk", dest = "cleanDir", default = False, action = "store_true" , help = "To remove some directories and reduce  disk space")

        (optarr, args) = parser.parse_args()
        
        
        if  optarr.standard :
            optarr.standard = 'yes'
        else :
            optarr.standard = 'no'
                   
        if   optarr.aos :
            print("## Obtaining the AOS configuration ...")
            aosCurrent = aosConfiguration()
            
            
            if optarr.removeAntenna != "":
                antennaToRemove = optarr.removeAntenna.split()
                print("#### Do not consider : %s"%antennaToRemove)
                optarr.inputfile = aosCurrent.getAOS(antennaToRemove, all12 = optarr.all12m, all7 = optarr.all7m)               
            else :
                optarr.inputfile = aosCurrent.getAOS(all12 = optarr.all12m, all7 = optarr.all7m)

            optarr.type = 'casa'
                      
        ## cleaning disk space option   
        if optarr.cleanDir :
            cleanDir = 'True'
        else:
            cleanDir = 'False'
            
            
        print optarr.standard
        
        print("## Simulation of an array configuration")
        print("## version: %s"%(__version__))
        print("## Input file: %s"%(optarr.inputfile))
        print("## Output file: %s"%(optarr.outputfile))
        print("## Frequency (GHz): %s"%(optarr.frequency))
        print("## Declination (Degree): %s"%(optarr.declination))
        print("## Observation Start (Hour Angle): %s"%(optarr.hourangle))
        print("## Duration: %s"%(optarr.length))
        print("## Standard: %s"%(optarr.standard))
        print("## Time Ratio: %s"%(optarr.timeRatio))
        print("## Disk component: %s (arcsec)"%(optarr.disk))
        print("## Weighting: %s "%(optarr.weight))
        print("## Online: %s "%(optarr.online))
        print("## Critical Pads: %s "%(optarr.critical))
        print("## Cycle: %s"%(optarr.cycle))
        print("## Project: %s"%(optarr.project))
        print("## Jason File:  %s"%(optarr.jasonFile))
        print("## Clean Directories:  %s"%(cleanDir))       
        print("##")
    
        ## Creating the CASA configuration file
        a = aC.ArrayConfigurationCasaFile(padPositionFile = PAD_CFG_FILE)
        
        
        listpad = []
        listant = []
        
        
        f = open(optarr.inputfile)
        
        for pad in f:
            if pad[0] != "#":
                data = pad.split()
                if len(data) == 2:
                    listant.append(data[0])
                    listpad.append(data[1])
            
            
        f.close()
        
        Nant = len(listpad)
        
        # print listpad
        if optarr.type == 'ascii':
            a.createCasaConfig(optarr.inputfile,listPads = listpad)
            casaFile = optarr.inputfile+'.cfg'
            
        elif optarr.type == 'casa':
            casaFile = optarr.inputfile
                  
        
        # Info 
        
        ai = aC.ArrayInfo(casaFile)
        ai.stats()
         
        
        # produce input for CASA scripts
        simParamFile = "%s.par"%(optarr.inputfile)
        f = open(simParamFile,"w")
        
        f.write("file         = %s \n"%(casaFile))
        f.write("inputfile    = %s \n"%(optarr.inputfile))
        f.write("reportFile   = %s \n"%(optarr.outputfile))
        f.write("Nant         = %s \n"%(Nant))
        f.write("frequency    = %s \n"%(optarr.frequency))
        f.write("declination  = %s \n"%(optarr.declination))
        f.write("hourAngle    = %s \n"%(optarr.hourangle))
        f.write("duration     = %s \n"%(optarr.length))
        f.write("minBl        = %f \n"%(ai.minBl))
        f.write("maxBl        = %f \n"%(ai.maxBl))
        f.write("rms          = %f \n"%(ai.rms))
        f.write("standard     = %s \n"%(optarr.standard))
        f.write("timeRatio    = %s \n"%(optarr.timeRatio))
        f.write("disk         = %s \n"%(optarr.disk))
        f.write("weighting    = %s \n"%(optarr.weight))
        f.write("cycle        = %s \n"%(optarr.cycle))
        f.write("online       = %s \n"%(optarr.online))
        f.write("criticalPads = %s \n"%(optarr.critical))
        f.write("jasonFile    = %s \n"%(optarr.jasonFile))
        f.write("projectName  = %s \n"%(optarr.project))
        f.write("cleanDir     = %s"%(cleanDir)) 
        
        f.close()
        
        print("## Simulation parameters written")

        ## run the simulations
        
        cmd = "casa  --nogui -c arrayConfigurationSim.py -i %s"%(simParamFile)
        cmdalt = "casapy  --nogui -c arrayConfigurationSim.py -i %s"%(simParamFile)
        
        ## change the casa executable if needed
        if optarr.casaExec != "casa":
            cmd = "%s  --nogui -c arrayConfigurationSim.py -i %s"%(optarr.casaExec, simParamFile)
        
        try:
            os.system(cmd)
        except:
            os.system(cmdalt)