def __init__( self, spec, xdb, pdb_dir, cappings_dir, metadata_dir, show_fusion=False, disable_capping=False, skip_unused=False, ): spec_complaint = validate_spec(spec) if spec_complaint: print('Error:', spec_complaint) exit() self.spec = spec self.xdb = xdb self.pdb_dir = pdb_dir self.cr_dir = cappings_dir self.show_fusion = show_fusion self.disable_capping = disable_capping self.skip_unused = skip_unused self.si = Bio.PDB.Superimposer() self.chain_id = 0 # Parse and convert capping repeat indicies into a dictionary self.capping_repeat_idx = {} meta_csv = utils.read_csv( metadata_dir + '/repeat_indicies.csv', delim=' ') for row in meta_csv: mod_name = row[0].split('.')[0].replace('DHR', 'D') self.capping_repeat_idx[mod_name] = \ [int(idx) for idx in row[1:]]
def weight_polling(polling_data, year, polling_date, polling_org, time_penalty): pollster_information = utilities.read_csv( "pollster-ratings_{0}.tsv".format(year), year=year, data_values=False, delim="\t" ) weighted_average = 0 weights_summed = 0 non_weighted_average = 0 num_polls = 0 for i, polling_result in enumerate(polling_data): pollster = polling_org[i] if pollster == "RCP Average" or pollster == "Final Results": continue polling_time = polling_date[i] difference_date = get_date_difference(polling_time, year) if difference_date is not None: if pollster in pollster_information.keys(): letter_grade = pollster_information[pollster][9] else: letter_grade = "C+" if letter_grade in pollster_grades: numerical_grade = pollster_grades[letter_grade] weighted_average += ( (1 / float(abs(difference_date.days) ** time_penalty)) * numerical_grade * polling_result ) non_weighted_average += polling_result weights_summed += numerical_grade * (1 / float(abs(difference_date.days) ** time_penalty)) num_polls += 1 return weighted_average / float(weights_summed), non_weighted_average / float(num_polls)
def __init__(self, label_file='../data/train_list.csv', resize=True, augmentation=True): self.resize = resize self.augmentation = augmentation self.files = UT.read_csv(label_file)
def read_epw(self): """Section 2 - Read EPW file properties: self.climateDataPath self.newPathName self._header # header data self.epwinput # timestep data for weather self.lat # latitude self.lon # longitude self.GMT # GMT self.nSoil # Number of soil depths self.Tsoil # nSoil x 12 matrix for soil temperture (K) self.depth_soil # nSoil x 1 matrix for soil depth (m) """ # Make dir path to epw file self.climateDataPath = os.path.join(self.epwDir, self.epwFileName) # Open epw file and feed csv data to climate_data try: climate_data = utilities.read_csv(self.climateDataPath) except Exception as e: raise Exception("Failed to read epw file! {}".format(e.message)) # Read header lines (1 to 8) from EPW and ensure TMY2 format. self._header = climate_data[0:8] # Read weather data from EPW for each time step in weather file. (lines 8 - end) self.epwinput = climate_data[8:] # Read Lat, Long (line 1 of EPW) self.lat = float(self._header[0][6]) self.lon = float(self._header[0][7]) self.GMT = float(self._header[0][8]) # Read in soil temperature data (assumes this is always there) # ref: http://bigladdersoftware.com/epx/docs/8-2/auxiliary-programs/epw-csv-format-inout.html soilData = self._header[3] self.nSoil = int(soilData[1]) # Number of ground temperature depths self.Tsoil = utilities.zeros( self.nSoil, 12) # nSoil x 12 matrix for soil temperture (K) self.depth_soil = utilities.zeros( self.nSoil, 1) # nSoil x 1 matrix for soil depth (m) # Read monthly data for each layer of soil from EPW file for i in xrange(self.nSoil): self.depth_soil[i][0] = float( soilData[2 + (i * 16)]) # get soil depth for each nSoil # Monthly data for j in xrange(12): self.Tsoil[i][j] = float(soilData[ 6 + (i * 16) + j]) + 273.15 # 12 months of soil T for specific depth # Set new directory path for the moprhed EPW file self.newPathName = os.path.join(self.destinationDir, self.destinationFileName)
def parse_accurate_csv_file(): coordinates = [] rows = read_csv('london_vic_railstrings') for row in rows[1:]: [lng_l, lat_l, ele_l, lng_r, lat_r, ele_r] = map(float, row) coordinates.append([ 0.5*(lng_r + lng_l), 0.5*(lat_r + lat_l), 0.5*(ele_r + ele_l), ]) gpx = create_gpx_file(coordinates) save_gpx_file('perfect', gpx)
def __init__(self, climate_file, HI, HF): #HI: Julian start date #HF: Julian final date #H1 and HF define the row we want # Open .epw file and feed csv data to self.climate_data try: self.climate_data = read_csv(climate_file) except Exception as e: raise Exception("Failed to read .epw file! {}".format(e.message)) self.location = self.climate_data[0][1] cd = self.climate_data[HI:HF + 1] self.staTemp = str2fl([cd[i][6] for i in xrange(len(cd))]) # drybulb [C] self.staTdp = str2fl([cd[i][7] for i in xrange(len(cd))]) # dewpoint [C] self.staRhum = str2fl([cd[i][8] for i in xrange(len(cd)) ]) # air relative humidity [%] self.staPres = str2fl([cd[i][9] for i in xrange(len(cd))]) # air pressure [Pa] self.staInfra = str2fl([ cd[i][12] for i in xrange(len(cd)) ]) # horizontal Infrared Radiation Intensity [W m^-2] self.staHor = str2fl([cd[i][13] for i in xrange(len(cd)) ]) # horizontal radiation [W m^-2] self.staDir = str2fl([cd[i][14] for i in xrange(len(cd)) ]) # normal solar direct radiation [W m^-2] self.staDif = str2fl([cd[i][15] for i in xrange(len(cd)) ]) # horizontal solar diffuse radiation [W m^-2] self.staUdir = str2fl([cd[i][20] for i in xrange(len(cd)) ]) # wind direction [deg] self.staUmod = str2fl([cd[i][21] for i in xrange(len(cd)) ]) # wind speed [m s^-1] self.staRobs = str2fl([cd[i][33] for i in xrange(len(cd)) ]) # Precipitation [mm h^-1] self.staHum = [0.0] * len(self.staTemp) # specific humidity [kg kg^-1] for i in xrange(len(self.staTemp)): self.staHum[i] = HumFromRHumTemp(self.staRhum[i], self.staTemp[i], self.staPres[i]) print(self.staHum) self.staTemp = [s + 273.15 for s in self.staTemp] # air temperature [K] print(HI) print(HF)
def readDOE(serialize_output=True): """ Read csv files of DOE buildings Sheet 1 = BuildingSummary Sheet 2 = ZoneSummary Sheet 3 = LocationSummary Sheet 4 = Schedules Note BLD8 & 10 = school Then make matrix of ref data as nested nested lists [16, 3, 16]: matrix refDOE = Building objs matrix Schedule = SchDef objs matrix refBEM (16,3,16) = BEMDef where: [16,3,16] is Type = 1-16, Era = 1-3, climate zone = 1-16 i.e. Type: FullServiceRestaurant, Era: Pre80, Zone: 6A Minneapolis Nested tree: [TYPE_1: ERA_1: CLIMATE_ZONE_1 ... CLIMATE_ZONE_16 ERA_2: CLIMATE_ZONE_1 ... CLIMATE_ZONE_16 ... ERA_3: CLIMATE_ZONE_1 ... CLIMATE_ZONE_16] """ #Nested, nested lists of Building, SchDef, BEMDef objects refDOE = map(lambda j_: map(lambda k_: [None] * 16, [None] * 3), [None] * 16) #refDOE(16,3,16) = Building; Schedule = map(lambda j_: map(lambda k_: [None] * 16, [None] * 3), [None] * 16) #Schedule (16,3,16) = SchDef; refBEM = map(lambda j_: map(lambda k_: [None] * 16, [None] * 3), [None] * 16) #refBEM (16,3,16) = BEMDef; #Purpose: Loop through every DOE reference csv and extract building data #Nested loop = 16 types, 3 era, 16 zones = time complexity O(n*m*k) = 768 for i in xrange(16): #i = 16 types of buildings #print "\tType: {} @i={}".format(BLDTYPE[i], i) # Read building summary (Sheet 1) file_doe_name_bld = os.path.join( "{}".format(DIR_DOE_PATH), "BLD{}".format(i + 1), "BLD{}_BuildingSummary.csv".format(i + 1)) list_doe1 = read_csv(file_doe_name_bld) #listof(listof 3 era values) nFloor = str2fl( list_doe1[3][3:6] ) # Number of Floors, this will be list of floats and str if "basement" glazing = str2fl(list_doe1[4][3:6]) # [?] Total hCeiling = str2fl(list_doe1[5][3:6]) # [m] Ceiling height ver2hor = str2fl(list_doe1[7][3:6]) # Wall to Skin Ratio AreaRoof = str2fl( list_doe1[8][3:6]) # [m2] Gross Dimensions - Total area # Read zone summary (Sheet 2) file_doe_name_zone = os.path.join( "{}".format(DIR_DOE_PATH), "BLD{}".format(i + 1), "BLD{}_ZoneSummary.csv".format(i + 1)) list_doe2 = read_csv(file_doe_name_zone) #listof(listof 3 eras) AreaFloor = str2fl([list_doe2[2][5], list_doe2[3][5], list_doe2[4][5]]) # [m2] Volume = str2fl([list_doe2[2][6], list_doe2[3][6], list_doe2[4][6]]) # [m3] AreaWall = str2fl([list_doe2[2][8], list_doe2[3][8], list_doe2[4][8]]) # [m2] AreaWindow = str2fl( [list_doe2[2][9], list_doe2[3][9], list_doe2[4][9]]) # [m2] Occupant = str2fl( [list_doe2[2][11], list_doe2[3][11], list_doe2[4][11]]) # Number of People Light = str2fl([list_doe2[2][12], list_doe2[3][12], list_doe2[4][12]]) # [W/m2] Elec = str2fl([list_doe2[2][13], list_doe2[3][13], list_doe2[4][13]]) # [W/m2] Electric Plug and Process Gas = str2fl([list_doe2[2][14], list_doe2[3][14], list_doe2[4][14]]) # [W/m2] Gas Plug and Process SHW = str2fl([list_doe2[2][15], list_doe2[3][15], list_doe2[4][15]]) # [Litres/hr] Peak Service Hot Water Vent = str2fl([list_doe2[2][17], list_doe2[3][17], list_doe2[4][17]]) # [L/s/m2] Ventilation Infil = str2fl([list_doe2[2][20], list_doe2[3][20], list_doe2[4][20] ]) # Air Changes Per Hour (ACH) Infiltration # Read location summary (Sheet 3) file_doe_name_location = os.path.join( "{}".format(DIR_DOE_PATH), "BLD{}".format(i + 1), "BLD{}_LocationSummary.csv".format(i + 1)) list_doe3 = read_csv(file_doe_name_location) #(listof (listof 3 eras (listof 16 climate types))) TypeWall = [ list_doe3[3][4:20], list_doe3[14][4:20], list_doe3[25][4:20] ] # Construction type RvalWall = str2fl( [list_doe3[4][4:20], list_doe3[15][4:20], list_doe3[26][4:20]]) # [m2*K/W] R-value TypeRoof = [ list_doe3[5][4:20], list_doe3[16][4:20], list_doe3[27][4:20] ] # Construction type RvalRoof = str2fl( [list_doe3[6][4:20], list_doe3[17][4:20], list_doe3[28][4:20]]) # [m2*K/W] R-value Uwindow = str2fl( [list_doe3[7][4:20], list_doe3[18][4:20], list_doe3[29][4:20]]) # [W/m2*K] U-factor SHGC = str2fl( [list_doe3[8][4:20], list_doe3[19][4:20], list_doe3[30][4:20]]) # [-] coefficient HVAC = str2fl( [list_doe3[9][4:20], list_doe3[20][4:20], list_doe3[31][4:20]]) # [kW] Air Conditioning HEAT = str2fl( [list_doe3[10][4:20], list_doe3[21][4:20], list_doe3[32][4:20]]) # [kW] Heating COP = str2fl( [list_doe3[11][4:20], list_doe3[22][4:20], list_doe3[33][4:20]]) # [-] Air Conditioning COP EffHeat = str2fl( [list_doe3[12][4:20], list_doe3[23][4:20], list_doe3[34][4:20]]) # [%] Heating Efficiency FanFlow = str2fl( [list_doe3[13][4:20], list_doe3[24][4:20], list_doe3[35][4:20]]) # [m3/s] Fan Max Flow Rate # Read Schedules (Sheet 4) file_doe_name_schedules = os.path.join( "{}".format(DIR_DOE_PATH), "BLD{}".format(i + 1), "BLD{}_Schedules.csv".format(i + 1)) list_doe4 = read_csv(file_doe_name_schedules) #listof(listof weekday, sat, sun (list of 24 fractions))) SchEquip = str2fl( [list_doe4[1][6:30], list_doe4[2][6:30], list_doe4[3][6:30]]) # Equipment Schedule 24 hrs SchLight = str2fl( [list_doe4[4][6:30], list_doe4[5][6:30], list_doe4[6][6:30]]) # Light Schedule 24 hrs; Wkday=Sat=Sun=Hol SchOcc = str2fl( [list_doe4[7][6:30], list_doe4[8][6:30], list_doe4[9][6:30]]) # Occupancy Schedule 24 hrs SetCool = str2fl( [list_doe4[10][6:30], list_doe4[11][6:30], list_doe4[12][6:30]]) # Cooling Setpoint Schedule 24 hrs SetHeat = str2fl([ list_doe4[13][6:30], list_doe4[14][6:30], list_doe4[15][6:30] ]) # Heating Setpoint Schedule 24 hrs; summer design SchGas = str2fl( [list_doe4[16][6:30], list_doe4[17][6:30], list_doe4[18][6:30]]) # Gas Equipment Schedule 24 hrs; wkday=sat SchSWH = str2fl( [list_doe4[19][6:30], list_doe4[20][6:30], list_doe4[21][6:30]] ) # Solar Water Heating Schedule 24 hrs; wkday=summerdesign, sat=winterdesgin for j in xrange(3): # j = 3 built eras #print"\tEra: {} @j={}".format(BUILTERA[j], j) for k in xrange(16): # k = 16 climate zones #print "\tClimate zone: {} @k={}".format(ZONETYPE[k], k) B = Building( hCeiling[j], # floorHeight by era 1, # intHeatNight 1, # intHeatDay 0.1, # intHeatFRad 0.1, # intHeatFLat Infil[j], # infil (ACH) by era Vent[j] / 1000., # vent (m^3/s/m^2) by era, converted from liters glazing[j], # glazing ratio by era Uwindow[j][k], # uValue by era, by climate type SHGC[j][k], # SHGC, by era, by climate type 'AIR', # cooling condensation system type: AIR, WATER COP[j][k], # cop by era, climate type 297, # coolSetpointDay = 24 C 297, # coolSetpointNight 293, # heatSetpointDay = 20 C 293, # heatSetpointNight (HVAC[j][k] * 1000.0) / AreaFloor[ j], # coolCap converted to W/m2 by era, climate type EffHeat[j][k], # heatEff by era, climate type 293) # initialTemp at 20 C #Not defined in the constructor B.heatCap = (HEAT[j][k] * 1000.0) / AreaFloor[ j] # heating Capacity converted to W/m2 by era, climate type B.Type = BLDTYPE[i] B.Era = BUILTERA[j] B.Zone = ZONETYPE[k] refDOE[i][j][k] = B # Define wall, mass(floor), roof # Reference from E+ for conductivity, thickness (reference below) # Material: (thermalCond, volHeat = specific heat * density) Concrete = Material(1.311, 836.8 * 2240, "Concrete") Insulation = Material(0.049, 836.8 * 265.0, "Insulation") Gypsum = Material(0.16, 830.0 * 784.9, "Gypsum") Wood = Material(0.11, 1210.0 * 544.62, "Wood") Stucco = Material(0.6918, 837.0 * 1858.0, "Stucco") # Wall (1 in stucco, concrete, insulation, gypsum) # Check TypWall by era, by climate if TypeWall[j][k] == "MassWall": #Construct wall based on R value of Wall from refDOE and properties defined above # 1" stucco, 8" concrete, tbd insulation, 1/2" gypsum Rbase = 0.271087 # R val based on stucco, concrete, gypsum Rins = RvalWall[j][k] - Rbase #find insulation value D_ins = Rins * Insulation.thermalCond # depth of ins from m2*K/W * W/m*K = m if D_ins > 0.01: thickness = [ 0.0254, 0.0508, 0.0508, 0.0508, 0.0508, D_ins, 0.0127 ] layers = [ Stucco, Concrete, Concrete, Concrete, Concrete, Insulation, Gypsum ] else: #if it's less then 1 cm don't include in layers thickness = [ 0.0254, 0.0508, 0.0508, 0.0508, 0.0508, 0.0127 ] layers = [ Stucco, Concrete, Concrete, Concrete, Concrete, Gypsum ] wall = Element(0.08, 0.92, thickness, layers, 0., 293., 0., "MassWall") # If mass wall, assume mass floor (4" concrete) # Mass (assume 4" concrete); alb = 0.2 emis = 0.9 thickness = [0.054, 0.054] concrete = Material(1.31, 2240.0 * 836.8) mass = Element(alb, emis, thickness, [concrete, concrete], 0, 293, 1, "MassFloor") elif TypeWall[j][k] == "WoodFrame": # 0.01m wood siding, tbd insulation, 1/2" gypsum Rbase = 0.170284091 # based on wood siding, gypsum Rins = RvalWall[j][k] - Rbase D_ins = Rins * Insulation.thermalCond #depth of insulatino if D_ins > 0.01: thickness = [0.01, D_ins, 0.0127] layers = [Wood, Insulation, Gypsum] else: thickness = [0.01, 0.0127] layers = [Wood, Gypsum] wall = Element(0.22, 0.92, thickness, layers, 0., 293., 0., "WoodFrameWall") # If wood frame wall, assume wooden floor alb = 0.2 emis = 0.9 thickness = [0.05, 0.05] wood = Material(1.31, 2240.0 * 836.8) mass = Element(alb, emis, thickness, [wood, wood], 0., 293., 1., "WoodFloor") elif TypeWall[j][k] == "SteelFrame": # 1" stucco, 8" concrete, tbd insulation, 1/2" gypsum Rbase = 0.271087 # based on stucco, concrete, gypsum Rins = RvalWall[j][k] - Rbase D_ins = Rins * Insulation.thermalCond if D_ins > 0.01: thickness = [ 0.0254, 0.0508, 0.0508, 0.0508, 0.0508, D_ins, 0.0127 ] layers = [ Stucco, Concrete, Concrete, Concrete, Concrete, Insulation, Gypsum ] else: # If insulation is too thin, assume no insulation thickness = [ 0.0254, 0.0508, 0.0508, 0.0508, 0.0508, 0.0127 ] layers = [ Stucco, Concrete, Concrete, Concrete, Concrete, Gypsum ] wall = Element(0.15, 0.92, thickness, layers, 0., 293., 0., "SteelFrame") # If mass wall, assume mass foor # Mass (assume 4" concrete), alb = 0.2 emis = 0.93 thickness = [0.05, 0.05] mass = Element(alb, emis, thickness, [Concrete, Concrete], 0., 293., 1., "MassFloor") elif TypeWall[j][k] == "MetalWall": # metal siding, insulation, 1/2" gypsum alb = 0.2 emis = 0.9 D_ins = max( (RvalWall[j][k] * Insulation.thermalCond) / 2, 0.01 ) #use derived insul thickness or 0.01 based on max thickness = [D_ins, D_ins, 0.0127] materials = [Insulation, Insulation, Gypsum] wall = Element(alb, emis, thickness, materials, 0, 293, 0, "MetalWall") # Mass (assume 4" concrete); alb = 0.2 emis = 0.9 thickness = [0.05, 0.05] concrete = Material(1.31, 2240.0 * 836.8) mass = Element(alb, emis, thickness, [concrete, concrete], 0., 293., 1., "MassFloor") # Roof if TypeRoof[j][k] == "IEAD": #Insulation Entirely Above Deck # IEAD-> membrane, insulation, decking alb = 0.2 emis = 0.93 D_ins = max(RvalRoof[j][k] * Insulation.thermalCond / 2., 0.01) roof = Element(alb, emis, [D_ins, D_ins], [Insulation, Insulation], 0., 293., 0., "IEAD") elif TypeRoof[j][k] == "Attic": # IEAD-> membrane, insulation, decking alb = 0.2 emis = 0.9 D_ins = max(RvalRoof[j][k] * Insulation.thermalCond / 2., 0.01) roof = Element(alb, emis, [D_ins, D_ins], [Insulation, Insulation], 0., 293., 0., "Attic") elif TypeRoof[j][k] == "MetalRoof": # IEAD-> membrane, insulation, decking alb = 0.2 emis = 0.9 D_ins = max(RvalRoof[j][k] * Insulation.thermalCond / 2., 0.01) roof = Element(alb, emis, [D_ins, D_ins], [Insulation, Insulation], 0., 293., 0., "MetalRoof") # Define bulding energy model, set fraction of the urban floor space of this typology to zero refBEM[i][j][k] = BEMDef(B, mass, wall, roof, 0.0) refBEM[i][j][k].building.FanMax = FanFlow[j][ k] # max fan flow rate (m^3/s) per DOE Schedule[i][j][k] = SchDef() Schedule[i][j][ k].Elec = SchEquip # 3x24 matrix of schedule for fraction electricity (WD,Sat,Sun) Schedule[i][j][ k].Light = SchLight # 3x24 matrix of schedule for fraction light (WD,Sat,Sun) Schedule[i][j][ k].Gas = SchGas # 3x24 matrix of schedule for fraction gas (WD,Sat,Sun) Schedule[i][j][ k].Occ = SchOcc # 3x24 matrix of schedule for fraction occupancy (WD,Sat,Sun) Schedule[i][j][ k].Cool = SetCool # 3x24 matrix of schedule for fraction cooling temp (WD,Sat,Sun) Schedule[i][j][ k].Heat = SetHeat # 3x24 matrix of schedule for fraction heating temp (WD,Sat,Sun) Schedule[i][j][ k].SWH = SchSWH # 3x24 matrix of schedule for fraction SWH (WD,Sat,Sun Schedule[i][j][k].Qelec = Elec[ j] # W/m^2 (max) for electrical plug process Schedule[i][j][k].Qlight = Light[j] # W/m^2 (max) for light Schedule[i][j][k].Nocc = Occupant[j] / AreaFloor[ j] # Person/m^2 Schedule[i][j][k].Qgas = Gas[j] # W/m^2 (max) for gas Schedule[i][j][k].Vent = Vent[j] / 1000.0 # m^3/m^2 per person Schedule[i][j][k].Vswh = SHW[j] / AreaFloor[ j] # litres per hour per m^2 of floor # if not test serialize refDOE,refBEM,Schedule and store in resources if serialize_output: # create a binary file for serialized obj pkl_file_path = os.path.join(DIR_CURR, '..', 'resources', 'readDOE.pkl') pickle_readDOE = open(pkl_file_path, 'wb') # dump in ../resources # Pickle objects, protocol 1 b/c binary file cPickle.dump(refDOE, pickle_readDOE, 1) cPickle.dump(refBEM, pickle_readDOE, 1) cPickle.dump(Schedule, pickle_readDOE, 1) pickle_readDOE.close() return refDOE, refBEM, Schedule
def compute_preds(model, num_classes, train_dir="data/model_train", test_dir="data/model_valid", test_csv="data/model_valid.csv"): batch_size = 16 # used for training as well as validation max_preds = 5 # number of ranked predictions (default 5) if model.name == 'InceptionV3' or model.name == 'Xception' or model.name == 'InceptionResNetV2': target_size = (299, 299) elif model.name == 'ResNet50' or model.name == 'MobileNet': target_size = (224, 224) else: print("invalid model: ", model.name) print("training model", model.name) ''' num_train_imgs, num_valid_imgs = ut.create_small_case( sel_whales = np.arange(1,num_classes+1), # whales to be considered all_train_dir = all_train_dir, all_train_csv = all_train_csv, train_dir = test_dir, train_csv = test_csv, valid_dir = None, # no validation, copy all data into test_dir "data/model_test" valid_csv = None, train_valid = 1., sub_dirs = True) ''' test_gen = image.ImageDataGenerator(rescale=1. / 255, fill_mode="nearest") test_flow = test_gen.flow_from_directory( test_dir, shuffle=False, batch_size=batch_size, target_size=target_size, class_mode=None) # use "categorical" ?? preds = model.predict_generator(test_flow, verbose=1) # whale_class_map = (test_flow.class_indices) # get dict mapping whalenames --> class_no class_whale_map = ut.make_label_dict( directory=train_dir) # get dict mapping class_no --> whalenames ''' print("whale_class_map:") print(whale_class_map) print("class_whale_map:") print(class_whale_map) print("preds.shape:") print(preds.shape) print("preds[:10]") print(preds[:10]) ''' # get list of model predictions: one ordered list of maxpred whalenames per image top_k = preds.argsort()[:, -max_preds:][:, ::-1] model_preds = [([class_whale_map[i] for i in line]) for line in top_k] # get list of true labels: one whalename per image true_labels = [] file_names = [] if test_csv != '': test_list = ut.read_csv( file_name=test_csv) # list with (filename, whalename) i = 0 for fn in test_flow.filenames: if i < 3: print("fn", fn) i = i + 1 offset, directory, filename = fn.split('/') file_names.append(filename) if test_csv != '': whale = [line[1] for line in test_list if line[0] == filename][0] true_labels.append(whale) return file_names, model_preds, true_labels
def get_data(year): polling_data, results = utilities.read_csv("{0}_all_polling.csv".format(year), year) fundamentals = utilities.read_csv("{0}_fundamentals.csv".format(year), year) return polling_data, fundamentals, results
def read_input(self): """Section 3 - Read Input File (.m, file) Note: UWG_Matlab input files are xlsm, XML, .m, file. properties: self._init_param_dict # dictionary of simulation initialization parameters self.sensAnth # non-building sensible heat (W/m^2) self.SchTraffic # Traffice schedule self.BEM # list of BEMDef objects extracted from readDOE self.Sch # list of Schedule objects extracted from readDOE """ uwg_param_file_path = os.path.join(self.uwgParamDir, self.uwgParamFileName) if not os.path.exists(uwg_param_file_path): raise Exception( "Param file: '{}' does not exist.".format(uwg_param_file_path)) # Open .uwg file and feed csv data to initializeDataFile try: uwg_param_data = utilities.read_csv(uwg_param_file_path) except Exception as e: raise Exception("Failed to read .uwg file! {}".format(e.message)) # The initialize.uwg is read with a dictionary so that users changing # line endings or line numbers doesn't make reading input incorrect self._init_param_dict = {} count = 0 while count < len(uwg_param_data): row = uwg_param_data[count] row = [row[i].replace(" ", "") for i in xrange(len(row))] # strip white spaces # Optional parameters might be empty so handle separately is_optional_parameter = ( row != [] and \ ( row[0] == "albRoof" or \ row[0] == "vegRoof" or \ row[0] == "glzR" or \ row[0] == "hvac" or \ row[0] == "albWall" or \ row[0] == "SHGC" ) ) if row == [] or "#" in row[0]: count += 1 continue elif row[0] == "SchTraffic": # SchTraffic: 3 x 24 matrix trafficrows = uwg_param_data[count + 1:count + 4] self._init_param_dict[row[0]] = map( lambda r: utilities.str2fl(r[:24]), trafficrows) count += 4 elif row[0] == "bld": #bld: 17 x 3 matrix bldrows = uwg_param_data[count + 1:count + 17] self._init_param_dict[row[0]] = map( lambda r: utilities.str2fl(r[:3]), bldrows) count += 17 elif is_optional_parameter: self._init_param_dict[row[0]] = float( row[1]) if row[1] != "" else None count += 1 else: self._init_param_dict[row[0]] = float(row[1]) count += 1 ipd = self._init_param_dict # Define Simulation and Weather parameters if self.Month is None: self.Month = ipd['Month'] if self.Day is None: self.Day = ipd['Day'] if self.nDay is None: self.nDay = ipd['nDay'] if self.dtSim is None: self.dtSim = ipd['dtSim'] if self.dtWeather is None: self.dtWeather = ipd['dtWeather'] # HVAC system and internal laod if self.autosize is None: self.autosize = ipd['autosize'] if self.sensOcc is None: self.sensOcc = ipd['sensOcc'] if self.LatFOcc is None: self.LatFOcc = ipd['LatFOcc'] if self.RadFOcc is None: self.RadFOcc = ipd['RadFOcc'] if self.RadFEquip is None: self.RadFEquip = ipd['RadFEquip'] if self.RadFLight is None: self.RadFLight = ipd['RadFLight'] # Define Urban microclimate parameters if self.h_ubl1 is None: self.h_ubl1 = ipd['h_ubl1'] if self.h_ubl2 is None: self.h_ubl2 = ipd['h_ubl2'] if self.h_ref is None: self.h_ref = ipd['h_ref'] if self.h_temp is None: self.h_temp = ipd['h_temp'] if self.h_wind is None: self.h_wind = ipd['h_wind'] if self.c_circ is None: self.c_circ = ipd['c_circ'] if self.c_exch is None: self.c_exch = ipd['c_exch'] if self.maxDay is None: self.maxDay = ipd['maxDay'] if self.maxNight is None: self.maxNight = ipd['maxNight'] if self.windMin is None: self.windMin = ipd['windMin'] if self.h_obs is None: self.h_obs = ipd['h_obs'] # Urban characteristics if self.bldHeight is None: self.bldHeight = ipd['bldHeight'] if self.h_mix is None: self.h_mix = ipd['h_mix'] if self.bldDensity is None: self.bldDensity = ipd['bldDensity'] if self.verToHor is None: self.verToHor = ipd['verToHor'] if self.charLength is None: self.charLength = ipd['charLength'] if self.alb_road is None: self.alb_road = ipd['albRoad'] if self.d_road is None: self.d_road = ipd['dRoad'] if self.sensAnth is None: self.sensAnth = ipd['sensAnth'] if self.latAnth is None: self.latAnth = ipd['latAnth'] # climate Zone if self.zone is None: self.zone = ipd['zone'] # Vegetation parameters if self.vegCover is None: self.vegCover = ipd['vegCover'] if self.treeCoverage is None: self.treeCoverage = ipd['treeCoverage'] if self.vegStart is None: self.vegStart = ipd['vegStart'] if self.vegEnd is None: self.vegEnd = ipd['vegEnd'] if self.albVeg is None: self.albVeg = ipd['albVeg'] if self.rurVegCover is None: self.rurVegCover = ipd['rurVegCover'] if self.latGrss is None: self.latGrss = ipd['latGrss'] if self.latTree is None: self.latTree = ipd['latTree'] # Define Traffic schedule if self.SchTraffic is None: self.SchTraffic = ipd['SchTraffic'] # Define Road (Assume 0.5m of asphalt) if self.kRoad is None: self.kRoad = ipd['kRoad'] if self.cRoad is None: self.cRoad = ipd['cRoad'] # Building stock fraction if self.bld is None: self.bld = ipd['bld'] # Optional parameters if self.albRoof is None: self.albRoof = ipd['albRoof'] if self.vegRoof is None: self.vegRoof = ipd['vegRoof'] if self.glzR is None: self.glzR = ipd['glzR'] if self.albWall is None: self.albWall = ipd['albWall'] if self.SHGC is None: self.SHGC = ipd['SHGC']
) args = parser.parse_args() trend_options = { "baseball": ["data/baseball_hourly.csv", "Baseball", 5, 4], "influenza": ["data/influenza_hourly.csv", "Influenza", 13, 5], "full moon": ["data/fullmoon_hourly.csv", "Full moon", 14, 5] } if not trend_options.has_key(args.keyword): print("Unsupported keyword supplied") exit() input_filepath, keyword, delay, m = trend_options[args.keyword] data = utilities.read_csv(input_filepath, " ") utilities.plot_series(data, input_filepath, keyword) embedding.mutual_information(input_filepath, len(data)) theiler = 0 min_dim = 1 max_dim = 10 ratio = 10.0 embedding.false_nearest_neighbors(input_filepath, delay, theiler, min_dim, max_dim, ratio) embedded = embedding.embedding(input_filepath, data, delay, m, keyword) utilities.plot_embedding(embedded, input_filepath, [1, 2]) #embedding.recurrence(input_filepath, delay)