koronascript 0.1__tar.gz → 0.2.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -27,11 +27,11 @@ class KoronaModule():
27
27
  self._name = name
28
28
  self._config = {}
29
29
  # Add defaults
30
- for k,v in modules_spec[name].items():
30
+ for k, v in modules_spec[name].items():
31
31
  self._config[k] = v
32
32
 
33
33
  for k in parameters:
34
- if k != 'Active' and not k in modules_spec[name]:
34
+ if k != 'Active' and k not in modules_spec[name]:
35
35
  print(f'Parameter "{k}" not valid for Korona module "{name}" - aborting')
36
36
  exit(-1)
37
37
  self._config[k] = parameters[k]
@@ -45,18 +45,18 @@ class KoronaModule():
45
45
  for k in self._config:
46
46
  if self._config[k] is None:
47
47
  res += f' <parameter name="{k}"/>\n'
48
- elif isinstance(self._config[k],list):
48
+ elif isinstance(self._config[k], list):
49
49
  res += f' <parameter name="{k}">'
50
50
  for v in self._config[k]:
51
- res += str(v)+','
52
- res = res[:-1] # remove last comma
51
+ res += str(v) + ','
52
+ res = res[:-1] # remove last comma
53
53
  res += '</parameter>\n'
54
- elif isinstance(self._config[k],dict):
54
+ elif isinstance(self._config[k], dict):
55
55
  res += f' <parameter name="{k}">\n'
56
56
  # Should maybe call recursively? Can they be lists or dicts?
57
- for key,val in self._config[k].items():
57
+ for key, val in self._config[k].items():
58
58
  res += f' <parameter name="{key}">{val}</parameter>\n'
59
- res += ' </parameter>\n'
59
+ res += ' </parameter>\n'
60
60
  else:
61
61
  res += (f' <parameter name="{k}">{self._config[k]}</parameter>\n')
62
62
  res += (' </parameters>\n')
@@ -1,6 +1,6 @@
1
1
  # Auto-generated, do not edit directly
2
2
  # see genmodule.py
3
- from .Configuration import modules_spec
3
+
4
4
  from .KoronaModule import KoronaModule
5
5
 
6
6
  class AngleDeletion(KoronaModule):
@@ -292,4 +292,3 @@ class NetcdfWriter(KoronaModule):
292
292
  """Writes to a .nc file"""
293
293
  def __init__(self, **parameters):
294
294
  super().__init__('NetcdfWriter', **parameters)
295
-
@@ -10,14 +10,17 @@ import subprocess
10
10
  import tempfile
11
11
  import os
12
12
  import sys
13
- import json
14
13
 
15
- from .KoronaModule import KoronaModule, global_spec
14
+ from .KoronaModule import global_spec
15
+
16
+ lsss = os.getenv('LSSS')
17
+ if lsss is None:
18
+ print('KoronaScript: Warning: $LSSS is not set.')
16
19
 
17
20
  class KoronaScript():
18
21
  '''Construct, store, and run a set of Korona modules'''
19
22
 
20
- def __init__(self, **parameters): # global parameters
23
+ def __init__(self, **parameters): # global parameters
21
24
  self._module_list = []
22
25
  self._config = global_spec
23
26
  for k in parameters:
@@ -36,7 +39,7 @@ class KoronaScript():
36
39
  cfs.write('<?xml version="1.0" encoding="UTF-8"?>\n\n')
37
40
  cfs.write('<ConfigFiles context="Korona">\n')
38
41
  cfs.write(f' <parameter name="ModuleConfiguration" ref="CfsDirectory">{cdsname}</parameter>\n')
39
- for k,v in self._config.items():
42
+ for k, v in self._config.items():
40
43
  if v is None:
41
44
  cfs.write(f' <parameter name="{k}"/>\n')
42
45
  else:
@@ -51,7 +54,7 @@ class KoronaScript():
51
54
  cds.write(' </modules>\n')
52
55
  cds.write('</ModuleContainer>\n')
53
56
 
