How to use sunpy - 10 common examples

To help you get started, we’ve selected a few sunpy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sunpy / ndcube / spectra / spectrogram.py View on Github external
def time_to_x(self, time):
        """ Return x-coordinate in spectrogram that corresponds to the
        passed datetime value.

        Parameters
        ----------
        time : parse_time compatible
            Datetime to find the x coordinate for.
        """
        # This is impossible for frequencies because that mapping
        # is not injective.
        time = parse_time(time)
        diff = time - self.start
        diff_s = SECONDS_PER_DAY * diff.days + diff.seconds
        result = diff_s // self.t_delt
        if 0 <= result <= self.shape[1]:
            return result
        raise ValueError("Out of range.")
github mbobra / calculating-spaceweather-keywords / calculate_swx_fits.py View on Github external
sys.exit(1)

    try:
        conf_disambig_map = sunpy.map.Map(file_conf_disambig)
    except:
        print("Could not open the conf_disambig fits file")
        sys.exit(1)

    try:
        bitmap_map = sunpy.map.Map(file_bitmap)
    except:
        print("Could not open the bitmap fits file")
        sys.exit(1)

    try:
        los_map = sunpy.map.Map(file_los)
    except:
        print("Could not open the LoS fits file")
        sys.exit(1)
        
    # get metadata
    header = bz.meta
    
    # get array data
    bz                = bz_map.data
    by                = by_map.data
    bx_map            = bx_map.data
    bz_err_map        = bz_err_map.data
    by_err_map        = by_err_map.data
    bx_err_map        = bx_err_map.data
    conf_disambig_map = conf_disambig_map.data
    bitmap_map        = bitmap_map.data
github mbobra / calculating-spaceweather-keywords / calculate_swx_fits.py View on Github external
sys.exit(1)

    try:
        bz_err_map = sunpy.map.Map(file_bz_err)
    except:
        print("Could not open the bz_err fits file")
        sys.exit(1)

    try:
        by_err_map = sunpy.map.Map(file_by_err)
    except:
        print("Could not open the by_err fits file")
        sys.exit(1)

    try:
        bx_err_map = sunpy.map.Map(file_bx_err)
    except:
        print("Could not open the bx_err fits file")
        sys.exit(1)

    try:
        conf_disambig_map = sunpy.map.Map(file_conf_disambig)
    except:
        print("Could not open the conf_disambig fits file")
        sys.exit(1)

    try:
        bitmap_map = sunpy.map.Map(file_bitmap)
    except:
        print("Could not open the bitmap fits file")
        sys.exit(1)
github mbobra / calculating-spaceweather-keywords / calculate_swx_fits.py View on Github external
def get_data(file_bz, file_by, file_bx, file_bz_err, file_by_err, file_bx_err, file_conf_disambig, file_bitmap, file_los):

    """function: get_data

    This function reads the appropriate data and metadata.
    """
    
    try:
        bz_map = sunpy.map.Map(file_bz)
    except:
        print("Could not open the bz fits file")
        sys.exit(1)

    try:
        by_map = sunpy.map.Map(file_by)
    except:
        print("Could not open the by fits file")
        sys.exit(1)

    try:
        bx_map = sunpy.map.Map(file_bx)
    except:
        print("Could not open the bx fits file")
        sys.exit(1)
github mbobra / calculating-spaceweather-keywords / calculate_swx_fits.py View on Github external
sys.exit(1)

    try:
        by_err_map = sunpy.map.Map(file_by_err)
    except:
        print("Could not open the by_err fits file")
        sys.exit(1)

    try:
        bx_err_map = sunpy.map.Map(file_bx_err)
    except:
        print("Could not open the bx_err fits file")
        sys.exit(1)

    try:
        conf_disambig_map = sunpy.map.Map(file_conf_disambig)
    except:
        print("Could not open the conf_disambig fits file")
        sys.exit(1)

    try:
        bitmap_map = sunpy.map.Map(file_bitmap)
    except:
        print("Could not open the bitmap fits file")
        sys.exit(1)

    try:
        los_map = sunpy.map.Map(file_los)
    except:
        print("Could not open the LoS fits file")
        sys.exit(1)
