stsdas.toolbox.tools¶
General utilities
Notes¶
For questions or comments please see our github page. We encourage and appreciate user feedback.
Contents:
base2dec-dec2base¶
Please review the Notes section above before running any examples in this notebook
The base2dec and dec2base tasks transfrom strings to decimal integers,
and decimal integers to other base strings. Python has various built ins
for these conversion. The int()
function can transform any base to
integer, which can then be printed in decimal. For the reverse direction
Python contains built in functionality to transfrom integers to octoal,
hexidecimal, and binary.
# base 16 to integer
a = int("b1", base=16)
print(a)
# integer to base 16
b = hex(177)
print(b)
# integer to binary
c = "{0:b}".format(177)
print(c)
177
0xb1
10110001
ddiff¶
Please review the Notes section above before running any examples in this notebook
Ddiff is used to print differences between two directory trees. This can be replicated using os.walk and a little bit of set maniputaion
# Standard Imports
import os
full_filepaths1 = []
full_filepaths2 = []
# loop through walk iterator
for root, dirs, files in os.walk("."):
for filestring in files:
full_filepaths1.append(os.path.join(root,filestring))
# We will use the same directory for this example, so the set difference should be empty
for root, dirs, files in os.walk("."):
for filestring in files:
full_filepaths2.append(os.path.join(root,filestring))
# Now we turn both filepath lists into sets, and take the difference
set1 = set(full_filepaths1)
set2 = set(full_filepaths2)
print(set1 - set2)
set([])
epoch-tepoch¶
Please review the Notes section above before running any examples in this notebook
Epoch and tepoch are used to convert time formats. This functionality is heavily covered by the Astropy time module and the Python datetime module. Please see the linked documentation for more details.
fparse¶
Please review the Notes section above before running any examples in this notebook
Fparse is used to parse file specifications and leave results in
parameters. This can be done using the os
path.split
function
and the built in String split
method.
# Standard Imports
import os
# code goes here
my_filepath = "/home/user/snowball/stars.txt"
directory, filename = os.path.split(my_filepath)
print(directory)
print(filename)
print(filename.split("."))
/home/user/snowball
stars.txt
['stars', 'txt']
tprecess¶
Please review the Notes section above before running any examples in this notebook
Tprecess is used to precess images, tables, or lists of coordinates. This capability is part of the Astropy coordinates package. Please explore the doumentation for more instruction.
Not Replacing¶
- mkapropos - Make the apropos database. Deprecated.
- uniqfile - Give a file a unique name prior to archiving. Deprecated.
- uniqid - Create a unique character string identifier. Deprecated.
- uniqname - Create a unique file name for archiving. Deprecated.
- uniqtab - Give all the files in an STSDAS table unique names. Deprecated.