54
- def run(self, src, dst):
57
+ def run(self, src, dst, debug=False):
55
58
  '''Save the files (to /tmp?) and call Korona to execute them'''
56
59
  cfs, cfsname = tempfile.mkstemp(suffix='.cfs')
57
60
  cds, cdsname = tempfile.mkstemp(suffix='.cds')
@@ -60,19 +63,25 @@ class KoronaScript():
60
63
  self.write(cfs=cfsfd, cds=cdsfd, cdsname=cdsname)
61
64
 
62
65
  # if os.getenv('JAVA_HOME'): (...)
63
- lsss = os.getenv('LSSS')
64
66
  if lsss is None:
65
- print('LSSS environment variable not specified')
67
+ print('KoronaScript: Error: LSSS environment variable not specified')
66
68
  exit(-1)
67
69
  os.environ['TOP_INSTALLATION_DIR'] = lsss
68
70
 
69
- java = lsss+'/jre/bin/java'
71
+ java = os.path.join(*[lsss, 'jre', 'bin', 'java'])
72
+
73
+ # "-Xmx${MAX_MEMORY_MB}m" -classpath "t$TOP_INSTALLATION_DIR/lib/jar/*" "-Djava.library.path=$JAVA_LIBRARY_PATH" "-Djna.library.path=$JAVA_LIBRARY_PATH" -XX:-UseGCOverheadLimit -XX:-OmitStackTraceInFastThrow -Dno.marec.incubator=true no.imr.korona.main.KoronaCliMain "$@"
74
+ javaopts = ['-classpath', os.path.join(*[lsss, "lib", "jar", "*"]), '-Dno.marec.incubator=true']
75
+ libpath = os.path.join(*[lsss, 'lib', 'native', 'win64'])
76
+ if os.path.exists(libpath):
77
+ for v in ['java.library.path', 'jna.library.path']:
78
+ javaopts.append(f'-D{v}={libpath}')
70
79
 
71
- # "-Xmx${MAX_MEMORY_MB}m" -classpath "$TOP_INSTALLATION_DIR/lib/jar/*" "-Djava.library.path=$JAVA_LIBRARY_PATH" "-Djna.library.path=$JAVA_LIBRARY_PATH" -XX:-UseGCOverheadLimit -XX:-OmitStackTraceInFastThrow -Dno.marec.incubator=true no.imr.korona.main.KoronaCliMain "$@"
72
- javaopts = ['-classpath', f'{lsss}/lib/jar/*', '-Dno.marec.incubator=true', 'no.imr.korona.main.KoronaCliMain']
73
- res = subprocess.run([java] + javaopts + ['batch', '--cfs', cfsname, '--source', src, '--destination', dst])
74
- print(res.stdout)
80
+ cmd = [java] + javaopts + ['no.imr.korona.main.KoronaCliMain', 'batch', '--cfs', cfsname, '--source', src, '--destination', dst]
81
+ if debug: print('Running:\n ', cmd)
82
+ res = subprocess.run(cmd, capture_output=True, text=True)
83
+ if debug: print(res.stdout)
75
84
  if res.returncode != 0:
76
- print(f'Warning: Java subprocess returned error code {res.returncode}')
77
- print('Errors:')
78
- print(res.stderr)
85
+ err_str = f'Korona subprocess returned an error code: {res.returncode}\n' + '----------------------------------------\n' + res.stderr
86
+ raise Exception(err_str)
87
+ return res.returncode
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: koronascript
3
- Version: 0.1
3
+ Version: 0.2.1
4
4
  Summary: Wrapper around Korona modules for processing echosounder data
5
5
  Home-page: https://github.com/CRIMAC-WP4-Machine-learning/CRIMAC-KoronaScript
6
6
  Author: Ketil Malde
@@ -21,11 +21,16 @@ Download the appropriate version from here:
21
21
 
22
22
  https://marec.no/tmp/lsss-2.16.0-alpha-20230922-1417-linux.zip
23
23
 
