Skip to content

Commit

Permalink
Add global attributes to IODA conversion output files (#686)
Browse files Browse the repository at this point in the history
* initial additions for global attributes

* added string global attributes

* cleanup, extra attribute

---------

Co-authored-by: Guillaume Vernieres <[email protected]>
Co-authored-by: Cory Martin <[email protected]>
  • Loading branch information
3 people authored Oct 26, 2023
1 parent 2b06747 commit 08e0c4a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 15 deletions.
14 changes: 13 additions & 1 deletion utils/obsproc/NetCDFToIodaConverter.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <iostream>
#include <map>
#include <string>
#include <vector>

Expand Down Expand Up @@ -43,6 +44,9 @@ namespace gdasapp {
Eigen::ArrayXXf intMetadata_; // Optional array of integer metadata
std::vector<std::string> intMetadataName_; // String descriptor of the integer metadata

// Optional global attributes
std::map<std::string, std::string> strGlobalAttr_;

// Constructor
explicit IodaVars(const int nobs = 0,
const std::vector<std::string> fmnames = {},
Expand Down Expand Up @@ -233,6 +237,14 @@ namespace gdasapp {
ogrp.vars.createWithScales<int>("PreQC/"+variable_,
{ogrp.vars["Location"]}, int_params);

// add input filenames to IODA file global attributes
ogrp.atts.add<std::string>("obs_source_files", inputFilenames_);

// add global attributes collected from the specific converter
for (const auto& globalAttr : iodaVars.strGlobalAttr_) {
ogrp.atts.add<std::string>(globalAttr.first , globalAttr.second);
}

// Create the optional IODA integer metadata
ioda::Variable tmpIntMeta;
int count = 0;
Expand All @@ -254,7 +266,7 @@ namespace gdasapp {
}

// Write obs info to group
oops::Log::info() << "Writting ioda file" << std::endl;
oops::Log::info() << "Writing ioda file" << std::endl;
iodaLon.writeWithEigenRegular(iodaVarsAll.longitude_);
iodaLat.writeWithEigenRegular(iodaVarsAll.latitude_);
iodaDatetime.writeWithEigenRegular(iodaVarsAll.datetime_);
Expand Down
36 changes: 22 additions & 14 deletions utils/obsproc/Rads2Ioda.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,31 @@ namespace gdasapp {
ncFile.getVar("time_mjd").getVar(datetime);
iodaVars.referenceDate_ = "seconds since 1858-11-17T00:00:00Z";

std::map<std::string, int> altimeterMap;
// TODO(All): This is incomplete, add missions to the list below
altimeterMap["SNTNL-3A"] = 1;
altimeterMap["SNTNL-3B"] = 2;
altimeterMap["JASON-1"] = 3;
altimeterMap["JASON-2"] = 4;
altimeterMap["JASON-3"] = 5;
altimeterMap["CRYOSAT2"] = 6;
altimeterMap["SARAL"] = 7;

// Read optional integer metadata "mission"
std::string mission_name;
ncFile.getAtt("mission_name").getValues(mission_name);
int mission_index = altimeterMissions(mission_name); // mission name mapped to integer
int mission_index = altimeterMap[mission_name]; // mission name mapped to integer

// convert mission map to string to add to global attributes
std::stringstream mapStr;
for (const auto& mapEntry : altimeterMap) {
mapStr << mapEntry.first << " = " << mapEntry.second << " ";
}
iodaVars.strGlobalAttr_["mission_index"] = mapStr.str();

std::string references;
ncFile.getAtt("references").getValues(references);
iodaVars.strGlobalAttr_["references"] = references;

// Read optional integer metadata "pass" and "cycle"
int pass[iodaVars.location_]; // NOLINT
Expand Down Expand Up @@ -96,18 +117,5 @@ namespace gdasapp {
}
return iodaVars;
};
int altimeterMissions(std::string missionName) {
std::map<std::string, int> altimeterMap;
// TODO(All): This is incomplete, add missions to the list below
// and add to global attribute
altimeterMap["SNTNL-3A"] = 1;
altimeterMap["SNTNL-3B"] = 2;
altimeterMap["JASON-1"] = 3;
altimeterMap["JASON-2"] = 4;
altimeterMap["JASON-3"] = 5;
altimeterMap["CRYOSAT2"] = 6;
altimeterMap["SARAL"] = 7;
return altimeterMap[missionName];
}
}; // class Rads2Ioda
} // namespace gdasapp

0 comments on commit 08e0c4a

Please sign in to comment.