Example #1
0
    def main(self):
        """
        main body of utiliy.

        Preconditions:
            utility setup
        Postconditions:
            utility is run
        """
        # set up
        data = DatFile(self.commands["--infile"],"4")
        latitude = float(self.commands["--lat"])
        longitude = float(self.commands["--long"])
        columns = [data.getColumn(0),
                   np.array(data.getColumn(1)).astype(float)]
        # test out put
        out_file = CsvFile(self.commands["--outfile"], opti = True)
        last_date = datetime(1000,1,1)
        if not out_file.exists():
            fd = open(self.commands["--infile"])
            first_line = fd.read().split(",")[0:2]
            first_line[1] += "\n"
            out_file.set_header([ first_line,
                                  ("timestamp", "Albedo\n"),
                                  ("","\n"),
                                  ("","Avg\n")])
        else:
            last_date = out_file[0][-1]
        alb_vals = []
        alb_dates = []
        idx = 0
        while idx < len(columns[0]):
            compVal = columns[0][idx]
            # I'm not sure what this does...
            if datetime.strptime(compVal,'"%Y-%m-%d %H:%M:%S"') <= last_date:
                idx = idx + 1
                continue
            # this point is where the magic happens.
            raw_index = float(columns[1][idx])
            isdark = self.calc_SunAngle(latitude,longitude,datetime.strptime(compVal,'"%Y-%m-%d %H:%M:%S"'))
            if isdark == 6999 :
                alb_vals.append(6999.0)
            else:
                alb_vals.append(raw_index)

            alb_dates.append(datetime.strptime(compVal,'"%Y-%m-%d %H:%M:%S"'))
            idx= idx+1
        # save
        out_file.add_dates(alb_dates)
        out_file.add_data(1,alb_vals)
        out_file.append()
Example #2
0
    def main(self):
        """
        main body of utiliy. 
        
        Preconditions:
            utility setup
        Postconditions:
            utility is run
        """
        # set up 
        data = DatFile(self.commands["--inFile"],"4")
        timeC = int(self.commands["--timeCol"])
        tempC = int(self.commands["--tempCol"])
        powerC = self.commands["--powerCol"]
        columns = [data.getColumn(0), 
                   np.array(data.getColumn(timeC)).astype(float),
                   np.array(data.getColumn(tempC)).astype(float)]
        if powerC != "":
            powerC = int(powerC)
            columns.append(np.array(data.getColumn(powerC)).astype(float))
        
        # test out put
        out_file = CsvFile(self.commands["--outFile"], opti = True)
        last_date = datetime(1000,1,1) 
        if not out_file.exists():
            fd = open(self.commands["--inFile"])
            first_line = fd.read().split(",")[0:2]
            first_line[1] += "\n"
            out_file.set_header([ first_line,
                                  ("timestamp","k\n"), 
                                  ("","w/mk\n"),
                                  ("","smp\n")])
        else:
            last_date = out_file[0][-1]
    
        # process k 
        k_vals = []
        k_dates = []
        idx = 0 
        while idx < len(columns[0]):
            compVal = columns[0][idx]
            begin = idx
            end = idx
            try:
                while compVal == columns[0][idx]:
                    idx += 1
                    end = idx
            except:
                pass
            if datetime.strptime(compVal,'"%Y-%m-%d %H:%M:%S"') <= last_date: 
                continue
            if powerC == "":
                k_vals.append(self.calc_K(columns[1][begin:end],
                                          columns[2][begin:end]))
            else:
                k_vals.append(self.calc_K(columns[1][begin:end],
                                          columns[2][begin:end],
                                          columns[3][begin:end]))
            k_dates.append(datetime.strptime(compVal,'"%Y-%m-%d %H:%M:%S"'))                                          
        
        
        # save 
        out_file.add_dates(k_dates)
        out_file.add_data(1,k_vals)

        out_file.append()