Exemple #1
0
    def test_types(self):
        key_c = Key('C')
        self.assertEqual(IonianScale, key_c.ionian_mode.base_scale)
        self.assertTrue(isinstance(key_c.ionian_mode, Mode))

        c_ionian_mode = Mode(C, IonianScale)
        self.assertEqual(IonianScale, c_ionian_mode.base_scale)
        self.assertTrue(isinstance(c_ionian_mode, Mode))
Exemple #2
0
 def test_dorian__sharp_tonics(self):
     self.assertEqual(('C#', 'D#', 'E', 'F#', 'G#', 'A#', 'B'),
                      Mode(C_sharp, DorianScale).notes)
     self.assertEqual(('D#', 'E#', 'F#', 'G#', 'A#', 'B#', 'C#'),
                      Mode(D_sharp, DorianScale).notes)
     self.assertEqual(('E#', 'F##', 'G#', 'A#', 'B#', 'C##', 'D#'),
                      Mode(E_sharp, DorianScale).notes)
     self.assertEqual(('F#', 'G#', 'A', 'B', 'C#', 'D#', 'E'),
                      Mode(F_sharp, DorianScale).notes)
     self.assertEqual(('G#', 'A#', 'B', 'C#', 'D#', 'E#', 'F#'),
                      Mode(G_sharp, DorianScale).notes)
     self.assertEqual(('A#', 'B#', 'C#', 'D#', 'E#', 'F##', 'G#'),
                      Mode(A_sharp, DorianScale).notes)
     self.assertEqual(('B#', 'C##', 'D#', 'E#', 'F##', 'G##', 'A#'),
                      Mode(B_sharp, DorianScale).notes)
Exemple #3
0
 def test_dorian__natural_tonics(self):
     self.assertEqual(('C', 'D', 'Eb', 'F', 'G', 'A', 'Bb'),
                      Mode(C, DorianScale).notes)
     self.assertEqual(('D', 'E', 'F', 'G', 'A', 'B', 'C'),
                      Mode(D, DorianScale).notes)
     self.assertEqual(('E', 'F#', 'G', 'A', 'B', 'C#', 'D'),
                      Mode(E, DorianScale).notes)
     self.assertEqual(('F', 'G', 'Ab', 'Bb', 'C', 'D', 'Eb'),
                      Mode(F, DorianScale).notes)
     self.assertEqual(('G', 'A', 'Bb', 'C', 'D', 'E', 'F'),
                      Mode(G, DorianScale).notes)
     self.assertEqual(('A', 'B', 'C', 'D', 'E', 'F#', 'G'),
                      Mode(A, DorianScale).notes)
     self.assertEqual(('B', 'C#', 'D', 'E', 'F#', 'G#', 'A'),
                      Mode(B, DorianScale).notes)
Exemple #4
0
 def test_ionian__flat_tonics(self):
     self.assertEqual(('Cb', 'Db', 'Eb', 'Fb', 'Gb', 'Ab', 'Bb'),
                      Mode(C_flat, IonianScale).notes)
     self.assertEqual(('Db', 'Eb', 'F', 'Gb', 'Ab', 'Bb', 'C'),
                      Mode(D_flat, IonianScale).notes)
     self.assertEqual(('Eb', 'F', 'G', 'Ab', 'Bb', 'C', 'D'),
                      Mode(E_flat, IonianScale).notes)
     self.assertEqual(('Fb', 'Gb', 'Ab', 'Bbb', 'Cb', 'Db', 'Eb'),
                      Mode(F_flat, IonianScale).notes)
     self.assertEqual(('Gb', 'Ab', 'Bb', 'Cb', 'Db', 'Eb', 'F'),
                      Mode(G_flat, IonianScale).notes)
     self.assertEqual(('Ab', 'Bb', 'C', 'Db', 'Eb', 'F', 'G'),
                      Mode(A_flat, IonianScale).notes)
     self.assertEqual(('Bb', 'C', 'D', 'Eb', 'F', 'G', 'A'),
                      Mode(B_flat, IonianScale).notes)
