-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from blevic/dev
Dev
- Loading branch information
Showing
7 changed files
with
131 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
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,42 @@ | ||
from nrarfcn.tables.gscn_parameters import table_gscn_parameters | ||
|
||
|
||
def get_frequency_by_gscn(gscn: int) -> float: | ||
"""Gets the frequency of a given GSCN (Global Synchronization Channel Number), in MHz. | ||
Args: | ||
gscn: The GSCN to get the frequency of. | ||
Returns: | ||
The frequency of the given GSCN, in MHz. | ||
Raises: | ||
ValueError: If the given GSCN is invalid | ||
""" | ||
if not isinstance(gscn, int): | ||
raise ValueError("GSCN must be an integer") | ||
|
||
if gscn < 2 or gscn > 26639: | ||
raise ValueError("GSCN must be between 2 and 26639") | ||
|
||
table = table_gscn_parameters() | ||
|
||
for row in table.data: | ||
if table.get_cell(row, 'gscn_min') <= gscn <= table.get_cell(row, 'gscn_max'): | ||
if table.get_cell(row, 'm_set') == {}: | ||
n = gscn - table.get_cell(row, 'g_offs') | ||
return table.get_cell(row, 'f_offs') + table.get_cell(row, 'n_coeff') * n | ||
else: | ||
if gscn % 3 == 0: | ||
n = gscn // table.get_cell(row, 'g_n_coeff') | ||
m = 3 | ||
elif gscn % 3 == 1: | ||
n = gscn // table.get_cell(row, 'g_n_coeff') | ||
m = 5 | ||
elif gscn % 3 == 2: | ||
n = (gscn + 1) // table.get_cell(row, 'g_n_coeff') | ||
m = 1 | ||
|
||
return table.get_cell(row, 'f_offs') + table.get_cell(row, 'n_coeff') * n + table.get_cell(row, 'm_coeff') * m | ||
|
||
raise ValueError("Expected to have found a GSCN in the table, but didn't") |
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,6 @@ | ||
from nrarfcn.tables.gscn_parameters import table_gscn_parameters | ||
|
||
|
||
def get_gscn_by_frequency(freq: float) -> int: | ||
table = table_gscn_parameters() | ||
return 0 |
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,10 @@ | ||
from typing import Union | ||
from nrarfcn.tables.applicable_ss_raster_fr1 import table_applicable_ss_raster_fr1 | ||
from nrarfcn.tables.applicable_ss_raster_fr2 import table_applicable_ss_raster_fr2 | ||
|
||
|
||
def get_gscn_range(band: Union[str, int]) -> tuple: | ||
table_fr1 = table_applicable_ss_raster_fr1() | ||
table_fr2 = table_applicable_ss_raster_fr2() | ||
|
||
return 0, 0 |
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,47 @@ | ||
import unittest | ||
from nrarfcn import get_frequency_by_gscn | ||
|
||
|
||
class TestGetFrequencyByGscn(unittest.TestCase): | ||
def test_valid_channels(self): | ||
gscn_freq_map = { | ||
2: 1.250, | ||
500: 200.450, | ||
1000: 399.850, | ||
5000: 2000.450, | ||
7498: 2999.050, | ||
7499: 3000.000, | ||
10000: 6601.440, | ||
15000: 13801.440, | ||
20000: 21001.440, | ||
22255: 24248.640, | ||
22256: 24250.080, | ||
23000: 37106.400, | ||
25000: 71666.400, | ||
26639: 99988.320 | ||
} | ||
|
||
for gscn, freq in gscn_freq_map.items(): | ||
self.assertAlmostEqual(get_frequency_by_gscn(gscn), freq, places=3) | ||
|
||
def test_different_channels(self): | ||
different_channels = [ | ||
(2, 3), | ||
(500, 501), | ||
(1000, 1001), | ||
(7498, 7499), | ||
(22255, 22256), | ||
(22256, 22257), | ||
(23000, 23001), | ||
(25000, 25001) | ||
] | ||
|
||
for gscn1, gscn2 in different_channels: | ||
self.assertNotAlmostEqual(get_frequency_by_gscn(gscn1), get_frequency_by_gscn(gscn2), places=3) | ||
|
||
def test_invalid_channels(self): | ||
invalid_channels = [-1, 0, 1, 2.0, 23000.5, None, '', '2', 26640] | ||
|
||
for channel in invalid_channels: | ||
with self.assertRaises(ValueError): | ||
get_frequency_by_gscn(channel) |
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,13 @@ | ||
import unittest | ||
from nrarfcn import get_gscn_by_frequency | ||
|
||
|
||
class TestGetGscnByFrequency(unittest.TestCase): | ||
def test_valid_freqs(self): | ||
pass | ||
|
||
def test_different_freqs(self): | ||
pass | ||
|
||
def test_invalid_freqs(self): | ||
pass |
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,10 @@ | ||
import unittest | ||
from nrarfcn import get_gscn_range | ||
|
||
|
||
class TestGetGscnRange(unittest.TestCase): | ||
def test_valid_bands(self): | ||
pass | ||
|
||
def test_invalid_bands(self): | ||
pass |