Esempio n. 1
0
 def average_image_serial(self, flux, spin, rhigh):
     imgnames = self.get_all_fnames(flux, spin, rhigh)
     image = read_image(imgnames[0])
     for i in range(1, len(imgnames)):
         image += read_image(imgnames[i])
     image /= len(imgnames)
     return image
Esempio n. 2
0
 def run_on(self, flux, spin, rhigh, fn, nprocs=N_PROCS):
     """Apply a function to every existing image in a model
     @return a list of results
     """
     read_and_fn = lambda imname: fn(read_image(imname))
     return map_parallel(read_and_fn,
                         self.get_all_fnames(flux, spin, rhigh), nprocs)
Esempio n. 3
0
 def run_lc_serial(self, flux, spin, rhigh, fn):
     results = []
     ts = []
     for imname in self.get_all_fnames(flux, spin, rhigh):
         image = read_image(imname)
         results.append(fn(image))
         ts.append(image.t)
         del image
     return (ts, results)
Esempio n. 4
0
 def run_lc(self, flux, spin, rhigh, fn, nprocs=N_PROCS):
     """Apply a function to every image in a model, and also return the simulation time of the image
     @return a list of tuples (t, fn(image))
     """
     fn_and_t = lambda image: (image.t, fn(image))
     read_and_fn_and_t = lambda imname: fn_and_t(read_image(imname))
     zipped = map_parallel(read_and_fn_and_t,
                           self.get_all_fnames(flux, spin, rhigh), nprocs)
     # return lists of t and fn(images) as the 2 elements of a list, rather than a single list of tuples
     return list(zip(*zipped))
Esempio n. 5
0
    def average_image(self, flux, spin, rhigh, nprocs=N_PROCS):
        """Return the "average" image of a run, summing all Stokes of all images and dividing
        This is not good for polarized images: the average will not be representative
        """
        def merge(n, other, output):
            output += other

        imgnames = self.get_all_fnames(flux, spin, rhigh)
        image = read_image(imgnames[0])
        iter_parallel(read_image, merge, imgnames[1:], image, nprocs=nprocs)
        image /= len(imgnames)

        return image
Esempio n. 6
0
 def run_on_serial(self, flux, spin, rhigh, fn):
     results = []
     for imname in self.get_all_fnames(flux, spin, rhigh):
         results.append(fn(read_image(imname)))
     return results
Esempio n. 7
0
 def get_image(self, flux, spin, rhigh, nimg, **kwargs):
     imgname = self.get_fname(flux, spin, rhigh, nimg, **kwargs)
     if imgname is None:
         return None
     else:
         return read_image(imgname)
Esempio n. 8
0
 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""

# Mimic the classic plot_pol.py in ipole
# This is now an automatic report, since it's useful

from imtools.io import read_image
from imtools.reports import plot_pol

import sys

if __name__ == "__main__":

  for fname in sys.argv[1:]:

    if fname[-3:] != ".h5": continue
    print("plotting {0:s}".format(fname))

    image = read_image(sys.argv[1])

    # create plots
    plot_pol(image, fname.replace(".h5",".png"))