Exemple #5
0
 def test_locrian__flat_tonics(self):
     self.assertEqual(('Cb', 'Dbb', 'Ebb', 'Fb', 'Gbb', 'Abb', 'Bbb'),
                      Mode(C_flat, LocrianScale).notes)
     self.assertEqual(('Db', 'Ebb', 'Fb', 'Gb', 'Abb', 'Bbb', 'Cb'),
                      Mode(D_flat, LocrianScale).notes)
     self.assertEqual(('Eb', 'Fb', 'Gb', 'Ab', 'Bbb', 'Cb', 'Db'),
                      Mode(E_flat, LocrianScale).notes)
     self.assertEqual(('Fb', 'Gbb', 'Abb', 'Bbb', 'Cbb', 'Dbb', 'Ebb'),
                      Mode(F_flat, LocrianScale).notes)
     self.assertEqual(('Gb', 'Abb', 'Bbb', 'Cb', 'Dbb', 'Ebb', 'Fb'),
                      Mode(G_flat, LocrianScale).notes)
     self.assertEqual(('Ab', 'Bbb', 'Cb', 'Db', 'Ebb', 'Fb', 'Gb'),
                      Mode(A_flat, LocrianScale).notes)
     self.assertEqual(('Bb', 'Cb', 'Db', 'Eb', 'Fb', 'Gb', 'Ab'),
                      Mode(B_flat, LocrianScale).notes)
Exemple #6
0
 def test_locrian__natural_tonics(self):
     self.assertEqual(('C', 'Db', 'Eb', 'F', 'Gb', 'Ab', 'Bb'),
                      Mode(C, LocrianScale).notes)
     self.assertEqual(('D', 'Eb', 'F', 'G', 'Ab', 'Bb', 'C'),
                      Mode(D, LocrianScale).notes)
     self.assertEqual(('E', 'F', 'G', 'A', 'Bb', 'C', 'D'),
                      Mode(E, LocrianScale).notes)
     self.assertEqual(('F', 'Gb', 'Ab', 'Bb', 'Cb', 'Db', 'Eb'),
                      Mode(F, LocrianScale).notes)
     self.assertEqual(('G', 'Ab', 'Bb', 'C', 'Db', 'Eb', 'F'),
                      Mode(G, LocrianScale).notes)
     self.assertEqual(('A', 'Bb', 'C', 'D', 'Eb', 'F', 'G'),
                      Mode(A, LocrianScale).notes)
     self.assertEqual(('B', 'C', 'D', 'E', 'F', 'G', 'A'),
                      Mode(B, LocrianScale).notes)
Exemple #7
0
 def test_ionian__natural_tonics(self):
     self.assertEqual(('C', 'D', 'E', 'F', 'G', 'A', 'B'),
                      Mode(C, IonianScale).notes)
     self.assertEqual(('D', 'E', 'F#', 'G', 'A', 'B', 'C#'),
                      Mode(D, IonianScale).notes)
     self.assertEqual(('E', 'F#', 'G#', 'A', 'B', 'C#', 'D#'),
                      Mode(E, IonianScale).notes)
     self.assertEqual(('F', 'G', 'A', 'Bb', 'C', 'D', 'E'),
                      Mode(F, IonianScale).notes)
     self.assertEqual(('G', 'A', 'B', 'C', 'D', 'E', 'F#'),
                      Mode(G, IonianScale).notes)
     self.assertEqual(('A', 'B', 'C#', 'D', 'E', 'F#', 'G#'),
                      Mode(A, IonianScale).notes)
     self.assertEqual(('B', 'C#', 'D#', 'E', 'F#', 'G#', 'A#'),
                      Mode(B, IonianScale).notes)
