Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions examples/sample_code_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

import numpy as np
import os
# The two lines below make it possible for people to sit in the examples directory and run the scripts.
import sys
sys.path.append('../..')
import sunpy.sunpy__load as sunpy__load #
import sunpy.sunpy__plot as sunpy__plot

Expand All @@ -18,14 +21,28 @@
dl_base='http://www.illustris-project.org'

try:
catalog = np.loadtxt('directory_catalog_135.txt',
dtype={'names' : ('subdirs', 'galaxy_numbers', 'galaxy_masses'),
'formats': ('S3', 'i10', 'f8')})
except:
# Depending on the NumPy version, the line below can raise a TypeError even if the file is
# present. The try/except block enables us to try loadtxt calls that work for more NumPy
# versions.
try:
catalog = np.loadtxt('directory_catalog_135.txt',
dtype={'names' : ('subdirs', 'galaxy_numbers', 'galaxy_masses'),
'formats': ('S3', 'i10', 'f8')})
except TypeError:
catalog = np.loadtxt('directory_catalog_135.txt',
dtype={'names' : ('subdirs', 'galaxy_numbers', 'galaxy_masses'),
'formats': ('S3', 'i8', 'f8')})
except IOError:
# If we don't already have the file, we have to download it and try again.
os.system("wget "+dl_base+"/files/directory_catalog_135.txt")
catalog = np.loadtxt('directory_catalog_135.txt',
dtype={'names' : ('subdirs', 'galaxy_numbers', 'galaxy_masses'),
'formats': ('S3', 'i10','f8')})
try:
catalog = np.loadtxt('directory_catalog_135.txt',
dtype={'names' : ('subdirs', 'galaxy_numbers', 'galaxy_masses'),
'formats': ('S3', 'i10','f8')})
except TypeError:
catalog = np.loadtxt('directory_catalog_135.txt',
dtype={'names' : ('subdirs', 'galaxy_numbers', 'galaxy_masses'),
'formats': ('S3', 'i8','f8')})


all_subdirs = catalog['subdirs']
Expand Down
38 changes: 34 additions & 4 deletions sunpy__load.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,24 @@ def load_broadband_image(filename,band=0, **kwargs):
The band can be specified as a number or a string (must match the "band_names") """

band_images = load_all_broadband_images(filename, **kwargs)
# This code change is needed because currently load_all_broadband_images seems to have been
# changed to return a tuple, but the code later in this routine assumes that it just returns an
# array. So check for this and get the array if a tuple was returned.
if isinstance(band_images, tuple):
if isinstance(band_images[0], np.ndarray):
band_images = band_images[0]
band_names = load_broadband_names(filename)

if type(band) is int:
return_image = band_images[band,:,:]
else:
band = (((band_names == band).nonzero())[0])[0]
# The original version of this code fails for some NumPy versions. New version will work for
# more systems (compatible with original version but also uses syntax that will work for other
# NumPy versions if an error is encountered.
try:
band = (((band_names == band).nonzero())[0])[0]
except AttributeError:
band = (((np.array(band_names) == band).astype(int).nonzero())[0])[0]
return_image = band_images[band,:,:]

return return_image
Expand Down Expand Up @@ -160,7 +172,13 @@ def load_broadband_effective_wavelengths(filename,band=None):
name_array = name_array[band]
else:
band_names = load_broadband_names(filename)
band_index = (((band_names == band).nonzero())[0])[0]
# The original version of this code fails for some NumPy versions. New version will work for
# more systems (compatible with original version but also uses syntax that will work for other
# NumPy versions if an error is encountered.
try:
band_index = (((band_names == band).nonzero())[0])[0]
except AttributeError:
band_index = (((np.array(band_names) == band).astype(int).nonzero())[0])[0]
name_array = name_array[band_index]

band=None
Expand Down Expand Up @@ -191,13 +209,25 @@ def load_all_broadband_images(filename,camera=0,openlist=None):

def load_broadband_image(filename,band=0,camera=0):
band_images = load_all_broadband_images(filename,camera=camera)
# This code change is needed because currently load_all_broadband_images seems to have been
# changed to return a tuple, but the code later in this routine assumes that it just returns an
# array. So check for this and get the array if a tuple was returned.
if isinstance(band_images, tuple):
if isinstance(band_images[0], np.ndarray):
band_images = band_images[0]
band_names = load_broadband_names(filename)

if type(band) is int:
return_image = band_images[band,:,:]
else:
band = (((band_names == band).nonzero())[0])[0]
return_image = band_images[band,:,:]
# The original version of this code fails for some NumPy versions. New version will work for
# more systems (compatible with original version but also uses syntax that will work for other
# NumPy versions if an error is encountered.
try:
band_index = (((band_names == band).nonzero())[0])[0]
except AttributeError:
band_index = (((np.array(band_names) == band).astype(int).nonzero())[0])[0]
return_image = band_images[int(band_index),:,:]

return return_image

Expand Down
13 changes: 9 additions & 4 deletions sunpy__plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,24 +117,29 @@ def return_synthetic_sdss_gri_img(filename,

n_iter+=1


b_image, rp, the_used_seed,this_fail_flag = sunpy__synthetic_image.build_synthetic_image(filename, 'g_SDSS.res',
# The calls to build_synthetic_image had to be updated to account for changes in the number
# of return values (previously 4, now 6). We don't need the other 2 values here, but we
# have to catch them so the code won't complain about too many return values to unpack.
b_image, rp, the_used_seed,this_fail_flag, _, _ = \
sunpy__synthetic_image.build_synthetic_image(filename, 'g_SDSS.res',
seed=seed,
r_petro_kpc=r_petro_kpc,
fix_seed=False,
**kwargs)
if(this_fail_flag):
fail_flag=True

g_image, dummy, the_used_seed,this_fail_flag = sunpy__synthetic_image.build_synthetic_image(filename, 'r_SDSS.res',
g_image, dummy, the_used_seed,this_fail_flag, _, _ = \
sunpy__synthetic_image.build_synthetic_image(filename, 'r_SDSS.res',
seed=the_used_seed,
r_petro_kpc=rp,
fix_seed=True,
**kwargs)
if(this_fail_flag):
fail_flag=True

r_image, dummy, the_used_seed, this_fail_flag = sunpy__synthetic_image.build_synthetic_image(filename, 'i_SDSS.res',
r_image, dummy, the_used_seed, this_fail_flag, _, _ = \
sunpy__synthetic_image.build_synthetic_image(filename, 'i_SDSS.res',
seed=the_used_seed,
r_petro_kpc=rp,
fix_seed=True,
Expand Down
2 changes: 2 additions & 0 deletions sunpy__synthetic_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,8 @@ def add_background(self, seed=1, add_background=True, rebin_gz=False, n_target_p
#=== load *full* bg image, and its properties ===#
bg_filename = (backgrounds[self.band])[0]
if not (os.path.isfile(bg_filename)):
## Note from RM: If I try to wget the files from the URLs given below, I get
## "Not Found" errors. So I think these are wrong and should be updated.
print " Background files were not found... "
print " The standard files used in Torrey al. (2015), Snyder et al., (2015) and Genel et al., (2014) ..."
print " can be downloaded using the download_backgrounds routine or manually from: "
Expand Down