24
+ https://marec.no/tmp/lsss-2.18.0-alpha-20240918-0847-linux.zip
25
+
24
26
  https://marec.no/tmp/lsss-2.16.0-alpha-20230922-1417-windows.zip
25
27
 
26
- If you run linux you need to install the netcdf library separately:
28
+ https://marec.no/tmp/lsss-2.18.0-alpha-20240918-0847-windows.zip
29
+
30
+ If you run linux you need to install the netcdf separately:
31
+
32
+ `apt-get install libnetcdf` or `sudo apt install libnetcdf-dev`
27
33
 
28
- `apt-get install libnetcdf`
29
34
 
30
35
  ### Add license
31
36
 
@@ -33,17 +38,17 @@ You need an LSSS licence. The licence have to be added according to the LSSS man
33
38
 
34
39
  ### Set system variables
35
40
 
36
- This can be set at run time either by setting the LSSS environment
41
+ The `LSSS` environment variable should point to the root directory of your
42
+ LSSS installation. It can be set at run time either by setting the LSSS environment
37
43
  variable in the shell
38
44
  ~~~
39
- export LSSS=~/lsss-2.16.0-alpha/korona
45
+ export LSSS=~/lsss-2.16.0-alpha
40
46
  ~~~
41
- before running your script, or by adding to path
47
+ before running your script, or by adding it manually from inside Python:
42
48
  ~~~
43
- lsss = '~/lsss-2.16.0-alpha/korona'
49
+ lsss = '~/lsss-2.16.0-alpha'
44
50
  os.environ["LSSS"] = lsss
45
51
  ~~~
46
- pointing at the LSSS environment to your script.
47
52
 
48
53
  # Usage
49
54
 
@@ -12,11 +12,16 @@ Download the appropriate version from here:
12
12
 
13
13
  https://marec.no/tmp/lsss-2.16.0-alpha-20230922-1417-linux.zip
14
14
 
15
+ https://marec.no/tmp/lsss-2.18.0-alpha-20240918-0847-linux.zip
16
+
15
17
  https://marec.no/tmp/lsss-2.16.0-alpha-20230922-1417-windows.zip
16
18
 
17
- If you run linux you need to install the netcdf library separately:
19
+ https://marec.no/tmp/lsss-2.18.0-alpha-20240918-0847-windows.zip
20
+
21
+ If you run linux you need to install the netcdf separately:
22
+
23
+ `apt-get install libnetcdf` or `sudo apt install libnetcdf-dev`
18
24
 
19
- `apt-get install libnetcdf`
20
25
 
21
26
  ### Add license
22
27
 
@@ -24,17 +29,17 @@ You need an LSSS licence. The licence have to be added according to the LSSS man
24
29
 
25
30
  ### Set system variables
26
31
 
27
- This can be set at run time either by setting the LSSS environment
32
+ The `LSSS` environment variable should point to the root directory of your
33
+ LSSS installation. It can be set at run time either by setting the LSSS environment
28
34
  variable in the shell
29
35
  ~~~
30
- export LSSS=~/lsss-2.16.0-alpha/korona
36
+ export LSSS=~/lsss-2.16.0-alpha
31
37
  ~~~
32
- before running your script, or by adding to path
38
+ before running your script, or by adding it manually from inside Python:
33
39
  ~~~
34
- lsss = '~/lsss-2.16.0-alpha/korona'
40
+ lsss = '~/lsss-2.16.0-alpha'
35
41
  os.environ["LSSS"] = lsss
36
42
  ~~~
37
- pointing at the LSSS environment to your script.
38
43
 
39
44
  # Usage
40
45
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: koronascript
3
- Version: 0.1
3
+ Version: 0.2.1
4
4
  Summary: Wrapper around Korona modules for processing echosounder data
5
5
  Home-page: https://github.com/CRIMAC-WP4-Machine-learning/CRIMAC-KoronaScript
6
6
  Author: Ketil Malde
@@ -21,11 +21,16 @@ Download the appropriate version from here:
21
21
 
