-
Notifications
You must be signed in to change notification settings - Fork 9
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
Added a rename function #40
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really like this Naheem! I think it would be also to incorporate this in!
I have a few small changes to match the overall patterns of the repo and a few bigger questions:
-
This will only work for ground projected interferogram pairs, so not Polsar or slant range uavsar images. Can we a check at the start of the script to ensure there are only .grd.tiff and .ann.tiff images? Also rename from rename.py to something like rename_interferogram_grd.py?
-
At the end if the user specifies clean_dir can we move all the images back into the original directory
in_dir
fromrenamed/
directory and get rid of renamed? I just don't want to have an empty directory with just arenamed/
directory. It would be better to just be left with the same directory with renamed files in it.
The renamed files are stored in a new directory called renamed. | ||
|
||
Args: | ||
dir_in (_type_): path to the directory containing the tiff files to be renamed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type should probably be string?
os.makedirs(dir_out) | ||
|
||
#read the metadata from the csv file | ||
metadata = pd.read_csv(glob.glob(dir_in + '/*grd.csv')[0]) #it gives a list, so select the only item in the list |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you from glob import glob and then just use glob here to match the pattern in the rest of the repo?
#grab the last two sets of strings from the tiff name | ||
set2 = (tiff.split('/')[-1]).split('_')[-2] | ||
set1 = (tiff.split('/')[-1]).split('_')[-1] | ||
new_name = dir_out + file_name + '_' + date1 + '_' + date2 + '_' + set2 + '_' + set1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider using an f-string here?
join(dir_out, f'{file_name}{date1}{date2}{set2}{set1}
file_name = (tiff.split('/')[-1]).split('_')[0] | ||
|
||
#grab the last two sets of strings from the tiff name | ||
set2 = (tiff.split('/')[-1]).split('_')[-2] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are set2 and set1 polarizations? What are these variables?
|
||
if clean_dir == False: | ||
shutil.copy(tiff, new_name) | ||
elif clean_dir == True: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the user passes clean_dir == true, could we move them to this new directory and then have a section that moves the tiffs back into the main directory and removes the newly created renamed
directory?
|
||
|
||
#loop through the files | ||
for tiff in glob.glob(dir_in + '/*grd.tiff'): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't work for POLSAR, slant range images. Maybe a different script name that clarifies this is only for renaming uavsar interferogram ground projected images? and a check to make sure that the in_dir contains that right type of images?
Hi @ZachKeskinen and @jacktarricone , I wrote a simple function that extracts info from the annotation and tiff files to rename UAVSAR data in a directory. I found it useful to append the date of first and second pass to the tiff files I am working with. Perhaps this might be a useful addition to the package.