github mbobra / calculating-spaceweather-keywords / calculate_swx_fits.py View on Github external
sys.exit(1)

    try:
        by_map = sunpy.map.Map(file_by)
    except:
        print("Could not open the by fits file")
        sys.exit(1)

    try:
        bx_map = sunpy.map.Map(file_bx)
    except:
        print("Could not open the bx fits file")
        sys.exit(1)

    try:
        bz_err_map = sunpy.map.Map(file_bz_err)
    except:
        print("Could not open the bz_err fits file")
        sys.exit(1)

    try:
        by_err_map = sunpy.map.Map(file_by_err)
    except:
        print("Could not open the by_err fits file")
        sys.exit(1)

    try:
        bx_err_map = sunpy.map.Map(file_bx_err)
    except:
        print("Could not open the bx_err fits file")
        sys.exit(1)
github mbobra / calculating-spaceweather-keywords / calculate_swx_fits.py View on Github external
sys.exit(1)

    try:
        bx_map = sunpy.map.Map(file_bx)
    except:
        print("Could not open the bx fits file")
        sys.exit(1)

    try:
        bz_err_map = sunpy.map.Map(file_bz_err)
    except:
        print("Could not open the bz_err fits file")
        sys.exit(1)

    try:
        by_err_map = sunpy.map.Map(file_by_err)
    except:
        print("Could not open the by_err fits file")
        sys.exit(1)

    try:
        bx_err_map = sunpy.map.Map(file_bx_err)
    except:
        print("Could not open the bx_err fits file")
        sys.exit(1)

    try:
        conf_disambig_map = sunpy.map.Map(file_conf_disambig)
    except:
        print("Could not open the conf_disambig fits file")
        sys.exit(1)
github sunpy / ndcube / spectra / spectrogram.py View on Github external
Parameters
        ----------
        start : None or datetime or parse_time compatible string or time string
            Start time of the part of the spectrogram that is returned. If the
            measurement only spans over one day, a colon separated string
            representing the time can be passed.
        end : None or datetime or parse_time compatible string or time string
            See start.
        """
        if start is not None:
            try:
                start = parse_time(start)
            except ValueError:
                # XXX: We could do better than that.
                if get_day(self.start) != get_day(self.end):
                    raise TypeError(
                        "Time ambiguous because data spans over more than one day"
                    )
                start = datetime.datetime(
                    self.start.year, self.start.month, self.start.day,
                    *map(int, start.split(":"))
                )
            start = self.time_to_x(start)
        if end is not None:
            try:
                end = parse_time(end)
            except ValueError:
                if get_day(self.start) != get_day(self.end):
                    raise TypeError(
                        "Time ambiguous because data spans over more than one day"
                    )
github sunpy / ndcube / spectra / spectrogram.py View on Github external
try:
                start = parse_time(start)
            except ValueError:
                # XXX: We could do better than that.
                if get_day(self.start) != get_day(self.end):
                    raise TypeError(
                        "Time ambiguous because data spans over more than one day"
                    )
                start = datetime.datetime(
                    self.start.year, self.start.month, self.start.day,
                    *map(int, start.split(":"))
                )
            start = self.time_to_x(start)
        if end is not None:
            try:
                end = parse_time(end)
            except ValueError:
                if get_day(self.start) != get_day(self.end):
                    raise TypeError(
                        "Time ambiguous because data spans over more than one day"
                    )
                end = datetime.datetime(
                    self.start.year, self.start.month, self.start.day,
                    *map(int, end.split(":"))
                )
            end = self.time_to_x(end)
        return self[:, start:end]
github sunpy / ndcube / spectra / spectrogram.py View on Github external
def in_interval(self, start=None, end=None):
        """ Return part of spectrogram that lies in [start, end).

        Parameters
        ----------
        start : None or datetime or parse_time compatible string or time string
            Start time of the part of the spectrogram that is returned. If the
            measurement only spans over one day, a colon separated string
            representing the time can be passed.
        end : None or datetime or parse_time compatible string or time string
            See start.
        """
        if start is not None:
            try:
                start = parse_time(start)
            except ValueError:
                # XXX: We could do better than that.
                if get_day(self.start) != get_day(self.end):
                    raise TypeError(
                        "Time ambiguous because data spans over more than one day"
                    )
                start = datetime.datetime(
                    self.start.year, self.start.month, self.start.day,
                    *map(int, start.split(":"))
                )
            start = self.time_to_x(start)
        if end is not None:
            try:
                end = parse_time(end)
            except ValueError:
                if get_day(self.start) != get_day(self.end):