-
Notifications
You must be signed in to change notification settings - Fork 50
Feature/rtofs in situ #1110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Feature/rtofs in situ #1110
Changes from 6 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
4335e71
added an empty test rtofsinsitu
givelberg 7d09684
Merge branch 'develop' into feature/RTOFSInSitu
givelberg 547f381
basic working code
givelberg f7fbda3
basic working code
givelberg 483430b
basic working code
givelberg 56b71c6
fixed almost all style issues
givelberg bc8cfa3
removed the rtofs dir/lib; everhthing is in one header file; passes t…
givelberg bc4474d
removed the rtofs dir/lib
givelberg 24a1882
removed the test (cause it uses binary file)
givelberg 967e8ca
Merge branch 'develop' into feature/RTOFSInSitu
guillaumevernieres 57dcca4
Merge branch 'develop' into feature/RTOFSInSitu
guillaumevernieres File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,25 @@ | ||
|
|
||
| add_subdirectory(rtofs) | ||
|
|
||
| # add_library(obsproc STATIC | ||
| # Ghrsst2Ioda.h | ||
| # IcecAmsr2Ioda.h | ||
| # NetCDFToIodaConverter.h | ||
| # Rads2Ioda.h | ||
| # RTOFSInSitu.h | ||
| # Smap2Ioda.h | ||
| # Smos2Ioda.h | ||
| # superob.h | ||
| # util.h | ||
| # Viirsaod2Ioda.h | ||
| # ) | ||
| # target_compile_features( | ||
| # onsproc | ||
| # PUBLIC cxx_std_17 | ||
| # ) | ||
| # target_link_libraries( | ||
| # obsproc | ||
| # PUBLIC oops ioda NetCDF::NetCDF_CXX | ||
| # ) | ||
|
|
||
| add_subdirectory(applications) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| #pragma once | ||
|
|
||
| #include <iostream> | ||
| #include <netcdf> // NOLINT (using C API) | ||
| #include <regex> | ||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| #include "eckit/config/LocalConfiguration.h" | ||
|
|
||
| #include <Eigen/Dense> // NOLINT | ||
|
|
||
| #include "ioda/Group.h" | ||
| #include "ioda/ObsGroup.h" | ||
|
|
||
| #include "NetCDFToIodaConverter.h" | ||
|
|
||
| #include "rtofs/RTOFSDataFile.h" | ||
| #include "rtofs/RTOFSOb.h" | ||
|
|
||
|
|
||
| namespace gdasapp | ||
| { | ||
|
|
||
|
|
||
| class RTOFSInSitu: | ||
| public NetCDFToIodaConverter | ||
| { | ||
| public: | ||
| explicit RTOFSInSitu( | ||
| const eckit::Configuration & fullConfig, | ||
| const eckit::mpi::Comm & comm): | ||
| NetCDFToIodaConverter(fullConfig, comm) | ||
| { | ||
| variable_ = "temperature"; | ||
|
guillaumevernieres marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| // Read binary file and populate iodaVars | ||
| gdasapp::obsproc::iodavars::IodaVars | ||
| providerToIodaVars(const std::string fileName) final | ||
| { | ||
| oops::Log::info() | ||
| << "Processing files provided by RTOFS" | ||
| << std::endl; | ||
|
|
||
| // Set the int metadata names | ||
| std::vector<std::string> intMetadataNames = {"temperature"}; | ||
|
|
||
| // Set the float metadata name | ||
| std::vector<std::string> floatMetadataNames = {}; | ||
|
|
||
| // read the file | ||
| oops::Log::info() | ||
| << "Processing file " | ||
| << fileName | ||
| << std::endl; | ||
|
|
||
| rtofs::RTOFSDataFile RTOFSFile(fileName); | ||
| int n = RTOFSFile.NumberOfObservations(); | ||
| rtofs::RTOFSOb & ob = RTOFSFile.observations(); | ||
|
|
||
| int NumberOfTemperatureValues = 0; | ||
| for (int i = 0; i < n; i ++) | ||
| NumberOfTemperatureValues += ob.lt[i]; | ||
|
|
||
| gdasapp::obsproc::iodavars::IodaVars iodaVars( | ||
| NumberOfTemperatureValues, | ||
| floatMetadataNames, | ||
| intMetadataNames); | ||
| iodaVars.referenceDate_ = "seconds since 1970-01-01T00:00:00Z"; | ||
|
|
||
| // debugging output: | ||
|
guillaumevernieres marked this conversation as resolved.
Outdated
|
||
| // std::string DataDirectory = | ||
| // "/home/edwardg/da/edwardg/global-workflow/sorc/gdas.cd/build/gdas-utils/test/obsproc/RTOFSdata"; | ||
| // ob.print(DataDirectory); | ||
|
|
||
| // oops::Log::debug() << "--- iodaVars.location_: " << iodaVars.location_ << std::endl; | ||
|
|
||
| int k = 0; | ||
| for (int i = 0; i < n; i ++) | ||
| for (int j = 0; j < ob.lt[i]; j ++) | ||
| { | ||
| iodaVars.longitude_(k) = ob.lon[i]; | ||
| iodaVars.latitude_(k) = ob.lat[i]; | ||
| iodaVars.obsVal_(k) = ob.tmp[i][j]; | ||
| iodaVars.obsError_(k) = ob.tmp_err[i][j]; | ||
| iodaVars.datetime_(k) = ob.dtg[i]; | ||
| // iodaVars.preQc_(k) = oneDimFlagsVal[i]; | ||
| // iodaVars.intMetadata_.row(k) << -999; | ||
|
|
||
| k++; | ||
| } | ||
|
|
||
| // basic test for iodaVars.trim | ||
| /* | ||
| Eigen::Array<bool, Eigen::Dynamic, 1> mask | ||
| = (iodaVars.obsVal_ > 0.0); | ||
| iodaVars.trim(mask); | ||
| */ | ||
|
|
||
|
guillaumevernieres marked this conversation as resolved.
|
||
|
|
||
| return iodaVars; | ||
| }; // providerToIodaVars | ||
| }; // class RTOFSInSitu | ||
|
|
||
|
|
||
| } // namespace gdasapp | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,16 @@ | ||
| list( APPEND gdasapp_provider2ioda_src_files | ||
| gdas_obsprovider2ioda.cc | ||
| gdas_obsprovider2ioda.h | ||
| ) | ||
| gdas_obsprovider2ioda.cc | ||
| gdas_obsprovider2ioda.h | ||
| ) | ||
|
|
||
| ecbuild_add_executable( TARGET gdas_obsprovider2ioda.x | ||
| SOURCES ${gdasapp_provider2ioda_src_files} ) | ||
|
|
||
| target_compile_features( gdas_obsprovider2ioda.x PUBLIC cxx_std_17) | ||
|
|
||
| target_link_libraries( gdas_obsprovider2ioda.x PUBLIC oops ioda NetCDF::NetCDF_CXX) | ||
|
|
||
| # message("CMAKE_SOURCE_DIR = ${CMAKE_SOURCE_DIR}") | ||
|
guillaumevernieres marked this conversation as resolved.
Outdated
|
||
| link_directories(${CMAKE_SOURCE_DIR}/rtofs) | ||
| target_link_libraries( gdas_obsprovider2ioda.x PRIVATE rtofs) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| set( | ||
| rtofs_src_files | ||
| RTOFSDataFile.h | ||
| RTOFSDataFile.cc | ||
| RTOFSOb.h | ||
| RTOFSOb.cc | ||
| util.cc | ||
| util.h | ||
| ) | ||
|
|
||
| list( | ||
| APPEND gdasapp_provider2ioda_src_files | ||
| ${rtofs_src_files} | ||
| ) | ||
|
|
||
|
|
||
| add_library(rtofs STATIC | ||
| ${rtofs_src_files} | ||
| ) | ||
|
|
||
| target_compile_features( | ||
| rtofs | ||
| PUBLIC cxx_std_17 | ||
| ) | ||
|
|
||
| # target_link_libraries( | ||
|
guillaumevernieres marked this conversation as resolved.
Outdated
|
||
| # rtofs | ||
| # PUBLIC oops ioda NetCDF::NetCDF_CXX | ||
| # ) | ||
|
|
||
|
|
||
| # ecbuild_add_executable( | ||
| # TARGET gdas_obsprovider2ioda.x | ||
| # SOURCES ${gdasapp_provider2ioda_src_files} | ||
| # ) | ||
|
|
||
| # target_compile_features( gdas_obsprovider2ioda.x PUBLIC cxx_std_17) | ||
| # target_link_libraries( gdas_obsprovider2ioda.x PUBLIC oops ioda NetCDF::NetCDF_CXX) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| Author: E. Givelberg | ||
| May 15, 2024 | ||
|
|
||
| The code in this rtofs directory reads a binary Fortran | ||
| file and generates a data object that can be ingested into ioda. | ||
|
|
||
| The fortran binary file consists of records, including additional | ||
| information that needs to be skipped. | ||
| There are typically 8 bytes to be skipped between 2 data arrays. | ||
| The read data is converted from the big endian to the host | ||
| format, which is little endian in linux. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| #include "RTOFSDataFile.h" | ||
|
|
||
| #include <ctime> | ||
|
|
||
| #include <iostream> | ||
| using std::cerr; | ||
| using std::endl; | ||
| using std::cout; | ||
| #include <iomanip> // std::get_time | ||
|
|
||
| #include <sstream> | ||
| #include <string> | ||
|
|
||
| #include "RTOFSOb.h" | ||
| #include "util.h" | ||
|
|
||
|
|
||
| namespace rtofs | ||
| { | ||
|
|
||
| typedef char char12[12]; | ||
| typedef char char7[7]; | ||
|
|
||
|
|
||
| std::time_t | ||
| SecondsSinceReferenceTime(char12 time) | ||
|
guillaumevernieres marked this conversation as resolved.
Outdated
|
||
| { | ||
| std::tm referenceTime = {}; | ||
| referenceTime.tm_year = 70; // 1970 | ||
| referenceTime.tm_mon = 0; // January (months are 0-based) | ||
| referenceTime.tm_mday = 1; // 1st day of the month | ||
| referenceTime.tm_hour = 0; | ||
| referenceTime.tm_min = 0; | ||
| referenceTime.tm_sec = 0; | ||
| std::time_t referenceTimestamp = std::mktime(&referenceTime); | ||
|
|
||
| std::tm t = {}; | ||
| std::istringstream ss(time); | ||
| ss >> std::get_time(&t, "%Y%m%d%H%M"); | ||
|
|
||
| std::time_t timestamp = std::mktime(&t); | ||
| return std::difftime(timestamp, referenceTimestamp); | ||
| } // SecondsSinceReferenceTime | ||
|
|
||
|
|
||
|
|
||
| RTOFSDataFile:: | ||
| RTOFSDataFile(std::string filename): | ||
| filename(filename) | ||
| { | ||
| if (!file_exists(filename)) | ||
| { | ||
| cerr << "File not found" << endl; | ||
| exit(1); | ||
| } | ||
|
|
||
|
|
||
| const char * fn = filename.c_str(); | ||
| f = fopen(fn, "rb"); | ||
| if (!f) | ||
| { | ||
| cerr << "Error opening file " << fn << endl; | ||
| exit(1); | ||
| } | ||
|
|
||
| read_file(); | ||
| } // RTOFSDataFile::RTOFSDataFile | ||
|
|
||
|
|
||
| void | ||
| RTOFSDataFile:: | ||
| read_file() | ||
| { | ||
| fseek(f, 4, SEEK_CUR); | ||
|
|
||
| int n_read = read_int(f); | ||
| int mx_lvl = read_int(f); | ||
| int vrsn = read_int(f); | ||
|
|
||
| ob = new RTOFSOb(n_read, mx_lvl, vrsn); | ||
| nobs = n_read; | ||
|
|
||
| ob->read(f); | ||
|
|
||
| skip8bytes(f); | ||
|
|
||
| char12 * ob_dtg = new char12[n_read]; | ||
| fread(ob_dtg, sizeof(char[12]), n_read, f); | ||
| for (int i = 0; i < n_read; i ++) | ||
| ob->dtg[i] = SecondsSinceReferenceTime(ob_dtg[i]); | ||
|
|
||
| skip8bytes(f); | ||
|
|
||
| char12 * ob_rct = new char12[n_read]; | ||
| fread(ob_rct, sizeof(char[12]), n_read, f); | ||
|
|
||
| skip8bytes(f); | ||
|
|
||
| char7 * ob_sgn = new char7[n_read]; | ||
| fread(ob_sgn, sizeof(char[7]), n_read, f); | ||
|
|
||
| if (vrsn == 2) | ||
| { | ||
| float ** glb_sal = new float * [n_read]; | ||
| for (int i = 0; i < n_read; i ++) | ||
| { | ||
| int k = ob->lt[i]; | ||
| glb_sal[i] = alloc_read_float_array(f, k); | ||
| } | ||
| } | ||
| } // read_file | ||
|
|
||
|
|
||
| } // namespace rtofs | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| #ifndef BUNDLE_GDAS_UTILS_OBSPROC_RTOFS_RTOFSDATAFILE_H_ | ||
| #define BUNDLE_GDAS_UTILS_OBSPROC_RTOFS_RTOFSDATAFILE_H_ | ||
|
|
||
| #include <string> | ||
|
|
||
|
|
||
| namespace rtofs | ||
| { | ||
|
|
||
| class RTOFSOb; | ||
|
|
||
| class RTOFSDataFile | ||
| { | ||
| public: | ||
| explicit RTOFSDataFile(std::string filename); | ||
| int NumberOfObservations() { return nobs; } | ||
| RTOFSOb & observations() { return * ob; } | ||
|
|
||
|
|
||
| private: | ||
| std::string filename; | ||
| int nobs; | ||
| FILE * f; | ||
| RTOFSOb * ob; | ||
|
|
||
| void read_file(); | ||
| }; // class RTOFSDataFile | ||
|
|
||
| } // namespace rtofs | ||
|
|
||
|
|
||
| #endif // BUNDLE_GDAS_UTILS_OBSPROC_RTOFS_RTOFSDATAFILE_H_ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.