Commit cb63e827 authored by Manuel Luis Alcazar Laynez's avatar Manuel Luis Alcazar Laynez
Browse files

Merge branch '9-get_images_sdss-update-the-csv-with-the-img-path' into 'clickable-image'

Resolve "`get_images_sdss`: update the csv with the img path"

See merge request !16
parents c508cc0c c9e2b904
Loading
Loading
Loading
Loading
+12 −3
Original line number Diff line number Diff line
@@ -37,8 +37,12 @@ def get_args():
                        help="Path to save image files.\n")
    parser.add_argument('-i', '--inputfile', type=dir_file, default='galaxies.csv',
                        help="Galaxy database file in *.csv format.\n")
    parser.add_argument('-o', '--outputfile', type=str, default=None,
                        help="""Output galaxy database file in *.csv format containing 
                        the path to the downloaded images. If not specified, the
                        paths will be written in the input CSV file.""")
    parser.add_argument('-s', '--size', type=int, default=512,
                        help="Size of the downloaded images.\n")
                        help="Size of the edges (in pixels) of the downloaded images.\n")
    
    return parser.parse_args()

@@ -46,10 +50,11 @@ def main():
    # Params
    args = get_args()
    path = Path(args.path)
    file = Path(args.inputfile)
    inputfile = Path(args.inputfile)
    size = args.size
    outputfile = args.outputfile
    # Read catalogue
    galaxies = pd.read_csv(file)
    galaxies = pd.read_csv(inputfile)

    # Download images
    n = len(galaxies)
@@ -63,11 +68,15 @@ def main():
                
            fname = f"{path}/img_{group}_{id}.jpeg"
            download_sdss(fname, row['ra'], row['dec'], size)
            galaxies.loc[index, 'filename'] = f"img_{group}_{id}.jpeg"
            
            if index % 10 == 0:
                print(f"Remaining {n-index}")
    except KeyError as e:
        print(f"KeyError: {e}")
    
    file = Path(outputfile) if outputfile else inputfile
    galaxies.to_csv(file, index=None)
    print("Done!")

if __name__ == '__main__':