Module: NumRu::GGraph
- Defined in:
- lib/numru/ggraph.rb,
lib/numru/ganalysis/histogram.rb,
lib/numru/ggraph_on_merdional_section.rb
Constant Summary collapse
- TONE_TONF_THRES =
10000
- @@nannot =
thresfold to swith uetonf and uetone under the auto=true option in the tone method
0
- @@fig =
Misc::KeywordOptAutoHelp.new( ['new_frame',true, 'whether to define a new frame by DCL.grfrm (otherwise, DCL.grfig is called)'], ['no_new_fig',false, 'If true, neither DCL.grfrm nor DCL.grfig is called (overrides new_frame) -- Then, you need to call one of them in advance. Convenient to set DCL parameters that are reset by grfrm or grfig.'], ['itr', 1, 'coordinate transformation number'], ['viewport',[0.2,0.8,0.2,0.8], '[vxmin, vxmax, vymin, vymax]'], ['eqdistvpt',false, 'modify viewport to equidistant for x and y (only for itr=1--4)'], ['window', nil, '(for itr<10,>50) [uxmin, uxmax, uymin, uymax]. each element allowd nil (only for itr<5,>50)'], ['xreverse','positive:down,units:hPa', '(for itr<10,>50) Assign max value to UXMIN and min value to UXMAX if condition is satisfied (nil:never, true:always, String: when an attibute has the value specified ("key:value,key:value,..")'], ['yreverse','positive:down,units:hPa', '(for itr<10,>50) Assign max value to UYMIN and min value to UYMAX if condition is satisfied (nil:never, true:always, String: when an attibute has the value specified ("key:value,key:value,..")'], ['round0', false, 'expand window range to good numbers (effective only to internal window settings)'], ['round1', false, 'expand window range to good numbers (effective even when "window" is explicitly specified)'], # for 5<=itr<=7 (Rectangular Curvilinear Coordinates) ['similar', nil, '3-element float array for similar transformation in a rectangular curvilinear coordinate, which is fed in DCL:grssim:[simfac,vxoff,vyoff], where simfac and [vxoff,vyoff] represent scaling factor and origin shift, respectively.'], # for 10<=itr<=50 (map projection): ['map_axis', nil, '(for all map projections) 3-element float array to be fed in DCL::umscnt: [uxc, uxy, rot], where [uxc, uyc] represents the tangential point (or the pole at top side for cylindrical projections), and rot represents the rotation angle. If nil, internally determined. (units: degrees)'], ['map_radius', nil, '(for itr>=20: conical/azimuhal map projections) raidus around the tangential point. (units: degrees)'], ['map_fit',nil,'(Only for itr=10(cylindrical) and 11 (Mercator)) true: fit the plot to the data window (overrides map_window and map_axis); false: do not fit (then map_window and map_axis are used); nil: true if itr==10, false if itr==11'], ['map_rsat',nil,'(Only for itr=30) satellite distance from the earth\'s center (Parameter "RSAT" for sgpack)'], ['map_window', [-180,180,-75,75], '(for itr<20: cylindrical map projections) lon-lat window [lon_min, lon_max, lat_min, lat_max ] to draw the map (units: degres)'] )
- @@next_fig =
nil
- @@axes =
Misc::KeywordOptAutoHelp.new( ['xside', 'tb', 'Where to draw xaxes (combination of t, b and u)'], ['yside', 'lr', 'Where to draw yaxes (combination of l, r and u)'], ['xtitle', nil, 'Title of x axis (if nil, internally determined)'], ['ytitle', nil, 'Title of y axis (if nil, internally determined)'], ['title', nil, 'Title of the figure'], ['xunits', nil, 'Units of x axis (if nil, internally determined)'], ['yunits', nil, 'Units of y axis (if nil, internally determined)'], ['xtickint', nil, 'Interval of x axis tickmark (if nil, internally determined)'], ['ytickint', nil, 'Interval of y axis tickmark (if nil, internally determined)'], ['xlabelint', nil, 'Interval of x axis label (if nil, internally determined)'], ['ylabelint', nil, 'Interval of y axis label (if nil, internally determined)'], ['xloglabelall', false, 'Show lavels for all log-level tick marks (x-axes) (e.g.,1000,900,800,... inseatd of 1000,500,200,...)'], ['yloglabelall', false, 'Show lavels for all log-level tick marks (y-axes) (e.g.,1000,900,800,... inseatd of 1000,500,200,...)'], ['xmaplabel', nil, 'If "lon"("lat"), use DCLExt::lon_ax(DCLExt::lat_ax) to draw xaxes; otherwise, DCL::usxaxs is used.'], ['ymaplabel', nil, 'If "lon"("lat"), use DCLExt::lon_ax(DCLExt::lat_ax) to draw yaxes; otherwise, DCL::usyaxs is used.'], ['time_ax', nil, 'Type of calendar-type time axis: nil (=> auto slection), false (do not use the time axis even if the units of the axis is a time one with since field), "h" (=> like nil, but always use the hour-resolving datetime_ax method in dclext_datetime_ax.rb), or "ymd" (=> like "h" but for y-m-d type using DCL.uc[xy]acl)'] )
- @@next_axes =
nil
- @@map =
Misc::KeywordOptAutoHelp.new( ['lim', true, 'draw map lim (t or f)'], ['grid', true, 'draw map grid (t or f)'], ['vpt_boundary', false, 'draw viewport boundaries (f, t or 1,2,3.., representing the line width)'], ['wwd_boundary', false, 'draw worksation window boundaries (f, t or 1,2,3.., representing the line width)'], ['fill', false, 'fill the map if coast_world or coast_japan is true (t or f)'], ['coast_world', false, 'draw world coast lines (t or f)'], ['border_world', false, 'draw nation borders (t or f)'], ['plate_world', false, 'draw plate boundaries (t or f)'], ['state_usa', false, 'draw state boundaries of US (t or f)'], ['coast_japan', false, 'draw japanese coast lines (t or f)'], ['pref_japan', false, 'draw japanese prefecture boundaries (t or f)'], ['dgridmj', nil, 'the interval between the major lines of latitudes and longitudes. If nil, internally determined. (units: degrees) (this is a UMPACK parameter, which is nullified when uminit or grfrm is called)'], ['dgridmn', nil, 'the interval between the minor lines of latitudes and longitudes. If nil, internally determined. (units: degrees) (this is a UMPACK parameter, which is nullified when uminit or grfrm is called)'] )
- @@next_map =
nil
- @@data_prep_options =
Misc::KeywordOptAutoHelp.new( ['exchange', false, 'whether to exchange x and y axes'], ['transpose', false, 'if true, exchange x and y axes'], ['xintv', 1, 'interval of data sampling in x'], ['yintv', 1, 'interval of data sampling in y'], ['xcoord', nil, 'Name of the coordinate variable for x-axis'], ['ycoord', nil, 'Name of the coordinate variable for y-axis'], ['slice', nil, 'An Array to be pathed to the GPhys#[] method to subset the data before plotting (order applied: slice -> cut -> mean)'], ['cut', nil, 'An Array or Hash to be pathed to the GPhys#cut method to subset the data before plotting (order applied: slice -> cut -> mean)'], ['mean', nil, 'An Array to be pathed to the GPhys#mean method to take mean of the data before plotting (order applied: slice -> cut -> mean)'] )
- @@line_options =
Misc::KeywordOptAutoHelp.new( ['title', nil, 'Title of the figure(if nil, internally determined)'], ['annotate', true, 'if false, do not put texts on the right margin even when newframe==true'], ['index', 1, 'line/mark index'], ['type', 1, 'line type'], ['label', nil, 'if a String is given, it is shown as the label'], ['max', nil, 'maximam data value'], ['min', nil, 'minimam data value'], ['legend', nil, 'legend to annotate the line type and index. nil (defalut -- do not show); a String as the legend; true to use the name of the GPhys as the legend'], ['legend_vx', nil, '(effective if legend) viewport x values of the lhs of the legend line (positive float); or nil for automatic settting (shown to the right of vpt); or move it to the left relatively (negtive float)'], ['legend_dx', nil, '(effective if legend) length of the legend line'], ['legend_vy', nil, '(effective if legend) viewport y value of the legend (Float; or nil for automatic settting)'], ['legend_size', nil, '(effective if legend) character size of the legend'], ['map_axes', false, '[USE IT ONLY WHEN itr=10 (cylindrical)] If true, draws axes by temprarilly switching to itr=1 and calling GGraph::axes.'], @@data_prep_options )
- @@mark_options =
Misc::KeywordOptAutoHelp.new( ['title', nil, 'Title of the figure(if nil, internally determined)'], ['annotate', true, 'if false, do not put texts on the right margin even when newframe==true'], ['index', 1, 'mark index'], ['type', 2, 'mark type'], ['size', 0.01, 'marks size'], ['max', nil, 'maximam data value'], ['min', nil, 'minimam data value'], ['legend', nil, 'legend to annotate the mark type, index, and size. nil (defalut -- do not to show); a String as the legend; true to use the name of the GPhys as the legend'], ['legend_vx', nil, '(effective if legend) viewport x values of the lhs of the legend line (positive float); or nil for automatic settting (shown to the right of vpt); or move it to the left relatively (negtive float)'], ['legend_vy', nil, '(effective if legend) viewport y value of the legend (Float; or nil for automatic settting)'], ['legend_size', nil, '(effective if legend) character size of the legend'], ['map_axes', false, '[USE IT ONLY WHEN itr=10 (cylindrical)] If true, draws axes by temprarilly switching to itr=1 and calling GGraph::axes.'], @@data_prep_options )
- @@linear_contour_options =
Misc::KeywordOptAutoHelp.new( ['min', nil, 'minimum contour level'], ['max', nil, 'maximum contour level'], ['nlev', nil, 'number of levels'], ['interval', nil, 'contour interval'], ['nozero', nil, 'delete zero contour'], ['coloring', false, 'set color contours with ud_coloring'], ['clr_min', 13, '(if coloring) minimum color number for the minimum data values'], ['clr_max', 99, '(if coloring) maximum color number for the maximum data values'] )
- @@next_linear_contour_options =
nil
- @@contour_levels =
Misc::KeywordOptAutoHelp.new( ['log', nil, 'approximately log-scaled levels (by using DCLExt::quasi_log_levels)'], ['log_cycle', 3, '(if log) number of levels in one-order (1 or 2 or 3)'], ['levels', nil, 'contour levels (Array/NArray of Numeric)'], ['index', nil, '(if levels) line index(es) (Array/NArray of integers, Integer, or nil)'], ['line_type',nil, '(if levels) line type(s) (Array/NArray of integers, Integer, or nil)'], ['label', nil, '(if levels) contour label(s) (Array/NArray of String, String, true, false, nil). nil is recommended.'], ['label_height',nil,'(if levels) label height(s) (Array/NArray of Numeric, Numeric, or nil). nil is recommended.'] )
- @@set_contour_levels =
false
- @@next_contour =
nil
- @@contour_options =
Misc::KeywordOptAutoHelp.new( ['title', nil, 'Title of the figure(if nil, internally determined)'], ['annotate', true, 'if false, do not put texts on the right margin even when newframe==true'], ['map_axes', false, '[USE IT ONLY WHEN itr=10 (cylindrical)] If true, draws axes by temprarilly switching to itr=1 and calling GGraph::axes.'], ['keep', false, 'Use the contour levels used previously'], @@linear_contour_options, @@contour_levels, @@data_prep_options )
- @@linear_tone_options =
Misc::KeywordOptAutoHelp.new( ['min', nil, 'minimum tone level'], ['max', nil, 'maximum tone level'], ['nlev', nil, 'number of levels'], ['interval', nil, 'contour interval'] )
- @@next_linear_tone_options =
nil
- @@tone_levels =
Misc::KeywordOptAutoHelp.new( ['log', nil, 'approximately log-scaled levels (by using DCLExt::quasi_log_levels)'], ['log_cycle', 3, '(if log) number of levels in one-order (1 or 2 or 3)'], ['levels', nil, 'tone levels (Array/NArray of Numeric). Works together with patterns'], ['patterns', nil, 'tone patters (Array/NArray of Numeric). Works together with levels'] )
- @@set_tone_levels =
false
- @@next_tone =
nil
- @@tone_options =
Misc::KeywordOptAutoHelp.new( ['title', nil, 'Title of the figure(if nil, internally determined)'], ['annotate', true, 'if false, do not put texts on the right margin even when newframe==true'], ['ltone', true, 'Same as udpack parameter ltone'], ['auto', false, 'Swith DCL.uetone and DCL.uetonf depending on the data size'], ['tonf', false, 'Use DCL.uetonf instead of DCL.uetone'], ['tonb', false, 'Use DCL.uetonb instead of DCL.uetone'], ['tonc', false, 'Use DCL.uetonc instead of DCL.uetone'], ['clr_min', nil, 'if an integer (in 10..99) is specified, used as the color number for the minimum data values. (the same can be done by setting the uepack parameter "icolor1")'], ['clr_max', nil, 'if an integer (in 10..99) is specified, used as the color number for the maximum data values. (the same can be done by setting the uepack parameter "icolor2")'], ['map_axes', false, '[USE IT ONLY WHEN itr=10 (cylindrical)] If true, draws axes by temprarilly switching to itr=1 and calling GGraph::axes.'], ['keep', false, 'Use the tone levels and patterns used previously'], ['color_bar', false, 'Add a color bar: THIS IS ONLY FOR QUICK LOOK. Use the GGraph::color_bar method explicitly for full option control'], @@linear_tone_options, @@tone_levels, @@data_prep_options )
- @@scatter_options =
< scatter diagram >
Misc::KeywordOptAutoHelp.new( ['title', "", 'Title of the figure(if nil, internally determined)'], ['annotate', true, 'if false, do not put texts on the right margin even when newframe==true'], ['index', 1, 'mark index'], ['type', 2, 'mark type'], ['size', 0.01, 'marks size'], ['map_axes', false, '[USE IT ONLY WHEN itr=10 (cylindrical)] If true, draws axes by temprarilly switching to itr=1 and calling GGraph::axes.'], ['correlation', false, 'calculate Pearson\'s correlation coefficient and show it on the bottom margin'], @@data_prep_options )
- @@next_scatter =
nil
- @@color_scatter_options =
< scatter diagram colored by values >
Misc::KeywordOptAutoHelp.new( ['title', nil, 'Title of the figure(if nil, internally determined)'], ['annotate', true, 'if false, do not put texts on the right margin even when newframe==true'], ['index', 3, 'mark index (1-9)'], ['type', 10, 'mark type'], ['size', 0.01, 'marks size'], ['map_axes', false, '[USE IT ONLY WHEN itr=10 (cylindrical)] If true, draws axes by temprarilly switching to itr=1 and calling GGraph::axes.'], ['clr_min', nil, 'if an integer (in 10..99) is specified, used as the color number for the minimum data values. (the same can be done by setting the uepack parameter "icolor1")'], ['clr_max', nil, 'if an integer (in 10..99) is specified, used as the color number for the maximum data values. (the same can be done by setting the uepack parameter "icolor2")'], ['keep', false, 'Use the tone levels and patterns used previously'], ['correlation', false, 'calculate Pearson\'s correlation coefficient and show it on the bottom margin'], @@linear_tone_options, @@tone_levels, @@data_prep_options )
- @@next_color_scatter =
nil
- @@add_mode_vectors_options =
Misc::KeywordOptAutoHelp.new( ['lineindex', 1, 'line index'], ['linetype', 1, 'line type'], ['fact', 2, 'scaling factor (line length = stddev * fact for each side)'], ['style', 'line', 'style of displaying modes (line, arrow, ellipse)'] )
- @@vxfxratio =
for flow_vect
nil
- @@vyfyratio =
for flow_vect
nil
- @@vfratio =
for flow_vect_anyproj
nil
- @@vector_options =
Misc::KeywordOptAutoHelp.new( ['title', nil, 'Title of the figure(if nil, internally determined)'], ['annotate', true, 'if false, do not put texts on the right margin even when newframe==true'], ['map_axes', false, '[USE IT ONLY WHEN itr=10 (cylindrical)] If true, draws axes by temprarilly switching to itr=1 and calling GGraph::axes.'], ['flow_vect', true, 'If true, use DCLExt::flow_vect to draw vectors; otherwise, DCL::ugvect is used.'], ['flow_vect_anyproj', nil, 'Whether to use flow_vect_anyproj. If nil, up to the current projection number (when >=2); if true, always; if false, never. (precedence if higher than the flow_vect parameter)'], ['keep', false, 'Use the same vector scaling as in the previous call. -- Currently, works only when "flow_vect" is true'], ['factor', 1.0, '(Effective only if flow_vect) scaling factor to strech/reduce the arrow lengths'], ['unit_vect', false, 'Show the unit vector'], ['max_unit_vect', false, '(Effective only if flow_vect && unit_vect) If true, use the maximum arrows to scale the unit vector; otherwise, normalize in V coordinate.'], ['ux_unit', nil, '(If Numeric) length of the x direction unit vector (precedence of this option is lower than max_unit_vect)'], ['uy_unit', nil, '(If Numeric) length of the y direction unit vector (precedence of this option is lower than max_unit_vect)'], ['len_unit', nil, '(Effective only when flow_vect_anyproj is used) If Numeric, length of the the unit vector in terms of (fx,fy); if nil (defualt), the unitvecto length is set to be the maximum one'], ['flow_itr5', false, 'If true, use DclExt::flow_itr5 to draw vectors on 2-dim polar coordinate. Should be set DCL.sgstrn(5)'], ['polar_thinning', nil, '(Effective only when flow_vect_anyproj is used) If Numeric, specifies the maximum grid isotrpy, with which thinning is made near the poles (recommended value: 0.3 ~ 1)'], ['distvect_map', true, '(effective only for flow_vect_anyproj when map projection) by default (true) it is assumed that the vector (fx,fy) is based on lengths (such as wind velocities in m/s and fluxes in which wind velocities are incorporated [q*u, q*v]); set it to false if the vector is based on angles (such as the time derivatives of longitude and latitude).'], @@data_prep_options )
- @@regression_line_options =
Misc::KeywordOptAutoHelp.new( ['x_given_y', false, 'If false (default), regress y for given x. If true, x given y.'], ['annot_slope', nil, 'Whether to show the slope on the right margin. nil: show when itr=1,4, do not show when itr=2,3; true: show; false: not show'], ['annot_intercept', false, '[Meaningful only when itr=1 (linear scaling plot)] if true, show the intercept on the right margin'], ['limit', false, 'If true, regression line is shown only over the range between max and min of the independent variable. If false, regression line is written over the whole range of the independent variable'], ['clip', true, "If true, use DCL's clipping not to show the line outside the viewport"], ['index', 1, 'line index'], ['type', 1, 'line type'] )
- @@next_regression_line =
nil
- @@histogram_options =
Misc::KeywordOptAutoHelp.new( ['window', [nil,nil,nil,nil], "window bounds"], ['title', "histogram", "window title"], ['exchange', false, "exchange x and y"], ['fill', false, "fill bars"] )
Class Method Summary collapse
-
.__calendar_ax(axtype, xax, side, sunits, calendar, ttl, tickint = nil, labelint = nil) ⇒ Object
axtype: nil (–>auto), ‘h’ (to resolve hours), or ‘ymd’.
- .__good_range(x0, x1) ⇒ Object
- .__round_window(window) ⇒ Object
-
.__shorten_path(str, maxlen) ⇒ Object
private methods in the module.
- ._get_axinfo(vary) ⇒ Object
- ._scatter_display_corr(gpx, gpy, opts) ⇒ Object
- ._set_contour_levels_(opts) ⇒ Object
- ._set_tone_levels_(opts) ⇒ Object
- .add_mode_vectors(mean, modes, options = nil) ⇒ Object
- .annotate(str_ary, noff = nil) ⇒ Object
- .annotate_at(str_ary, vx, vy, charsize = nil, align = -1.0,, dvyfact = -1.5,, noff = nil) ⇒ Object
- .axes(xax = nil, yax = nil, options = nil) ⇒ Object
- .axes_or_map_and_ttl(gp, opts, xax, yax, gp2 = nil) ⇒ Object
- .clear_contour_levels ⇒ Object
- .clear_tone_levels ⇒ Object
- .color_bar(*args) ⇒ Object
- .color_scatter(fx, fy, fz, newframe = true, options = nil) ⇒ Object
- .contour(gphys, newframe = true, options = nil) ⇒ Object
- .current_itr(fig_yet_to_be_called = false) ⇒ Object
- .data_prep_1D(gphys, opts) ⇒ Object
- .data_prep_1D2(fx, fy, opts) ⇒ Object
- .data_prep_2D(gps, newframe, opts) ⇒ Object
- .data_prep_multidim(gphys, opts) ⇒ Object
- .fig(xax = nil, yax = nil, options = nil) ⇒ Object
- .gropn_1_if_not_yet ⇒ Object
- .histogram(gphys, newframe = true, options = nil) ⇒ Object (also: histogram1D)
- .itr_is?(itr, fig_yet_to_be_called = false) ⇒ Boolean
- .line(gphys, newframe = true, options = nil) ⇒ Object
- .map(options = nil) ⇒ Object
- .map_trn?(fig_yet_to_be_called = false) ⇒ Boolean
- .margin_info(program = nil, data_source = nil, char_height = nil, date = nil, xl = 0.0, xr = 0.0, yb = nil, yt = 0.0) ⇒ Object
- .mark(gphys, newframe = true, options = nil) ⇒ Object
- .name_selector(gp, limit) ⇒ Object
- .next_axes(options) ⇒ Object
- .next_color_scatter(options) ⇒ Object
- .next_contour(options) ⇒ Object
- .next_fig(options) ⇒ Object
- .next_linear_contour_options(options) ⇒ Object
- .next_linear_tone_options(options) ⇒ Object
- .next_map(options) ⇒ Object
- .next_regression_line(options) ⇒ Object
- .next_scatter(options) ⇒ Object
- .next_tone(options) ⇒ Object
- .next_unit_vect_options(options) ⇒ Object
- .polar_coordinate_boundaries(xax = nil, yax = nil) ⇒ Object
-
.profile(gphys, newframe = true, options = nil) ⇒ Object
———————————————————- Added at 080207 –.
- .regression_line(x, y, options = nil) ⇒ Object
- .scatter(fx, fy, newframe = true, options = nil) ⇒ Object
- .set_axes(options) ⇒ Object
-
.set_color_scatter(options) ⇒ Object
@@color_scatter_options.delete(“transpose”) # delete is yet to be supported @@color_scatter_options.delete(“exchange”) # (2010-01).
- .set_contour(options) ⇒ Object
- .set_contour_levels(options) ⇒ Object
- .set_fig(options) ⇒ Object
- .set_linear_contour_options(options) ⇒ Object
- .set_linear_tone_options(options) ⇒ Object
- .set_map(options) ⇒ Object
- .set_regression_line(options) ⇒ Object
-
.set_scatter(options) ⇒ Object
@@scatter_options.delete(“transpose”) # delete is yet to be supported @@scatter_options.delete(“exchange”) # (2010-01).
- .set_tone(options) ⇒ Object
- .set_tone_levels(options) ⇒ Object
-
.set_unit_vect_options(options) ⇒ Object
< vector >.
- .sim_trn? ⇒ Boolean
-
.timeplot(gphys, newframe = true, options = nil) ⇒ Object
timeplot 0802011 ######.
- .title(string) ⇒ Object
- .tone(gphys, newframe = true, options = nil) ⇒ Object
- .tone_and_contour(gphys, newframe = true, options = nil) ⇒ Object
- .vector(fx, fy, newframe = true, options = nil) ⇒ Object
- .vector_on_merdional_section(fx, fy, newframe = true, options = nil) ⇒ Object
Class Method Details
.__calendar_ax(axtype, xax, side, sunits, calendar, ttl, tickint = nil, labelint = nil) ⇒ Object
axtype: nil (–>auto), ‘h’ (to resolve hours), or ‘ymd’
1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 |
# File 'lib/numru/ggraph.rb', line 1547 def __calendar_ax(axtype, xax, side, sunits, calendar, ttl, \ tickint=nil, labelint=nil) window = DCL.sgqwnd = DCL.sgqvpt /(.*) *since *(.*)/ =~ sunits if (!$1 or !$2) raise("Units mismatch. Requires time units that includes 'since'") end tun = Units[$1] dayun = Units['days'] if xax t0 = window[0] t1 = window[1] else t0 = window[2] t1 = window[3] end time = UNumeric.new(t0,sunits) tstr = time.to_datetime(0.1,calendar) jd0 = tstr.strftime('%Y%m%d').to_i tlen = tun.convert( t1-t0, dayun ) if !axtype if tlen < 5 axtype = 'h' else axtype = 'ymd' end end if xax DCL.grswnd(0.0, tlen, window[2], window[3] ) DCL.grstrf if axtype == 'h' opts = {'cside'=>side} opts['dtick1'] = tickint if tickint opts['dtick2'] = labelint if labelint DCLExt.datetime_ax(tstr, tstr+tlen, opts ) else DCL.ucxacl(side,jd0,tlen) end DCL.grswnd(*window) DCL.grstrf else DCL.grswnd(window[0], window[1], 0.0, tlen) DCL.grstrf if axtype == 'h' opts = {'yax'=>true, 'cside'=>side} opts['dtick1'] = tickint if tickint opts['dtick2'] = labelint if labelint DCLExt.datetime_ax(tstr, tstr+tlen, opts ) else DCL.ucyacl(side,jd0,tlen) end DCL.grswnd(*window) DCL.grstrf end end |
.__good_range(x0, x1) ⇒ Object
1490 1491 1492 1493 1494 1495 1496 1497 |
# File 'lib/numru/ggraph.rb', line 1490 def __good_range(x0,x1) x0 = x0.to_f x1 = x1.to_f xw = (x1-x0).abs e10, lx = (Math::log10(xw)).divmod(1.0) ef = 5.0 * 10**(-e10) [(x0*ef).floor/ef,(x1*ef).ceil/ef] end |
.__round_window(window) ⇒ Object
1499 1500 1501 1502 1503 |
# File 'lib/numru/ggraph.rb', line 1499 def __round_window(window) x0,x1 = __good_range(window[0],window[1]) y0,y1 = __good_range(window[2],window[3]) [ x0, x1, y0, y1 ] end |
.__shorten_path(str, maxlen) ⇒ Object
private methods in the module
1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 |
# File 'lib/numru/ggraph.rb', line 1082 def __shorten_path(str,maxlen) return str if str.length <= maxlen astr = str.split(/\//) while(str.length > maxlen) astr.length!=2 ? at = (astr.length)/2 : at = 0 astr.delete_at( at ) (a = astr.dup)[at, 0] = '...' # insert(at,'...') if Ruby>=1.8 str = a.join('/') end str end |
._get_axinfo(vary) ⇒ Object
1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 |
# File 'lib/numru/ggraph.rb', line 1709 def _get_axinfo(vary) if vary.nil? hash = { 'title'=>'', 'units'=>'' } else #raise "Not 1D" if vary.rank!=1 hash = { 'title'=>(vary.long_name || vary.name), #.gsub('_','' ) 'units'=>(vary.get_att('units') || '') #.gsub('_',' ') } end hash end |
._scatter_display_corr(gpx, gpy, opts) ⇒ Object
2887 2888 2889 2890 2891 2892 2893 |
# File 'lib/numru/ggraph.rb', line 2887 def _scatter_display_corr(gpx, gpy, opts) require "numru/ganalysis/covariance" r, n = gpx.correlation(gpy,0) r = r.val if r.is_a?(GPhys) DCL::uxsttl("B","r=#{DCL.chval('A',r)}", 0) return [r, n] end |
._set_contour_levels_(opts) ⇒ Object
2360 2361 2362 2363 2364 2365 2366 |
# File 'lib/numru/ggraph.rb', line 2360 def _set_contour_levels_(opts) raise ArgumentError, "'levels' must be explicitly set" if !opts['levels'] DCLExt.ud_set_contour(opts['levels'],opts['index'],opts['line_type'], opts['label'],opts['label_height']) @@set_contour_levels=true nil end |
._set_tone_levels_(opts) ⇒ Object
2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 |
# File 'lib/numru/ggraph.rb', line 2556 def _set_tone_levels_(opts) if !opts['levels'] && !opts['patterns'] end if opts['levels'] levels = opts['levels'] else raise ArgumentError,"'levels' must be explicitly set" end if opts['patterns'] patterns = opts['patterns'] else nlev = levels.length - 1 itpat = DCL.ueiget('itpat') iclr1 = DCL.ueiget('icolor1') iclr2 = DCL.ueiget('icolor2') patterns = (0...nlev).collect{|i| (((iclr2-iclr1)/(nlev-1.0)*i+iclr1).round) * 1000 + itpat } end DCLExt.ue_set_tone(levels,patterns) @@set_tone_levels=true nil end |
.add_mode_vectors(mean, modes, options = nil) ⇒ Object
2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 |
# File 'lib/numru/ggraph.rb', line 2902 def add_mode_vectors(mean, modes, =nil) opts = @@add_mode_vectors_options.interpret() unless modes.shape == [2,2] || modes.shape[2,1] || modes.shape == [2] raise ArgumentError, "the second arg must be a NArray of the shape [2,2], [2,1], or [2]." end unless (mean.length == 2) && (mean.is_a?(GPhys) || mean.is_a?(NArray) || mean.is_a?(Array)) raise ArgumentError, "the 1st arg must be a GPhys, NArray, or Array with length of 2" end mean = mean.val if mean.is_a?(GPhys) modes = modes.val * opts['fact'] index = opts['lineindex'] type = opts['linetype'] modes = modes.newdim(-1) if modes.rank == 1 for i in 0...(modes.shape[1]) case opts['style'] when "line" DCL::sgplzu([mean[0]-modes[0,i],mean[0]+modes[0,i]], [mean[1]-modes[1,i],mean[1]+modes[1,i]], type,index) when "arrow" DCL::sglazu(mean[0]-modes[0,i],mean[1]-modes[1,i], mean[0]+modes[0,i],mean[1]+modes[1,i], type,index) when "ellipse" raise "Drawing an ellipse needs two modes" unless modes.shape[1]==2 arg = NArray.int(361).indgen!.to_f / 180.0 * NMath::PI s = NMath.sin(arg) c = NMath.cos(arg) x = mean[0] + modes[0,0] * c + modes[0,1] * s y = mean[1] + modes[1,0] * c + modes[1,1] * s DCL::sgplzu(x,y,type,index) else raise "invalid value for the option 'style' in add_mode_vectors: #{kind}" end end end |
.annotate(str_ary, noff = nil) ⇒ Object
1152 1153 1154 1155 1156 1157 1158 1159 |
# File 'lib/numru/ggraph.rb', line 1152 def annotate(str_ary, noff=nil) charsize = 0.7 * DCL.uzpget('rsizec1') vxmin,vxmax,vymin,vymax = DCL.sgqvpt vx = vxmax + 0.01 vy = vymax - charsize/2 nannot = annotate_at(str_ary,vx,vy,charsize,-1.0,-1.5,noff) @@nannot = nannot end |
.annotate_at(str_ary, vx, vy, charsize = nil, align = -1.0,, dvyfact = -1.5,, noff = nil) ⇒ Object
1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 |
# File 'lib/numru/ggraph.rb', line 1161 def annotate_at(str_ary,vx,vy,charsize=nil, align=-1.0, dvyfact=-1.5, noff=nil) raise TypeError,"Array expected" if ! str_ary.is_a?(Array) charsize = 0.7 * DCL.uzpget('rsizec1') unless(charsize) dvy = charsize*dvyfact vy += noff*dvy if noff str_ary.each{|str| DCL::sgtxzr(vx,vy,str,charsize,0,align,1) vy += dvy } nannot = str_ary.length nannot += noff if noff nannot end |
.axes(xax = nil, yax = nil, options = nil) ⇒ Object
1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 |
# File 'lib/numru/ggraph.rb', line 1606 def axes(xax=nil, yax=nil, =nil) if @@next_axes = ( ? @@next_axes.update() : @@next_axes ) @@next_axes = nil end opts = @@axes.interpret() if itr51 = (DCL.sgqtrn == 51) wnd = DCL::sgqwnd DCL::sgswnd( *(cwd = DCL::sgqcwd) ) DCL::sgstrn(1) DCL::sgstrf end if opts['xside'].length > 0 xai = _get_axinfo(xax) if opts['xmaplabel'] == "lon" opts['xside'].split('').each{|s| # scan('.') also works DCLExt.lon_ax('cside'=>s, 'dtick1'=>opts['xtickint'], 'dtick2'=>opts['xlabelint']) } DCL.uxsttl('b', (opts['xtitle'] || xai['title']), 0.0) elsif opts['xmaplabel'] == "lat" opts['xside'].split('').each{|s| # scan('.') also works DCLExt.lat_ax('xax'=>true, 'cside'=>s, 'dtick1'=>opts['xtickint'], 'dtick2'=>opts['xlabelint']) } DCL.uxsttl('b', (opts['xtitle'] || xai['title']), 0.0) else sunits = opts['xunits'] || xai['units'] units = Units[sunits] if opts['time_ax'] != false && \ /since/ =~ sunits && units =~ Units['days since 0001-01-01'] && \ ( calendar = ( xax.get_att('calendar') || nil ) ; \ UNumeric::supported_calendar?(calendar) ) opts['xside'].split('').each do |s| # scan('.') also works ttl = opts['xtitle'] || xai['title'] __calendar_ax(opts['time_ax'], true, s, sunits, calendar, ttl, opts['xtickint'], opts['xlabelint']) end else DCL.uscset('cxttl', (opts['xtitle'] || xai['title']) ) DCL.uscset('cxunit', sunits) DCL.uspset('dxt', opts['xtickint']) if(opts['xtickint']) DCL.uspset('dxl', opts['xlabelint']) if(opts['xlabelint']) if(opts['xloglabelall']) DCL.uspset('nlblx', 4) DCL.ulsxbl([1,2,3,4,5,6,7,8,9]) end opts['xside'].split('').each{|s| # scan('.') also works DCL.usxaxs(s) } end end end if opts['yside'].length > 0 yai = _get_axinfo(yax) if opts['ymaplabel'] == "lon" opts['yside'].split('').each{|s| # scan('.') also works DCLExt.lon_ax('yax'=>true, 'cside'=>s, 'dtick1'=>opts['ytickint'], 'dtick2'=>opts['ylabelint']) } DCL.uysttl('l', (opts['ytitle'] || yai['title']), 0.0) elsif opts['ymaplabel'] == "lat" opts['yside'].split('').each{|s| # scan('.') also works DCLExt.lat_ax('cside'=>s, 'dtick1'=>opts['ytickint'], 'dtick2'=>opts['ylabelint']) } DCL.uysttl('l', (opts['ytitle'] || yai['title']), 0.0) else sunits=(opts['yunits'] || yai['units']) units = Units[sunits] if opts['time_ax'] != false && \ /since/ =~ sunits && units =~ Units['days since 0001-01-01'] && \ ( calendar = ( yax.get_att('calendar') || nil ) ; \ UNumeric::supported_calendar?(calendar) ) opts['yside'].split('').each do |s| # scan('.') also works ttl = opts['ytitle'] || yai['title'] __calendar_ax(opts['time_ax'], false, s, sunits, calendar, ttl, opts['ytickint'], opts['ylabelint']) end else DCL.uscset('cyttl', (opts['ytitle'] || yai['title']) ) DCL.uscset('cyunit', sunits ) DCL.uspset('dyt', opts['ytickint']) if(opts['ytickint']) DCL.uspset('dyl', opts['ylabelint']) if(opts['ylabelint']) if(opts['yloglabelall']) DCL.uspset('nlbly', 4) DCL.ulsybl([1,2,3,4,5,6,7,8,9]) end opts['yside'].split('').each{|s| # scan('.') also works DCL.usyaxs(s) if s=='l' && sunits && sunits != '' DCL.uzpset('roffxt', DCL.uzpget('rsizec1')*1.5 ) end } end end title(opts['title']) if opts['title'] end if itr51 DCL::sgstrn(51) DCL::sgswnd( *wnd ) DCL::sgscwd( *cwd ) DCL::sgstrf end nil end |
.axes_or_map_and_ttl(gp, opts, xax, yax, gp2 = nil) ⇒ Object
2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 |
# File 'lib/numru/ggraph.rb', line 2411 def axes_or_map_and_ttl(gp, opts, xax, yax, gp2=nil) if !gp2 ttl = opts['title'] || name_selector(gp, 30) else ttl = opts['title'] || '(' << name_selector(gp, 15) << ',' << name_selector(gp2, 15) << ')' end if map_trn? map if opts['map_axes'] && itr_is?(10) vpt = DCL.sgqvpt wnd = DCL.sgqwnd if wnd.include?(DCL.glrget('rundef')) map_fit = false wnd = DCL.sgqtxy cnt = DCL.umqcnt else map_fit = true end vrat = ( (vpt[3]-vpt[2]) / (vpt[1]-vpt[0]) ).abs wrat = ( (wnd[3]-wnd[2]) / (wnd[1]-wnd[0]) ).abs if wrat < vrat vyoff = (vpt[3]+vpt[2])/2 dvy2 = (vpt[1]-vpt[0])*wrat/2 vpt[2] = vyoff - dvy2 vpt[3] = vyoff + dvy2 else vxoff = (vpt[1]+vpt[0])/2 dvx2 = (vpt[3]-vpt[2])/wrat/2 vpt[0] = vxoff - dvx2 vpt[1] = vxoff + dvx2 end trn = DCL.sgqtrn if map_fit fig(xax,yax, {'itr'=>1, 'new_frame'=>false, 'viewport'=>vpt}) axes(xax, yax, 'title'=>ttl) fig(xax,yax,{'itr'=>trn, 'new_frame'=>false, 'viewport'=>vpt, 'map_fit'=>true}) else xax_map = xax[0..1].copy xax_map[0] = cnt[0] + wnd[0] xax_map[1] = cnt[0] + wnd[1] yax_map = yax[0..1].copy yax_map[0] = wnd[2] yax_map[1] = wnd[3] fig(xax_map,yax_map,{'itr'=>1, 'new_frame'=>false, 'viewport'=>vpt}) axes(xax_map, yax_map, 'title'=>ttl) fig(xax_map,yax_map,{'itr'=>trn, 'new_frame'=>false, 'viewport'=>vpt, 'map_fit'=>false, 'map_axis'=>cnt, 'map_window'=>wnd}) end else title( ttl ) end elsif itr_is?(5) polar_coordinate_boundaries(xax,yax) title( ttl ) else axes(xax, yax, 'title'=>ttl) end annotate(gp.lost_axes) if opts['annotate'] end |
.clear_contour_levels ⇒ Object
2368 2369 2370 2371 2372 |
# File 'lib/numru/ggraph.rb', line 2368 def clear_contour_levels @@set_contour_levels=false DCL.udiclv # this may not be needed nil end |
.clear_tone_levels ⇒ Object
2579 2580 2581 2582 |
# File 'lib/numru/ggraph.rb', line 2579 def clear_tone_levels @@set_tone_levels=false nil end |
.color_bar(*args) ⇒ Object
1133 1134 1135 |
# File 'lib/numru/ggraph.rb', line 1133 def (*args) DCLExt.(*args) end |
.color_scatter(fx, fy, fz, newframe = true, options = nil) ⇒ Object
2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 |
# File 'lib/numru/ggraph.rb', line 2800 def color_scatter(fx, fy, fz, newframe=true, =nil) gropn_1_if_not_yet if newframe!=true && newframe!=false raise ArgumentError, "4th arg (newframe) must be true or false" end if @@next_color_scatter = ( ? @@next_color_scatter.update() : @@next_color_scatter ) @@next_color_scatter = nil end opts = @@color_scatter_options.interpret() # interpret cut, slice, etc gpx, closerx = data_prep_multidim(fx, opts) gpy, closery = data_prep_multidim(fy, opts) gpz, closerz = data_prep_multidim(fz, opts) # flatten gphys data ----- fakeaxis = Axis.new.set_pos(VArray.new(NArray.int(gpx.length).indgen!, {"long_name"=>"fake", "units"=>""}, "fake")) fakegrid = Grid.new(fakeaxis) gpx, gpy, gpz = [gpx, gpy, gpz].collect{|gp| na = gp.val.reshape!(gp.length) attr = gp.data.attr_copy newgp = GPhys.new(fakegrid,VArray.new(na,attr,gp.name)) newgp.set_lost_axes(gp.lost_axes) newgp } # ------------------------ xax = gpx.data yax = gpy.data if newframe fig(xax, yax) axes_or_map_and_ttl(gpz, opts, xax, yax) end zval = gpz.data.val # < levels setting --- taken from tone > if opts['clr_min'] icolor1_bak = DCL.uepget('icolor1') DCL.uepset('icolor1', opts['clr_min']) end if opts['clr_max'] icolor2_bak = DCL.uepget('icolor2') DCL.uepset('icolor2', opts['clr_max']) end rmiss = DCL.glrget('rmiss') if !opts['keep'] or DCL.ueqntl==0 if !opts['levels'] && opts['log'] levels, = DCLExt.quasi_log_levels_z(zval, opts['nlev'], opts['max'], opts['min'], opts['log_cycle']) levels.unshift(rmiss) if !opts['max'] && levels[0]<0 levels.push(rmiss) if !opts['max'] && levels[-1]>0 opts['levels'] = levels end if opts['levels'] backup = @@set_tone_levels _set_tone_levels_(opts) @@set_tone_levels = backup elsif opts['patterns'] # Here only the colors are used from patterns raise "option 'patterns' is not effective unless 'levels' is specified" elsif !@@set_tone_levels DCL.ueitlv DCLExt.ue_set_linear_levs(zval, opts) else DCL.ueitlv if !@@set_tone_levels end end DCL::uemrkz(xax.val, yax.val, zval, opts['type'], opts['index'], opts['size']) if opts['correlation'] return _scatter_display_corr(gpx, gpy, opts) else return nil end #< finish > ensure DCL.uepset('icolor1', icolor1_bak) if opts['clr_min'] DCL.uepset('icolor2', icolor2_bak) if opts['clr_max'] closerx.call if closerx closery.call if closery closerz.call if closerz end |
.contour(gphys, newframe = true, options = nil) ⇒ Object
2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 |
# File 'lib/numru/ggraph.rb', line 2470 def contour(gphys, newframe=true, =nil) gropn_1_if_not_yet if newframe!=true && newframe!=false raise ArgumentError, "2nd arg (newframe) must be true or false" end if @@next_contour = ( ? @@next_contour.update() : @@next_contour ) @@next_contour = nil end if @@next_linear_contour_options = ( ? @@next_linear_contour_options.update() : @@next_linear_contour_options ) @@next_linear_contour_options = nil end opts = @@contour_options.interpret() xax, yax, closer, gp = data_prep_2D([gphys], newframe, opts) if newframe fig(xax, yax) end if newframe axes_or_map_and_ttl(gp,opts, xax, yax) end if !opts['keep'] or DCL.udqcln==0 if !opts['levels'] && opts['log'] levels, mjmn = DCLExt.quasi_log_levels_z(gp.data.val, opts['nlev'], opts['max'], opts['min'], opts['log_cycle']) opts['levels'] = levels opts['index'] = NArray.to_na(mjmn)*2 + 1 if !opts['index'] opts['label'] = true if opts['label'].nil? end if (opts['levels']) backup = @@set_contour_levels _set_contour_levels_(opts) @@set_contour_levels = backup elsif !@@set_contour_levels DCLExt.ud_set_linear_levs(gp.data.val, opts) end end saved_udparams = nil if DCL.udqcln >= 3 lv1, = DCL.udqclv(1) lv2, = DCL.udqclv(2) lv3, = DCL.udqclv(3) if lv2-lv1 != lv3-lv2 saved_udparams = DCLExt.ud_set_params({'lmsg'=>false}) end end DCL.uwsgxa(xax.val) if xax.rank==1 DCL.uwsgya(yax.val) if yax.rank==1 DCL.udcntz(gp.data.val) DCLExt.ud_set_params(saved_udparams) if saved_udparams closer.call if closer nil end |
.current_itr(fig_yet_to_be_called = false) ⇒ Object
1228 1229 1230 1231 1232 1233 1234 1235 |
# File 'lib/numru/ggraph.rb', line 1228 def current_itr( fig_yet_to_be_called=false ) if fig_yet_to_be_called current_itr = ( @@next_fig && @@next_fig['itr'] ) || @@fig['itr'] else current_itr = DCL.sgqtrn end current_itr end |
.data_prep_1D(gphys, opts) ⇒ Object
1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 |
# File 'lib/numru/ggraph.rb', line 1903 def data_prep_1D(gphys, opts) gp = gphys if gp.is_a?(String) gp = GPhys::IO.str2gphys(gp) closer = Proc.new{gp.close} else closer = nil end gp = gp[*opts['slice']] if opts['slice'] if (cut = opts['cut']) # substitution, not == if cut.is_a?(Array) gp = gp.cut(*cut) else gp = gp.cut(cut) end end gp = gp.mean(*opts['mean']) if opts['mean'] gp = gp.first1D window = ( @@next_fig['window'] if @@next_fig ) || @@fig['window'] window = ( window ? window.dup : [nil, nil, nil, nil]) max = opts['max']; min = opts['min'] if !opts['exchange'] xd = gp.coord(0) yd = gp.data window[2] = min if min window[3] = max if max else yd = gp.coord(0) xd = gp.data window[0] = min if min window[1] = max if max end [xd, yd, closer, gp, window] end |
.data_prep_1D2(fx, fy, opts) ⇒ Object
1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 |
# File 'lib/numru/ggraph.rb', line 1938 def data_prep_1D2(fx, fy, opts) gpx = fx gpy = fy to_close = Array.new if gpx.is_a?(String) gpx = GPhys::IO.str2gphys(gpx) to_close.push(gpx) end if gpy.is_a?(String) gpy = GPhys::IO.str2gphys(gpy) to_close.push(gpy) end if to_close.length > 0 closer = Proc.new{to_close.each{|gp| gp.close}} else closer = nil end gpx = gpx[*opts['slice']] if opts['slice'] if (cut = opts['cut']) # substitution, not == if cut.is_a?(Array) gpx = gpx.cut(*cut) else gpx = gpx.cut(cut) end end gpx = gpx.mean(*opts['mean']) if opts['mean'] gpx = gpx.first1D gpy = gpy[*opts['slice']] if opts['slice'] if (cut = opts['cut']) # substitution, not == if cut.is_a?(Array) gpy = gpy.cut(*cut) else gpy = gpy.cut(cut) end end gpy = gpy.mean(*opts['mean']) if opts['mean'] gpy = gpy.first1D [gpx, gpy, closer] end |
.data_prep_2D(gps, newframe, opts) ⇒ Object
1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 |
# File 'lib/numru/ggraph.rb', line 1827 def data_prep_2D(gps, newframe, opts) opend_here = [] gps.collect!{|gp| if gp.is_a?(String) gp = GPhys::IO.str2gphys(gp) opend_here.push(gp) end gp = gp[*opts['slice']] if opts['slice'] if (cut = opts['cut']) # substitution, not == if cut.is_a?(Array) gp = gp.cut(*cut) else gp = gp.cut(cut) end end gp = gp.mean(*opts['mean']) if opts['mean'] gp = gp.first2D gp = gp.transpose(1,0) if opts['transpose'] || opts['exchange'] if opts['xintv'] || opts['yintv'] gp = gp.copy sh = gp.shape if opts['xintv'] && ((xi=opts['xintv']) >= 2) idx = NArray.int((sh[0]/xi.to_f).ceil).indgen!*xi # 0,xi,2*xi,.. gp = gp[idx, true] end if opts['yintv'] && ((yi=opts['yintv']) >= 2) idx = NArray.int((sh[1]/yi.to_f).ceil).indgen!*yi # 0,yi,2*yi,.. gp = gp[true, idx] end end gp } if opend_here.length > 0 closer = Proc.new{opend_here.each{|gp| gp.data.file.close}} else closer = nil end xd = gps[0].coord(0) yd = gps[0].coord(1) if xc=opts['xcoord'] xa = gps[0].coord(xc) if xa.rank == 1 && xa.length != xd.length raise("Len of #{xc} do not agree with the #{xd.name} dim") elsif xa.rank == 2 && xa.shape != gps[0].shape raise("Invalid 2D coord shape. #{xc} : #{xa.shape.inspect}" + " vs #{gps[0].shape.inspect}") end xd = xa end if yc=opts['ycoord'] ya = gps[0].coord(yc) if ya.rank == 1 && ya.length != yd.length raise("Len of #{yc} do not agree with the #{yd.name} dim") elsif ya.rank == 2 && ya.shape != gps[0].shape raise("Invalid 2D coord shape. #{yc} : #{ya.shape.inspect}" + " vs #{gps[0].shape.inspect}") end yd = ya end if map_trn?(newframe) # // convert to the anti-clockwise coordinate in case for map filling # (Because of a bug in UMFMAP in DCL 5.3) --> if ( (xd[-1].val-xd[0].val)*(yd[-1].val-yd[0].val) < 0 ) gps.collect!{|gp| gp.copy[true,-1..0]} yd = gps[0].coord(1) end # <-- /// gps.collect!{|gp| gp.cyclic_ext(0, 360.0)} #cyclic extentn along lon xd = gps[0].coord(0) elsif itr_is?(5, newframe) gps.collect!{|gp| gp.cyclic_ext(1, 360.0)} #cyclic ext along azimuth yd = gps[0].coord(1) end [xd, yd, closer, *gps] end |
.data_prep_multidim(gphys, opts) ⇒ Object
1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 |
# File 'lib/numru/ggraph.rb', line 1981 def data_prep_multidim(gphys, opts) gp = gphys if gp.is_a?(String) gp = GPhys::IO.str2gphys(gp) closer = Proc.new{gp.close} else closer = nil end gp = gp[*opts['slice']] if opts['slice'] if (cut = opts['cut']) # substitution, not == if cut.is_a?(Array) gp = gp.cut(*cut) else gp = gp.cut(cut) end end gp = gp.mean(*opts['mean']) if opts['mean'] [gp, closer] end |
.fig(xax = nil, yax = nil, options = nil) ⇒ Object
1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 |
# File 'lib/numru/ggraph.rb', line 1247 def fig(xax=nil, yax=nil, =nil) # xax and yax are needed (i.e. Axis objects) if not map projection if @@next_fig = ( ? @@next_fig.update() : @@next_fig ) @@next_fig = nil end opts = @@fig.interpret() if opts['no_new_fig'] # do nothing elsif opts['new_frame'] DCL.grfrm else DCL.grfig end raise "viewport's length must be 4" if opts['viewport'].length != 4 DCL.grsvpt(*opts['viewport']) @@nannot = 0 if opts['window'] if !opts['window'].is_a?(Array) || opts['window'].length!=4 raise "Option 'window' must be an Array of length==4" end end itr = opts['itr'] DCL.grstrn(itr) map_fit = ( (itr==10 and opts['map_fit']!=false) or (itr==11 and opts['map_fit']==true) ) DCL.sgpset("RSAT",opts['map_rsat']) if (opts['map_rsat']) if ( (1<=itr and itr<=4) or (51<=itr and itr<=99) or map_fit ) window = opts['window'] window = ( window ? window.dup : [nil, nil, nil, nil]) if window.include?(nil) raise(ArgumentError, "xax and yax must be provided") if !xax or !yax if (xreverse=opts['xreverse']).is_a?(String) atts = opts['xreverse'].split(',').collect{|v| v.split(':')} xreverse = false atts.each{|key,val| xreverse = ( key.downcase=="units" ? (Units.new(xax.get_att(key)) =~ Units.new(val)) : (xax.get_att(key) == val) ) break if xreverse } end if (yreverse=opts['yreverse']).is_a?(String) atts = opts['yreverse'].split(',').collect{|v| v.split(':')} yreverse = false atts.each{|key,val| yreverse = ( key.downcase=="units" ? (Units.new(yax.get_att(key)) =~ Units.new(val)) : (yax.get_att(key) == val) ) break if yreverse } end if xreverse xrange = [ xax.max, xax.min ] else xrange = [ xax.min, xax.max ] end if yreverse yrange = [ yax.max, yax.min ] else yrange = [ yax.min, yax.max ] end [ xrange, yrange ].each do |range| r0 = range[0] r1 = range[1] if r0 == r1 if r0.nil? raise("Cannot set a window. Maybe plotting all-missing data?") end # if the max and min of the range is the same, shift them a bit range[0] = DCL.rgnlt(r0) range[1] = DCL.rgngt(r0) if range[0] == range[1] # if min and max are still the same range[0] -= 1 range[1] += 1 end end end default_window=[xrange[0], xrange[1], yrange[0], yrange[1]] default_window = __round_window(default_window) if opts['round0'] if (if [].respond_to?("nitems") window.nitems == 0 else window.none? end) # if all elements is nil window = default_window else window.each_index do |i| window[i] = default_window[i] if window[i] == nil end end window = __round_window(window) if opts['round1'] end end case itr when 1..4,51..99 # all but for map projections and curvilinear coordinates if xax.rank==2 || yax.rank==2 if xax.rank==2 nx,ny = xax.shape else nx,ny = yax.shape end if x2d = (xax.rank==2) ux = NArray.sfloat(nx).indgen! cx = xax.val else ux = xax.val cx = NArray.sfloat(nx,ny) cx[0,0] = DCL::glrget('rundef') end if y2d = (yax.rank==2) uy = NArray.sfloat(ny).indgen! cy = yax.val else uy = yax.val cy = NArray.sfloat(nx,ny) cy[0,0] = DCL::glrget('rundef') end DCL::grswnd(0.0,ux.max,0.0,uy.max) DCL::grscwd(*window) DCL::g2sctr(ux,uy,cx,cy) DCL::grstrn(51) DCL.uwsgxa(ux) DCL.uwsgya(uy) else DCL.grswnd(*window) end if itr <= 4 and opts['eqdistvpt'] # modify viewport to equidistant vx1,vx2,vy1,vy2 = opts['viewport'] wx1,wx2,wy1,wy2 = window vxw = (vx2-vx1).abs vyw = (vy2-vy1).abs wxw = (wx2-wx1).abs wyw = (wy2-wy1).abs if ( [vxw,vyw,wxw,wyw].min > 0 ) rx = wxw / vxw ry = wyw / vyw if rx > ry rc = ry/rx vym = (vy1+vy2)/2.0 vy1 = vym - rc*vyw/2.0 vy2 = vym + rc*vyw/2.0 elsif rx < ry rc = rx/ry vxm = (vx1+vx2)/2.0 vx1 = vxm - rc*vxw/2.0 vx2 = vxm + rc*vxw/2.0 end DCL.grsvpt(vx1,vx2,vy1,vy2) end end when 5,6 if opts['similar'] similar=opts['similar'] DCL.grssim(*similar) elsif opts['window'] if defined?(DCL::DCLVERSION) && DCL::DCLVERSION >= '5.3' DCL.sgscwd(*opts['window']) else raise "You need DCL 5.3 or later to use the 'window' parameter in this transform (#{itr}). Use 'similar' instead." end else case itr when 5 vxmin,vxmax,vymin,vymax=DCL.sgqvpt raise(ArgumentError, "xax must be provided") if !xax simfac = (vymax-vymin)/(xax.max*2) # only xax is used similar = [simfac,0.0,0.0] DCL.grssim(*similar) else raise NotImplementedError, "Sorry, automatic window setting is yet to be available for the transform #{itr}. Please specify the 'similar' or 'window' parameter" end end when 10..19 sv = DCL.umpget('lglobe') if !map_fit map_axis = opts['map_axis'] || [180.0, 0.0, 0.0] DCL::umscnt( *map_axis ) map_window = opts['map_window'] raise "map_window's length must be 4" if map_window.length != 4 map_lat_range = [ map_window[2], map_window[3] ] if map_lat_range.is_a?(Range) map_lat_range = [map_lat_range.first, map_lat_range.end] end case ( map_axis[2] - map_axis[1] ) % 360 when 0 tyrange = map_lat_range when 180 tyrange = [ -map_lat_range[1], -map_lat_range[0] ] else tyrange = [ -75, 75 ] # latange is ignored end DCL::grstxy(map_window[0], map_window[1], tyrange[0], tyrange[1]) # 'lglobe' becomes true when itr >= 12 or data coverage is almost global for Mercator DCL.umpset('lglobe', (itr >= 12) || ((itr == 11) && (tyrange[0].abs >= 75) && (tyrange[1].abs >= 75) && (tyrange[0] * tyrange[1] < 0))) else lon_cent =( window[0] + window[1] ) / 2.0 dlon2 = ( window[1] - window[0] ) / 2.0 map_axis = [ lon_cent, 0.0, 0.0 ] DCL::sgswnd(*window) DCL::umscnt( *map_axis ) DCL::grstxy( -dlon2, dlon2, window[2], window[3] ) # 'lglobe' becomes true when data coverage is almost global for Mercator DCL.umpset('lglobe', (itr == 11) && (window[2].abs >= 75) && (window[3].abs >= 75) && (window[2] * window[3] < 0)) end DCL::umpfit when 20..34 map_axis = opts['map_axis'] || [180.0, 90.0, 0.0] map_radius = opts['map_radius'] || 70.0 DCL::umscnt( *map_axis ) case itr when 31 v = opts['viewport'] vptsize = [ v[1]-v[0], v[3]-v[2] ].min DCL::grssim( vptsize*0.25/Math::tan(0.5*Math::PI*map_radius/180.0), 0.0, 0.0 ) when 22 v = opts['viewport'] vptsize = [ v[1]-v[0], v[3]-v[2] ].min DCL::grssim( vptsize*0.35*(90.0/map_radius), 0.0, 0.0 ) DCL::grstxy(-180.0, 180.0, 90.0-map_radius, 90.0) else DCL::grstxy(-180.0, 180.0, 90.0-map_radius, 90.0) end sv = DCL.umpget('lglobe') DCL.umpset('lglobe', true) DCL::umpfit DCL.umpset('lglobe', sv) else raise "unsupported transformation number: #{itr}" end DCL.grstrf DCL.umpset('lglobe', sv) nil end |
.gropn_1_if_not_yet ⇒ Object
1098 1099 1100 1101 1102 1103 1104 |
# File 'lib/numru/ggraph.rb', line 1098 def gropn_1_if_not_yet begin DCL.stqwrc rescue DCL.gropn(1) end end |
.histogram(gphys, newframe = true, options = nil) ⇒ Object Also known as: histogram1D
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'lib/numru/ganalysis/histogram.rb', line 162 def histogram(gphys, newframe=true, =nil) gropn_1_if_not_yet if newframe!=true && newframe!=false raise ArgumentError, "2nd arg (newframe) must be true of false" end unless gphys.rank == 1 raise ArgumentError, "rank of gphys must be 1" end unless gphys.axis(0).cell? raise ArgumentError, "axis must be cell type" end # if window is specified via GGraph#fig or GGraph#set_fig, use it. opts = @@histogram_options.interpret() exchange = opts["exchange"] window = opts["window"] || @@fig['window'] unless exchange x = gphys.axis(0).cell_bounds y = gphys window[2] ||= 0 else y = gphys.axis(0).cell_bounds x = gphys window[0] ||= 0 end itr = @@fig['itr'] || DCL::sgpget("itr") if (itr==2 || itr==4) tmp = y.val if tmp.min * tmp.max < 0 if tmp.min.abs < tmp.max mask = tmp.lt(0) else mask = tmp.gt(0) end else mask = tmp.ne(0) end if tmp.is_a?(NArrayMiss) tmp.set_mask(mask * tmp.get_mask) else tmp = NArrayMiss.to_nam_no_dup(tmp, mask) end y.replace_val(tmp) window[2] = tmp.abs.min * (tmp.min < 0 ? -1 : 1) end if (itr==3 || itr==4) tmp = x.val if tmp.min * tmp.max < 0 if tmp.min.abs < tmp.max mask = tmp.lt(0) else mask = tmp.gt(0) end else mask = tmp.ne(0) end if tmp.is_a?(NArrayMiss) tmp.set_mask(mask * tmp.get_mask) else tmp = NArrayMiss.to_nam_no_dup(tmp, mask) end x.replace_val(tmp) window[0] = tmp.abs.min * (tmp.min < 0 ? -1 : 1) end opts["window"] = window if newframe fig(x, y, "window"=>opts["window"]) axes(x, y, "title"=>opts["title"]) end lmiss = DCL::gllget("lmiss") DCL::gllset("lmiss", true) unless exchange if opts["fill"] DCL::uvbxa(x.val, [window[2]] * y.length, y.val) end if (itr == 2) || (itr == 4) bottom = [y.val.min] * y.length else bottom = [window[2]] * y.length end DCL::uvbxf(x.val, bottom, y.val) else if opts["fill"] DCL::uhbxa([window[0]] * x.length, x.val, y.val) end if (itr == 3) || (itr == 4) bottom = [x.val.min] * x.length else bottom = [window[0]] * x.length end DCL::uhbxf(bottom, x.val, y.val) end DCL::gllset("lmiss", lmiss) return nil end |
.itr_is?(itr, fig_yet_to_be_called = false) ⇒ Boolean
1224 1225 1226 |
# File 'lib/numru/ggraph.rb', line 1224 def itr_is?( itr, fig_yet_to_be_called=false ) itr == current_itr( fig_yet_to_be_called ) end |
.line(gphys, newframe = true, options = nil) ⇒ Object
2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 |
# File 'lib/numru/ggraph.rb', line 2018 def line(gphys, newframe=true, =nil) gropn_1_if_not_yet if newframe!=true && newframe!=false raise ArgumentError, "2nd arg (newframe) must be true or false" end opts = @@line_options.interpret() x, y, closer, gp, window = data_prep_1D(gphys, opts) if newframe fig(x, y, {'window'=>window}) axes_or_map_and_ttl(gp, opts, x, y) end if opts['label'] lcharbk = DCL.sgpget('lchar') DCL.sgpset('lchar',true) DCL.sgsplc(opts['label']) end DCL.uulinz(x.val, y.val, opts['type'], opts['index']) DCL.sgpset('lchar',lcharbk) if opts['label'] legend = opts['legend'] if legend legend = gp.name if legend==true DCLExt::legend(legend,opts['type'],opts['index'],true, opts['legend_size'],opts['legend_vx'],opts['legend_dx'], opts['legend_vy'],newframe) end closer.call if closer nil end |
.map(options = nil) ⇒ Object
1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 |
# File 'lib/numru/ggraph.rb', line 1776 def map(=nil) if @@next_map = ( ? @@next_map.update() : @@next_map ) @@next_map = nil end opts = @@map.interpret() DCL.umplim if opts['lim'] DCL.umpset('dgridmj',opts['dgridmj']) if opts['dgridmj'] DCL.umpset('dgridmn',opts['dgridmn']) if opts['dgridmn'] DCL.umpgrd if opts['grid'] if opts['vpt_boundary'] if opts['vpt_boundary'].is_a?(Integer) idx = opts['vpt_boundary'] else idx = 1 end DCL.slpvpr( idx ) end if opts['wwd_boundary'] if opts['wwd_boundary'].is_a?(Integer) idx = opts['wwd_boundary'] else idx = 1 end DCL.slpwwr( idx ) end DCL.umpmap('coast_world') if opts['coast_world'] DCL.umpmap('coast_japan') if opts['coast_japan'] if opts['fill'] DCL.umfmap('coast_world') if opts['coast_world'] DCL.umfmap('coast_japan') if opts['coast_japan'] end DCL.umpmap('border_world') if opts['border_world'] DCL.umpmap('plate_world') if opts['plate_world'] DCL.umpmap('state_usa') if opts['state_usa'] DCL.umpmap('pref_japan') if opts['pref_japan'] nil end |
.map_trn?(fig_yet_to_be_called = false) ⇒ Boolean
1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 |
# File 'lib/numru/ggraph.rb', line 1210 def map_trn?( fig_yet_to_be_called=false ) if fig_yet_to_be_called itr = ( @@next_fig && @@next_fig['itr'] ) || @@fig['itr'] else itr = DCL.sgqtrn end case itr when 1..9,51..99 false else true end end |
.margin_info(program = nil, data_source = nil, char_height = nil, date = nil, xl = 0.0, xr = 0.0, yb = nil, yt = 0.0) ⇒ Object
1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 |
# File 'lib/numru/ggraph.rb', line 1106 def margin_info(program=nil, data_source=nil, char_height=nil, date=nil, xl=0.0, xr=0.0, yb=nil, yt=0.0) program = File.($0) if !program if date program = __shorten_path(program,77) + ' ' + Date.today.to_s else program = __shorten_path(program,99) if date.nil? program = program + ' ' + Date.today.to_s if program.length < 77 end end if !data_source data_source = Dir.pwd data_source = '' if data_source == program.sub(/\/[^\/]+$/,'') end data_source = __shorten_path(data_source,99) sz = 1.0/( program.length + data_source.length ) char_height = [0.008, sz].min if !char_height yb = 2.0 * char_height if !yb DCL.slmgn(xl, xr, yb, yt) DCL.slsttl(program, 'b', -1.0, -1.0, char_height, 1) DCL.slsttl(data_source, 'b', 1.0, -1.0, char_height, 2) nil end |
.mark(gphys, newframe = true, options = nil) ⇒ Object
2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 |
# File 'lib/numru/ggraph.rb', line 2110 def mark(gphys, newframe=true, =nil) gropn_1_if_not_yet if newframe!=true && newframe!=false raise ArgumentError, "2nd arg (newframe) must be true or false" end opts = @@mark_options.interpret() x, y, closer, gp, window = data_prep_1D(gphys, opts) if newframe fig(x, y, {'window'=>window}) axes_or_map_and_ttl(gp, opts, x, y) end DCL.uumrkz(x.val, y.val, opts['type'], opts['index'], opts['size']) legend = opts['legend'] if legend legend = gp.name if legend==true DCLExt::legend(legend,opts['type'],opts['index'],false, opts['legend_size'],opts['legend_vx'],nil, opts['legend_vy'],newframe,opts['size']) end closer.call if closer nil end |
.name_selector(gp, limit) ⇒ Object
2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 |
# File 'lib/numru/ggraph.rb', line 2398 def name_selector(gp, limit) if gp.long_name && gp.name if gp.long_name.length > limit && gp.long_name.length > gp.name.length && !gp.name.empty? gp.name else gp.long_name end else gp.long_name || gp.name end end |
.next_axes(options) ⇒ Object
1537 1538 1539 1540 1541 1542 1543 1544 |
# File 'lib/numru/ggraph.rb', line 1537 def next_axes() if .is_a?(Hash) @@next_axes = else raise TypeError,"Hash expected" end nil end |
.next_color_scatter(options) ⇒ Object
2791 2792 2793 2794 2795 2796 2797 2798 |
# File 'lib/numru/ggraph.rb', line 2791 def next_color_scatter() if .is_a?(Hash) @@next_color_scatter = else raise TypeError,"Hash expected" end nil end |
.next_contour(options) ⇒ Object
2379 2380 2381 2382 2383 2384 2385 2386 |
# File 'lib/numru/ggraph.rb', line 2379 def next_contour() if .is_a?(Hash) @@next_contour = else raise TypeError,"Hash expected" end nil end |
.next_fig(options) ⇒ Object
1201 1202 1203 1204 1205 1206 1207 1208 |
# File 'lib/numru/ggraph.rb', line 1201 def next_fig() if .is_a?(Hash) @@next_fig = else raise TypeError,"Hash expected" end nil end |
.next_linear_contour_options(options) ⇒ Object
2149 2150 2151 2152 2153 2154 2155 2156 |
# File 'lib/numru/ggraph.rb', line 2149 def () if .is_a?(Hash) @@next_linear_contour_options = else raise TypeError,"Hash expected" end nil end |
.next_linear_tone_options(options) ⇒ Object
2536 2537 2538 2539 2540 2541 2542 2543 |
# File 'lib/numru/ggraph.rb', line 2536 def () if .is_a?(Hash) @@next_linear_tone_options = else raise TypeError,"Hash expected" end nil end |
.next_map(options) ⇒ Object
1767 1768 1769 1770 1771 1772 1773 1774 |
# File 'lib/numru/ggraph.rb', line 1767 def next_map() if .is_a?(Hash) @@next_map = else raise TypeError,"Hash expected" end nil end |
.next_regression_line(options) ⇒ Object
3040 3041 3042 3043 3044 3045 3046 3047 |
# File 'lib/numru/ggraph.rb', line 3040 def next_regression_line() if .is_a?(Hash) @@next_regression_line = else raise TypeError,"Hash expected" end nil end |
.next_scatter(options) ⇒ Object
2713 2714 2715 2716 2717 2718 2719 2720 |
# File 'lib/numru/ggraph.rb', line 2713 def next_scatter() if .is_a?(Hash) @@next_scatter = else raise TypeError,"Hash expected" end nil end |
.next_tone(options) ⇒ Object
2589 2590 2591 2592 2593 2594 2595 2596 |
# File 'lib/numru/ggraph.rb', line 2589 def next_tone() if .is_a?(Hash) @@next_tone = else raise TypeError,"Hash expected" end nil end |
.next_unit_vect_options(options) ⇒ Object
2944 2945 2946 |
# File 'lib/numru/ggraph.rb', line 2944 def () DCLExt.() end |
.polar_coordinate_boundaries(xax = nil, yax = nil) ⇒ Object
1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 |
# File 'lib/numru/ggraph.rb', line 1725 def polar_coordinate_boundaries(xax=nil,yax=nil) slln=DCL.sgpget('LLNINT') ; slgc=DCL.sgpget('LGCINT') DCL.sgpset('LLNINT',true) ; DCL.sgpset('LGCINT',true) xmin=xax.min ; xmax=xax.max ; ymin=yax.min ; ymax=yax.max azimuth_len = ymax-ymin azimuth_len = azimuth_len.val if azimuth_len.is_a?(UNumeric) unless( (azimuth_len - 360.0).abs < 1e-2 ) # not a full circle DCL.sgplzu([xmin,xmax],[ymin,ymin],1,5) DCL.sgplzu([xmin,xmax],[ymax,ymax],1,5) end DCL.sgplzu([xmin,xmin],[ymin,ymax],1,5) DCL.sgplzu([xmax,xmax],[ymin,ymax],1,5) DCL.sgpset('LLNINT',slln) ; DCL.sgpset('LGCINT',slgc) nil end |
.profile(gphys, newframe = true, options = nil) ⇒ Object
———————————————————- Added at 080207 –
2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 |
# File 'lib/numru/ggraph.rb', line 2049 def profile(gphys, newframe=true, =nil) gropn_1_if_not_yet if newframe!=true && newframe!=false raise ArgumentError, "2nd arg (newframe) must be true or false" end opts = @@line_options.interpret() check_max = opts['max'] opts['max'] = nil opts['exchange']= true x, y, closer, gp, window = data_prep_1D(gphys, opts) if newframe fig(x, y, {'window'=>window}) axes_or_map_and_ttl(gp, opts, x, y) end if opts['label'] lcharbk = DCL.sgpget('lchar') DCL.sgpset('lchar',true) DCL.sgsplc(opts['label']) end if opts['index'] iat=opts['index'] end if check_max if x.val.max > check_max iat=21 end end DCL.uulinz(x.val, y.val, opts['type'], iat ) DCL.sgpset('lchar',lcharbk) if opts['label'] legend = opts['legend'] if legend legend = gp.name if legend==true DCLExt::legend(legend,opts['type'],opts['index'],true, opts['legend_size'],opts['legend_vx'],opts['legend_dx'], opts['legend_vy'],newframe) end nil end |
.regression_line(x, y, options = nil) ⇒ Object
3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 |
# File 'lib/numru/ggraph.rb', line 3049 def regression_line(x,y, =nil) if @@next_regression_line = ( ? @@next_regression_line.update() : @@next_regression_line ) @@next_regression_line = nil end opts = @@regression_line_options.interpret() x = x.val if x.respond_to?(:val) # GPhys or VArray like y = y.val if y.respond_to?(:val) # GPhys or VArray like x = NArray.to_na(x) if x.is_a?(Array) y = NArray.to_na(y) if y.is_a?(Array) xs = x # scaled x: x or log(x) (see below) ys = y # scaled y: y or log(y) (see below) xlog = ylog = false # can be overwritten below itr = current_itr() case itr when 1 # nothing to do when 2 ys = NMMath.log(ys) ylog = true when 3 xs = NMMath.log(xs) xlog = true when 4 xs = NMMath.log(xs) ys = NMMath.log(ys) xlog = ylog = true else raise "Drawing a linear regression line is limited to itr = 1~4 (linear or log plots), while the current itr is #{itr}. (itr is a coordinate transformation parameter set by fig (or set_fig or next_fig).)" end y_given_x = !opts['x_given_y'] xr = NArray.sfloat(2) # --> x ends of the regression line yr = NArray.sfloat(2) # --> y ends of the regression line if y_given_x a,b = linear_regression(xs,ys) if opts["limit"] xr[0] = x.min xr[1] = x.max else xr[0],xr[1], = DCL.sgqwnd end xrs = !xlog ? xr : NMath::log(xr) yrs = a + b*xrs yr = !ylog ? yrs : NMath::exp(yrs) else a,b = linear_regression(ys,xs) if opts["limit"] yr[0] = y.min yr[1] = y.max else dum0,dum1, yr[0], yr[1] = DCL.sgqwnd end yrs = !ylog ? yr : Math::log(yr) xrs = a + b*yrs xr = !xlog ? xrs : Math::exp(xrs) end before = DCLExt.sg_set_params({'lclip'=>opts['clip']}) DCL.sgplzu(xr,yr,opts["type"],opts["index"]) DCLExt.sg_set_params(before) ai = opts['annot_intercept'] || opts['annot_intercept'].nil? && itr==1 as = opts['annot_slope'] || opts['annot_slope'].nil? && (itr==1 or itr==4) if as && ai if y_given_x annot = ["regr y=a+bx:", " a=#{DCL.chval('A',a)}", " b=#{DCL.chval('A',b)}"] else annot = ["regr x=a+by:", " a=#{DCL.chval('A',a)}", " b=#{DCL.chval('A',b)}"] end annotate(annot, @@nannot) elsif as if y_given_x annot = ["slope: #{DCL.chval('A',b)}"] else annot = ["regress x given y:", " x(y) slope: #{DCL.chval('A',b)}"] end annotate(annot, @@nannot) end [a,b] end |
.scatter(fx, fy, newframe = true, options = nil) ⇒ Object
2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 |
# File 'lib/numru/ggraph.rb', line 2722 def scatter(fx, fy, newframe=true, =nil) gropn_1_if_not_yet if newframe!=true && newframe!=false raise ArgumentError, "3rd arg (newframe) must be true or false" end if @@next_scatter = ( ? @@next_scatter.update() : @@next_scatter ) @@next_scatter = nil end opts = @@scatter_options.interpret() # interpret cut, slice, etc gpx, closerx = data_prep_multidim(fx, opts) gpy, closery = data_prep_multidim(fy, opts) # flatten gphys data ----- fakeaxis = Axis.new.set_pos(VArray.new(NArray.int(gpx.length).indgen!, {"long_name"=>"fake", "units"=>""}, "fake")) fakegrid = Grid.new(fakeaxis) gpx, gpy = [gpx, gpy].collect{|gp| na = gp.val.reshape!(gp.length) attr = gp.data.attr_copy newgp = GPhys.new(fakegrid,VArray.new(na,attr,gp.name)) newgp.set_lost_axes(gp.lost_axes) newgp } # ------------------------ x = gpx.data y = gpy.data if newframe fig(x, y) axes_or_map_and_ttl(gpx, opts, x, y, gpy) end DCL.uumrkz(x.val, y.val, opts['type'], opts['index'], opts['size']) if opts['correlation'] return _scatter_display_corr(gpx, gpy, opts) else return nil end # close if necessary ----- closerx.call if closerx closery.call if closery nil end |
.set_axes(options) ⇒ Object
1532 1533 1534 |
# File 'lib/numru/ggraph.rb', line 1532 def set_axes() @@axes.set() end |
.set_color_scatter(options) ⇒ Object
@@color_scatter_options.delete(“transpose”) # delete is yet to be supported @@color_scatter_options.delete(“exchange”) # (2010-01)
2787 2788 2789 |
# File 'lib/numru/ggraph.rb', line 2787 def set_color_scatter() @@color_scatter_options.set() end |
.set_contour(options) ⇒ Object
2374 2375 2376 |
# File 'lib/numru/ggraph.rb', line 2374 def set_contour() @@contour_options.set() end |
.set_contour_levels(options) ⇒ Object
2356 2357 2358 2359 |
# File 'lib/numru/ggraph.rb', line 2356 def set_contour_levels() opts = @@contour_levels.interpret() _set_contour_levels_(opts) end |
.set_fig(options) ⇒ Object
1196 1197 1198 |
# File 'lib/numru/ggraph.rb', line 1196 def set_fig() @@fig.set() end |
.set_linear_contour_options(options) ⇒ Object
2145 2146 2147 |
# File 'lib/numru/ggraph.rb', line 2145 def () @@linear_contour_options.set() end |
.set_linear_tone_options(options) ⇒ Object
2532 2533 2534 |
# File 'lib/numru/ggraph.rb', line 2532 def () @@linear_tone_options.set() end |
.set_map(options) ⇒ Object
1762 1763 1764 |
# File 'lib/numru/ggraph.rb', line 1762 def set_map() @@map.set() end |
.set_regression_line(options) ⇒ Object
3036 3037 3038 |
# File 'lib/numru/ggraph.rb', line 3036 def set_regression_line() @@regression_line_options.set() end |
.set_scatter(options) ⇒ Object
@@scatter_options.delete(“transpose”) # delete is yet to be supported @@scatter_options.delete(“exchange”) # (2010-01)
2709 2710 2711 |
# File 'lib/numru/ggraph.rb', line 2709 def set_scatter() @@scatter_options.set() end |
.set_tone(options) ⇒ Object
2584 2585 2586 |
# File 'lib/numru/ggraph.rb', line 2584 def set_tone() @@tone_options.set() end |
.set_tone_levels(options) ⇒ Object
2552 2553 2554 2555 |
# File 'lib/numru/ggraph.rb', line 2552 def set_tone_levels() opts = @@tone_levels.interpret() _set_tone_levels_(opts) end |
.set_unit_vect_options(options) ⇒ Object
< vector >
2941 2942 2943 |
# File 'lib/numru/ggraph.rb', line 2941 def () DCLExt.() end |
.sim_trn? ⇒ Boolean
1237 1238 1239 1240 1241 1242 1243 1244 1245 |
# File 'lib/numru/ggraph.rb', line 1237 def sim_trn? itr = DCL.sgqtrn case itr when 5..7 true else false end end |
.timeplot(gphys, newframe = true, options = nil) ⇒ Object
timeplot 0802011 ######
2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 |
# File 'lib/numru/ggraph.rb', line 2159 def timeplot(gphys, newframe=true, =nil) gropn_1_if_not_yet if newframe!=true && newframe!=false raise ArgumentError, "2nd arg (newframe) must be true or false" end if ! defined?(@@timeplot_options) @@timeplot_options = Misc::KeywordOptAutoHelp.new( ['size', 0.01, 'marks size'], ['lamin', nil, 'minimam latitude value'], ['lamax', nil, 'maximam latitude value'], ['lomin', nil, 'minimam longitude value'], ['lomax', nil, 'maximam longitude value'], ['ltone', true, 'Same as udpack parameter ltone'], ['tonf', false, 'Use DCL.uetonf instead of DCL.uetone'], ['tonb', false, 'Use DCL.uetonb instead of DCL.uetone'], ['tonc', false, 'Use DCL.uetonc instead of DCL.uetone'], ['clr_min', 13, 'if an integer (in 10..99) is specified, used as the color number for the minimum data values. (the same can be done by setting the uepack parameter "icolor1")'], ['clr_max', 99, 'if an integer (in 10..99) is specified, used as the color number for the maximum data values. (the same can be done by setting the uepack parameter "icolor2")'], ['keep', false, 'Use the tone levels and patterns used previously'], @@line_options ) end opts = @@timeplot_options.interpret() opts['type'] = 2 if opts['clr_min'] icolor1_bak = DCL.uepget('icolor1') DCL.uepset('icolor1', opts['clr_min']) end if opts['clr_max'] icolor2_bak = DCL.uepget('icolor2') DCL.uepset('icolor2', opts['clr_max']) end cmn=opts['clr_min']+1 cmx=opts['clr_max']-1 if opts['lamin'] && opts['lamax'] latmn= opts['lamin'] latmx= opts['lamax'] if latmn > latmx raise ArgumentError,"Specific Settings parameter is invalid.(1)" end elsif opts['lamin'] || opts['lamax'] raise ArgumentError,"Specific Settings parameter is invalid.(2)" else latmn=false latmx=false end if opts['lomin'] && opts['lomax'] lonmn= opts['lomin'] lonmx= opts['lomax'] if lonmn > lonmx raise ArgumentError,"Specific Settings parameter is invalid.(3)" end elsif opts['lomin'] || opts['lomax'] raise ArgumentError,"Specific Settings parameter is invalid.(4)" else lonmn=false lonmx=false end gp = gphys.first2D gp = gp.transpose(1,0) if opts['transpose'] || opts['exchange'] #-- x = gp.coord(0) y = gp.coord(1) zv = gp.data.val idim=0 case x.name.downcase when "time" idim=0 else case y.name.downcase when "time" idim=1 end end latp=VArray.new lonp=VArray.new lat_flag = false lon_flag = false if gp.has_assoccoord? gp.assoc_coords.coordnames.each do |auxname| if auxname == "Latitude" latp=gp.coord(auxname) lat_flag = true elsif auxname == "Longitude" lonp=gp.coord(auxname) lon_flag = true end end end #------ for color bar DCL.uwsgxa(x.val) DCL.uwsgya(y.val) if !opts['keep'] or DCL.ueqntl==0 if !opts['levels'] && opts['log'] levels, = DCLExt.quasi_log_levels_z(gp.data.val, opts['nlev'], opts['max'], opts['min'], opts['log_cycle']) rmiss = DCL.glrget('rmiss') levels.unshift(rmiss) if !opts['max'] && levels[0]<0 levels.push(rmiss) if !opts['max'] && levels[-1]>0 opts['levels'] = levels end if opts['levels'] backup = @@set_tone_levels _set_tone_levels_(opts) @@set_tone_levels = backup elsif opts['patterns'] raise "option 'patterns' is not effective unless 'levels' is specified" elsif !@@set_tone_levels && opts['ltone'] DCL.ueitlv DCLExt.ue_set_linear_levs(gp.data.val, opts) else DCL.ueitlv if !@@set_tone_levels end end #------- if newframe fig(x, y) axes_or_map_and_ttl(gp, opts, x, y) end zmn=gp.data.val.min zmx=gp.data.val.max zmax = ((cmx-cmn)+cmn).round*10+3 zmin = cmn.round*10+3 #------- xx=x.val.to_a yy=y.val.to_a plat=latp.val.to_a if lat_flag plon=lonp.val.to_a if lon_flag zz=zv k=0 for i in 0..yy.length-1 for j in 0..xx.length-1 tflg=0 idim == 0 ? h=j : h=i tflg=1 if latmn && latmx && ( plat[h] < latmn || plat[h] > latmx ) tflg=2 if lonmn && lonmx && ( plon[h] < lonmn || plon[h] > lonmx ) if tflg == 0 xx1=NArray.to_na(Array.new(1,xx[j]*1.0)) yy1=NArray.to_na(Array.new(1,yy[i]*1.0)) z = zz[j,i] if zz[j,i].is_a?(Numeric) z = zmn if zz[j,i].is_a?(Array) iz=((z-zmn)/(zmx-zmn)*(cmx-cmn)+cmn).round*10+3 DCL.uumrkz(xx1, yy1, 230, iz, 0.005 ) end k+=1 end end legend = opts['legend'] if legend legend = gp.name if legend==true DCLExt::legend(legend,opts['type'],opts['index'],false, opts['legend_size'],opts['legend_vx'],nil, opts['legend_vy'],newframe,opts['size']) end DCL.uepset('icolor1', icolor1_bak) if opts['clr_min'] DCL.uepset('icolor2', icolor2_bak) if opts['clr_max'] #----------------------------- color bar unit -- 08.01.31 ---- vx1, vx2, vy1, vy2 = DCL.sgqvpt x1=vx2+0.02 y1=vy1-0.02 if "#{gp.data.units}".length >0 DCL.sgtxzv(x1, y1, "#{gp.data.units}", 0.02, 0, -1 ,11 ) end #----------------------------------------- nil end |
.title(string) ⇒ Object
1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 |
# File 'lib/numru/ggraph.rb', line 1137 def title(string) if string if map_trn? || itr_is?(5) v = DCL::sgqvpt txhgt = DCL.uzpget('rsizec2') # rsizec2: larger text vx = (v[0]+v[1])/2 vy = v[3] + (0.5 + DCL.uzpget('pad1')) * txhgt DCL::sgtxzr(vx , vy, string, txhgt, 0, 0, 3) else DCL.uxmttl('t',string,0.0) end end nil end |
.tone(gphys, newframe = true, options = nil) ⇒ Object
2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 |
# File 'lib/numru/ggraph.rb', line 2616 def tone(gphys, newframe=true, =nil) gropn_1_if_not_yet if newframe!=true && newframe!=false raise ArgumentError, "2nd arg (newframe) must be true or false" end if @@next_tone = ( ? @@next_tone.update() : @@next_tone ) @@next_tone = nil end if @@next_linear_tone_options = ( ? @@next_linear_tone_options.update() : @@next_linear_tone_options ) @@next_linear_tone_options = nil end opts = @@tone_options.interpret() xax, yax, closer, gp = data_prep_2D([gphys], newframe, opts) if opts['clr_min'] icolor1_bak = DCL.uepget('icolor1') DCL.uepset('icolor1', opts['clr_min']) end if opts['clr_max'] icolor2_bak = DCL.uepget('icolor2') DCL.uepset('icolor2', opts['clr_max']) end if newframe fig(xax, yax) end DCL.uwsgxa(xax.val) if xax.rank==1 DCL.uwsgya(yax.val) if yax.rank==1 if !opts['keep'] or DCL.ueqntl==0 if !opts['levels'] && opts['log'] levels, = DCLExt.quasi_log_levels_z(gp.data.val, opts['nlev'], opts['max'], opts['min'], opts['log_cycle']) rmiss = DCL.glrget('rmiss') levels.unshift(rmiss) if !opts['max'] && levels[0]<0 levels.push(rmiss) if !opts['max'] && levels[-1]>0 opts['levels'] = levels end if opts['levels'] backup = @@set_tone_levels _set_tone_levels_(opts) @@set_tone_levels = backup elsif opts['patterns'] raise "option 'patterns' is not effective unless 'levels' is specified" elsif !@@set_tone_levels && opts['ltone'] DCL.ueitlv DCLExt.ue_set_linear_levs(gp.data.val, opts) else DCL.ueitlv if !@@set_tone_levels end end val = gp.data.val if ( opts['ltone'] && ( opts['tonf'] || opts['auto'] && val.length > TONE_TONF_THRES ) ) DCL.uetonf(val) elsif opts['tonb'] && opts['ltone'] DCL.uetonb(val) elsif opts['tonc'] && opts['ltone'] DCL.uetonc(val) else DCL.uetone(val) end if newframe axes_or_map_and_ttl(gp,opts, xax, yax) end DCL.uepset('icolor1', icolor1_bak) if opts['clr_min'] DCL.uepset('icolor2', icolor2_bak) if opts['clr_max'] if opts['color_bar'] "log"=>opts['log'] end closer.call if closer nil end |
.tone_and_contour(gphys, newframe = true, options = nil) ⇒ Object
2339 2340 2341 2342 2343 2344 |
# File 'lib/numru/ggraph.rb', line 2339 def tone_and_contour(gphys, newframe=true, =nil) ? copt=@@contour_options.select_existent() : copt=nil ? topt=@@tone_options.select_existent() : topt=nil tone(gphys, newframe, topt) contour(gphys, false, copt) end |
.vector(fx, fy, newframe = true, options = nil) ⇒ Object
2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 |
# File 'lib/numru/ggraph.rb', line 2971 def vector(fx, fy, newframe=true, =nil) gropn_1_if_not_yet if newframe!=true && newframe!=false raise ArgumentError, "2nd arg (newframe) must be true or false" end opts = @@vector_options.interpret() xax, yax, closer, fx, fy = data_prep_2D([fx,fy], newframe, opts) if newframe fig(xax, yax) end if newframe axes_or_map_and_ttl(fx, opts, xax, yax, fy) end itr = current_itr xaxv = xax.val yaxv = yax.val DCL.uwsgxa(xaxv) DCL.uwsgya(yaxv) if opts['flow_itr5'] if itr_is?(5) DCLExt.flow_itr5( fx, fy, opts['factor'], opts['unit_vect'] ) else raise "flow_itr5 option should use with itr=5." end elsif opts['flow_vect_anyproj'] || ( opts['flow_vect_anyproj'].nil? && opts['flow_vect'] && itr >=2 ) @@vfratio, flenmax = DCLExt.flow_vect_anyproj(fx.val, fy.val, xaxv, yaxv, opts['factor'], 1, 1, opts['distvect_map'], (opts['keep'] && @@vfratio), opts['polar_thinning'] ) if opts['unit_vect'] len_unit = opts['len_unit'] || flenmax DCLExt.unit_vect_single(@@vfratio, len_unit) end elsif opts['flow_vect'] uninfo = DCLExt.flow_vect(fx.val, fy.val, opts['factor'], 1, 1, (opts['keep']&& @@vxfxratio), (opts['keep'] && @@vyfyratio) ) @@vxfxratio, @@vyfyratio, = uninfo if opts['unit_vect'] unless opts['max_unit_vect'] uninfo[2] = opts['ux_unit'] # nil or a Numeric to specify the len uninfo[3] = opts['uy_unit'] # nil or a Numeric to specify the len end DCLExt.unit_vect(*uninfo) end else before=DCLExt.ug_set_params({'lunit'=>true}) if opts['unit_vect'] DCL.ugvect(fx.val, fy.val) DCLExt.ug_set_params(before) if opts['unit_vect'] end closer.call if closer nil end |
.vector_on_merdional_section(fx, fy, newframe = true, options = nil) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/numru/ggraph_on_merdional_section.rb', line 72 def vector_on_merdional_section(fx, fy, newframe=true, =nil) if ! defined?(@@vector_on_merdional_section_options) @@vector_on_merdional_section_options = Misc::KeywordOptAutoHelp.new( ['newfig', true, 'if false, do not cleared before figure setting.'], ['title', nil, 'Title of the figure(if nil, internally determined)'], ['annotate', true, 'if false, do not put texts on the right margin even when newframe==true'], ['transpose', false, 'if true, exchange x and y axes'], ['flow_vect', true, 'If true, use DCLExt::flow_vect to draw vectors; otherwise, DCL::ugvect is used.'], ['xintv', 1, '(Effective only if flow_vect) interval of data sampling in x'], ['yintv', 1, '(Effective only if flow_vect) interval of data sampling in y'], ['factor', 1.0, '(Effective only if flow_vect) scaling factor to strech/reduce the arrow lengths'], ['unit_vect', false, 'Show the unit vector'], ['use_before_scale', false, '(Effective only unless flow_vect) If true, use scale factor before vector.'], ['max_unit_vect', false, '(Effective only if flow_vect && unit_vect) If true, use the maximum arrows to scale the unit vector; otherwise, normalize in V coordinate.'] ) end opts = @@vector_on_merdional_section_options.interpret() fx = fx.first2D.copy fy = fy.first2D.copy sh = fx.shape if sh != fy.shape raise ArgumentError, "shapes of fx and fy do not agree with each other" end fx = fx.transpose(1,0) if opts['transpose'] fy = fy.transpose(1,0) if opts['transpose'] if ((xi=opts['xintv']) >= 2) idx = NArray.int(sh[0]/xi).indgen!*xi # [0,xi,2*xi,..] fx = fx[idx, true] fy = fy[idx, true] end if ((yi=opts['xintv']) >= 2) idx = NArray.int(sh[1]/yi).indgen!*yi # [0,yi,2*yi,..] fx = fx[true, idx] fy = fy[true, idx] end xax = fx.coord(0) yax = fy.coord(1) aphi_ax, z_ax, was_proportional_to_p = \ GPhys::EP_Flux::preparate_for_vector_on_merdional_section(xax, yax) if was_proportional_to_p itr = 2 else itr = 1 end if newframe nextfig = @@next_fig.dup if ( @@next_fig != nil ) # backup next_fig fig(xax, yax, {'itr'=>itr}) axes(xax, yax) if opts['title'] ttl = opts['title'] else fxnm = fx.data.get_att('long_name') || fx.name fynm = fy.data.get_att('long_name') || fy.name ttl = '('+fxnm+','+fynm+')' end title( ttl ) annotate(fx.lost_axes) if opts['annotate'] @@next_fig = nextfig if ( @@next_fig != nil ) end fig(aphi_ax, z_ax, {'new_frame'=>false, 'itr'=>1, 'yreverse'=>false}) \ if (opts['newfig']) DCL.uwsgxa(aphi_ax.val) DCL.uwsgya(z_ax.val) if opts['flow_vect'] if opts['use_before_scale'] vxfxratio = @@uninfo[0]; vxfyratio = @@uninfo[1] before=DCLExt.ug_set_params( {'LNRMAL'=>false, 'LMSG'=>false, 'XFACT1'=>1.0, 'YFACT1'=>1.0} ) DCL.ugvect(vxfxratio*fx.val, vxfyratio*fy.val) DCLExt.ug_set_params(before) if opts['unit_vect'] if opts['max_unit_vect'] DCLExt.unit_vect(*@@uninfo) else DCLExt.unit_vect(*@@uninfo[0..1]) end end else @@uninfo = DCLExt.flow_vect(fx.val, fy.val, opts['factor'] ) if opts['unit_vect'] if opts['max_unit_vect'] DCLExt.unit_vect(*@@uninfo) else DCLExt.unit_vect(*@@uninfo[0..1]) end end end else if opts['use_before_scale'] vxfxratio = @@uninfo[0]; vxfyratio = @@uninfo[1] before1=DCLExt.ug_set_params({'lunit'=>true}) if opts['unit_vect'] before2=DCLExt.ug_set_params( {'LNRMAL'=>false, 'LMSG'=>false, 'XFACT1'=>1.0, 'YFACT1'=>1.0} ) DCL.ugvect(vxfxratio*fx.val, vxfyratio*fy.val) DCLExt.ug_set_params(before1) if opts['unit_vect'] DCLExt.ug_set_params(before2) else before=DCLExt.ug_set_params({'lunit'=>true}) if opts['unit_vect'] DCL.ugvect(fx.val, fy.val) DCLExt.ug_set_params(before) if opts['unit_vect'] end nil end end |