Skip to content

Commit

Permalink
initial import of MSNoise
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasLecocq committed Aug 25, 2013
1 parent e98618a commit dc7c8cd
Show file tree
Hide file tree
Showing 17 changed files with 2,882 additions and 0 deletions.
58 changes: 58 additions & 0 deletions 00.0.installer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import cPickle
from database_tools import *
from getpass import getpass

print "Welcome to MsNoise"
print

try:
f = open("db.ini","r")
hostname,database,username,password = cPickle.load(f)
a = raw_input("Parameters for %s@%s defined, use them? [Y]/N"%(username,hostname))
use = True if a in ['y','Y',''] else False
except:
use = False

if not use:
a = raw_input('mysql hostname [localhost]:')
hostname = a if len(a) != 0 else "localhost"

a = raw_input('mysql database [msnoise-test]:')
database = a if len(a) != 0 else "msnoise-test"

a = raw_input('mysql username [msnoise]:')
username = a if len(a) != 0 else "msnoise"

a = getpass('mysql password [msnoise]:')
password = a if len(a) != 0 else "msnoise"

create_database_inifile(hostname,database,username,password)

try:
db = connect()
except:
a = raw_input("This database doesn't exist, do you want to create it? [Y]/N")
createdb = True if a in ['y','Y',''] else False
if createdb:
a = raw_input("Who has CREATE DATABASE privilege to this host? [root]:")
root = a if len(a) != 0 else "root"

a = getpass("His password?:")
passwd = a if len(a) != 0 else ""

create_database(root, passwd)
db = connect()
create_stations_table(db)
create_filters_table(db)
create_config_table(db)
create_data_availability_table(db)
create_jobs_table(db)
create_dtt_table(db)

## THIS IS BRAND NEW, HELL YEAH
if get_config(db,'data_folder') == "":
print "*"*70
print "Now edit the configuration (data_structure and data_folder) using either \
configurator.py or phpMyAdmin and \
launch the intaller_populatestationtable.py script for populating the station table"
print "*"*70
223 changes: 223 additions & 0 deletions 00.1.configurator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
from traits.api import HasTraits, Str, List, Instance,\
Float,CInt,CBool, Enum
from traitsui.api import Item, View, TreeEditor, TreeNode, TableEditor

from traitsui.table_column \
import ObjectColumn

from traitsui.extras.checkbox_column \
import CheckboxColumn

from database_tools import *

class StationColumn ( ObjectColumn ):
def get_text_color ( self, object ):
return [ 'light grey', 'black' ][ object.used ]

class TFilter(HasTraits):
ref = CInt
low = Float
mwcs_low = Float
high = Float
mwcs_high = Float
rms_threshold = Float
mwcs_wlen = Float
mwcs_step = Float
used = CBool
view = View('low','high','rms_threshold','used')

class TStation(HasTraits):
""" Defines a company employee. """
ref = CInt
net = Str
sta = Str
X = Float
Y = Float
altitude = Float
coordinates = Enum('UTM','DEG')
instrument= Str
used= CBool

view = View('net','sta','X','Y','altitude','coordinates','instrument','used')

station_editor = TableEditor(
sortable = True,
configurable = False,
auto_size = True,
columns = [ CheckboxColumn( name = 'used', label = 'Used ?'),
StationColumn( name = 'net', editable = False, width = 0.24,
horizontal_alignment = 'left' ),
StationColumn( name = 'sta' ),
StationColumn( name = 'X' ),
StationColumn( name = 'Y' ),
StationColumn( name = 'altitude' ),
StationColumn( name = 'coordinates' ),
StationColumn( name = 'instrument' )
] )

filter_editor = TableEditor(
sortable = True,
configurable = True,
auto_size = True,
row_factory = TFilter,
auto_add =True,
columns = [
StationColumn( name = 'ref',editable = False ),
CheckboxColumn( name = 'used', label = 'Used ?'),
StationColumn( name = 'low' ),
StationColumn( name = 'mwcs_low' ),
StationColumn( name = 'mwcs_high' ),
StationColumn( name = 'high' ),
StationColumn( name = 'rms_threshold' ),
StationColumn( name = 'mwcs_wlen' ),
StationColumn( name = 'mwcs_step' ),
] )

config_editor = TableEditor(
sortable = True,
configurable = True,
auto_size = True,
columns = [
ObjectColumn( name = 'name',editable = False ),
ObjectColumn( name = 'value',),
ObjectColumn( name = 'info',editable = False ),
ObjectColumn( name = 'default',editable = False ),
] )


class TNetwork(HasTraits):
""" Defines a department with employees. """

name = Str('<unknown>')
stations = List(TStation)


class ConfigItem(HasTraits):
name = Str('<unknown>')
value = Str('')
info = Str('')
default = Str('')

class Software(HasTraits):
""" Defines a company with departments and employees. """

