generated from DLR-MF-DAS/general-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jancauskas
committed
Dec 5, 2024
1 parent
3792fd1
commit addab43
Showing
2 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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,54 @@ | ||
import click | ||
import numpy as np | ||
import datetime | ||
|
||
def check_if_inside(csv_line, lat_window, lon_window, time_window): | ||
if np.count_nonzero(lat_window == -1000) == (lat_window.shape[0] * lat_window.shape[1]): | ||
return False | ||
csv_line = csv_line.strip().split(',') | ||
csv_year = int(csv_line[0][0:4]) | ||
csv_month = int(csv_line[0][4:6]) | ||
csv_day = int(csv_line[0][6:8]) | ||
csv_time = csv_line[1].split(':') | ||
csv_hour = int(csv_time[0]) | ||
csv_minute = int(csv_time[1]) | ||
csv_second = int(csv_time[2]) | ||
csv_datetime = datetime.datetime(csv_year, csv_month, csv_day, csv_hour, csv_minute, csv_second) | ||
csv_lat = float(csv_line[2]) | ||
csv_lon = float(csv_line[3]) | ||
mask = lat_window != -1000 | ||
min_datetime = time_window[mask].min() | ||
max_datetime = time_window[mask].max() | ||
min_lat = lat_window[mask].min() | ||
max_lat = lat_window[mask].max() | ||
min_lon = lon_window[mask].min() | ||
max_lon = lon_window[mask].max() | ||
return ((min_datetime <= csv_datetime <= max_datetime) and | ||
(min_lat <= csv_lat <= max_lat) and | ||
(min_lon <= csv_lon <= max_lon)) | ||
|
||
@click.command() | ||
@click.option('-i', '--input-file', help='Input CSV with super-emitter locations') | ||
@click.option('-m', '--matrix-file', help='Input NPZ file with methane data from TROPOMI') | ||
def main(input_file, matrix_file): | ||
methane_data = np.load(matrix_file, allow_pickle=True) | ||
with open(input_file, 'r') as fd: | ||
data = fd.readlines()[1:] | ||
methane_matrix = methane_data['methane'] | ||
lat_matrix = methane_data['lat'] | ||
lon_matrix = methane_data['lon'] | ||
time_matrix = methane_data['time'] | ||
rows, cols = methane_matrix.shape | ||
for row in range(0, rows, 16): | ||
for col in range(0, cols, 16): | ||
if row + 32 < rows and col + 32 < cols: | ||
methane_window = methane_matrix[row:row + 32][:, col:col + 32] | ||
lat_window = lat_matrix[row:row + 32][:, col:col + 32] | ||
lon_window = lon_matrix[row:row + 32][:, col:col + 32] | ||
time_window = time_matrix[row:row + 32][:, col:col + 32] | ||
for csv_line in data: | ||
if check_if_inside(csv_line, lat_window, lon_window, time_window): | ||
print("FOUND!") | ||
|
||
if __name__ == '__main__': | ||
main() |