Exemple #8
0
 def test_mixolydian__natural_tonics(self):
     self.assertEqual(('C', 'D', 'E', 'F', 'G', 'A', 'Bb'),
                      Mode(C, MixolydianScale).notes)
     self.assertEqual(('D', 'E', 'F#', 'G', 'A', 'B', 'C'),
                      Mode(D, MixolydianScale).notes)
     self.assertEqual(('E', 'F#', 'G#', 'A', 'B', 'C#', 'D'),
                      Mode(E, MixolydianScale).notes)
     self.assertEqual(('F', 'G', 'A', 'Bb', 'C', 'D', 'Eb'),
                      Mode(F, MixolydianScale).notes)
     self.assertEqual(('G', 'A', 'B', 'C', 'D', 'E', 'F'),
                      Mode(G, MixolydianScale).notes)
     self.assertEqual(('A', 'B', 'C#', 'D', 'E', 'F#', 'G'),
                      Mode(A, MixolydianScale).notes)
     self.assertEqual(('B', 'C#', 'D#', 'E', 'F#', 'G#', 'A'),
                      Mode(B, MixolydianScale).notes)
Exemple #9
0
 def test_lydian__natural_tonics(self):
     self.assertEqual(('C', 'D', 'E', 'F#', 'G', 'A', 'B'),
                      Mode(C, LydianScale).notes)
     self.assertEqual(('D', 'E', 'F#', 'G#', 'A', 'B', 'C#'),
                      Mode(D, LydianScale).notes)
     self.assertEqual(('E', 'F#', 'G#', 'A#', 'B', 'C#', 'D#'),
                      Mode(E, LydianScale).notes)
     self.assertEqual(('F', 'G', 'A', 'B', 'C', 'D', 'E'),
                      Mode(F, LydianScale).notes)
     self.assertEqual(('G', 'A', 'B', 'C#', 'D', 'E', 'F#'),
                      Mode(G, LydianScale).notes)
     self.assertEqual(('A', 'B', 'C#', 'D#', 'E', 'F#', 'G#'),
                      Mode(A, LydianScale).notes)
     self.assertEqual(('B', 'C#', 'D#', 'E#', 'F#', 'G#', 'A#'),
                      Mode(B, LydianScale).notes)
Exemple #10
0
 def test_phrygian__natural_tonics(self):
     self.assertEqual(('C', 'Db', 'Eb', 'F', 'G', 'Ab', 'Bb'),
                      Mode(C, PhrygianScale).notes)
     self.assertEqual(('D', 'Eb', 'F', 'G', 'A', 'Bb', 'C'),
                      Mode(D, PhrygianScale).notes)
     self.assertEqual(('E', 'F', 'G', 'A', 'B', 'C', 'D'),
                      Mode(E, PhrygianScale).notes)
     self.assertEqual(('F', 'Gb', 'Ab', 'Bb', 'C', 'Db', 'Eb'),
                      Mode(F, PhrygianScale).notes)
     self.assertEqual(('G', 'Ab', 'Bb', 'C', 'D', 'Eb', 'F'),
                      Mode(G, PhrygianScale).notes)
     self.assertEqual(('A', 'Bb', 'C', 'D', 'E', 'F', 'G'),
                      Mode(A, PhrygianScale).notes)
     self.assertEqual(('B', 'C', 'D', 'E', 'F#', 'G', 'A'),
                      Mode(B, PhrygianScale).notes)
Exemple #11
0
 def test_aeolian__natural_tonics(self):
     self.assertEqual(('C', 'D', 'Eb', 'F', 'G', 'Ab', 'Bb'),
                      Mode(C, AeolianScale).notes)
     self.assertEqual(('D', 'E', 'F', 'G', 'A', 'Bb', 'C'),
                      Mode(D, AeolianScale).notes)
     self.assertEqual(('E', 'F#', 'G', 'A', 'B', 'C', 'D'),
                      Mode(E, AeolianScale).notes)
     self.assertEqual(('F', 'G', 'Ab', 'Bb', 'C', 'Db', 'Eb'),
                      Mode(F, AeolianScale).notes)
     self.assertEqual(('G', 'A', 'Bb', 'C', 'D', 'Eb', 'F'),
                      Mode(G, AeolianScale).notes)
     self.assertEqual(('A', 'B', 'C', 'D', 'E', 'F', 'G'),
                      Mode(A, AeolianScale).notes)
     self.assertEqual(('B', 'C#', 'D', 'E', 'F#', 'G', 'A'),
                      Mode(B, AeolianScale).notes)
