text stringlengths 0 828 |
|---|
if flag_single: |
if ch == ""'"": |
flag_single = False |
elif not flag_double and ch == ""'"": |
flag_single = True |
if flag_double: |
if ch == '""': |
flag_double = False |
elif not flag_single and ch == '""': |
flag_double = True |
if flag_single or flag_double: |
ll.append(ch) |
else: |
ll.append(MAP.get(ch, ch)) |
return """".join(ll)" |
3859,"def chunk_string(string, length): |
"""""" |
Splits a string into fixed-length chunks. |
This function returns a generator, using a generator comprehension. The |
generator returns the string sliced, from 0 + a multiple of the length |
of the chunks, to the length of the chunks + a multiple of the length |
of the chunks. |
Reference: http://stackoverflow.com/questions/18854620 |
"""""" |
return (string[0 + i:length + i] for i in range(0, len(string), length))" |
3860,"def seconds2str(seconds): |
""""""Returns string such as 1h 05m 55s."""""" |
if seconds < 0: |
return ""{0:.3g}s"".format(seconds) |
elif math.isnan(seconds): |
return ""NaN"" |
elif math.isinf(seconds): |
return ""Inf"" |
m, s = divmod(seconds, 60) |
h, m = divmod(m, 60) |
if h >= 1: |
return ""{0:g}h {1:02g}m {2:.3g}s"".format(h, m, s) |
elif m >= 1: |
return ""{0:02g}m {1:.3g}s"".format(m, s) |
else: |
return ""{0:.3g}s"".format(s)" |
3861,"def make_fits_keys_dict(keys): |
"""""" |
Returns a dictionary to translate to unique FITS header keys up to 8 characters long |
This is similar to Windows making up 8-character names for filenames that |
are longer than this |
""The keyword names may be up to 8 characters long and can only contain |
uppercase letters A to Z, the digits 0 to 9, the hyphen, and the underscore |
character."" [1] |
Arguments: |
keys -- list of strings |
Returns: |
dictionary whose keys are the elements in the ""keys"" argument, and whose |
values are made-up uppercase names |
References: |
[1] http://fits.gsfc.nasa.gov/fits_primer.html |
"""""" |
key_dict = {} |
new_keys = [] |
for key in keys: |
# converts to valid FITS key according to reference [1] above |
fits_key = valid_fits_key(key) |
num_digits = 1 |
i = -1 |
i_max = 9 |
while fits_key in new_keys: |
i += 1 |
if i > i_max: |
i = 0 |
i_max = i_max * 10 + 9 |
num_digits += 1 |
fits_key = fits_key[:(8 - num_digits)] + ((""%0{0:d}d"".format(num_digits)) % i) |
key_dict[key] = fits_key |
new_keys.append(fits_key) |
return key_dict" |
3862,"def valid_fits_key(key): |
"""""" |
Makes valid key for a FITS header |
""The keyword names may be up to 8 characters long and can only contain |
uppercase letters A to Z, the digits 0 to 9, the hyphen, and the underscore |
character."" (http://fits.gsfc.nasa.gov/fits_primer.html) |
"""""" |
ret = re.sub(""[^A-Z0-9\-_]"", """", key.upper())[:8] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.