Loading galassify.py +3 −4 Original line number Diff line number Diff line Loading @@ -13,18 +13,17 @@ VERSION = '0.1.2' if __name__ == '__main__': args = utils.getOptions(VERSION) selectedFiles, selectedVoids = utils.getFiles() selectedFiles, selectedGroups = utils.getFiles() if len(selectedFiles) > 0: if args.list: print(selectedFiles.filename) else: print('INFO:\t' + str(len(selectedFiles)) + ' galaxies found '+ 'in selected voids.') print(f"INFO:\t {str(len(selectedFiles))} galaxies found in selected groups.") df = utils.expand_df(selectedFiles) app = QtWidgets.QApplication(sys.argv) window = gui.Ui(df, selectedVoids) window = gui.Ui(df, selectedGroups) app.exec_() else: print('ERROR: No files found with the arguments given.') src/gui.py +13 −13 Original line number Diff line number Diff line Loading @@ -8,16 +8,16 @@ import sys class Ui(QtWidgets.QMainWindow): def __init__(self, df, selectedVoids): def __init__(self, df, selectedGroups): super(Ui, self).__init__() uic.loadUi(str(Path('src')/Path('gui.ui')), self) self.title = 'CAVIssify ' + utils.getVersion() self.title = 'GALAssify ' + utils.getVersion() self.setWindowIcon(QIcon(str(Path('res/window_icon.png')))) # Load data frame and make it accessible along the class: self.df = df self.voids = selectedVoids self.galaxies = selectedGroups # Find buttons: self.pb_prev = self.findChild(QtWidgets.QPushButton, 'pb_prev') Loading Loading @@ -93,10 +93,10 @@ class Ui(QtWidgets.QMainWindow): def fillList(self, showAllSavedData=False): #self.fileList.setRowCount(len(self.df.index)) self.fileList.setColumnCount(6) self.fileList.setHorizontalHeaderLabels(['Void', self.fileList.setHorizontalHeaderLabels(['Group', 'Galaxy', 'Processed', 'RA', 'Ra', 'Dec', 'Filename']) self.fileList.horizontalHeaderItem(2).setTextAlignment(Qt.AlignHCenter) Loading @@ -119,7 +119,7 @@ class Ui(QtWidgets.QMainWindow): for i, row in self.df.iterrows(): # Place void data in integer format: self.fileList.setItem(i, 0, QtWidgets.QTableWidgetItem()) self.fileList.item(i, 0).setData(Qt.DisplayRole, int(row['void'])) self.fileList.item(i, 0).setData(Qt.DisplayRole, int(row['group'])) # Place galaxy data in integer format: self.fileList.setItem(i, 1, QtWidgets.QTableWidgetItem()) Loading @@ -137,7 +137,7 @@ class Ui(QtWidgets.QMainWindow): # Place filename in the row: self.fileList.setItem(i, 5, QtWidgets.QTableWidgetItem(str(row['filename']))) if (not showAllSavedData) and (int(row['void']) not in self.voids): if (not showAllSavedData) and (int(row['group']) not in self.galaxies): self.fileList.hideRow(i) # Order by RA coordinate: Loading Loading @@ -200,10 +200,10 @@ class Ui(QtWidgets.QMainWindow): item = self.df.loc[self.df['filename'] == fn] self.imgPath = item['fullpath'].item() v = str(item['void'].item()) g = str(item['galaxy'].item()) self.setWindowTitle('V: ' + v + ' | G: ' + g + grp = str(item['group'].item()) gal = str(item['galaxy'].item()) self.setWindowTitle('Grp: ' + grp + ' | Gal: ' + gal + ' | ' + self.title) self.fileList.setCellWidget(index, 2, Loading Loading @@ -259,8 +259,8 @@ class Ui(QtWidgets.QMainWindow): def toggleAIDVisibility(self): showAllSavedData = self.act_allSavedData.isChecked() for i in range(self.fileList.rowCount()): rowVoid = self.fileList.item(i, 0).text() if (not showAllSavedData) and (int(rowVoid) not in self.voids): row = self.fileList.item(i, 0).text() if (not showAllSavedData) and (int(row) not in self.galaxies): self.fileList.hideRow(i) else: self.fileList.showRow(i) Loading src/gui.ui +1 −1 Original line number Diff line number Diff line Loading @@ -583,7 +583,7 @@ </widget> <action name="action_vn"> <property name="text"> <string>Void number...</string> <string>Group number...</string> </property> </action> <action name="action_folder"> Loading src/utils.py +72 −55 Original line number Diff line number Diff line Loading @@ -13,13 +13,13 @@ from typing import Union args = None VERSION = '' importData = pd.DataFrame() voids = pd.DataFrame() groups = pd.DataFrame() def getOptions(version): global args global VERSION parser = argparse.ArgumentParser(prog='CAVYssify', description="CAVYssify: Tool to manually classify void galaxies.") parser = argparse.ArgumentParser(prog='GALAssify', description="GALAssify: Tool to manually classify galaxies.") parser.add_argument('--version', action='version', version='%(prog)s ' + version, help="Prints software version and exit.\n") Loading @@ -29,17 +29,17 @@ def getOptions(version): # required=not('-p' in sys.argv # or '--path' in sys.argv # or '--version' in sys.argv), type=dir_file, # help="Image or list to classify. Not required if path or path + void are given.\n") # help="Image or list to classify. Not required if path or path + group are given.\n") parser.add_argument('-s', '--savefile', #required=not('--version' in sys.argv), default='output.csv', help="CSV file to load and export changes. If does not exists, a new one is created.\n") parser.add_argument("-l", "--list", action="store_true", help="List selected files only and exit.\n") parser.add_argument('-vf', '--voidsfile', default='voids.csv', help="Voids database file in *.csv format.\n") parser.add_argument('void', metavar='VOID', type=int, nargs='+', help="Void number. Selects images with name format: *_<void>_*_*.png\n") parser.add_argument('-vf', '--inputfile', default='galaxies.csv', help="Galaxy database file in *.csv format.\n") parser.add_argument('group', metavar='GROUP', type=int, nargs='*', help="Group number. Selects images with name format: *_<group>_*_*.png\n") args = parser.parse_args() VERSION = version Loading @@ -53,28 +53,33 @@ def getVersion(): def getFiles(): global args global voids files = [] selectedVoids = [] selectedFiles = pd.DataFrame() global groups # files = [] selectedGroups = [] selectedFiles = pd.DataFrame(columns = groups.columns) if args.path: if Path(args.voidsfile).is_file(): voids = readVoidsFile() if Path(args.inputfile).is_file(): groups = readInputFile() else: voids = createVoidsFile() groups = createInputFile() availableGroups = groups.group.unique() print(f"INFO:\tAvailable groups: {str(availableGroups)}") availableVoids = voids.void.unique() print('INFO:\tAvailable voids: ' + str(availableVoids)) if len(args.void) > 0: for void in args.void: if void in availableVoids: selectedFiles = pd_concat(selectedFiles, voids[voids.void == void]) #selectedFiles = selectedFiles.append(voids[voids.void == void ]) selectedVoids.append(int(void)) if len(args.group) > 0: for group in args.group: if group in availableGroups: selectedFiles = pd_concat(selectedFiles, groups[groups.group == group]) selectedGroups.append(int(group)) else: print(f'WARNING:\tGroup {group} not available.') else: print('WARNING:\tVoid ', void, 'not available.') print(f'INFO:\tNo subgroup selected. Using all available by default.') selectedFiles = groups.copy() selectedGroups = availableGroups #else: # formats = ['*.png'] Loading @@ -88,8 +93,7 @@ def getFiles(): #else: # files = [] return selectedFiles, selectedVoids return selectedFiles, selectedGroups def dir_path(path): Loading @@ -109,49 +113,51 @@ def dir_file(file): raise argparse.ArgumentTypeError("readable_file:" + file + " is not a valid file.") VFCOLUMNS = ['void','galaxy','ra','dec','filename'] VFCOLUMNS = ['group','galaxy','ra','dec','filename'] def readVoidsFile(): print('INFO:\tReading from voids.csv file... ', end='', flush=True) voids = pd.read_csv(args.voidsfile, def readInputFile(): fname = args.inputfile print(f'INFO:\tReading from {fname} file... ', end='', flush=True) groups = pd.read_csv(fname, converters={ 'void': int, 'group': int, 'galaxy': int, 'ra': float, 'dec': float, } ) voids = voids.sort_values(by=['void', 'ra', 'galaxy']) groups = groups.sort_values(by=['group', 'ra', 'galaxy']) print('Done!') return voids return groups def createVoidsFile(): print('INFO:\tCreating voids.csv file... ', end='', flush=True) voids = pd.DataFrame(columns=VFCOLUMNS) def createInputFile(): fname = args.inputfile print(f'INFO:\tCreating {fname} file... ', end='', flush=True) groups = pd.DataFrame(columns=VFCOLUMNS) if args.path: for file in Path(args.path).glob('pan_*_*_ppak.png'): entry = { 'void': int(file.stem.split('_')[1]), 'group': int(file.stem.split('_')[1]), 'galaxy': int(file.stem.split('_')[2]), 'ra':float(0), 'dec':float(0), 'filename': str(file.name), } voids = pd_concat(voids, entry) #voids = voids.append(entry, ignore_index=True) voids = voids.sort_values(by=['void','galaxy']) voids.to_csv(args.voidsfile, columns=VFCOLUMNS, index=False) groups = pd_concat(groups, entry) #groups = groups.append(entry, ignore_index=True) groups = groups.sort_values(by=['group','galaxy']) groups.to_csv(fname, columns=VFCOLUMNS, index=False) print('Done!') return voids return groups ### PANDAS UTILS COLUMNS = ["filename", "void", "galaxy", "morphology", "large", "tiny", "faceon", COLUMNS = ["filename", "group", "galaxy", "morphology", "large", "tiny", "faceon", "edgeon", "star", "calibration", "recentre", "duplicated", "member", "hiiregion", "yes", "no", "comment", "processed", "fullpath"] "fullpath", "ra", "dec"] MORPHOLOGY = ['elliptical', 'spiral', 'irregular', 'other', ''] Loading @@ -169,11 +175,11 @@ def getRadioButtonsMorphology(): def getCheckBoxesColumns(): return COLUMNS[4:-3] return COLUMNS[4:-5] def getExportableColumns(): return COLUMNS[:-2] return COLUMNS[:-4] def checkColumnsMismatch(importDataColumns): Loading @@ -194,11 +200,11 @@ def checkColumnsMismatch(importDataColumns): def expand_df(selectedFiles): global args global importData global voids global groups if Path(args.savefile).is_file(): importData = pd.read_csv(args.savefile, converters={ 'void': int, 'group': int, 'galaxy': int, } ) Loading Loading @@ -227,8 +233,8 @@ def expand_df(selectedFiles): processedUnselectedData = importData[importData.fullpath == ''] for i, row in processedUnselectedData.iterrows(): file = Path(args.path) / Path(row['filename']) ra = voids.loc[voids.galaxy == row.galaxy].ra.item() dec = voids.loc[voids.galaxy == row.galaxy].dec.item() ra = groups.loc[groups.galaxy == row.galaxy].ra.item() dec = groups.loc[groups.galaxy == row.galaxy].dec.item() importData.loc[importData.galaxy == row.galaxy, 'fullpath'] = file.absolute() importData.loc[importData.galaxy == row.galaxy, 'ra'] = ra importData.loc[importData.galaxy == row.galaxy, 'dec'] = dec Loading @@ -248,7 +254,7 @@ def newEntry(row): file = Path(args.path) / Path(row['filename']) entry = { 'filename': file.name, 'void': row.void, 'group': row.group, 'galaxy': row.galaxy, 'morphology': MORPHOLOGY[-1], } Loading Loading @@ -279,14 +285,14 @@ def save_df(df): # df.loc[df['processed'] == True]]) # Remove old values, keep last ones: exportData = processedItems.drop_duplicates(['void','galaxy'],keep='last').sort_values('void') exportData = processedItems.drop_duplicates(['group','galaxy'],keep='last').sort_values('group') # Export final dataframe: exportData.to_csv(args.savefile, columns=getExportableColumns(), index=False) def pd_concat(df: pd.DataFrame, data: Union[pd.DataFrame, list, dict]) -> pd.DataFrame: """ Concats data in an array to the given dataframe """ Concats data to the given dataframe Parameters ---------- Loading @@ -296,7 +302,9 @@ def pd_concat(df: pd.DataFrame, data: Union[pd.DataFrame, list, dict]) -> pd.Dat data: list, dict or pandas.Dataframe Data to be concatenated to the input pandas Dataframe. - List of the values to be concatenated (order of input values and Dataframe columns must match). - Dict of the key:values, where keys match the Dataframe columns. - Dict of the 'key:values', where keys match the Dataframe columns (if not, values are put to NaN). - pandas.Dataframe where columns (should) match the input Dataframe (if not, new columns are created or values are put to NaN). Returns ------- Loading @@ -309,9 +317,18 @@ def pd_concat(df: pd.DataFrame, data: Union[pd.DataFrame, list, dict]) -> pd.Dat df_data = pd.DataFrame([data], columns=df.columns) elif type(data) == dict: if len(data) != len(df.columns): warnings.warn('Input data [dict] missing input dataframe keys. Missing values insterted as NaN') warnings.warn('Input data [dict] missing input dataframe keys. Missing values inserted as NaN') print(list(data.keys())) print(list(df.columns)) df_data = pd.DataFrame([data]) elif type(data) == pd.DataFrame: if not df.empty: cmp_df_data = list(df.keys()[~df.keys().isin(data.keys())]) cmp_data_df = list(data.keys()[~data.keys().isin(df.keys())]) if len(cmp_df_data) > 0: warnings.warn(f'Input data missing input dataframe column. {cmp_df_data}') if len(cmp_data_df) > 0: warnings.warn(f'Input data column(s) not in input dataframe. {cmp_data_df}') df_data = data df = pd.concat([df, df_data], ignore_index=True) Loading Loading
galassify.py +3 −4 Original line number Diff line number Diff line Loading @@ -13,18 +13,17 @@ VERSION = '0.1.2' if __name__ == '__main__': args = utils.getOptions(VERSION) selectedFiles, selectedVoids = utils.getFiles() selectedFiles, selectedGroups = utils.getFiles() if len(selectedFiles) > 0: if args.list: print(selectedFiles.filename) else: print('INFO:\t' + str(len(selectedFiles)) + ' galaxies found '+ 'in selected voids.') print(f"INFO:\t {str(len(selectedFiles))} galaxies found in selected groups.") df = utils.expand_df(selectedFiles) app = QtWidgets.QApplication(sys.argv) window = gui.Ui(df, selectedVoids) window = gui.Ui(df, selectedGroups) app.exec_() else: print('ERROR: No files found with the arguments given.')
src/gui.py +13 −13 Original line number Diff line number Diff line Loading @@ -8,16 +8,16 @@ import sys class Ui(QtWidgets.QMainWindow): def __init__(self, df, selectedVoids): def __init__(self, df, selectedGroups): super(Ui, self).__init__() uic.loadUi(str(Path('src')/Path('gui.ui')), self) self.title = 'CAVIssify ' + utils.getVersion() self.title = 'GALAssify ' + utils.getVersion() self.setWindowIcon(QIcon(str(Path('res/window_icon.png')))) # Load data frame and make it accessible along the class: self.df = df self.voids = selectedVoids self.galaxies = selectedGroups # Find buttons: self.pb_prev = self.findChild(QtWidgets.QPushButton, 'pb_prev') Loading Loading @@ -93,10 +93,10 @@ class Ui(QtWidgets.QMainWindow): def fillList(self, showAllSavedData=False): #self.fileList.setRowCount(len(self.df.index)) self.fileList.setColumnCount(6) self.fileList.setHorizontalHeaderLabels(['Void', self.fileList.setHorizontalHeaderLabels(['Group', 'Galaxy', 'Processed', 'RA', 'Ra', 'Dec', 'Filename']) self.fileList.horizontalHeaderItem(2).setTextAlignment(Qt.AlignHCenter) Loading @@ -119,7 +119,7 @@ class Ui(QtWidgets.QMainWindow): for i, row in self.df.iterrows(): # Place void data in integer format: self.fileList.setItem(i, 0, QtWidgets.QTableWidgetItem()) self.fileList.item(i, 0).setData(Qt.DisplayRole, int(row['void'])) self.fileList.item(i, 0).setData(Qt.DisplayRole, int(row['group'])) # Place galaxy data in integer format: self.fileList.setItem(i, 1, QtWidgets.QTableWidgetItem()) Loading @@ -137,7 +137,7 @@ class Ui(QtWidgets.QMainWindow): # Place filename in the row: self.fileList.setItem(i, 5, QtWidgets.QTableWidgetItem(str(row['filename']))) if (not showAllSavedData) and (int(row['void']) not in self.voids): if (not showAllSavedData) and (int(row['group']) not in self.galaxies): self.fileList.hideRow(i) # Order by RA coordinate: Loading Loading @@ -200,10 +200,10 @@ class Ui(QtWidgets.QMainWindow): item = self.df.loc[self.df['filename'] == fn] self.imgPath = item['fullpath'].item() v = str(item['void'].item()) g = str(item['galaxy'].item()) self.setWindowTitle('V: ' + v + ' | G: ' + g + grp = str(item['group'].item()) gal = str(item['galaxy'].item()) self.setWindowTitle('Grp: ' + grp + ' | Gal: ' + gal + ' | ' + self.title) self.fileList.setCellWidget(index, 2, Loading Loading @@ -259,8 +259,8 @@ class Ui(QtWidgets.QMainWindow): def toggleAIDVisibility(self): showAllSavedData = self.act_allSavedData.isChecked() for i in range(self.fileList.rowCount()): rowVoid = self.fileList.item(i, 0).text() if (not showAllSavedData) and (int(rowVoid) not in self.voids): row = self.fileList.item(i, 0).text() if (not showAllSavedData) and (int(row) not in self.galaxies): self.fileList.hideRow(i) else: self.fileList.showRow(i) Loading
src/gui.ui +1 −1 Original line number Diff line number Diff line Loading @@ -583,7 +583,7 @@ </widget> <action name="action_vn"> <property name="text"> <string>Void number...</string> <string>Group number...</string> </property> </action> <action name="action_folder"> Loading
src/utils.py +72 −55 Original line number Diff line number Diff line Loading @@ -13,13 +13,13 @@ from typing import Union args = None VERSION = '' importData = pd.DataFrame() voids = pd.DataFrame() groups = pd.DataFrame() def getOptions(version): global args global VERSION parser = argparse.ArgumentParser(prog='CAVYssify', description="CAVYssify: Tool to manually classify void galaxies.") parser = argparse.ArgumentParser(prog='GALAssify', description="GALAssify: Tool to manually classify galaxies.") parser.add_argument('--version', action='version', version='%(prog)s ' + version, help="Prints software version and exit.\n") Loading @@ -29,17 +29,17 @@ def getOptions(version): # required=not('-p' in sys.argv # or '--path' in sys.argv # or '--version' in sys.argv), type=dir_file, # help="Image or list to classify. Not required if path or path + void are given.\n") # help="Image or list to classify. Not required if path or path + group are given.\n") parser.add_argument('-s', '--savefile', #required=not('--version' in sys.argv), default='output.csv', help="CSV file to load and export changes. If does not exists, a new one is created.\n") parser.add_argument("-l", "--list", action="store_true", help="List selected files only and exit.\n") parser.add_argument('-vf', '--voidsfile', default='voids.csv', help="Voids database file in *.csv format.\n") parser.add_argument('void', metavar='VOID', type=int, nargs='+', help="Void number. Selects images with name format: *_<void>_*_*.png\n") parser.add_argument('-vf', '--inputfile', default='galaxies.csv', help="Galaxy database file in *.csv format.\n") parser.add_argument('group', metavar='GROUP', type=int, nargs='*', help="Group number. Selects images with name format: *_<group>_*_*.png\n") args = parser.parse_args() VERSION = version Loading @@ -53,28 +53,33 @@ def getVersion(): def getFiles(): global args global voids files = [] selectedVoids = [] selectedFiles = pd.DataFrame() global groups # files = [] selectedGroups = [] selectedFiles = pd.DataFrame(columns = groups.columns) if args.path: if Path(args.voidsfile).is_file(): voids = readVoidsFile() if Path(args.inputfile).is_file(): groups = readInputFile() else: voids = createVoidsFile() groups = createInputFile() availableGroups = groups.group.unique() print(f"INFO:\tAvailable groups: {str(availableGroups)}") availableVoids = voids.void.unique() print('INFO:\tAvailable voids: ' + str(availableVoids)) if len(args.void) > 0: for void in args.void: if void in availableVoids: selectedFiles = pd_concat(selectedFiles, voids[voids.void == void]) #selectedFiles = selectedFiles.append(voids[voids.void == void ]) selectedVoids.append(int(void)) if len(args.group) > 0: for group in args.group: if group in availableGroups: selectedFiles = pd_concat(selectedFiles, groups[groups.group == group]) selectedGroups.append(int(group)) else: print(f'WARNING:\tGroup {group} not available.') else: print('WARNING:\tVoid ', void, 'not available.') print(f'INFO:\tNo subgroup selected. Using all available by default.') selectedFiles = groups.copy() selectedGroups = availableGroups #else: # formats = ['*.png'] Loading @@ -88,8 +93,7 @@ def getFiles(): #else: # files = [] return selectedFiles, selectedVoids return selectedFiles, selectedGroups def dir_path(path): Loading @@ -109,49 +113,51 @@ def dir_file(file): raise argparse.ArgumentTypeError("readable_file:" + file + " is not a valid file.") VFCOLUMNS = ['void','galaxy','ra','dec','filename'] VFCOLUMNS = ['group','galaxy','ra','dec','filename'] def readVoidsFile(): print('INFO:\tReading from voids.csv file... ', end='', flush=True) voids = pd.read_csv(args.voidsfile, def readInputFile(): fname = args.inputfile print(f'INFO:\tReading from {fname} file... ', end='', flush=True) groups = pd.read_csv(fname, converters={ 'void': int, 'group': int, 'galaxy': int, 'ra': float, 'dec': float, } ) voids = voids.sort_values(by=['void', 'ra', 'galaxy']) groups = groups.sort_values(by=['group', 'ra', 'galaxy']) print('Done!') return voids return groups def createVoidsFile(): print('INFO:\tCreating voids.csv file... ', end='', flush=True) voids = pd.DataFrame(columns=VFCOLUMNS) def createInputFile(): fname = args.inputfile print(f'INFO:\tCreating {fname} file... ', end='', flush=True) groups = pd.DataFrame(columns=VFCOLUMNS) if args.path: for file in Path(args.path).glob('pan_*_*_ppak.png'): entry = { 'void': int(file.stem.split('_')[1]), 'group': int(file.stem.split('_')[1]), 'galaxy': int(file.stem.split('_')[2]), 'ra':float(0), 'dec':float(0), 'filename': str(file.name), } voids = pd_concat(voids, entry) #voids = voids.append(entry, ignore_index=True) voids = voids.sort_values(by=['void','galaxy']) voids.to_csv(args.voidsfile, columns=VFCOLUMNS, index=False) groups = pd_concat(groups, entry) #groups = groups.append(entry, ignore_index=True) groups = groups.sort_values(by=['group','galaxy']) groups.to_csv(fname, columns=VFCOLUMNS, index=False) print('Done!') return voids return groups ### PANDAS UTILS COLUMNS = ["filename", "void", "galaxy", "morphology", "large", "tiny", "faceon", COLUMNS = ["filename", "group", "galaxy", "morphology", "large", "tiny", "faceon", "edgeon", "star", "calibration", "recentre", "duplicated", "member", "hiiregion", "yes", "no", "comment", "processed", "fullpath"] "fullpath", "ra", "dec"] MORPHOLOGY = ['elliptical', 'spiral', 'irregular', 'other', ''] Loading @@ -169,11 +175,11 @@ def getRadioButtonsMorphology(): def getCheckBoxesColumns(): return COLUMNS[4:-3] return COLUMNS[4:-5] def getExportableColumns(): return COLUMNS[:-2] return COLUMNS[:-4] def checkColumnsMismatch(importDataColumns): Loading @@ -194,11 +200,11 @@ def checkColumnsMismatch(importDataColumns): def expand_df(selectedFiles): global args global importData global voids global groups if Path(args.savefile).is_file(): importData = pd.read_csv(args.savefile, converters={ 'void': int, 'group': int, 'galaxy': int, } ) Loading Loading @@ -227,8 +233,8 @@ def expand_df(selectedFiles): processedUnselectedData = importData[importData.fullpath == ''] for i, row in processedUnselectedData.iterrows(): file = Path(args.path) / Path(row['filename']) ra = voids.loc[voids.galaxy == row.galaxy].ra.item() dec = voids.loc[voids.galaxy == row.galaxy].dec.item() ra = groups.loc[groups.galaxy == row.galaxy].ra.item() dec = groups.loc[groups.galaxy == row.galaxy].dec.item() importData.loc[importData.galaxy == row.galaxy, 'fullpath'] = file.absolute() importData.loc[importData.galaxy == row.galaxy, 'ra'] = ra importData.loc[importData.galaxy == row.galaxy, 'dec'] = dec Loading @@ -248,7 +254,7 @@ def newEntry(row): file = Path(args.path) / Path(row['filename']) entry = { 'filename': file.name, 'void': row.void, 'group': row.group, 'galaxy': row.galaxy, 'morphology': MORPHOLOGY[-1], } Loading Loading @@ -279,14 +285,14 @@ def save_df(df): # df.loc[df['processed'] == True]]) # Remove old values, keep last ones: exportData = processedItems.drop_duplicates(['void','galaxy'],keep='last').sort_values('void') exportData = processedItems.drop_duplicates(['group','galaxy'],keep='last').sort_values('group') # Export final dataframe: exportData.to_csv(args.savefile, columns=getExportableColumns(), index=False) def pd_concat(df: pd.DataFrame, data: Union[pd.DataFrame, list, dict]) -> pd.DataFrame: """ Concats data in an array to the given dataframe """ Concats data to the given dataframe Parameters ---------- Loading @@ -296,7 +302,9 @@ def pd_concat(df: pd.DataFrame, data: Union[pd.DataFrame, list, dict]) -> pd.Dat data: list, dict or pandas.Dataframe Data to be concatenated to the input pandas Dataframe. - List of the values to be concatenated (order of input values and Dataframe columns must match). - Dict of the key:values, where keys match the Dataframe columns. - Dict of the 'key:values', where keys match the Dataframe columns (if not, values are put to NaN). - pandas.Dataframe where columns (should) match the input Dataframe (if not, new columns are created or values are put to NaN). Returns ------- Loading @@ -309,9 +317,18 @@ def pd_concat(df: pd.DataFrame, data: Union[pd.DataFrame, list, dict]) -> pd.Dat df_data = pd.DataFrame([data], columns=df.columns) elif type(data) == dict: if len(data) != len(df.columns): warnings.warn('Input data [dict] missing input dataframe keys. Missing values insterted as NaN') warnings.warn('Input data [dict] missing input dataframe keys. Missing values inserted as NaN') print(list(data.keys())) print(list(df.columns)) df_data = pd.DataFrame([data]) elif type(data) == pd.DataFrame: if not df.empty: cmp_df_data = list(df.keys()[~df.keys().isin(data.keys())]) cmp_data_df = list(data.keys()[~data.keys().isin(df.keys())]) if len(cmp_df_data) > 0: warnings.warn(f'Input data missing input dataframe column. {cmp_df_data}') if len(cmp_data_df) > 0: warnings.warn(f'Input data column(s) not in input dataframe. {cmp_data_df}') df_data = data df = pd.concat([df, df_data], ignore_index=True) Loading