Exemple #12
0
app.register_blueprint(users_blueprint)

ALLOWED_EXTENSIONS = set(['txt', 'plv', 'csv', 'mdi', 'dif'])
UPLOAD_DIR = 'uploads'

import os

app.config.from_object(os.environ['APP_SETTINGS'])
app.config['UPLOAD_FOLDER'] = UPLOAD_DIR

if not os.path.isdir(UPLOAD_DIR):
    os.mkdir(UPLOAD_DIR)

# app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://localhost/qanalyze'
defaultMode = Mode('Default', 0, 'Co', 0, 0.3, 'rockforming')


def before_request():
    app.jinja_env.cache = {}


def rebal(selected, inventory):
    if inventory == "cement":
        db = sorted(phaselist.cementPhases)
    elif inventory == "pigment":
        db = sorted(phaselist.pigmentPhases)
    elif inventory == "rockforming":
        db = sorted(phaselist.rockPhases)
    elif inventory == "chemin":
        db = sorted(phaselist.cheminPhases)
Exemple #13
0
def upgrade():
    # -- Feed using ADIF Enumerations
    # RTTY note: it should be 'ASCII' according to ADIF format but
    # I think that 'RTTY' is more well-known that 'ASCII'
    # CW or PSK are ASCII too, why RTTY should be named 'ASCII' ?
    modes = {
        "AM": ["AM"],
        "FM": ["FM"],
        "CW": ["CW"],
        "ATV": ["ATV"],
        "RTTY": ["RTTY"],
        "SSTV": ["SSTV"],
        "CHIP": ["CHIP64", "CHIP128"],
        "CLO": ["CLO"],
        "CONTESTI": ["CONTESTI"],
        "DIGITALVOICE": ["DIGITALVOICE"],
        "DOMINO": ["DOMINOEX", "DOMINOF"],
        "DSTAR": ["DSTAR"],
        "FAX": ["FAX"],
        "FSK441": ["FSK441"],
        "HELL": ["FMHELL", "FSKHELL", "HELL80", "HFSK", "PSKHELL"],
        "ISCAT": ["ISCAT-A", "ISCAT-B"],
        "JT4": ["JT4A", "JT4B", "JT4C", "JT4D", "JT4E", "JT4F", "JT4G"],
        "JT6M": ["JT6M"],
        "JT9": ["JT9-1", "JT9-2", "JT9-5", "JT9-10", "JT9-30"],
        "JT44": ["JT44"],
        "JT65": ["JT65A", "JT65B", "JT65B2", "JT65C", "JT65C2"],
        "MFSK": [
            "MFSK4", "MFSK8", "MFSK11", "MFSK16", "MFSK22", "MFSK31", "MFSK32",
            "MFSK64", "MFSK128"
        ],
        "MT63": ["MT63"],
        "OLIVIA": [
            "OLIVIA 4/125",
            "OLIVIA 4/250",
            "OLIVIA 8/250",
            "OLIVIA 8/500",
            "OLIVIA 16/500",
            "OLIVIA 16/1000",
            "OLIVIA 32/1000",
        ],
        "OPERA": ["OPERA-BEACON", "OPERA-QSO"],
        "PAC": ["PAC2", "PAC3", "PAC4"],
        "PAX": ["PAX2"],
        "PKT": ["PKT"],
        "PSK": [
            "FSK31",
            "PSK10",
            "PSK31",
            "PSK63",
            "PSK63F",
            "PSK125",
            "PSK250",
            "PSK500",
            "PSK1000",
            "PSKAM10",
            "PSKAM31",
            "PSKAM50",
            "PSKFEC31",
            "QPSK31",
            "QPSK63",
            "QPSK125",
            "QPSK250",
            "QPSK500",
        ],
        "PSK2K": ["PSK2K"],
        "Q15": ["Q15"],
        "ROS": ["ROS-EME", "ROS-HF", "ROS-MF"],
        "RTTYM": ["RTTYM"],
        "SSB": ["USB", "LSB"],
        "THOR": ["THOR"],
        "THRB": ["THRBX"],
        "TOR": ["AMTORFEC", "GTOR"],
        "V4": ["V4"],
        "VOI": ["VOI"],
        "WINMOR": ["WINMOR"],
        "WSPR": ["WSPR"],
    }

    for mode in modes.keys():
        for submode in modes[mode]:
            db.session.add(Mode(mode=mode, submode=submode))

    db.session.commit()
Exemple #14
0
 def test_invalid_mode(self):
     with self.assertRaises(InvalidModeError):
         Mode(C, MajorScale)
Exemple #15
0
def chemin():
    if request.method == 'POST':
        # print request.__dict__
        # Load data from request
        # Ajax case
        if request.is_json:
            json_data = request.get_json()
            data = json_data
        # Regular post, text/plain encoded in body
        else:
            # Regular post x-www-form-urlencoded
            dsample = request.form['data']
            data = json.loads(dsample)
            # Other type of encoding via text/plain
            # a, b = request.data.split('=')
            # data = json.loads(b)

        sample = data['sample']
        filename = sample['name']
        array = sample['data']
        odr_phases = data['phases']
        app.logger.warning('Size of ODR array: %d', len(array))
        app.logger.debug(sample)
        app.logger.warning('Size of ODR phases: %d', len(odr_phases))
        app.logger.warning('ODR Phases: %s', odr_phases)

        # Save to file
        with open(os.path.join(app.config['UPLOAD_FOLDER'], filename), 'w') as outfile:
            json.dump(array, outfile)

        # Initialize the session object with chemin data
        session['autoremove'] = False
        session['dbname'] = 'difdata_chemin.txt'
        session['selected'] = phaselist.cheminPhases
        session['available'] = phaselist.availablePhases
        session['filename'] = filename

        x = [li['x'] for li in array]
        y = [li['y'] for li in array]

        angle = np.asfarray(np.array(x))
        diff = np.asfarray(np.array(y))

        # Force mode
        Lambda = 1.79027
        Target = 'Co'
        FWHMa = 0.0
        FWHMb = 0.35
        InstrParams = {"Lambda": Lambda,
                       "Target": Target,
                       "FWHMa": FWHMa,
                       "FWHMb": FWHMb}

        # Parse phases sent by ODR
        phasearray = data['phases']
        selectedphases = [(d['name'], d['AMCSD_code']) for d in phasearray]

        # TODO 2nd pass with selected

        # Force Chemin for ODR
        # Dif data captures all cristallographic data
        # Load in the DB file
        DBname = session['dbname']
        difdata = open(DBname, 'r').readlines()
        userData = (angle, diff)
        # results, BG, calcdiff = qxrd.Qanalyze(userData,
        # print session
        results, BG, Sum, mineralpatterns = qxrd.Qanalyze(userData,
                                                          difdata,
                                                          selectedphases,
                                                          InstrParams,
                                                          session['autoremove'],
                                                          True)

        # Re-create the subset of phases to select
        sel, ava = rebalance(results)
        session['selected'] = sel
        session['available'] = ava
        # print(twoT.tolist(), file=sys.stderr)
        # print(userData, file=sys.stderr)

        twoT = userData[0]
        diff = userData[1]
        angle = twoT
        bgpoly = BG
        xmin = min(angle)
        xmax = max(angle)
        # xmax = max(angle)
        Imax = max(diff[min(np.where(np.array(angle) > xmin)[0])                        :max(np.where(np.array(angle) > xmin)[0])])
        offset = Imax / 2 * 3
        offsetline = [offset] * len(angle)

        difference_magnification = 1
        difference = (diff - Sum) * difference_magnification
        # logging.debug(results)
        # logging.info("Done with processing")
        offsetdiff = difference + offset

        csv = 'ODR'
        session['results'] = results

        app.logger.warning('Length of angle array: %d', len(angle))
        minerallist = [(l + BG).tolist() for l in mineralpatterns]

        session['filename'] = filename

        cheminMode = Mode('DefaultChemin', 0, 'Co', 0, 0, 'chemin')

        template_vars = {
            'phaselist': results,
            'angle': angle.tolist(),
            'diff': diff.tolist(),
            'bgpoly': bgpoly.tolist(),
            'sum': Sum.tolist(),
            'difference': offsetdiff.tolist(),
            'minerals': minerallist,
            'url_text': csv,
            'key': 'chemin',
            'samplename': filename,
            'mode': cheminMode,
            'availablephaselist': session['available'],
            'selectedphaselist': session['selected']
        }
        return render_template('chemin.html', **template_vars)
    else:
        return '''<html><body><h1>Did not get a post!</h1></body></html>'''
Exemple #16
0
def chemin_process():
    # Load parameters for computation
    filename = session['filename']

    # Extract angle, diff to populate userData
    with open(os.path.join(app.config['UPLOAD_FOLDER'], filename)) as infile:
        array = json.load(infile)
        x = [li['x'] for li in array]
        y = [li['y'] for li in array]
        angle = np.asfarray(np.array(x))
        diff = np.asfarray(np.array(y))

    # Force mode
    Lambda = 0.0
    Target = 'Co'
    FWHMa = 0.0
    FWHMb = 0.35
    InstrParams = {"Lambda": Lambda,
                   "Target": Target,
                   "FWHMa": FWHMa,
                   "FWHMb": FWHMb}

    # Phase selection
    selectedPhases = session['selected']
    # Dif data captures all cristallographic data
    selectedphases = []
    for i in range(len(selectedPhases)):
        name, code = selectedPhases[i].split('\t')
        code = int(code)
        selectedphases.append((name, code))

    # Load in the DB file
    DBname = session['dbname']
    difdata = open(DBname, 'r').readlines()
    userData = (angle, diff)
    results, BG, Sum, mineralpatterns = qxrd.Qanalyze(userData,
                                                      difdata,
                                                      selectedphases,
                                                      InstrParams,
                                                      session['autoremove'],
                                                      True)

    # Re-create the subset of phases to select
    sel, ava = rebalance(results)
    session['selected'] = sel
    session['available'] = ava
    # print(twoT.tolist(), file=sys.stderr)
    # print(userData, file=sys.stderr)

    twoT = userData[0]
    diff = userData[1]
    angle = twoT
    bgpoly = BG
    xmin = min(angle)
    xmax = max(angle)
    Imax = max(diff[min(np.where(np.array(angle) > xmin)[0])
               :max(np.where(np.array(angle) > xmin)[0])])
    offset = Imax / 2 * 3
    offsetline = [offset] * len(angle)

    difference_magnification = 1
    difference = (diff - Sum) * difference_magnification
    # logging.debug(results)
    # logging.info("Done with processing")
    offsetdiff = difference + offset

    csv = 'ODR'
    app.logger.warning('Length of angle array: %d', len(angle))
    minerallist = [(l + BG).tolist() for l in mineralpatterns]

    session['results'] = results

    cheminMode = Mode('DefaultChemin', 0, 'Co', 0, 0, 'chemin')

    template_vars = {
        'phaselist': results,
        'angle': angle.tolist(),
        'diff': diff.tolist(),
        'bgpoly': bgpoly.tolist(),
        'sum': Sum.tolist(),
        'difference': offsetdiff.tolist(),
        'minerals': minerallist,
        'url_text': csv,
        'key': 'chemin',
        'samplename': filename,
        'mode': cheminMode,
        'availablephaselist': session['available'],
        'selectedphaselist': session['selected']
    }
    return render_template('chemin.html', **template_vars)
from app import db
from models import Mode

# create the database and the db table
db.create_all()

# insert data
db.session.add(Mode("default", "rock"))
db.session.add(Mode("ludo", "pigment"))

# commit the changes
db.session.commit()