name = Str('<unknown>')
networks = List(TNetwork)
configs = List(ConfigItem)
filters = List(TFilter)

no_view = View()

tree_editor = TreeEditor(
nodes = [
TreeNode(node_for = [ Software ],
auto_open = True,
children = '',
label = 'name',
view = View(Item( 'configs',
show_label = False,editor = config_editor))),
TreeNode(node_for = [ Software ],
auto_open = True,
children = 'networks',
label = '=Networks',
view = no_view,
add = [ TNetwork ],),
TreeNode(node_for = [ TNetwork ],
auto_open = False,
children = 'stations',
label = 'name',
view = View(Item( 'stations',
show_label = False,
editor = station_editor)
),
add = [ TStation ]),
TreeNode(node_for = [ TStation ],
auto_open = True,
label = 'sta',
view = View([ 'net','sta','X', 'Y','altitude','coordinates','used','instrument'])),

TreeNode(node_for = [ Software ],
auto_open = True,
label = '=Filters',
view = View(Item( 'filters',
show_label = False,
editor = filter_editor)),
add = [ TFilter ],),
]
)

class StationConfigurator(HasTraits):
""" Defines a business partner."""

name = Str('<unknown>')
company = Instance(Software)

view = View(
Item(name = 'company',
editor = tree_editor,
show_label = False,
),
title = 'Station Configuration GUI',
buttons = [ 'OK' ,'Cancel'],
resizable = True,
style = 'custom',
width = 1024,
height = 768
)




if __name__ == '__main__':

db = connect()

networks = []
for network in get_networks(db):
networks.append(TNetwork(name=network))
for s in get_stations(db,net=network):
station = TStation(ref=s.ref, net=s.net, sta=s.sta, X=s.X, Y=s.Y,altitude=s.altitude,used=s.used,instrument=s.instrument,coordinates=s.coordinates)
networks[-1].stations.append(station)

filters = []
for f in get_filters(db):
filters.append( TFilter(ref=f.ref, low=f.low,high=f.high,mwcs_low=f.mwcs_low, mwcs_high=f.mwcs_high,
rms_threshold=f.rms_threshold,mwcs_wlen=f.mwcs_wlen,mwcs_step=f.mwcs_step,used=f.used ) )

configs = []
for name in default.keys():
value = get_config(db,name)
configs.append( ConfigItem(name=name,value=value,info=default[name][0],default=default[name][1]) )

disconnect(db)
demo = StationConfigurator(
name = 'MSNoise',
company = Software(
name = 'MSNoise',
networks = networks,
configs = configs,
filters = filters
)
)


if demo.configure_traits():
db = connect()

print "Updating Config Table"
for config in demo.company.configs:
update_config(db,config.name,config.value)

print "Updating Station Table"
for network in demo.company.networks:
for s in network.stations:
update_station(db, s.net, s.sta, s.X, s.Y, s.altitude, s.coordinates,s.instrument,s.used)

print "Updating Filter Table"
for f in demo.company.filters:
update_filter(db, f.ref, f.low, f.high, f.mwcs_low, f.mwcs_high, f.rms_threshold, f.mwcs_wlen, f.mwcs_step, f.used)

disconnect(db)
print "Done !"

#EOF
49 changes: 49 additions & 0 deletions 00.2.populate_station_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import glob
from database_tools import *

db = connect()
print
print ">> Populating the Station table"
print
data_folder = get_config(db,'data_folder')
data_structure = get_config(db,'data_structure')
if data_structure in ["SDS","IDDS"]:
datalist = sorted(glob.glob( os.path.join(data_folder, "*","*","*")))
stations = []
for di in datalist:
tmp = os.path.split(di)
sta = tmp[1]
net = os.path.split(tmp[0])[1]
stations.append("%s_%s"%(net,sta))
del datalist
elif data_structure in ["BUD",]:
datalist = sorted(glob.glob( os.path.join(data_folder, "*","*",)))
stations = []
for di in datalist:
tmp = os.path.split(di)
sta = tmp[1]
net = os.path.split(tmp[0])[1]
stations.append("%s_%s"%(net,sta))
del datalist
elif data_structure in ["PDF",]:
datalist = sorted(glob.glob( os.path.join(data_folder, "*","*",)))
stations = []
for di in datalist:
tmp = os.path.split(di)
sta = tmp[1]
net = get_config(db,'network')
stations.append("%s_%s"%(net,sta))
del datalist

stations = np.unique(stations)

db = connect()
for station in stations:
net, sta = station.split('_')
print 'Adding:', net, sta
X = 0.0
Y = 0.0
altitude = 0.0
coordinates = 'UTM'
instrument = 'N/A'
update_station(db, net, sta, X, Y, altitude, coordinates = coordinates, instrument=instrument)

0 comments on commit dc7c8cd

Please sign in to comment.