def test_all_polar_receptors(self): """ Verify that the all polar receptors output file is identical to the test fixture. """ for facid in self.testHarness.model.facids: self.testHarness.model.facops = self.testHarness.model.faclist.dataframe.loc[ self.testHarness.model.faclist.dataframe["fac_id"] == facid] fixture = AllPolarReceptors("fixtures/output/", facid, self.testHarness.model, None) checksum_expected = self.hashFile(fixture.filename) generated = AllPolarReceptors("output/TST/" + facid, facid, self.testHarness.model, None) checksum_generated = self.hashFile(generated.filename) self.assertEqual( checksum_expected, checksum_generated, "The contents of the AllPolarReceptors output file are inconsistent with the test fixture:" + checksum_expected + " != " + checksum_generated)
def visualize(self): # Suppress various bokeh warnings warnings.filterwarnings("ignore") flag_list = [] acuteImpacts = AcuteImpacts(targetDir=self.sourceDir, facilityIds=self.facilityIds, parameters=[self.basepath]) flag_df = acuteImpacts.createDataframe() for index, row in flag_df.iterrows(): if row[hq_rel] >= 1.5: flag_list.append((row[fac_id], row.pollutant, "REL")) if row[hq_aegl1] >= 1.5: flag_list.append((row[fac_id], row.pollutant, "AEGL-1 1-hr")) if row[hq_erpg1] >= 1.5: flag_list.append((row[fac_id], row.pollutant, "ERPG-1")) if row[hq_aegl2] >= 1.5: flag_list.append((row[fac_id], row.pollutant, "AEGL-2 1-hr")) if row[hq_erpg2] >= 1.5: flag_list.append((row[fac_id], row.pollutant, "ERPG-2")) flag_list.sort() # If the flag file has no cases of interest, don't do anything. # Otherwise, create a directory for the created acute files. if len(flag_list) == 0: Logger.logMessage( "Acute impacts visualization - " + "No acute impact was greater than or equal to 1.5. No HTML files were generated." ) return else: if os.path.isdir(self.sourceDir + '/Acute Maps') == 0: os.mkdir(self.sourceDir + '/Acute Maps') # Find the HEM dose-response library and create df of it # Under the HEM4 dir names, "Reference" would be "Resources" RefFile = 'resources/Dose_Response_Library.xlsx' RefDF = pd.read_excel(RefFile) RefDF['Pollutant'] = RefDF['Pollutant'].str.lower() RefDF.set_index('Pollutant', inplace=True) RefDict = {'REL': 'REL\n(mg/m3)',\ 'AEGL-1 1-hr':'AEGL-1 (1-hr)\n(mg/m3)',\ 'ERPG-1':'ERPG-1\n(mg/m3)',\ 'AEGL-2 1-hr':'AEGL-2 (1-hr)\n(mg/m3)',\ 'ERPG-2':'ERPG-2\n(mg/m3)',\ 'AEGL-1 8-hr':'AEGL-1 (8-hr)\n(mg/m3)',\ 'AEGL-2 8-hr':'AEGL-2 (8-hr)\n(mg/m3)'} tablist = [] for acuteset in (flag_list): Fac = acuteset[0] HAP = acuteset[1] refType = acuteset[2] path = self.sourceDir + '/' + Fac + '/' HAP = HAP.lower() # Find the all polar file for a given facility, create df of it allpolar = AllPolarReceptors(targetDir=path, facilityId=Fac, acuteyn='Y') allpolar_df = allpolar.createDataframe() allpolar_df[pollutant] = allpolar_df[pollutant].str.lower() # Find the reference value ref_typ_col = RefDict[refType] refVal = RefDF.loc[HAP, ref_typ_col] # Aggregate the all polar file to get HQ for each receptor allpolar_df.set_index('pollutant', inplace=True) HAP_df = allpolar_df.loc[HAP, :] f = {distance: 'first', angle: 'first', aconc: 'sum'} df = HAP_df.groupby([lat, lon], as_index=False).agg(f) df['HQ'] = df[aconc] / refVal / 1000 ac_File = '%s%s%s%s%s' % (self.sourceDir, '/Acute Maps/', Fac + '_', HAP + '_', refType + '.csv') df.to_csv(path_or_buf=ac_File, mode='w+') #Convert df to geo df df['Coordinates'] = list(zip(df.lon, df.lat)) df['Coordinates'] = df['Coordinates'].apply(Point) gdf = gp.GeoDataFrame(df, geometry='Coordinates', crs={'init': 'epsg:4326'}) gdf = gdf.to_crs(epsg=3857) ESRI_tile = WMTSTileSource( url= 'https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{Z}/{Y}/{X}.jpg' ) gdf['x'] = gdf.centroid.map(lambda p: p.x) gdf['y'] = gdf.centroid.map(lambda p: p.y) avg_x = gdf['x'].mean() avg_y = gdf['y'].mean() gdf = gdf.drop('Coordinates', axis=1) gdf['HQ'] = gdf['HQ'].map(lambda x: '%.1g' % x) gdf['lat'] = gdf['lat'].map(lambda x: '%.6f' % x) gdf['lon'] = gdf['lon'].map(lambda x: '%.6f' % x) gdf['angle'] = gdf['angle'].map(lambda x: '%.1f' % x) source = ColumnDataSource(gdf) tooltips = [("Latitude", "@lat"), ("Longitude", "@lon"), ("Acute HQ", "@HQ"), ("Distance (m)", "@distance"), ("Angle (deg)", "@angle")] title = '%s %s Acute HQ (%s)' % (Fac, HAP.title(), refType) tools = [ZoomInTool(), ZoomOutTool(), PanTool(),\ WheelZoomTool(), ResetTool(), HoverTool(tooltips=tooltips)] p = figure(plot_width=800, plot_height=600, tools = tools,\ x_range=(avg_x-3000, avg_x+3000), y_range=(avg_y-3000, avg_y+3000),\ title=title) p.toolbar.active_scroll = p.select_one(WheelZoomTool) p.add_tile(ESRI_tile) p.add_tile(STAMEN_TONER_LABELS) p.circle('x', 'y', color='yellow', size=7, source=source) p.xaxis.visible = False p.yaxis.visible = False p.xgrid.visible = False p.ygrid.visible = False p.background_fill_color = None p.border_fill_color = None # labels = LabelSet(x='x', y='y', text='HQ', source = source,\ # level='glyph', x_offset=0, y_offset=0, text_font_size='8pt',\ # text_color='black', background_fill_color='yellow',\ # text_font_style='bold', text_align='center', text_baseline='middle') labels = LabelSet(x='x', y='y', text='HQ', source = source,\ x_offset=0, y_offset=0, text_font_size='8pt',\ text_color='black', background_fill_color='yellow',\ text_font_style='bold', text_align='center', text_baseline='middle') p.add_layout(labels) curdoc().add_root(p) mapName = '%s%s%s%s%s' % (self.sourceDir, '/Acute Maps/', Fac + '_', HAP + '_', refType + '.html') save(p, filename=mapName) tab = Panel(child=p, title=HAP.title() + " (" + refType + ")") tablist.append(tab) tabs = Tabs(tabs=tablist) curdoc().add_root(tabs) mapName2 = '%s%s%s' % (self.sourceDir, '/Acute Maps/', "All Acute Maps.html") save(tabs, filename=mapName2, title="All Acute HQ Maps") Logger.logMessage( "Acute impacts visualization - HTML files successfully created.")
def generateOutputs(self): rows = [] # HAP emis...load file and filter by fac id, source id, and pollutant haplib = DoseResponse() hapemis = HAPEmissions(hapemis_path, haplib, {self.fac_id}) hapemis_df = hapemis.dataframe hapemis_df = hapemis_df.loc[(hapemis_df[fac_id] == self.fac_id) & (hapemis_df[source_id] == self.source_id) & (hapemis_df[pollutant].str.lower() == self.pollutant.lower())] # Aermod plotfile plotfile_name = "plotfile_p" if emistype == 'P' else "plotfile_v" plotfile_name += ".plt" facilityRunner = FacilityRunner(self.fac_id, None, False) ppfile = open(self.output_dir + "/" + plotfile_name, "r") plot_df = facilityRunner.readplotf(ppfile, runtype) plot_df = plot_df.loc[plot_df[source_id] == self.source_id] plotcolumn = wdp if deptype == 'W' else ddp column = wetdep if deptype == 'W' else drydep # multiply by the hapemis value and the conversion factor plot_df[plotcolumn] = plot_df[plotcolumn].multiply( hapemis_df.iloc[0][emis_tpy]) plot_df[plotcolumn] = plot_df[plotcolumn].multiply(2000 * 0.4536 / 3600 / 8760) plot_df[plotcolumn] = plot_df[plotcolumn].multiply(hapemis_df.iloc[0][part_frac]) if emistype == 'P' else \ plot_df[plotcolumn].multiply(1 - hapemis_df.iloc[0][part_frac]) # Compare plot values to polar dep values produced by HEM4 plot_polar_df = plot_df.loc[plot_df[net_id] == 'POLGRID1'] allpolar = AllPolarReceptors(targetDir=self.output_dir, facilityId=self.fac_id, model=None, plot_df=plot_df, acuteyn=acute) allpolar_df = allpolar.createDataframe() allpolar_df = allpolar_df.loc[ (allpolar_df[source_id] == self.source_id) & (allpolar_df[pollutant].str.lower() == self.pollutant.lower()) & (allpolar_df[emis_type] == emistype)] for index, row in allpolar_df.iterrows(): utm_n, utm_e, zone, hemi, epsg = UTM.ll2utm(row[lat], row[lon]) plot_row = plot_polar_df.loc[(plot_polar_df[utmn] == utm_n) & (plot_polar_df[utme] == utm_e)] plot_row = plot_row.iloc[0] computed = self.round_to_sigfig(plot_row[plotcolumn], 8) retrieved = self.round_to_sigfig(row[column], 8) diff = self.round_to_sigfig( 100 * ((retrieved - computed) / retrieved), 3) record = { fac_id: self.fac_id, source_id: self.source_id, pollutant: self.pollutant, rec_type: "polar", lat: row[lat], lon: row[lon], utme: utm_e, utmn: utm_n, 'r_dep': retrieved, 'c_dep': computed, 'change': diff } rows.append(record) # Compare plot values to inner concentrations produced by HEM4 plot_inner_df = plot_df.loc[plot_df[net_id] != 'POLGRID1'] allinner = AllInnerReceptors(targetDir=self.output_dir, facilityId=self.fac_id, model=None, plot_df=plot_df, acuteyn=acute) allinner_df = allinner.createDataframe() allinner_df = allinner_df.loc[ (allinner_df[source_id] == self.source_id) & (allinner_df[pollutant].str.lower() == self.pollutant.lower()) & (allinner_df[emis_type] == emistype)] for index, row in allinner_df.iterrows(): utm_n, utm_e, zone, hemi, epsg = UTM.ll2utm(row[lat], row[lon]) plot_row = plot_inner_df.loc[(plot_inner_df[utmn] == utm_n) & (plot_inner_df[utme] == utm_e)] plot_row = plot_row.iloc[0] computed = self.round_to_sigfig(plot_row[plotcolumn], 8) retrieved = self.round_to_sigfig(row[column], 8) diff = self.round_to_sigfig( 100 * ((retrieved - computed) / retrieved), 3) record = { fac_id: self.fac_id, source_id: self.source_id, pollutant: self.pollutant, rec_type: "block", lat: row[lat], lon: row[lon], utme: utm_e, utmn: utm_n, 'r_dep': retrieved, 'c_dep': computed, 'change': diff } rows.append(record) # Return results self.dataframe = pd.DataFrame(rows, columns=self.getColumns()) self.data = self.dataframe.values yield self.dataframe
def compare(self): #---------- All inner receptors -----------# hem3File = facid + "_all_inner_receptors.csv" hem4File = facid + "_all_inner_receptors.csv" diffFile = "diff_all_inner_receptors.csv" joinColumns = [fips, block, source_id, pollutant] diffColumns = [conc] if self.acute == 'Y': diffColumns.append(aconc) #------------------------------------------# hem4allinner = AllInnerReceptors(targetDir=self.hem4Dir, facilityId=None, model=None, plot_df=None, acuteyn=self.acute, filenameOverride=hem4File) hem3allinner = Hem3AllInnerReceptors(targetDir=self.hem3Dir, facilityId=None, model=None, plot_df=None, acuteyn=self.acute, filenameOverride=hem3File) allinner_diff = AllInnerReceptors(targetDir=self.diff_target, facilityId=None, model=None, plot_df=None, acuteyn=self.acute, filenameOverride=diffFile) allinner_diff.writeHeader() diff_df = self.calculateNumericDiffs(hem3allinner, hem4allinner, joinColumns, diffColumns) allinner_diff.appendToFile(diff_df) #---------- All polar receptors -----------# hem3File = facid + "_all_polar_receptors.csv" hem4File = facid + "_all_polar_receptors.csv" diffFile = "diff_all_polar_receptors.csv" joinColumns = [sector, ring, source_id, pollutant] diffColumns = [conc] if self.acute == 'Y': diffColumns.append(aconc) #------------------------------------------# hem4allpolar = AllPolarReceptors(targetDir=self.hem4Dir, facilityId=None, model=None, plot_df=None, acuteyn=self.acute, filenameOverride=hem4File) hem3allpolar = Hem3AllPolarReceptors(targetDir=self.hem3Dir, facilityId=None, model=None, plot_df=None, acuteyn=self.acute, filenameOverride=hem3File) allpolar_diff = AllPolarReceptors(targetDir=self.diff_target, facilityId=None, model=None, plot_df=None, acuteyn=self.acute, filenameOverride=diffFile) allpolar_diff.writeHeader() diff_df = self.calculateNumericDiffs(hem3allpolar, hem4allpolar, joinColumns, diffColumns) allpolar_diff.appendToFile(diff_df) if self.temporal == 'Y': #---------- Temporal output -----------# hem3File = facid + "_temporal.csv" hem4File = facid + "_temporal.csv" diffFile = "diff_temporal.csv" joinColumns = [fips, block, pollutant] diffColumns = [ 'C_01', 'C_02', 'C_03', 'C_04', 'C_05', 'C_06', 'C_07', 'C_08' ] model = Model() model.tempvar = 12 model.model_optns = {} model.model_optns['runtype'] = 0 model.seasonvar = True #------------------------------------------# hem4temporal = Temporal(targetDir=self.hem4Dir, facilityId=None, model=model, plot_df=None, filenameOverride=hem4File) hem3temporal = Hem3Temporal(targetDir=self.hem3Dir, facilityId=None, model=model, plot_df=None, filenameOverride=hem3File) temporal_diff = Temporal(targetDir=self.diff_target, facilityId=None, model=model, plot_df=None, filenameOverride=diffFile) temporal_diff.writeHeader() diff_df = self.calculateNumericDiffs(hem3temporal, hem4temporal, joinColumns, diffColumns) temporal_diff.appendToFile(diff_df) #---------- Maximum individual risks -----------# hem3File = facid + "_maximum_indiv_risks.xlsx" hem4File = facid + "_maximum_indiv_risks.xlsx" diffFile = "diff_maximum_indiv_risks.xlsx" joinColumns = [parameter] diffColumns = [value] #------------------------------------------# hem4risks = MaximumIndividualRisks(targetDir=self.hem4Dir, facilityId=None, model=None, plot_df=None, filenameOverride=hem4File) hem3risks = Hem3MaximumIndividualRisks(targetDir=self.hem3Dir, facilityId=None, model=None, plot_df=None, filenameOverride=hem3File) risks_diff = MaximumIndividualRisks(targetDir=self.diff_target, facilityId=None, model=None, plot_df=None, filenameOverride=diffFile) risks_diff.writeHeader() diff_df = self.calculateNumericDiffs(hem3risks, hem4risks, joinColumns, diffColumns) risks_diff.appendToFile(diff_df) #---------- Risk breakdown -----------# hem3File = facid + "_risk_breakdown.xlsx" hem4File = facid + "_risk_breakdown.xlsx" diffFile = "diff_risk_breakdown.xlsx" joinColumns = [site_type, parameter, source_id, pollutant] diffColumns = [value] #------------------------------------------# hem4risks = RiskBreakdown(targetDir=self.hem4Dir, facilityId=None, model=None, plot_df=None, filenameOverride=hem4File) hem3risks = Hem3RiskBreakdown(targetDir=self.hem3Dir, facilityId=None, model=None, plot_df=None, filenameOverride=hem3File) risks_diff = RiskBreakdown(targetDir=self.diff_target, facilityId=None, model=None, plot_df=None, filenameOverride=diffFile) risks_diff.writeHeader() diff_df = self.calculateNumericDiffs(hem3risks, hem4risks, joinColumns, diffColumns) risks_diff.appendToFile(diff_df) #---------- Block Summary Chronic -----------# hem3File = facid + "_block_summary_chronic.csv" hem4File = facid + "_block_summary_chronic.csv" diffFile = "diff_block_summary_chronic.csv" joinColumns = [fips, block] diffColumns = [ mir, hi_resp, hi_live, hi_neur, hi_deve, hi_repr, hi_kidn, hi_ocul, hi_endo, hi_hema, hi_immu, hi_skel, hi_sple, hi_thyr, hi_whol ] #------------------------------------------# hem4summary = BlockSummaryChronic(targetDir=self.hem4Dir, facilityId=None, model=None, plot_df=None, filenameOverride=hem4File) hem3summary = Hem3BlockSummaryChronic(targetDir=self.hem3Dir, facilityId=None, model=None, plot_df=None, filenameOverride=hem3File) summary_diff = BlockSummaryChronic(targetDir=self.diff_target, facilityId=None, model=None, plot_df=None, filenameOverride=diffFile) summary_diff.writeHeader() diff_df = self.calculateNumericDiffs(hem3summary, hem4summary, joinColumns, diffColumns) summary_diff.appendToFile(diff_df) #---------- Ring Summary Chronic -----------# hem3File = facid + "_ring_summary_chronic.csv" hem4File = facid + "_ring_summary_chronic.csv" diffFile = "diff_ring_summary_chronic.csv" joinColumns = [utme, utmn] diffColumns = [ mir, hi_resp, hi_live, hi_neur, hi_deve, hi_repr, hi_kidn, hi_ocul, hi_endo, hi_hema, hi_immu, hi_skel, hi_sple, hi_thyr, hi_whol ] #------------------------------------------# hem4summary = RingSummaryChronic(targetDir=self.hem4Dir, facilityId=None, model=None, plot_df=None, filenameOverride=hem4File) hem3summary = Hem3RingSummaryChronic(targetDir=self.hem3Dir, facilityId=None, model=None, plot_df=None, filenameOverride=hem3File) summary_diff = RingSummaryChronic(targetDir=self.diff_target, facilityId=None, model=None, plot_df=None, filenameOverride=diffFile) summary_diff.writeHeader() diff_df = self.calculateNumericDiffs(hem3summary, hem4summary, joinColumns, diffColumns) summary_diff.appendToFile(diff_df) if self.acute == 'Y': #---------- Acute Chemical Max -----------# hem3File = facid + "_acute_chem_unpop.xlsx" hem4File = facid + "_acute_chem_max.xlsx" diffFile = "diff_acute_chem_max.xlsx" joinColumns = [pollutant] diffColumns = [aconc] #------------------------------------------# hem4max = AcuteChemicalMax(targetDir=self.hem4Dir, facilityId=None, model=None, plot_df=None, filenameOverride=hem4File) hem3max = Hem3AcuteChemicalMax(targetDir=self.hem3Dir, facilityId=None, model=None, plot_df=None, filenameOverride=hem3File) max_diff = AcuteChemicalMax(targetDir=self.diff_target, facilityId=None, model=None, plot_df=None, filenameOverride=diffFile) max_diff.writeHeader() diff_df = self.calculateNumericDiffs(hem3max, hem4max, joinColumns, diffColumns) max_diff.appendToFile(diff_df) #---------- Acute Chemical Pop -----------# hem3File = facid + "_acute_chem_pop.xlsx" hem4File = facid + "_acute_chem_pop.xlsx" diffFile = "diff_acute_chem_pop.xlsx" joinColumns = [pollutant] diffColumns = [aconc] #------------------------------------------# hem4pop = AcuteChemicalPopulated(targetDir=self.hem4Dir, facilityId=None, model=None, plot_df=None, filenameOverride=hem4File) hem3pop = Hem3AcuteChemicalPopulated(targetDir=self.hem3Dir, facilityId=None, model=None, plot_df=None, filenameOverride=hem3File) pop_diff = AcuteChemicalPopulated(targetDir=self.diff_target, facilityId=None, model=None, plot_df=None, filenameOverride=diffFile) pop_diff.writeHeader() diff_df = self.calculateNumericDiffs(hem3pop, hem4pop, joinColumns, diffColumns) pop_diff.appendToFile(diff_df) #---------- Acute Breakdown -----------# hem3File = facid + "_acute_bkdn.xlsx" hem4File = facid + "_acute_bkdn.xlsx" diffFile = "diff_acute_bkdn.xlsx" joinColumns = [source_id, pollutant] diffColumns = [aconc_pop, aconc_all] #------------------------------------------# hem4bkdn = AcuteBreakdown(targetDir=self.hem4Dir, facilityId=None, model=None, plot_df=None, filenameOverride=hem4File) hem3bkdn = Hem3AcuteBreakdown(targetDir=self.hem3Dir, facilityId=None, model=None, plot_df=None, filenameOverride=hem3File) bkdn_diff = AcuteBreakdown(targetDir=self.diff_target, facilityId=None, model=None, plot_df=None, filenameOverride=diffFile) bkdn_diff.writeHeader() diff_df = self.calculateNumericDiffs(hem3bkdn, hem4bkdn, joinColumns, diffColumns) bkdn_diff.appendToFile(diff_df) #---------- All outer receptors -----------# hem3File = facid + "_all_outer_receptors.csv" hem4File = facid + "_all_outer_receptors.csv" diffFile = "diff_all_outer_receptors.csv" joinColumns = [fips, block, source_id, pollutant] diffColumns = [conc] if self.acute == 'Y': diffColumns.append(aconc) #------------------------------------------# hem4allouter = AllOuterReceptors(targetDir=self.hem4Dir, facilityId=None, model=None, plot_df=None, acuteyn=self.acute, filenameOverride=hem4File) hem3allouter = Hem3AllOuterReceptors(targetDir=self.hem3Dir, facilityId=None, model=None, plot_df=None, acuteyn=self.acute, filenameOverride=hem3File) allouter_diff = AllOuterReceptors(targetDir=self.diff_target, facilityId=None, model=None, plot_df=None, acuteyn=self.acute, filenameOverride=diffFile) allouter_diff.writeHeader() diff_df = self.calculateNumericDiffs(hem3allouter, hem4allouter, joinColumns, diffColumns) allouter_diff.appendToFile(diff_df)
def generateOutputs(self): Logger.log("Creating " + self.name + " report...", None, False) for facilityId in self.facilityIds: targetDir = self.categoryFolder + "/" + facilityId # Determine if this facility was run with acute or not inputops = InputSelectionOptions(targetDir=targetDir, facilityId=facilityId) inputops_df = inputops.createDataframe() acute_yn = inputops_df['acute_yn'].iloc[0] all_df = pd.DataFrame() # Polar recs allpolar = AllPolarReceptors(targetDir=targetDir, facilityId=facilityId, acuteyn=acute_yn) allpolar_df = allpolar.createDataframe() allpolar_df = allpolar_df.loc[~(allpolar_df[overlap] == 'Y')] allpolar_df = allpolar_df.loc[allpolar_df[pollutant].str.contains( self.hap, regex=True)] allpolar_df = allpolar_df.groupby(by=[lat, lon, pollutant], as_index=False) \ .sum().reset_index(drop=True) allpolar_df[fips] = '' allpolar_df[block] = '' allpolar_df[rec_type] = 'P' allpolar_df[fac_id] = facilityId all_df = all_df.append(allpolar_df) # Inner recs allinner = AllInnerReceptors(targetDir=targetDir, facilityId=facilityId, acuteyn=acute_yn) allinner_df = allinner.createDataframe() allinner_df = allinner_df.loc[~( (allinner_df[block].str.contains('S')) | (allinner_df[block].str.contains('M')) | (allinner_df[overlap] == 'Y'))] allinner_df = allinner_df.loc[allinner_df[pollutant].str.contains( self.hap, regex=True)] allinner_df = allinner_df.groupby(by=[fips, block, lat, lon, pollutant], as_index=False) \ .sum().reset_index(drop=True) allinner_df[rec_type] = allinner_df.apply( lambda row: MaxOffsiteConcentration.add_rec_type(row), axis=1) allinner_df[fac_id] = facilityId all_df = all_df.append(allinner_df) # Outer recs listOuter = [] listDirfiles = os.listdir(targetDir) pattern = "*_all_outer_receptors*.csv" for entry in listDirfiles: if fnmatch.fnmatch(entry, pattern): listOuter.append(entry) for f in listOuter: allouter = AllOuterReceptors(targetDir=targetDir, acuteyn=acute_yn, filenameOverride=f) allouter_df = allouter.createDataframe() if not allouter_df.empty: allouter_df = allouter_df.loc[~( (allouter_df[block].str.contains('S')) | (allouter_df[block].str.contains('M')) | (allouter_df[overlap] == 'Y'))] allouter_df = allouter_df.loc[ allouter_df[pollutant].str.contains(self.hap, regex=True)] allouter_df = allouter_df.groupby(by=[fips, block, lat, lon, pollutant], as_index=False) \ .sum().reset_index(drop=True) allouter_df[fac_id] = facilityId allouter_df[rec_type] = allouter_df.apply( lambda row: MaxOffsiteConcentration.add_rec_type(row), axis=1) all_df = all_df.append(allouter_df) # Group by pollutant and then find the max max_conc_df = all_df.groupby( by=[pollutant], as_index=False).max().reset_index(drop=True) # Put final df into array self.dataframe = pd.DataFrame(data=max_conc_df, columns=self.getColumns()) self.data = self.dataframe.values yield self.dataframe