22
22
  https://marec.no/tmp/lsss-2.16.0-alpha-20230922-1417-linux.zip
23
23
 
24
+ https://marec.no/tmp/lsss-2.18.0-alpha-20240918-0847-linux.zip
25
+
24
26
  https://marec.no/tmp/lsss-2.16.0-alpha-20230922-1417-windows.zip
25
27
 
26
- If you run linux you need to install the netcdf library separately:
28
+ https://marec.no/tmp/lsss-2.18.0-alpha-20240918-0847-windows.zip
29
+
30
+ If you run linux you need to install the netcdf separately:
31
+
32
+ `apt-get install libnetcdf` or `sudo apt install libnetcdf-dev`
27
33
 
28
- `apt-get install libnetcdf`
29
34
 
30
35
  ### Add license
31
36
 
@@ -33,17 +38,17 @@ You need an LSSS licence. The licence have to be added according to the LSSS man
33
38
 
34
39
  ### Set system variables
35
40
 
36
- This can be set at run time either by setting the LSSS environment
41
+ The `LSSS` environment variable should point to the root directory of your
42
+ LSSS installation. It can be set at run time either by setting the LSSS environment
37
43
  variable in the shell
38
44
  ~~~
39
- export LSSS=~/lsss-2.16.0-alpha/korona
45
+ export LSSS=~/lsss-2.16.0-alpha
40
46
  ~~~
41
- before running your script, or by adding to path
47
+ before running your script, or by adding it manually from inside Python:
42
48
  ~~~
43
- lsss = '~/lsss-2.16.0-alpha/korona'
49
+ lsss = '~/lsss-2.16.0-alpha'
44
50
  os.environ["LSSS"] = lsss
45
51
  ~~~
46
- pointing at the LSSS environment to your script.
47
52
 
48
53
  # Usage
49
54
 
@@ -1,12 +1,13 @@
1
1
  README.md
2
+ setup.cfg
2
3
  setup.py
3
4
  KoronaScript/Configuration.py
4
5
  KoronaScript/KoronaModule.py
5
6
  KoronaScript/Modules.py
6
7
  KoronaScript/__init__.py
7
- configuration/korona-info.json
8
8
  koronascript.egg-info/PKG-INFO
9
9
  koronascript.egg-info/SOURCES.txt
10
10
  koronascript.egg-info/dependency_links.txt
11
11
  koronascript.egg-info/not-zip-safe
12
- koronascript.egg-info/top_level.txt
12
+ koronascript.egg-info/top_level.txt
13
+ tests/test_examples.py
@@ -0,0 +1,7 @@
1
+ [flake8]
2
+ ignore = E302,E501,E203,E701
3
+
4
+ [egg_info]
5
+ tag_build =
6
+ tag_date = 0
7
+
@@ -1,7 +1,7 @@
1
1
  from setuptools import setup
2
2
 
3
3
  setup(name='koronascript',
4
- version='0.1',
4
+ version='0.2.1',
5
5
  description='Wrapper around Korona modules for processing echosounder data',
6
6
  long_description=open('README.md').read(),
7
7
  long_description_content_type='text/markdown',
@@ -0,0 +1,15 @@
1
+ import os
2
+ import examples.channelRemoval as CR
3
+
4
+ TESTDATA = 'test_data/EK60'
5
+
6
+ def test_get_data():
7
+ if not os.path.exists(TESTDATA):
8
+ # Get test data from pyEchoLab examples:
9
+ os.system('mkdir -p test_data && cd test_data && wget --recursive --no-parent -nH --cut-dirs=6 ftp://ftp.ngdc.noaa.gov/pub/outgoing/mgg/wcd/pyEcholab_data/examples/EK60')
10
+
11
+ def test_channelRemoval():
12
+ """This fails to fail if no data is present"""
13
+ CR.ks.run('test_data/EK60', 'test_out/cr_out')
14
+
15
+
@@ -1 +0,0 @@
1
- include configuration/korona-info.json