-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_download_script.py
114 lines (94 loc) · 3.98 KB
/
generate_download_script.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# Copyright 2018 The TensorFlow Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
r"""Generates a bash script for downloading light curves.
The input to this script is a CSV file of Kepler targets, for example the DR24
TCE table, which can be downloaded in CSV format from the NASA Exoplanet Archive
at:
https://exoplanetarchive.ipac.caltech.edu/cgi-bin/TblView/nph-tblView?app=ExoTbls&config=q1_q17_dr24_tce
Example usage:
python generate_download_script.py \
--kepler_csv_file=dr24_tce.csv \
--download_dir=${HOME}/astronet/kepler
"""
#PRAVA NAVODILA
#1. v tem programu spremeni kaj je csv file znotraj maina
#2. v bash shellu spremni na direktorij machine
#3. dej v bash
# python kepler/download_skripte/generate_download_script.py \
# --kepler_csv_file= "$(pwd)/ne_planeti.csv" \
# --download_dir="$(pwd)/kepler/"
#pozeni skripto ki jo nardi in ti jo predlaga
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import argparse
import csv
import os
import stat
import sys
parser = argparse.ArgumentParser()
parser.add_argument(
"--kepler_csv_file",
type=str,
required=True,
help="CSV file containing Kepler targets to download. Must contain a "
"'kepid' column.")
parser.add_argument(
"--download_dir",
type=str,
required=True,
help="Directory into which the Kepler data will be downloaded.")
parser.add_argument(
"--output_file",
type=str,
default="get_kepler.sh",
help="Filename of the output download script.")
_WGET_CMD = ("wget -q -nH --cut-dirs=6 -r -l0 -c -N -np -erobots=off "
"-R 'index*' -A _llc.fits") #I changed it here!!!!!!!!!!!!!!!!!!!!
_BASE_URL = "http://archive.stsci.edu/pub/kepler/lightcurves"
def main(argv):
del argv # Unused.
# Read Kepler targets.
kepids = set()
FLAGS.kepler_csv_file = "C:/Users/USER/Documents/Physics/kepler/download_skripte/ne_planeti600.csv"
with open(FLAGS.kepler_csv_file) as f:
reader = csv.DictReader(row for row in f if not row.startswith("#"))
for row in reader:
kepids.add(row["kepid"])
num_kepids = len(kepids)
# Write wget commands to script file.
with open(FLAGS.output_file, "w") as f:
f.write("#!/bin/sh\n")
f.write("echo 'Downloading {} Kepler targets to {}'\n".format(
num_kepids, FLAGS.download_dir))
for i, kepid in enumerate(kepids):
if i and not i % 10:
f.write("echo 'Downloaded {}/{}'\n".format(i, num_kepids))
kepid = "{0:09d}".format(int(kepid)) # Pad with zeros.
subdir = "{}/{}".format(kepid[0:4], kepid)
download_dir = os.path.join(FLAGS.download_dir, subdir)
url = "{}/{}/".format(_BASE_URL, subdir)
f.write("{} -P {} {}\n".format(_WGET_CMD, download_dir, url))
f.write("echo 'Finished downloading {} Kepler targets to {}'\n".format(
num_kepids, FLAGS.download_dir))
# Make the download script executable.
os.chmod(FLAGS.output_file, stat.S_IRWXU | stat.S_IRGRP | stat.S_IROTH)
print("{} Kepler targets will be downloaded to {}".format(
num_kepids, FLAGS.output_file))
print("To start download, run:\n {}".format("./" + FLAGS.output_file
if "/" not in FLAGS.output_file
else FLAGS.output_file))
if __name__ == "__main__":
FLAGS, unparsed = parser.parse_known_args()
main(argv=[sys.argv[0]] + unparsed)