Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

file handling #6

Closed
Kamuish opened this issue May 25, 2020 · 0 comments
Closed

file handling #6

Kamuish opened this issue May 25, 2020 · 0 comments

Comments

@Kamuish
Copy link
Collaborator

Kamuish commented May 25, 2020

if savePath:
os.chdir(savePath)
stars = np.loadtxt(filename, skiprows = header, usecols=(column),
dtype = str, delimiter = '\t')
if not dec:
dec = 180
for i, j in enumerate(stars):
checkLash = j.find('/') #to separate the stars that have two names
stars[i] = ' '.join(j.split(' ', -1)[:-2]) #remove last 2 columns
if checkLash != -1:
newStar = j.split('/')
stars[i] = newStar[0]
stars = np.append(stars, ' '.join(newStar[1].split(' ',
-1)[:-2]))
now = datetime.now()
if saveFile:
f = open("summary_{0}.txt".format(now.strftime("%Y-%m-%dT%H:%M:%S")),
"a")
else:
f = stdout
noSpectra = [] #to add the stars with no spectra on archive
for _, j in enumerate(stars):
try:
print(j)
self.summaryStar(j, instrument=instrument, date=date, SNR=SNR,
fromList=f);
except:
noSpectra.append(j)
print('{0} not found in archive\n'.format(j), file = f)
f.close()
if saveFile:
f1 = open("{0}_noSpectra.txt".format(filename[0:-4]), "a")
f2 = open("{0}_checkStar.txt".format(filename[0:-4]), "a")
for _, j in enumerate(noSpectra):
try:
jSearch = Simbad.query_object(j)
RAandDEC = HMS2deg(jSearch['RA'][0], jSearch['DEC'][0])
if float(RAandDEC[1]) > dec:
pass
else:
print('{0}\t{1}degress'.format(j, RAandDEC[1]),
file = f1)
except:
print('{0} not found on SIMBAD'.format(j),
file = f2)
f1.close(); f2.close()

I think it is not a good ideia to do a chdir to the save path.
It's easier to simply do a
os.path.join(save_path, <filename>

and avoid moving the "working path" of the terminal.

Once again, you should avoid opening and closing files manually

@Kamuish Kamuish closed this as completed May 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant