slider

package
v0.5.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 22, 2025 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Overview

Package slider provides functionality for downloading and animating weather satellite imagery.

Index

Constants

View Source
const ProductsJSURL = "https://rammb-slider.cira.colostate.edu/js/define-products---rammb-slider.js"

ProductsJSURL is the address to download the latest product data from.

View Source
const TileImageURI = "https://rammb-slider.cira.colostate.edu/data/imagery/%s/%s---%s/%s/%s/%02d/%03d_%03d.png"

TileImageURI is the request address for images. It contains the following fields:

  • Date
  • Satellite
  • Sector
  • Product
  • Image Timestamp
  • Zoom Level
  • Tile Y-Position
  • Tile X-Position

Example: https://rammb-slider.cira.colostate.edu/data/imagery/20210404/jpss---northern_hemisphere/cira_geocolor/20210404215820/04/011_007.png

Variables

View Source
var AvailableDatesURI = "https://rammb-slider.cira.colostate.edu/data/json/%s/%s/%s/available_dates.json"

AvailableDatesURI is the address for retrieving the latest dates for available images.

  • Satellite
  • Sector
  • Product

Example: https://rammb-slider.cira.colostate.edu/data/json/jpss/northern_hemisphere/cira_geocolor/available_dates.json

View Source
var BackupProductsJS []byte

BackupProductsJS is a copy of the define-products.js for use in the event the file can't be retrieved from the SLIDER server.

View Source
var LatestTimes5760URI = "https://rammb-slider.cira.colostate.edu/data/json/%s/%s/%s/latest_times_5760.json"

LatestTimes5760URI is the same as LatestTimesURI but with more times.

View Source
var LatestTimesURI = "https://rammb-slider.cira.colostate.edu/data/json/%s/%s/%s/latest_times.json"

LatestTimesURI is the address for retrieving the latest times for available images.

  • Satellite
  • Sector
  • Product

Example: https://rammb-slider.cira.colostate.edu/data/json/jpss/northern_hemisphere/cira_geocolor/latest_times.json

View Source
var NoProductDownload = false

NoProductDownload will disable downloading the latest products from SLIDER.

View Source
var SectorCropTable = map[string]map[string]*CropSettings{
	"goes-16": {
		"conus": {RatioX: 1, RatioY: 0.6},
	},
	"goes-17": {
		"conus": {RatioX: 1, RatioY: 0.6},
	},
}

SectorCropTable includes the builtin crop settings for satellites and sectors.

Functions

func AnimateGIF added in v0.3.0

func AnimateGIF(images []image.Image, delay int, style LoopStyle) (*gif.GIF, error)

AnimateGIF animates the supplied images into a GIF image. This will convert RGB images to a 256-color palette due to the GIF color limit of 256. This will likely result in some down-sampling of your image colors.

func AnimatePNG added in v0.5.0

func AnimatePNG(images []image.Image, delay int, style LoopStyle) (*apng.APNG, error)

AnimatePNG animates the supplied images into a PNG image.

func AvailableDates

func AvailableDates(satellite *Satellite, sector *Sector, product *Product) ([]int, error)

AvailableDates returns the list of dates that SLIDER has available data for as ints in the form of YYYYMMDD.

func CreateLoop

func CreateLoop(opts *LoopOptions) error

CreateLoop creates a new loop with the options specified in the provided LoopOptions.

func DownloadImage

func DownloadImage(uri string) (image.Image, error)

DownloadImage downloads an individual image file.

func DownloadProductsJS added in v0.5.0

func DownloadProductsJS() ([]byte, error)

DownloadProductsJS will download and return the bytes for the define-products.js file.

func ImageTileURL added in v0.5.0

func ImageTileURL(request *TileImageRequest) string

ImageTileURL returns the full request URL for an image tile.

func LatestTimes

func LatestTimes(satellite *Satellite, sector *Sector, product *Product, count int) ([]int, error)

LatestTimes returns the list of timestamps that SLIDER has available data for as ints in the form of YYYYMMDDhhmmss.

func SaveGIF

func SaveGIF(output string, img *gif.GIF) (string, error)

