geodesymiami / rsmas_insar

RSMAS InSAR code
https://rsmas-insar.readthedocs.io/
GNU General Public License v3.0
59 stars 23 forks source link

Refactoring out `os.chdir()` #104

Closed gravelcycles closed 3 years ago

gravelcycles commented 5 years ago

os.chdir() has global, unintended, and unanticipated effects on a program. Should we refactor out uses of os.chdir()? How do we replace the concept of a working directory when possible?

Related issue: #103

@falkamelung @Ovec8hkin

gravelcycles commented 5 years ago

@yunjunz, please weigh in on your thoughts from PySAR.

I think the way PySAR does this is that they change the directory back to its original cwd (current working directory) at the end. This seems to work, but could be good to avoid for a couple of reasons: 1. it's an unnecessary step and is easy to forget 2. calling another function that expects a certain working directory or modifies the cwd would still have unintended consequences.

yunjunz commented 5 years ago

Hi @2gotgrossman, I completely agree, all file/directory name should be in full path, and without the need of changing directory.

PySAR should not using os.chdir() at all. Feel free to change it whenever you got a chance.

falkamelung commented 5 years ago

I agree. There are only a few instances (see below) so it is very easy to do. Sara could eliminate some of those during her restructuring efforts.

//login3/nethome/famelung/test/test1/rsmas_insar/sources/rsmas_isce[1013] grep chdir *
create_batch.py:    os.chdir(work_dir)
create_batch.py:    os.chdir(work_dir)
create_squeesar_run_files.py:    os.chdir(inps.work_dir)
create_stacksentinel_run_files.py:    os.chdir(inps.work_dir)
dem_rsmas_kawan.py:    os.chdir('DEM')
dem_rsmas_kawan.py:                os.chdir('..')
dem_rsmas.py:    os.chdir('DEM')
dem_rsmas.py:          os.chdir('..')
download_asfserial_rsmas.py: os.chdir(inps.work_dir)
download_asfserial_rsmas.py: os.chdir(inps.slcDir)
download_rsmas.py:    os.chdir(work_dir)
download_ssara_rsmas.py:    os.chdir(inps.work_dir)
download_ssara_rsmas.py:    os.chdir(inps.slcDir)
ingest_insarmaps.py:    os.chdir(inps.work_dir)
process_rsmas.py:    os.chdir(inps.work_dir)
_processSteps.py:        os.chdir(inps.work_dir)

Falk Amelung Professor Department of Marine Geosciences Rosenstiel School of Marine and Atmospheric Sciences University of Miami 4600 Rickenbacker Causeway Miami, FL 33149 USA Tel: 305 421 4949 E-mail: famelung@rsmas.miami.edumailto:famelung@rsmas.miami.edu Web: http://insar.rsmas.miami.edu InSAR data: http://insarmaps.miami.edu

On Mar 21, 2019, at 7:47 PM, Zhang Yunjun notifications@github.com<mailto:notifications@github.com> wrote:

Hi @2gotgrossmanhttps://nam01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2F2gotgrossman&data=02%7C01%7Cfamelung%40rsmas.miami.edu%7Ce53f1d7f3b5641919a1a08d6ae57891a%7C2a144b72f23942d48c0e6f0f17c48e33%7C0%7C0%7C636888088320464276&sdata=xLuSbZriIAVKgRTAULfTf1YBL8OYxpqRG7DSZPZjG6E%3D&reserved=0, I completely agree, all file/directory name should be in full path, and without the need of changing directory.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://nam01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fgeodesymiami%2Frsmas_isce%2Fissues%2F104%23issuecomment-475444893&data=02%7C01%7Cfamelung%40rsmas.miami.edu%7Ce53f1d7f3b5641919a1a08d6ae57891a%7C2a144b72f23942d48c0e6f0f17c48e33%7C0%7C0%7C636888088320464276&sdata=%2FI1TfBifE6mNveRFNjgMSZfKLXM662MLvRwg2TOqbKI%3D&reserved=0, or mute the threadhttps://nam01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAKpT3Co227-ka3LC-wZCccHxY6pip6iNks5vZBn-gaJpZM4cB_D8&data=02%7C01%7Cfamelung%40rsmas.miami.edu%7Ce53f1d7f3b5641919a1a08d6ae57891a%7C2a144b72f23942d48c0e6f0f17c48e33%7C0%7C0%7C636888088320474280&sdata=k7%2FCQHrPIFrVtG6RJ1a7mpVO2U15XfnaUcsC6DcJwc8%3D&reserved=0.