-
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
0 parents
commit 8da7f90
Showing
5 changed files
with
164 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
FROM bitnami/jupyter-base-notebook | ||
|
||
WORKDIR /workspace | ||
USER root | ||
|
||
RUN apt-get update -y | ||
RUN apt-get install -y cifs-utils | ||
|
||
RUN pip install scipy | ||
RUN pip install pandas | ||
RUN pip install h5py | ||
RUN pip install matplotlib | ||
|
||
|
||
RUN touch /credentials.txt | ||
|
||
RUN mkdir /NAS | ||
|
||
EXPOSE 8888 | ||
|
||
CMD ["jupyter", "notebook", "--port=8888", "--no-browser", "--ip=0.0.0.0", "--allow-root", "--NotebookApp.token='letmein'", "--NotebookApp.password='', --NotebookApp.allow_remote_access=true"] |
Empty file.
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,117 @@ | ||
import numpy as np | ||
import pandas as pd | ||
|
||
class Signal(object): | ||
signal_id = -1 | ||
|
||
def __init__(self, name="", initial_value=0, low=0, high=1, slew=1e-3): | ||
Signal.signal_id = Signal.signal_id + 1 | ||
self.id = Signal.signal_id | ||
|
||
if name: | ||
self.name = name | ||
else: | ||
self.name = "signal-" + str(self.signal_id) | ||
|
||
self.data = [ | ||
[0, initial_value] | ||
] | ||
|
||
self.slew = slew | ||
self.at_time = 0 | ||
|
||
def value_at(self, time): | ||
previous_point = None | ||
|
||
for point in self.data: | ||
if point[0] == time: | ||
return point[1] | ||
elif point[0] > time: | ||
print("here") | ||
|
||
previous_point = point | ||
|
||
return previous_point[1] | ||
|
||
def end_time(self): | ||
return self.data[-1][0] | ||
|
||
def at(self, time): | ||
self.at_time = time | ||
return self | ||
|
||
def to(self, value): | ||
self.data.append([self.at_time, self.value_at(self.at_time)]) | ||
|
||
self.at_time = self.at_time + self.slew | ||
self.data.append([self.at_time, value]) | ||
|
||
return self | ||
|
||
def extend_to(self, time): | ||
if self.end_time() < time: | ||
self.data.append([time, self.value_at(self.end_time())]) | ||
|
||
|
||
def save(self): | ||
file_name = self.name + ".pwl" | ||
with open(file_name, "w") as f: | ||
for point in self.data: | ||
f.write(str(point[0]) + "\t" + str(point[1]) + "\n") | ||
|
||
def as_lists(self): | ||
return tuple([list(t) for t in zip(*self.data)]) | ||
|
||
def scale_time(self, factor): | ||
self.data = [[point[0]*factor, point[1]] for point in self.data] | ||
|
||
def scale_value(self, factor): | ||
self.data = [[point[0], point[1]*factor] for point in self.data] | ||
|
||
|
||
class MySignal(Signal): | ||
|
||
def __init__(self, name="", initial_value=0, low=0, high=1, slew=1e-3): | ||
super().__init__(name="", initial_value=0, low=0, high=1, slew=1e-3) | ||
|
||
def to_numpy(self): | ||
self.data_np = np.array(self.data) | ||
return self.data_np | ||
def get_time(self): | ||
data_np = self.to_numpy() | ||
return self.data_np[:,0] | ||
def get_values(self): | ||
data_np = self.to_numpy() | ||
return self.data_np[:,1] | ||
def repeat(self, N): | ||
assert N > 1, "N is the number of periods" | ||
values = self.get_values() | ||
time = self.get_time() | ||
|
||
for period in range(N-1): | ||
new_time = time+self.end_time() | ||
new_data = np.stack([new_time, values], axis=1) | ||
|
||
self.data += new_data.tolist() | ||
self.data = np.unique(self.data, axis=0).tolist() | ||
return self.data | ||
|
||
def make_pandas_table(self): | ||
table = pd.DataFrame(self.data, columns=["time", "value"]).set_index("time") | ||
return table | ||
|
||
def from_func(self, func, time): | ||
self.data = get_PWL_from_function(func, time) | ||
return self.data | ||
|
||
|
||
|
||
def get_PWL_from_function(func, time): | ||
values = func(time) | ||
data = [[t, value] for (t, value) in zip(time, values)] | ||
return data | ||
|
||
|
||
|
||
|
||
|
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 @@ | ||
# SignalAnalysis |
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,25 @@ | ||
#!/bin/bash | ||
image=tm95mon/jupyter:w_pandas | ||
|
||
name=my_container | ||
|
||
NAS_address_from_local=10.79.0.165 | ||
NAS_address_from_PolimiNW=10.75.4.20 | ||
|
||
#get_credentials | ||
user=monopoli | ||
pass='9SuRh2:c.c!T8rf' | ||
|
||
docker run \ | ||
--rm -d \ | ||
--cap-add SYS_ADMIN --cap-add DAC_READ_SEARCH \ | ||
--name $name \ | ||
-p ${1:-8888}:8888 \ | ||
-v $(pwd):/workspace \ | ||
-e password=$pass \ | ||
-e username=$user \ | ||
$image | ||
|
||
docker exec -d $name bash -c 'printf "username=$username\npassword=$password" > /credentials.txt' | ||
docker exec -d $name bash -c "mount -t cifs //$NAS_address_from_local/monopoli /NAS --verbose -o credentials=/credentials.txt" | ||
|