Skip to content

Commit

Permalink
Fixed some bugs in Image Generation
Browse files Browse the repository at this point in the history
  • Loading branch information
racerxdl committed Mar 9, 2019
1 parent 8a47f87 commit a54977f
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 16 deletions.
12 changes: 11 additions & 1 deletion ImageProcessor/GOESABI.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/opensatelliteproject/SatHelperApp/Tools"
"github.com/opensatelliteproject/SatHelperApp/XRIT"
"github.com/opensatelliteproject/SatHelperApp/XRIT/Geo"
"io/ioutil"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -80,7 +81,7 @@ func ProcessFalseColor(ip *ImageProcessor, xh *XRIT.Header, filename string) {

visFilename := strings.Replace(filename, mdch, vismdch, -1)
irFilename := strings.Replace(filename, mdch, irmdch, -1)
fsclrFileName := strings.Replace(filename, mdch, md+"99", -1)
fsclrFileName := strings.Replace(filename, mdch, md+"C99", -1)
fsclrFileName = strings.Replace(fsclrFileName, "-nomap", "", -1)

if !Tools.Exists(visFilename) || !Tools.Exists(irFilename) {
Expand Down Expand Up @@ -141,6 +142,14 @@ func ProcessFalseColor(ip *ImageProcessor, xh *XRIT.Header, filename string) {
SLog.Error("Cannot crate GeoConverter: %s", err)
}

xh.NOAASpecificHeader.ProductSubID = 99 // False Color

metaName := strings.Replace(fsclrFileName, ".png", ".json", -1)
err = ioutil.WriteFile(metaName, []byte(xh.ToJSON()), os.ModePerm)
if err != nil {
SLog.Error("Cannot write Meta file %s: %s", metaName, err)
}

err = ImageTools.SaveImage(fsclrFileName, fsclr)
if err != nil {
SLog.Error("Error saving false color image to %s: %s", fsclrFileName, err)
Expand All @@ -152,6 +161,7 @@ func ProcessFalseColor(ip *ImageProcessor, xh *XRIT.Header, filename string) {
if err != nil {
SLog.Error("Error erasing %s: %s", visFilename, err)
}

SLog.Debug("Removing %s", irFilename)
err = os.Remove(irFilename)
if err != nil {
Expand Down
12 changes: 6 additions & 6 deletions ImageProcessor/ImageTools/MultiSegmentDump.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ func DumpMultiSegment(msi *Structs.MultiSegmentImage, mapDrawer *MapDrawer.MapDr
return err, ""
}

metaName := path.Join(folder, msi.Name+".json")
err = ioutil.WriteFile(metaName, []byte(msi.FirstSegmentHeader.ToJSON()), os.ModePerm)
if err != nil {
SLog.Error("Cannot write Meta file %s: %s", metaName, err)
}

if mapDrawer != nil {
if saveNoMap && !Tools.Exists(newFilenameNoMap) {
SLog.Debug("Saving No Map Image: %s", newFilenameNoMap)
Expand Down Expand Up @@ -164,11 +170,5 @@ func DumpMultiSegment(msi *Structs.MultiSegmentImage, mapDrawer *MapDrawer.MapDr
return err, ""
}

metaName := path.Join(folder, msi.Name+".json")
err = ioutil.WriteFile(metaName, []byte(msi.FirstSegmentHeader.ToJSON()), os.ModePerm)
if err != nil {
SLog.Error("Cannot write Meta file %s: %s", metaName, err)
}

return nil, newFilename
}
2 changes: 1 addition & 1 deletion ImageProcessor/Structs/MultiSegmentImage.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (msi *MultiSegmentImage) PutSegment(filename string, xh *XRIT.Header) {
msi.Files = append(msi.Files, filename)
}

if (xh.SegmentIdentificationHeader.Sequence == 0 || xh.SegmentIdentificationHeader.Sequence == 1) && msi.FirstSegmentHeader == nil {
if msi.FirstSegmentHeader == nil || xh.SegmentIdentificationHeader.Sequence < msi.FirstSegmentHeader.SegmentIdentificationHeader.Sequence {
msi.FirstSegmentHeader = xh
msi.FirstSegmentFilename = filename
}
Expand Down
18 changes: 18 additions & 0 deletions Tools/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,21 @@ func Exists(name string) bool {
}
return true
}

func IsDir(name string) bool {
s, err := os.Stat(name)
if err != nil {
return false
}

return s.IsDir()
}

func IsFile(name string) bool {
s, err := os.Stat(name)
if err != nil {
return false
}

return !s.IsDir()
}
2 changes: 1 addition & 1 deletion XRIT/XRITHeader.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type Header struct {
TimestampHeader *Structs.TimestampRecord
UnknownHeaders []*Structs.UnknownHeader

AllHeaders []Structs.BaseRecord
AllHeaders []Structs.BaseRecord `json:"-"`
}

func (xh *Header) Product() *PacketData.NOAAProduct {
Expand Down
46 changes: 39 additions & 7 deletions cmd/MultiSegmentDump/multiSegmentDump.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,35 @@ import (
"github.com/opensatelliteproject/SatHelperApp"
"github.com/opensatelliteproject/SatHelperApp/ImageProcessor"
"github.com/opensatelliteproject/SatHelperApp/Logger"
"github.com/opensatelliteproject/SatHelperApp/Tools"
"github.com/opensatelliteproject/SatHelperApp/XRIT"
"gopkg.in/alecthomas/kingpin.v2"
"io/ioutil"
"path"
"strings"
)

func ProcessFile(filename string, ip *ImageProcessor.ImageProcessor) {

SLog.Debug("Processing %s", filename)
xh, err := XRIT.ParseFile(filename)

if err != nil {
SLog.Error("Error processing file %s: %s", filename, err)
return
}

ImageProcessor.ProcessGOESABI(ip, filename, xh)
}

func main() {
kingpin.Version(SatHelperApp.GetVersion())

reproject := kingpin.Flag("linear", "Reproject to linear").Bool()
drawMap := kingpin.Flag("drawMap", "Draw Map Overlay").Bool()
falseColor := kingpin.Flag("falsecolor", "Generate False Color Image").Bool()
files := kingpin.Arg("filenames", "File names to dump image").Required().ExistingFiles()
purge := kingpin.Flag("purge", "Purge LRIT files after generating").Bool()
files := kingpin.Arg("filenames", "File names to dump image").Required().ExistingFilesOrDirs()

kingpin.Parse()

Expand All @@ -23,15 +41,29 @@ func main() {
ip.SetReproject(*reproject)
ip.SetFalseColor(*falseColor)

ImageProcessor.SetPurgeFiles(*purge)

for _, v := range *files {
SLog.Debug("Processing %s", v)
xh, err := XRIT.ParseFile(v)
if Tools.IsDir(v) {
ffiles, err := ioutil.ReadDir(v)
if err != nil {
SLog.Error("Cannot read folder %s: %s", v, err)
continue
}

if err != nil {
SLog.Error("Error processing file %s: %s", v, err)
for _, v2 := range ffiles {
if !v2.IsDir() && strings.Contains(v2.Name(), ".lrit") {
ProcessFile(path.Join(v, v2.Name()), ip)
} else {
SLog.Debug("Skipping file %s, does not end with .lrit", v2.Name())
}
}
continue
}

ImageProcessor.ProcessGOESABI(ip, v, xh)
if strings.Contains(v, ".lrit") {
ProcessFile(v, ip)
} else {
SLog.Debug("Skipping file %s, does not end with .lrit", v)
}
}
}

0 comments on commit a54977f

Please sign in to comment.