Skip to content

Commit

Permalink
command line outid
Browse files Browse the repository at this point in the history
  • Loading branch information
chrystalchern committed May 27, 2024
1 parent d631c86 commit 155fcb2
Showing 1 changed file with 34 additions and 7 deletions.
41 changes: 34 additions & 7 deletions src/mdof/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def parse_time(argi, config, channels, method=None):
config.update(conf_arg)

elif arg == "--inputs":
channels["intpus"] = next(argi)
channels["inputs"] = next(argi)

elif arg == "--outputs":
channels["outputs"] = next(argi)
Expand Down Expand Up @@ -155,12 +155,23 @@ def parse_time(argi, config, channels, method=None):
}[method]

periods, amplitudes = spectrum_modes(
*f(inputs=inputs.flatten(), outputs=outputs.flatten(), step = dt, **config)
)
*f(inputs=inputs.flatten(), outputs=outputs.flatten(), step = dt, **config), prominence=None
)

output = [
{"period": period, "amplitude": amplitude}
for period, amplitude in zip(periods, amplitudes)
for period, amplitude, in zip(periods, amplitudes)
]

# periods, amplitudes = f(inputs=inputs.flatten(), outputs=outputs.flatten(), step = dt, **config)

# peak_periods, peak_amplitudes = spectrum_modes(periods, amplitudes, prominence=0.2*max(amplitudes))

# output = [
# {"peak period": peak_period, "peak amplitude": peak_amplitude}
# for peak_period, peak_amplitude, in zip(peak_periods, peak_amplitudes)
# ].append({"periods": periods, "amplitudes": amplitudes})

print(json.dumps({"data": output}, cls=JSON_Encoder, indent=4))


Expand Down Expand Up @@ -235,10 +246,10 @@ def parse_srim(argi, config, channels, method=None):

output = [
{
"period": 1/mode["freq"],
"period": 1/mode["freq"],
"frequency": mode["freq"],
"damping": mode["damp"],
"shape": np.real(mode["modeshape"]),
"shape": np.round(np.abs(mode["modeshape"]),3),
"emac": mode["energy_condensed_emaco"],
"mpc": mode["mpc"],
}
Expand All @@ -248,6 +259,21 @@ def parse_srim(argi, config, channels, method=None):
print(json.dumps({"data": output}, cls=JSON_Encoder, indent=4))
return config

def parse_outid(argi):
outputs = None
for arg in argi:
if arg == "--dt":
dt = float(next(argi))
elif outputs is None:
output_file = str(argi)
if output_file == "-":
outputs = np.loadtxt(sys.stdin)
else:
np.loadtxt(output_file)
else:
raise ValueError("Whaddya think you're doin!!")

return mdof.outid(outputs, dt)

def parse_args(args):
outputs = []
Expand All @@ -257,7 +283,8 @@ def parse_args(args):
"fourier": parse_time,
"test": parse_srim,
"okid": parse_srim,
"okid": parse_srim
"okid": parse_srim,
"outid": parse_outid
}
method = None
config = {}
Expand Down

0 comments on commit 155fcb2

Please sign in to comment.