1. /**
  2. * @module meteoJS/modelviewer/nwpResources
  3. */
  4. import Resources from './Resources.js';
  5. import VariableCollection from './VariableCollection.js';
  6. import Node from './Node.js';
  7. import Variable from './Variable.js';
  8. import TimeVariable from './TimeVariable.js';
  9. /**
  10. * @classdesc For usage of NWP (numerical weather prediction). This class is
  11. * designed to use the modelviewer for NWP.
  12. */
  13. export class NWPResources extends Resources {
  14. constructor() {
  15. let collections = new Set();
  16. ['models', 'runs', 'regions', 'fields', 'levels', 'accumulations', 'thresholds']
  17. .forEach(id => collections.add(new VariableCollection({ id })));
  18. let nodes = {};
  19. for (let collection of collections)
  20. nodes[collection.id] = new Node(collection);
  21. // build hierarchy
  22. nodes.models.appendChild(nodes.runs);
  23. nodes.runs.appendChild(nodes.regions);
  24. nodes.regions.appendChild(nodes.fields);
  25. nodes.fields.appendChild(nodes.levels, nodes.accumulations);
  26. nodes.accumulations.appendChild(nodes.thresholds);
  27. super({
  28. topNode: nodes.models,
  29. timesVariableCollections: new Set([nodes.models.variableCollection, nodes.runs.variableCollection])
  30. });
  31. }
  32. /**
  33. * Creates a Variable-Object and adds it to the VariableCollection.
  34. *
  35. * @param {module:meteoJS/modelviewer/variableCollection.VariableCollection}
  36. * variableCollection - VariableCollection.
  37. * @param {Object} [options] - Variable options.
  38. * @param {mixed} [options.id] - Variable id.
  39. * @param {string} [options.name] - Default name.
  40. * @param {Object.<string,string>} [options.names] - Names.
  41. * @param {string[]} [options.langSortation] - Priority of language codes.
  42. * @param {Date|undefined} [option.sdatetime] - Datetime.
  43. * @returns {module:meteoJS/modelviewer/nwpResources.NWPResources} This.
  44. */
  45. addVariable(variableCollection,
  46. { id,
  47. name = undefined,
  48. names = {},
  49. langSortation = [],
  50. datetime = undefined } = {}) {
  51. let variable =
  52. (datetime === undefined)
  53. ? new Variable({
  54. id,
  55. name,
  56. names,
  57. langSortation
  58. })
  59. : new TimeVariable({
  60. id,
  61. name,
  62. names,
  63. langSortation,
  64. datetime
  65. });
  66. variableCollection.append(variable);
  67. return this;
  68. }
  69. /**
  70. * Collection of all defined models.
  71. *
  72. * @type module:meteoJS/modelviewer/variableCollection.VariableCollection
  73. * @readonly
  74. */
  75. get models() {
  76. return this.getNodeByVariableCollectionId('models').variableCollection;
  77. }
  78. /**
  79. * Collection of all defined runs.
  80. *
  81. * @type module:meteoJS/modelviewer/variableCollection.VariableCollection
  82. * @readonly
  83. */
  84. get runs() {
  85. return this.getNodeByVariableCollectionId('runs').variableCollection;
  86. }
  87. /**
  88. * Collection of all defined regions.
  89. *
  90. * @type module:meteoJS/modelviewer/variableCollection.VariableCollection
  91. * @readonly
  92. */
  93. get regions() {
  94. return this.getNodeByVariableCollectionId('regions').variableCollection;
  95. }
  96. /**
  97. * Collection of all defined fields.
  98. *
  99. * @type module:meteoJS/modelviewer/variableCollection.VariableCollection
  100. * @readonly
  101. */
  102. get fields() {
  103. return this.getNodeByVariableCollectionId('fields').variableCollection;
  104. }
  105. /**
  106. * Collection of all defined levels.
  107. *
  108. * @type module:meteoJS/modelviewer/variableCollection.VariableCollection
  109. * @readonly
  110. */
  111. get levels() {
  112. return this.getNodeByVariableCollectionId('levels').variableCollection;
  113. }
  114. /**
  115. * Collection of all defined accumulations.
  116. *
  117. * @type module:meteoJS/modelviewer/variableCollection.VariableCollection
  118. * @readonly
  119. */
  120. get accumulations() {
  121. return this.getNodeByVariableCollectionId('accumulations').variableCollection;
  122. }
  123. /**
  124. * Collection of all defined thresholds.
  125. *
  126. * @type module:meteoJS/modelviewer/variableCollection.VariableCollection
  127. * @readonly
  128. */
  129. get thresholds() {
  130. return this.getNodeByVariableCollectionId('thresholds').variableCollection;
  131. }
  132. }
  133. export default NWPResources;