This repository has been archived on 2021-01-07. You can view files and clone it, but cannot push or open issues/pull-requests.
nasa-hackathon/code/grace_diff.pl

67 lines
1.2 KiB
Perl

#!/usr/bin/perl
use strict;
use warnings;
use 5.010;
use autodie;
use JSON;
sub parse_json_file {
my ($filename) = @_;
local $/;
open my $fh, '<', $filename;
my $json_text = <$fh>;
my $json = decode_json($json_text) or die;
return $json;
}
sub output_json_file {
my ($json, $filename) = @_;
open my $out, '>', $filename;
my $json_text = encode_json($json);
print {$out} $json_text;
}
my $json_1 = parse_json_file('grace_1.json');
my $json_2 = parse_json_file('grace_2.json');
my $data_1 = $json_1->{data};
my $data_2 = $json_2->{data};
my $min = 0;
my $max = 0;
foreach my $x (0..$#{ $data_1 }) {
foreach my $y (0..$#{ $data_1->[$x] }) {
foreach my $z (0..$#{ $data_1->[$x][$y] }) {
my $datum_1 = $data_1->[$x][$y][$z];
my $datum_2 = $data_2->[$x][$y][$z];
my $datum
= $data_2->[$x][$y][$z]
- $data_1->[$x][$y][$z];
$datum = 32767 if ($datum_1 == 32767 or $datum_2 == 32767);
$data_1->[$x][$y][$z] = $datum;
$min = $datum if $datum < $min;
$max = $datum if $datum > $max;
}
}
}
output_json_file($json_1, 'grace_1_2_diff_v2.json');
# use Data::Dumper;
#
# print Data::Dumper->Dump([parse_json_file('grace_1.json')], [qw/json/]);