SaveGIF encodes the GIF data into a .gif file. The .gif extension will be added automatically. If a file with the same name exists an incrementing number will be appended to the end of the file name.

func SavePNG added in v0.5.0

func SavePNG(output string, img *apng.APNG) (string, error)

SavePNG encodes the PNG data into a .png file. The .png extension will be added automatically. If a file with the same name exists an incrementing number will be appended to the end of the file name.

func SelectTimestamps

func SelectTimestamps(times []int, opts *LoopOptions) ([]time.Time, error)

SelectTimestamps selects the desired timestamps from the list of int timestamps returned by SLIDER. Timestamps are returned in sorted chronological order.

func URLToFilePath added in v0.5.0

func URLToFilePath(urlString string) (string, error)

URLToFilePath converts a URL to a file system path by removing the URL scheme (e.g. https://) and converting the URL path to a file system directory path. For example 'https://example.com/a/b/c/d' will return 'example.com/a/b/c/d'

Types

type CropSettings added in v0.5.0

type CropSettings struct {
	RatioX float32
	RatioY float32
}

CropSettings contains the crop ratio settings for a single satellite sector.

func GetCropSettings added in v0.5.0

func GetCropSettings(satelliteID, sectorID string) *CropSettings

GetCropSettings will return the crop settings for the specified satellite and sector if they exist, otherwise nil.

type FileFormat added in v0.5.0

type FileFormat int

FileFormat is an output file format type.

const (
	// GIF is the .gif file format.
	GIF FileFormat = iota
	// PNG is the .png file format.
	PNG
)

type ImageCache added in v0.5.0

type ImageCache struct {
	// Dir is the directory to store the cache in.
	Dir string
}

ImageCache is a file system cache for image files.

func (*ImageCache) Delete added in v0.5.0

func (c *ImageCache) Delete(filePath string) error

Delete will delete the image in Dir at filePath. No error will be returned if the file doesn't exist.

func (*ImageCache) Get added in v0.5.0

func (c *ImageCache) Get(filePath string) (image.Image, error)

Get will return the image stored in Dir at filePath or nil if that filePath doesn't exist.

func (*ImageCache) Write added in v0.5.0

func (c *ImageCache) Write(filePath string, img image.Image) error

Write will store an image at the file path. Write will overwrite any existing files and create missing paths or directories.

type LoopOptions

type LoopOptions struct {
	// AllowStaleImages allows imagery that is over one year old to be included in animations. Disallowing this old
	// imagery by default helps to prevent old images from being accidentally included in loops.
	AllowStaleImages bool
	// Angle is the number of degrees to rotate the image.
	Angle float64
	// BeginTime is the desired capture time of the first image in the loop.
	BeginTime time.Time
	// CacheDirectory is the directory to cache downloaded images in. Caching will only happen if a directory is
	// supplied here.
	CacheDirectory string
	// Crop is the area to crop the animation to.
	Crop *image.Rectangle
	// EndTime is the desired capture time of the last image in the loop.
	EndTime time.Time
	// FileFormat is the output file format of the animation.
	FileFormat FileFormat
	// LoopStyle is the animation style of the output animation.
	Loop LoopStyle
	// NumberOfImages is the number of frames in the output animation.
	NumberOfImages int
	// OutputDirectory is the directory to save output animations in.
	OutputDirectory string
	// Product is the product to request imagery for.
	Product *Product
	// Satellite is the satellite to request imagery from.
	Satellite *Satellite
	// Sector is the sector to request imagery for.
	Sector *Sector
	// Speed is the interval between frames. A higher number increases the delay between frames.
	Speed int
	// TimeStep is the interval between image capture times in minutes.
	TimeStep int
	// ZoomLevel is the zoom level to request imagery for. Increasing ZoomLevel increases the output animation
	// resolution and therefore filesize.
	ZoomLevel int
	// contains filtered or unexported fields
}

LoopOptions are the config options used to create a new loop.

func LoopOptsFromURL added in v0.3.0

func LoopOptsFromURL(uri string) (*LoopOptions, error)

LoopOptsFromURL creates a new set of loop options from a SLIDER URL starting with https://rammb-slider.cira.colostate.edu/?...

type LoopStyle

type LoopStyle int

LoopStyle is the animation direction of the images, for example forward or backward.

const (
	// ForwardLoop animates loops with images in chronological order.
	ForwardLoop LoopStyle = iota
	// ReverseLoop animates loops in reverse order from ForwardLoop
	ReverseLoop
	// RockLoop animates the loop forward first then in reverse. Note that using the RockLoop style will cause
	// animation file sizes to be nearly twice the size has a forward and reverse loops due there being twice the
	// number of frames.
	RockLoop
)

type Product

type Product struct {
	// ColorTableName is the name of the color table legend
	ColorTableName string `json:"color_table_name"`
	// ProductTitle is the friendly human-readable name for this product
	ProductTitle string `json:"product_title"`
	// ProductDescription is a long description of this product
	ProductDescription string `json:"product_description"`
	// Resolution is the minimum resolution for imagery for this product.
	Resolution string `json:"resolution"`
	// Value is the string sent to SLIDER for this product when requesting images
	Value string
	// ZoomLevelAdjust is the number of zoom levels to remove from available zoom levels for this product.
	ZoomLevelAdjust int `json:"zoom_level_adjust"`
}

Product contains all of the information for a single product captured by a weather satellite.

func (*Product) ID

func (p *Product) ID() string

ID is the shorthand string used on the command-line and in the config for this product

type ProductDefaults added in v0.5.0

type ProductDefaults struct {
	StartingOpacity      float64           `json:"starting_opacity"`
	ZoomLevelAdjust      int               `json:"zoom_level_adjust"`
	MaxZoomLevel         int               `json:"max_zoom_level"`
	MinutesBetweenImages float64           `json:"minutes_between_images"`
	Colors               map[string]string `json:"colors"`
	Maps                 map[string]string `json:"maps"`
}

ProductDefaults contains the default settings for satellites, sectors, and products.

type ProductInventory added in v0.5.0

type ProductInventory struct {
	NumberOfImagesOptions []int                 `json:"number_of_images_options"`
	TimeStepOptions       []int                 `json:"time_step_options"`
	DefaultSatellite      string                `json:"default_satellite"`
	Defaults              *ProductDefaults      `json:"defaults"`
	Colors                map[string]string     `json:"colors"`
	UniqueColors          map[string]string     `json:"unique_colors"`
	IgnoreWhiteMapsOnly   []string              `json:"ignore_white_maps_only"`
	Satellites            map[string]*Satellite `json:"satellites"`
}

ProductInventory contains all of the product information for SLIDER.

func GetProductInventory added in v0.5.0

func GetProductInventory() (*ProductInventory, error)

GetProductInventory will download the latest products from SLIDER or return the builtin fail-safe product inventory if the latest products cannot be downloaded.

func ParseProductsJS added in v0.5.0

func ParseProductsJS(data []byte) (*ProductInventory, error)

ParseProductsJS will parse the define-products.js file which is available on the SLIDER server. ParseProductsJS can also parse the BackupProductsJS data in the event that the file cannot be retrieved from the SLIDER server.

type ProductNavigation added in v0.5.0

type ProductNavigation struct {
	Up    *ProductNavigationDirection `json:"up"`
	Right *ProductNavigationDirection `json:"right"`
	Left  *ProductNavigationDirection `json:"left"`
	Down  *ProductNavigationDirection `json:"down"`
}

ProductNavigation contains details for navigating between products in the SLIDER UI.

type ProductNavigationDirection added in v0.5.0

type ProductNavigationDirection struct {
	Satellite string `json:"satellite"`
	Sector    string `json:"sector"`
}

ProductNavigationDirection contains details for navigating between products in the SLIDER UI.

type Satellite

type Satellite struct {
	// Defaults contains default settings for products on this satellite
	Defaults *ProductDefaults `json:"defaults"`
	// DefaultSector is the default sector selected by SLIDER
	DefaultSector string `json:"default_sector"`
	// ImageryResolutions is the list of imagery resolutions used by SLIDER. Using ZoomLevels() is preferred to
	// to using ImageryResolutions.
	ImageryResolutions map[string]string `json:"imagery_resolutions"`
	// Products contains a list of available products for this satellite keyed by ID.
	Products map[string]*Product
	// SatelliteTitle is the friendly human-readable name for this satellite
	SatelliteTitle string `json:"satellite_title"`
	// Sectors contains a list of available sectors for this Satellite keyed by ID.
	Sectors map[string]*Sector
	// Value is the string sent to SLIDER for this satellite when requesting images
	Value string
}

Satellite contains all of the information for a single weather satellite and all of it's sectors and products.

func (*Satellite) ID

func (s *Satellite) ID() string

ID is the value sent in the request to SLIDER

func (*Satellite) ValidProduct added in v0.3.0

func (s *Satellite) ValidProduct(product *Product) bool

ValidProduct returns true if the provided product is available for this satellite.

func (*Satellite) ValidSector

func (s *Satellite) ValidSector(sector *Sector) bool

ValidSector returns true if the provided sector is available for this satellite.

func (*Satellite) ValidSectorProduct

func (s *Satellite) ValidSectorProduct(sector *Sector, product *Product) bool

ValidSectorProduct returns true if the provided sector and products are available for this satellite AND the product is not included in the sector's MissingProducts list. Generally this is the method that should be used to validate that sectors and products are available for the satellite.

func (*Satellite) ZoomLevels added in v0.3.0

func (s *Satellite) ZoomLevels() []*Zoom

ZoomLevels is the list of available zoom levels or resolutions for this satellite

type Sector

type Sector struct {
	// CropRatioX is the amount to crop the image on the X-axis from 0 to 1
	CropRatioX float32
	// CropRatioY is the amount to crop the image on the X-axis from 0 to 1
	CropRatioY float32
	// Defaults contains the default products settings for this sector
	Defaults *ProductDefaults `json:"defaults"`
	// DefaultProduct is the default product selected by SLIDER for this sector.
	DefaultProduct string `json:"default_product"`
	// MaxZoomLevel is the max zoom level or resolution that this is available for this sector.
	MaxZoomLevel int `json:"max_zoom_level"`
	// MissingProducts is a list of satellite products that are unavailable for this sector (typically due to the lack
	// of data availability).
	MissingProducts []string `json:"missing_products"`
	// Navigation contains the navigation configuration for the SLIDER UI
	Navigation *ProductNavigation `json:"navigation"`
	// SectorTitle is a longer string with a human-readable name for the sector
	SectorTitle string `json:"sector_title"`
	// TileSize is the size of each tile in pixels
	TileSize int `json:"tile_size"`
	// Value is the string for this sector sent to SLIDER when requesting images
	Value string
}

Sector contains all of the information for a single sector captured by a weather satellite.

func (*Sector) ID

func (s *Sector) ID() string

ID is the shorthand string used on the command-line and in the config

func (*Sector) ProductMissing added in v0.3.0

func (s *Sector) ProductMissing(product *Product) bool

ProductMissing returns true if the provided product is present in the MissingProducts list.

func (*Sector) XSize added in v0.3.0

func (s *Sector) XSize(zoom *Zoom) int

XSize is the number of pixels along the X-axis after the image is cropped

func (*Sector) YSize added in v0.3.0

func (s *Sector) YSize(zoom *Zoom) int

YSize is the number of pixels along the Y-axis after the image is cropped

type TileImageRequest added in v0.5.0

type TileImageRequest struct {
	Date           string
	Satellite      string
	Sector         string
	Product        string
	ImageTimestamp string
	ZoomLevel      int
	TileXPosition  int
	TileYPosition  int
}

TileImageRequest contains the parameters required to request an individual image tile from SLIDER.

type Zoom

type Zoom struct {
	Level int
	Scale string
}

Zoom contains information for a single zoom level or resolution.

func (*Zoom) NumTiles added in v0.5.0

func (z *Zoom) NumTiles() int

NumTiles is the number of tiles along each axis of the image. Tile X/Y axis origin (0,0) is the upper-left-hand corner of the image.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL