Skip to content
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

Azimuth and range cuts #33

Merged
merged 8 commits into from
Jan 8, 2024
4 changes: 2 additions & 2 deletions VERSION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#define VERSION_MAJOR 0
#define VERSION_MINOR 1
#define VERSION_PATCH 2
#define VERSION_MINOR 2
#define VERSION_PATCH 0

#define STRINGIZE(s) #s
#define STRINGIZE_VAL(s) STRINGIZE(s)
Expand Down
6 changes: 3 additions & 3 deletions envisat_format/src/envisat_lvl1_writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ void FillMainProcessingParams(const SARMetadata& sar_meta, const ASARMetadata& a
r.range_samp_rate = sar_meta.chirp.range_sampling_rate;
r.radar_freq = sar_meta.carrier_frequency;
r.num_looks_range = 1;
CopyStrPad(r.filter_range, "NONE"); // rc windowning TODO
r.filter_coef_range = 0.0f;
// r.filter_window has been prefilled.
// r.filter_coef_range has been prefilled.
r.look_bw_range[0] = out.downlink_header.tx_pulse_bw_value[0];
r.tot_bw_range[0] = out.downlink_header.tx_pulse_bw_value[0];

Expand All @@ -100,7 +100,7 @@ void FillMainProcessingParams(const SARMetadata& sar_meta, const ASARMetadata& a

{
auto& az = out.azimuth_processing_information;
az.num_lines_proc = sar_meta.img.azimuth_size;
// Prefilled - az.num_lines_proc
az.num_look_az = 1;
az.to_bw_az = sar_meta.pulse_repetition_frequency * sar_meta.azimuth_bandwidth_fraction;
CopyStrPad(az.filter_az, "NONE");
Expand Down
78 changes: 49 additions & 29 deletions main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@
#include "envisat_types.h"
#include "file_async.h"
#include "geo_tools.h"
#include "img_output.h"
#include "main_flow.h"
#include "math_utils.h"
#include "mem_alloc.h"
#include "sar/focussing_details.h"
#include "sar/fractional_doppler_centroid.cuh"
#include "sar/iq_correction.cuh"
#include "sar/processing_velocity_estimation.h"
Expand Down Expand Up @@ -118,10 +117,10 @@ int main(int argc, char* argv[]) {
(void)target_product_type;
// Get packets' sensing start/end ... from which can be decided offset in binary and windowing offset?
const auto fetch_meta_start = TimeStart();
// Default request is 1000 before and after, which should be enough.
// It would not influence performance on GPU anyway.
size_t packets_before_sensing_start{0};
size_t packets_after_sensing_stop{packets_before_sensing_start};
// Default request is 3000 before and after, which should be enough, exact amount is calculated later based
// on the data. It would not influence performance on GPU anyway.
size_t packets_before_sensing_start{3000};
size_t packets_after_sensing_stop{3000};
// This will make sure that sequence starts with an echo packet in case of envisat.
const auto packets_fetch_meta =
alus::asar::envformat::FetchMeta(l0_ds, asar_meta.sensing_start, asar_meta.sensing_stop, product_type,
Expand Down Expand Up @@ -166,7 +165,6 @@ int main(int argc, char* argv[]) {
LOGD << "Total fetched meta for forecast - " << packets_fetch_meta.size();
LOGD << "Total parsed L0 packet - " << sar_meta.img.azimuth_size;


{
const auto& orbit_l1_metadata = orbit_source.GetL1ProductMetadata();
asar_meta.orbit_metadata.vector_source = orbit_l1_metadata.vector_source;
Expand Down Expand Up @@ -226,6 +224,9 @@ int main(int argc, char* argv[]) {
TimeStop(correction_start, "I/Q correction");

auto vr_start = TimeStart();
// TODO - Would give exactly the same results as in EstimateProcessingVelocity()'s sub step.
// Results would change after VR_poly and doppler_centroid_poly are updated ?!
auto aperture_pixels = CalcAperturePixels(sar_meta);
sar_meta.results.Vr_poly = EstimateProcessingVelocity(sar_meta);
TimeStop(vr_start, "Vr estimation");

Expand Down Expand Up @@ -255,15 +256,13 @@ int main(int argc, char* argv[]) {
alus::asar::mainflow::StoreIntensity(args.GetOutputPath().data(), wif_name_base, "rc", img);
}

constexpr size_t record_header_bytes = 12 + 1 + 4;
const auto mds_record_size = img.XSize() * sizeof(IQ16) + record_header_bytes;
const auto mds_record_count = img.YSize();
MDS mds;
mds.n_records = mds_record_count;
mds.record_size = mds_record_size;
auto mds_buffer_init = std::async(std::launch::async, [&mds] {
mds.buf = static_cast<char*>(alus::util::Memalloc(mds.n_records * mds.record_size));
});
auto az_comp_start = TimeStart();
DevicePaddedImage az_compressed_image;
// img is unused after, everything will be traded to 'az_compressed_image'.
RangeDopplerAlgorithm(sar_meta, img, az_compressed_image, d_workspace);
const auto rcmc_parameters = alus::sar::focus::GetRcmcParameters();

az_compressed_image.ZeroFillPaddings();

std::string lvl1_out_name = asar_meta.product_name;
lvl1_out_name.at(6) = 'S';
Expand All @@ -272,13 +271,38 @@ int main(int argc, char* argv[]) {
std::string(args.GetOutputPath()) + std::filesystem::path::preferred_separator + lvl1_out_name;
auto lvl1_file_handle = alus::util::FileAsync(lvl1_out_full_path);

auto az_comp_start = TimeStart();
DevicePaddedImage out;
RangeDopplerAlgorithm(sar_meta, img, out, d_workspace);
const auto az_rg_windowing = alus::asar::mainflow::CalcResultsWindow(
sar_meta.results.doppler_centroid_poly.back(), packets_before_sensing_start, packets_after_sensing_stop,
*std::max_element(aperture_pixels.cbegin(), aperture_pixels.cend()), rcmc_parameters);

CHECK_CUDA_ERR(cudaDeviceSynchronize()); // For ZeroFillPaddings() - the kernel was left running async.
TimeStop(az_comp_start, "Azimuth compression");

if (args.StoreIntensity()) {
alus::asar::mainflow::StoreIntensity(args.GetOutputPath().data(), wif_name_base, "proc_slc",
az_compressed_image);
}

out.ZeroFillPaddings();
auto result_file_assembly = TimeStart();

EnvisatIMS ims{};
alus::asar::mainflow::PrefillIms(ims, packets_metadata.size(), rcmc_parameters);

DevicePaddedImage subsetted_raster;
alus::asar::mainflow::SubsetResultsAndReassembleMeta(az_compressed_image, az_rg_windowing, packets_metadata,
asar_meta, sar_meta, ins_file, product_type, d_workspace,
subsetted_raster);
// az_compressed_image is unused from now on.
constexpr size_t record_header_bytes = 12 + 1 + 4;
const auto mds_record_size = subsetted_raster.XSize() * sizeof(IQ16) + record_header_bytes;
const auto mds_record_count = subsetted_raster.YSize();
MDS mds;
mds.n_records = mds_record_count;
mds.record_size = mds_record_size;
auto mds_buffer_init = std::async(std::launch::async, [&mds] {
mds.buf = static_cast<char*>(alus::util::Memalloc(mds.n_records * mds.record_size));
});

ConstructIMS(ims, sar_meta, asar_meta, mds, GetSoftwareVersion());
if (!lvl1_file_handle.CanWrite(std::chrono::seconds(10))) {
throw std::runtime_error("Could not create L1 file at " + lvl1_out_full_path);
Expand All @@ -290,24 +314,20 @@ int main(int argc, char* argv[]) {

lvl1_file_handle.Write(&ims, sizeof(ims));

CHECK_CUDA_ERR(cudaDeviceSynchronize());
TimeStop(az_comp_start, "Azimuth compression");

if (args.StoreIntensity()) {
alus::asar::mainflow::StoreIntensity(args.GetOutputPath().data(), wif_name_base, "slc", out);
}
TimeStop(result_file_assembly, "Creating IMS and write start, subsetting data");

auto result_correction_start = TimeStart();
if (d_workspace.ByteSize() < static_cast<size_t>(mds.record_size * mds.n_records)) {
throw std::logic_error(
"Implementation error occurred - CUDA workspace buffer shall be made larger or equal to what is "
"required for MDS buffer.");
}

float tambov{120000 / 100};
// const auto swath_idx = alus::asar::envformat::SwathIdx(asar_meta.swath);
// const auto tambov = xca.scaling_factor_im_slc_vv[swath_idx];
// const auto swath_idx = alus::asar::envformat::SwathIdx(asar_meta.swath);
// const auto tambov = xca.scaling_factor_im_slc_vv[swath_idx];
auto device_mds_buf = d_workspace.GetAs<char>();
alus::asar::mainflow::FormatResults(out, device_mds_buf, record_header_bytes, tambov);
alus::asar::mainflow::FormatResults(subsetted_raster, device_mds_buf, record_header_bytes, tambov);
TimeStop(result_correction_start, "Image results correction");

auto mds_formation = TimeStart();
Expand Down
Loading