-
Notifications
You must be signed in to change notification settings - Fork 8
/
antenna_spacing.py
executable file
·78 lines (67 loc) · 2.75 KB
/
antenna_spacing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#! /usr/bin/env python
# coding: utf-8
'''
###############################################################
# Script : antenna_spacing.py
# Author : Fanny Ekblom Johansson
# Date : 2017-10-15
# Last Edited: 2017-10-18, Henrik Engström
# Description: takes a .csv genereted by h5_dumpmeta.py,
# keeps the FID-column, adds antenna spacing
# and exports it as a new .txt-file in /offsets
##############################################################
# Purpose:
# - generate input required by join_radar.py
# Requirements:
# - irlib, python 2/3 and dumpmeta.csv file as input
# Notes:
# - she is an angel
##############################################################
Note that join_radar.py can do everything in this script IF the antenna
separation is constant.
'''
import pandas as pd
import numpy as np
import os
import sys
# Check input variables and print usage syntax
if len(sys.argv) != 3:
sys.stdout.write("No input given\n")
sys.stdout.write("\n")
sys.stdout.write(" SYNTAX:\n")
sys.stdout.write(" antenna_spacing.py INFILE SPACING\n")
sys.stdout.write("\n")
sys.stdout.write(" DESCRIPTION:\n")
sys.stdout.write(" Takes FID column from INFILE and adds SPACING. Output is saved in '/offsets' folder.\n\n")
sys.stdout.write(" INFILE: The .csv-file generated by h5_dumpmeta.py.\n")
sys.stdout.write(" SPACING: Antenna spacing in meters.\n\n")
sys.stdout.write("\n")
sys.stdout.write(" EXAMPLES:\n")
sys.stdout.write(" antenna_spacing.py data/gl3_radar_2012_utm_offsets.csv 60\n\n")
sys.exit(1)
# Give filename (no ending) and input/output path and antenna spacing
infile = str(sys.argv[1]) # Passed input file
an_space = str(sys.argv[2]) # Passed antenna spacing
filename = os.path.basename(infile) # gl3_radar_2012_utm_offsets.csv
path_out = 'offsets/'
file_out = filename.replace("_metadata.csv", "_offsets.txt")
if not file_out.endswith("_offsets.txt"):
file_out = os.basename(file_out) + "_offsets.txt"
# Check if source file exists
if os.path.isfile(infile) == False:
sys.stdout.write("Source file does not exist.\n")
sys.exit(3)
# Reads in the file as a pandas dafaframe
df = pd.read_csv(infile, dtype={'FID': str})
# Make an array of line one as strings to keep leading zeroes
FID = np.array(df['FID'])
# Create antenna spacing array
antenna_spacing = np.repeat(an_space, len(df))
# Concatinate the arrays to 2D
file = np.column_stack((FID, antenna_spacing))
if not os.path.exists(path_out):
os.makedirs(path_out)
# Saves the array as a .txt-file
np.savetxt(path_out + file_out, file, fmt='%s', delimiter='\t')
sys.stdout.write(" Created '" + path_out + file_out + "'\n")
sys.exit(0)